Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more
Merge main into pr-152 and preserve spinner layout fix
altic-dev6e664ddce92d
diff --git a/.gitignore b/.gitignoreindex 564b05c2..2cb9b48a 100644--- a/.gitignore+++ b/.gitignore@@ -215,3 +215,4 @@ scripts/**.profrawicon_work/sample/+.codexdiff --git a/Fluid.xcodeproj/project.pbxproj b/Fluid.xcodeproj/project.pbxprojindex 3029da4d..8a85af7f 100644--- a/Fluid.xcodeproj/project.pbxproj+++ b/Fluid.xcodeproj/project.pbxproj@@ -17,8 +17,6 @@7CDB0A2F2F3C4D5600FB7CAD /* dictation_fixture.wav in Resources */ = {isa = PBXBuildFile; fileRef = 7CDB0A2B2F3C4D5600FB7CAD /* dictation_fixture.wav */; };7CDB0A302F3C4D5600FB7CAD /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7CDB0A2C2F3C4D5600FB7CAD /* XCTest.framework */; };7CE006BD2E80EBE600DDCCD6 /* AppUpdater in Frameworks */ = {isa = PBXBuildFile; productRef = 7CE006BC2E80EBE600DDCCD6 /* AppUpdater */; };- 7CF7A1A530AA000100F00001 /* FV_start.m4a in Resources */ = {isa = PBXBuildFile; fileRef = 7CF7A1A730AA000100F00001 /* FV_start.m4a */; };- 7CF7A1A630AA000100F00001 /* FV_start_2.m4a in Resources */ = {isa = PBXBuildFile; fileRef = 7CF7A1A830AA000100F00001 /* FV_start_2.m4a */; };/* End PBXBuildFile section *//* Begin PBXContainerItemProxy section */@@ -38,8 +36,6 @@7CDB0A2A2F3C4D5600FB7CAD /* AudioFixtureLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioFixtureLoader.swift; sourceTree = "<group>"; };7CDB0A2B2F3C4D5600FB7CAD /* dictation_fixture.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = dictation_fixture.wav; sourceTree = "<group>"; };7CDB0A2C2F3C4D5600FB7CAD /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };- 7CF7A1A730AA000100F00001 /* FV_start.m4a */ = {isa = PBXFileReference; lastKnownFileType = audio.m4a; path = Sources/Fluid/Resources/FV_start.m4a; sourceTree = "<group>"; };- 7CF7A1A830AA000100F00001 /* FV_start_2.m4a */ = {isa = PBXFileReference; lastKnownFileType = audio.m4a; path = Sources/Fluid/Resources/FV_start_2.m4a; sourceTree = "<group>"; };/* End PBXFileReference section *//* Begin PBXFileSystemSynchronizedRootGroup section */@@ -235,8 +231,6 @@isa = PBXResourcesBuildPhase;buildActionMask = 2147483647;files = (- 7CF7A1A530AA000100F00001 /* FV_start.m4a in Resources */,- 7CF7A1A630AA000100F00001 /* FV_start_2.m4a in Resources */,);runOnlyForDeploymentPostprocessing = 0;};diff --git a/Fluid.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Fluid.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolvedindex 38f98307..58514681 100644--- a/Fluid.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved+++ b/Fluid.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved@@ -1,5 +1,5 @@{- "originHash" : "fa2e9405853259eb2f24fbfe3ef89e5e3e19325301af0756884cfdbda6ac819c",+ "originHash" : "f521508b82d28f1791de94693be786cfcf7bd2e0f4ca46267c31e159f5bf10f3","pins" : [{"identity" : "appupdater",@@ -33,8 +33,8 @@"kind" : "remoteSourceControl","location" : "https://github.com/FluidInference/FluidAudio.git","state" : {- "revision" : "d540f0092da772e19715dfdfbb606ee8fc3b6023",- "version" : "0.7.10"+ "revision" : "9fcdf2f32cd879f494826db0e4945e8cf1187a62",+ "version" : "0.12.0"}},{@@ -73,6 +73,24 @@"version" : "6.22.1"}},+ {+ "identity" : "swift-collections",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/apple/swift-collections.git",+ "state" : {+ "revision" : "7b847a3b7008b2dc2f47ca3110d8c782fb2e5c7e",+ "version" : "1.3.0"+ }+ },+ {+ "identity" : "swift-jinja",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/huggingface/swift-jinja.git",+ "state" : {+ "revision" : "d81197f35f41445bc10e94600795e68c6f5e94b0",+ "version" : "2.3.1"+ }+ },{"identity" : "swift-log","kind" : "remoteSourceControl",@@ -100,6 +118,15 @@"version" : "1.6.3"}},+ {+ "identity" : "swift-transformers",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/huggingface/swift-transformers",+ "state" : {+ "revision" : "573e5c9036c2f136b3a8a071da8e8907322403d0",+ "version" : "1.1.6"+ }+ },{"identity" : "swiftwhisper","kind" : "remoteSourceControl",diff --git a/Info.plist b/Info.plistindex 92e65827..5e5cfc6a 100644--- a/Info.plist+++ b/Info.plist@@ -13,9 +13,9 @@<key>CFBundleIdentifier</key><string>$(PRODUCT_BUNDLE_IDENTIFIER)</string><key>CFBundleVersion</key>- <string>1</string>+ <string>8</string><key>CFBundleShortVersionString</key>- <string>1.5.5</string>+ <string>1.5.9</string><key>LSMinimumSystemVersion</key><string>$(MACOSX_DEPLOYMENT_TARGET)</string><key>LSApplicationCategoryType</key>diff --git a/LICENSE b/LICENSEindex d6456956..f288702d 100644--- a/LICENSE+++ b/LICENSE@@ -1,202 +1,674 @@-- Apache License- Version 2.0, January 2004- http://www.apache.org/licenses/-- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION-- 1. Definitions.-- "License" shall mean the terms and conditions for use, reproduction,- and distribution as defined by Sections 1 through 9 of this document.-- "Licensor" shall mean the copyright owner or entity authorized by- the copyright owner that is granting the License.-- "Legal Entity" shall mean the union of the acting entity and all- other entities that control, are controlled by, or are under common- control with that entity. For the purposes of this definition,- "control" means (i) the power, direct or indirect, to cause the- direction or management of such entity, whether by contract or- otherwise, or (ii) ownership of fifty percent (50%) or more of the- outstanding shares, or (iii) beneficial ownership of such entity.-- "You" (or "Your") shall mean an individual or Legal Entity- exercising permissions granted by this License.-- "Source" form shall mean the preferred form for making modifications,- including but not limited to software source code, documentation- source, and configuration files.-- "Object" form shall mean any form resulting from mechanical- transformation or translation of a Source form, including but- not limited to compiled object code, generated documentation,- and conversions to other media types.-- "Work" shall mean the work of authorship, whether in Source or- Object form, made available under the License, as indicated by a- copyright notice that is included in or attached to the work- (an example is provided in the Appendix below).-- "Derivative Works" shall mean any work, whether in Source or Object- form, that is based on (or derived from) the Work and for which the- editorial revisions, annotations, elaborations, or other modifications- represent, as a whole, an original work of authorship. For the purposes- of this License, Derivative Works shall not include works that remain- separable from, or merely link (or bind by name) to the interfaces of,- the Work and Derivative Works thereof.-- "Contribution" shall mean any work of authorship, including- the original version of the Work and any modifications or additions- to that Work or Derivative Works thereof, that is intentionally- submitted to Licensor for inclusion in the Work by the copyright owner- or by an individual or Legal Entity authorized to submit on behalf of- the copyright owner. For the purposes of this definition, "submitted"- means any form of electronic, verbal, or written communication sent- to the Licensor or its representatives, including but not limited to- communication on electronic mailing lists, source code control systems,- and issue tracking systems that are managed by, or on behalf of, the- Licensor for the purpose of discussing and improving the Work, but- excluding communication that is conspicuously marked or otherwise- designated in writing by the copyright owner as "Not a Contribution."-- "Contributor" shall mean Licensor and any individual or Legal Entity- on behalf of whom a Contribution has been received by Licensor and- subsequently incorporated within the Work.-- 2. Grant of Copyright License. Subject to the terms and conditions of- this License, each Contributor hereby grants to You a perpetual,- worldwide, non-exclusive, no-charge, royalty-free, irrevocable- copyright license to reproduce, prepare Derivative Works of,- publicly display, publicly perform, sublicense, and distribute the- Work and such Derivative Works in Source or Object form.-- 3. Grant of Patent License. Subject to the terms and conditions of- this License, each Contributor hereby grants to You a perpetual,- worldwide, non-exclusive, no-charge, royalty-free, irrevocable- (except as stated in this section) patent license to make, have made,- use, offer to sell, sell, import, and otherwise transfer the Work,- where such license applies only to those patent claims licensable- by such Contributor that are necessarily infringed by their- Contribution(s) alone or by combination of their Contribution(s)- with the Work to which such Contribution(s) was submitted. If You- institute patent litigation against any entity (including a- cross-claim or counterclaim in a lawsuit) alleging that the Work- or a Contribution incorporated within the Work constitutes direct- or contributory patent infringement, then any patent licenses- granted to You under this License for that Work shall terminate- as of the date such litigation is filed.-- 4. Redistribution. You may reproduce and distribute copies of the- Work or Derivative Works thereof in any medium, with or without- modifications, and in Source or Object form, provided that You- meet the following conditions:-- (a) You must give any other recipients of the Work or- Derivative Works a copy of this License; and-- (b) You must cause any modified files to carry prominent notices- stating that You changed the files; and-- (c) You must retain, in the Source form of any Derivative Works- that You distribute, all copyright, patent, trademark, and- attribution notices from the Source form of the Work,- excluding those notices that do not pertain to any part of- the Derivative Works; and-- (d) If the Work includes a "NOTICE" text file as part of its- distribution, then any Derivative Works that You distribute must- include a readable copy of the attribution notices contained- within such NOTICE file, excluding those notices that do not- pertain to any part of the Derivative Works, in at least one- of the following places: within a NOTICE text file distributed- as part of the Derivative Works; within the Source form or- documentation, if provided along with the Derivative Works; or,- within a display generated by the Derivative Works, if and- wherever such third-party notices normally appear. The contents- of the NOTICE file are for informational purposes only and- do not modify the License. You may add Your own attribution- notices within Derivative Works that You distribute, alongside- or as an addendum to the NOTICE text from the Work, provided- that such additional attribution notices cannot be construed- as modifying the License.-- You may add Your own copyright statement to Your modifications and- may provide additional or different license terms and conditions- for use, reproduction, or distribution of Your modifications, or- for any such Derivative Works as a whole, provided Your use,- reproduction, and distribution of the Work otherwise complies with- the conditions stated in this License.-- 5. Submission of Contributions. Unless You explicitly state otherwise,- any Contribution intentionally submitted for inclusion in the Work- by You to the Licensor shall be under the terms and conditions of- this License, without any additional terms or conditions.- Notwithstanding the above, nothing herein shall supersede or modify- the terms of any separate license agreement you may have executed- with Licensor regarding such Contributions.-- 6. Trademarks. This License does not grant permission to use the trade- names, trademarks, service marks, or product names of the Licensor,- except as required for reasonable and customary use in describing the- origin of the Work and reproducing the content of the NOTICE file.-- 7. Disclaimer of Warranty. Unless required by applicable law or- agreed to in writing, Licensor provides the Work (and each- Contributor provides its Contributions) on an "AS IS" BASIS,- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or- implied, including, without limitation, any warranties or conditions- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A- PARTICULAR PURPOSE. You are solely responsible for determining the- appropriateness of using or redistributing the Work and assume any- risks associated with Your exercise of permissions under this License.-- 8. Limitation of Liability. In no event and under no legal theory,- whether in tort (including negligence), contract, or otherwise,- unless required by applicable law (such as deliberate and grossly- negligent acts) or agreed to in writing, shall any Contributor be- liable to You for damages, including any direct, indirect, special,- incidental, or consequential damages of any character arising as a- result of this License or out of the use or inability to use the- Work (including but not limited to damages for loss of goodwill,- work stoppage, computer failure or malfunction, or any and all- other commercial damages or losses), even if such Contributor- has been advised of the possibility of such damages.-- 9. Accepting Warranty or Additional Liability. While redistributing- the Work or Derivative Works thereof, You may choose to offer,- and charge a fee for, acceptance of support, warranty, indemnity,- or other liability obligations and/or rights consistent with this- License. However, in accepting such obligations, You may act only- on Your own behalf and on Your sole responsibility, not on behalf- of any other Contributor, and only if You agree to indemnify,- defend, and hold each Contributor harmless for any liability- incurred by, or claims asserted against, such Contributor by reason- of your accepting any such warranty or additional liability.-- END OF TERMS AND CONDITIONS-- APPENDIX: How to apply the Apache License to your work.-- To apply the Apache License to your work, attach the following- boilerplate notice, with the fields enclosed by brackets "[]"- replaced with your own identifying information. (Don't include- the brackets!) The text should be enclosed in the appropriate- comment syntax for the file format. We also recommend that a- file or class name and description of purpose be included on the- same "printed page" as the copyright notice for easier- identification within third-party archives.-- Copyright [yyyy] [name of copyright owner]-- Licensed under the Apache License, Version 2.0 (the "License");- you may not use this file except in compliance with the License.- You may obtain a copy of the License at-- http://www.apache.org/licenses/LICENSE-2.0-- Unless required by applicable law or agreed to in writing, software- distributed under the License is distributed on an "AS IS" BASIS,- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- See the License for the specific language governing permissions and- limitations under the License.+ GNU GENERAL PUBLIC LICENSE+ Version 3, 29 June 2007++ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.++ Preamble++ The GNU General Public License is a free, copyleft license for+software and other kinds of works.++ The licenses for most software and other practical works are designed+to take away your freedom to share and change the works. By contrast,+the GNU General Public License is intended to guarantee your freedom to+share and change all versions of a program--to make sure it remains free+software for all its users. We, the Free Software Foundation, use the+GNU General Public License for most of our software; it applies also to+any other work released this way by its authors. You can apply it to+your programs, too.++ When we speak of free software, we are referring to freedom, not+price. Our General Public Licenses are designed to make sure that you+have the freedom to distribute copies of free software (and charge for+them if you wish), that you receive source code or can get it if you+want it, that you can change the software or use pieces of it in new+free programs, and that you know you can do these things.++ To protect your rights, we need to prevent others from denying you+these rights or asking you to surrender the rights. Therefore, you have+certain responsibilities if you distribute copies of the software, or if+you modify it: responsibilities to respect the freedom of others.++ For example, if you distribute copies of such a program, whether+gratis or for a fee, you must pass on to the recipients the same+freedoms that you received. You must make sure that they, too, receive+or can get the source code. And you must show them these terms so they+know their rights.++ Developers that use the GNU GPL protect your rights with two steps:+(1) assert copyright on the software, and (2) offer you this License+giving you legal permission to copy, distribute and/or modify it.++ For the developers' and authors' protection, the GPL clearly explains+that there is no warranty for this free software. For both users' and+authors' sake, the GPL requires that modified versions be marked as+changed, so that their problems will not be attributed erroneously to+authors of previous versions.++ Some devices are designed to deny users access to install or run+modified versions of the software inside them, although the manufacturer+can do so. This is fundamentally incompatible with the aim of+protecting users' freedom to change the software. The systematic+pattern of such abuse occurs in the area of products for individuals to+use, which is precisely where it is most unacceptable. Therefore, we+have designed this version of the GPL to prohibit the practice for those+products. If such problems arise substantially in other domains, we+stand ready to extend this provision to those domains in future versions+of the GPL, as needed to protect the freedom of users.++ Finally, every program is threatened constantly by software patents.+States should not allow patents to restrict development and use of+software on general-purpose computers, but in those that do, we wish to+avoid the special danger that patents applied to a free program could+make it effectively proprietary. To prevent this, the GPL assures that+patents cannot be used to render the program non-free.++ The precise terms and conditions for copying, distribution and+modification follow.++ TERMS AND CONDITIONS++ 0. Definitions.++ "This License" refers to version 3 of the GNU General Public License.++ "Copyright" also means copyright-like laws that apply to other kinds of+works, such as semiconductor masks.++ "The Program" refers to any copyrightable work licensed under this+License. Each licensee is addressed as "you". "Licensees" and+"recipients" may be individuals or organizations.++ To "modify" a work means to copy from or adapt all or part of the work+in a fashion requiring copyright permission, other than the making of an+exact copy. The resulting work is called a "modified version" of the+earlier work or a work "based on" the earlier work.++ A "covered work" means either the unmodified Program or a work based+on the Program.++ To "propagate" a work means to do anything with it that, without+permission, would make you directly or secondarily liable for+infringement under applicable copyright law, except executing it on a+computer or modifying a private copy. Propagation includes copying,+distribution (with or without modification), making available to the+public, and in some countries other activities as well.++ To "convey" a work means any kind of propagation that enables other+parties to make or receive copies. Mere interaction with a user through+a computer network, with no transfer of a copy, is not conveying.++ An interactive user interface displays "Appropriate Legal Notices"+to the extent that it includes a convenient and prominently visible+feature that (1) displays an appropriate copyright notice, and (2)+tells the user that there is no warranty for the work (except to the+extent that warranties are provided), that licensees may convey the+work under this License, and how to view a copy of this License. If+the interface presents a list of user commands or options, such as a+menu, a prominent item in the list meets this criterion.++ 1. Source Code.++ The "source code" for a work means the preferred form of the work+for making modifications to it. "Object code" means any non-source+form of a work.++ A "Standard Interface" means an interface that either is an official+standard defined by a recognized standards body, or, in the case of+interfaces specified for a particular programming language, one that+is widely used among developers working in that language.++ The "System Libraries" of an executable work include anything, other+than the work as a whole, that (a) is included in the normal form of+packaging a Major Component, but which is not part of that Major+Component, and (b) serves only to enable use of the work with that+Major Component, or to implement a Standard Interface for which an+implementation is available to the public in source code form. A+"Major Component", in this context, means a major essential component+(kernel, window system, and so on) of the specific operating system+(if any) on which the executable work runs, or a compiler used to+produce the work, or an object code interpreter used to run it.++ The "Corresponding Source" for a work in object code form means all+the source code needed to generate, install, and (for an executable+work) run the object code and to modify the work, including scripts to+control those activities. However, it does not include the work's+System Libraries, or general-purpose tools or generally available free+programs which are used unmodified in performing those activities but+which are not part of the work. For example, Corresponding Source+includes interface definition files associated with source files for+the work, and the source code for shared libraries and dynamically+linked subprograms that the work is specifically designed to require,+such as by intimate data communication or control flow between those+subprograms and other parts of the work.++ The Corresponding Source need not include anything that users+can regenerate automatically from other parts of the Corresponding+Source.++ The Corresponding Source for a work in source code form is that+same work.++ 2. Basic Permissions.++ All rights granted under this License are granted for the term of+copyright on the Program, and are irrevocable provided the stated+conditions are met. This License explicitly affirms your unlimited+permission to run the unmodified Program. The output from running a+covered work is covered by this License only if the output, given its+content, constitutes a covered work. This License acknowledges your+rights of fair use or other equivalent, as provided by copyright law.++ You may make, run and propagate covered works that you do not+convey, without conditions so long as your license otherwise remains+in force. You may convey covered works to others for the sole purpose+of having them make modifications exclusively for you, or provide you+with facilities for running those works, provided that you comply with+the terms of this License in conveying all material for which you do+not control copyright. Those thus making or running the covered works+for you must do so exclusively on your behalf, under your direction+and control, on terms that prohibit them from making any copies of+your copyrighted material outside their relationship with you.++ Conveying under any other circumstances is permitted solely under+the conditions stated below. Sublicensing is not allowed; section 10+makes it unnecessary.++ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.++ No covered work shall be deemed part of an effective technological+measure under any applicable law fulfilling obligations under article+11 of the WIPO copyright treaty adopted on 20 December 1996, or+similar laws prohibiting or restricting circumvention of such+measures.++ When you convey a covered work, you waive any legal power to forbid+circumvention of technological measures to the extent such circumvention+is effected by exercising rights under this License with respect to+the covered work, and you disclaim any intention to limit operation or+modification of the work as a means of enforcing, against the work's+users, your or third parties' legal rights to forbid circumvention of+technological measures.++ 4. Conveying Verbatim Copies.++ You may convey verbatim copies of the Program's source code as you+receive it, in any medium, provided that you conspicuously and+appropriately publish on each copy an appropriate copyright notice;+keep intact all notices stating that this License and any+non-permissive terms added in accord with section 7 apply to the code;+keep intact all notices of the absence of any warranty; and give all+recipients a copy of this License along with the Program.++ You may charge any price or no price for each copy that you convey,+and you may offer support or warranty protection for a fee.++ 5. Conveying Modified Source Versions.++ You may convey a work based on the Program, or the modifications to+produce it from the Program, in the form of source code under the+terms of section 4, provided that you also meet all of these conditions:++ a) The work must carry prominent notices stating that you modified+ it, and giving a relevant date.++ b) The work must carry prominent notices stating that it is+ released under this License and any conditions added under section+ 7. This requirement modifies the requirement in section 4 to+ "keep intact all notices".++ c) You must license the entire work, as a whole, under this+ License to anyone who comes into possession of a copy. This+ License will therefore apply, along with any applicable section 7+ additional terms, to the whole of the work, and all its parts,+ regardless of how they are packaged. This License gives no+ permission to license the work in any other way, but it does not+ invalidate such permission if you have separately received it.++ d) If the work has interactive user interfaces, each must display+ Appropriate Legal Notices; however, if the Program has interactive+ interfaces that do not display Appropriate Legal Notices, your+ work need not make them do so.++ A compilation of a covered work with other separate and independent+works, which are not by their nature extensions of the covered work,+and which are not combined with it such as to form a larger program,+in or on a volume of a storage or distribution medium, is called an+"aggregate" if the compilation and its resulting copyright are not+used to limit the access or legal rights of the compilation's users+beyond what the individual works permit. Inclusion of a covered work+in an aggregate does not cause this License to apply to the other+parts of the aggregate.++ 6. Conveying Non-Source Forms.++ You may convey a covered work in object code form under the terms+of sections 4 and 5, provided that you also convey the+machine-readable Corresponding Source under the terms of this License,+in one of these ways:++ a) Convey the object code in, or embodied in, a physical product+ (including a physical distribution medium), accompanied by the+ Corresponding Source fixed on a durable physical medium+ customarily used for software interchange.++ b) Convey the object code in, or embodied in, a physical product+ (including a physical distribution medium), accompanied by a+ written offer, valid for at least three years and valid for as+ long as you offer spare parts or customer support for that product+ model, to give anyone who possesses the object code either (1) a+ copy of the Corresponding Source for all the software in the+ product that is covered by this License, on a durable physical+ medium customarily used for software interchange, for a price no+ more than your reasonable cost of physically performing this+ conveying of source, or (2) access to copy the+ Corresponding Source from a network server at no charge.++ c) Convey individual copies of the object code with a copy of the+ written offer to provide the Corresponding Source. This+ alternative is allowed only occasionally and noncommercially, and+ only if you received the object code with such an offer, in accord+ with subsection 6b.++ d) Convey the object code by offering access from a designated+ place (gratis or for a charge), and offer equivalent access to the+ Corresponding Source in the same way through the same place at no+ further charge. You need not require recipients to copy the+ Corresponding Source along with the object code. If the place to+ copy the object code is a network server, the Corresponding Source+ may be on a different server (operated by you or a third party)+ that supports equivalent copying facilities, provided you maintain+ clear directions next to the object code saying where to find the+ Corresponding Source. Regardless of what server hosts the+ Corresponding Source, you remain obligated to ensure that it is+ available for as long as needed to satisfy these requirements.++ e) Convey the object code using peer-to-peer transmission, provided+ you inform other peers where the object code and Corresponding+ Source of the work are being offered to the general public at no+ charge under subsection 6d.++ A separable portion of the object code, whose source code is excluded+from the Corresponding Source as a System Library, need not be+included in conveying the object code work.++ A "User Product" is either (1) a "consumer product", which means any+tangible personal property which is normally used for personal, family,+or household purposes, or (2) anything designed or sold for incorporation+into a dwelling. In determining whether a product is a consumer product,+doubtful cases shall be resolved in favor of coverage. For a particular+product received by a particular user, "normally used" refers to a+typical or common use of that class of product, regardless of the status+of the particular user or of the way in which the particular user+actually uses, or expects or is expected to use, the product. A product+is a consumer product regardless of whether the product has substantial+commercial, industrial or non-consumer uses, unless such uses represent+the only significant mode of use of the product.++ "Installation Information" for a User Product means any methods,+procedures, authorization keys, or other information required to install+and execute modified versions of a covered work in that User Product from+a modified version of its Corresponding Source. The information must+suffice to ensure that the continued functioning of the modified object+code is in no case prevented or interfered with solely because+modification has been made.++ If you convey an object code work under this section in, or with, or+specifically for use in, a User Product, and the conveying occurs as+part of a transaction in which the right of possession and use of the+User Product is transferred to the recipient in perpetuity or for a+fixed term (regardless of how the transaction is characterized), the+Corresponding Source conveyed under this section must be accompanied+by the Installation Information. But this requirement does not apply+if neither you nor any third party retains the ability to install+modified object code on the User Product (for example, the work has+been installed in ROM).++ The requirement to provide Installation Information does not include a+requirement to continue to provide support service, warranty, or updates+for a work that has been modified or installed by the recipient, or for+the User Product in which it has been modified or installed. Access to a+network may be denied when the modification itself materially and+adversely affects the operation of the network or violates the rules and+protocols for communication across the network.++ Corresponding Source conveyed, and Installation Information provided,+in accord with this section must be in a format that is publicly+documented (and with an implementation available to the public in+source code form), and must require no special password or key for+unpacking, reading or copying.++ 7. Additional Terms.++ "Additional permissions" are terms that supplement the terms of this+License by making exceptions from one or more of its conditions.+Additional permissions that are applicable to the entire Program shall+be treated as though they were included in this License, to the extent+that they are valid under applicable law. If additional permissions+apply only to part of the Program, that part may be used separately+under those permissions, but the entire Program remains governed by+this License without regard to the additional permissions.++ When you convey a copy of a covered work, you may at your option+remove any additional permissions from that copy, or from any part of+it. (Additional permissions may be written to require their own+removal in certain cases when you modify the work.) You may place+additional permissions on material, added by you to a covered work,+for which you have or can give appropriate copyright permission.++ Notwithstanding any other provision of this License, for material you+add to a covered work, you may (if authorized by the copyright holders of+that material) supplement the terms of this License with terms:++ a) Disclaiming warranty or limiting liability differently from the+ terms of sections 15 and 16 of this License; or++ b) Requiring preservation of specified reasonable legal notices or+ author attributions in that material or in the Appropriate Legal+ Notices displayed by works containing it; or++ c) Prohibiting misrepresentation of the origin of that material, or+ requiring that modified versions of such material be marked in+ reasonable ways as different from the original version; or++ d) Limiting the use for publicity purposes of names of licensors or+ authors of the material; or++ e) Declining to grant rights under trademark law for use of some+ trade names, trademarks, or service marks; or++ f) Requiring indemnification of licensors and authors of that+ material by anyone who conveys the material (or modified versions of+ it) with contractual assumptions of liability to the recipient, for+ any liability that these contractual assumptions directly impose on+ those licensors and authors.++ All other non-permissive additional terms are considered "further+restrictions" within the meaning of section 10. If the Program as you+received it, or any part of it, contains a notice stating that it is+governed by this License along with a term that is a further+restriction, you may remove that term. If a license document contains+a further restriction but permits relicensing or conveying under this+License, you may add to a covered work material governed by the terms+of that license document, provided that the further restriction does+not survive such relicensing or conveying.++ If you add terms to a covered work in accord with this section, you+must place, in the relevant source files, a statement of the+additional terms that apply to those files, or a notice indicating+where to find the applicable terms.++ Additional terms, permissive or non-permissive, may be stated in the+form of a separately written license, or stated as exceptions;+the above requirements apply either way.++ 8. Termination.++ You may not propagate or modify a covered work except as expressly+provided under this License. Any attempt otherwise to propagate or+modify it is void, and will automatically terminate your rights under+this License (including any patent licenses granted under the third+paragraph of section 11).++ However, if you cease all violation of this License, then your+license from a particular copyright holder is reinstated (a)+provisionally, unless and until the copyright holder explicitly and+finally terminates your license, and (b) permanently, if the copyright+holder fails to notify you of the violation by some reasonable means+prior to 60 days after the cessation.++ Moreover, your license from a particular copyright holder is+reinstated permanently if the copyright holder notifies you of the+violation by some reasonable means, this is the first time you have+received notice of violation of this License (for any work) from that+copyright holder, and you cure the violation prior to 30 days after+your receipt of the notice.++ Termination of your rights under this section does not terminate the+licenses of parties who have received copies or rights from you under+this License. If your rights have been terminated and not permanently+reinstated, you do not qualify to receive new licenses for the same+material under section 10.++ 9. Acceptance Not Required for Having Copies.++ You are not required to accept this License in order to receive or+run a copy of the Program. Ancillary propagation of a covered work+occurring solely as a consequence of using peer-to-peer transmission+to receive a copy likewise does not require acceptance. However,+nothing other than this License grants you permission to propagate or+modify any covered work. These actions infringe copyright if you do+not accept this License. Therefore, by modifying or propagating a+covered work, you indicate your acceptance of this License to do so.++ 10. Automatic Licensing of Downstream Recipients.++ Each time you convey a covered work, the recipient automatically+receives a license from the original licensors, to run, modify and+propagate that work, subject to this License. You are not responsible+for enforcing compliance by third parties with this License.++ An "entity transaction" is a transaction transferring control of an+organization, or substantially all assets of one, or subdividing an+organization, or merging organizations. If propagation of a covered+work results from an entity transaction, each party to that+transaction who receives a copy of the work also receives whatever+licenses to the work the party's predecessor in interest had or could+give under the previous paragraph, plus a right to possession of the+Corresponding Source of the work from the predecessor in interest, if+the predecessor has it or can get it with reasonable efforts.++ You may not impose any further restrictions on the exercise of the+rights granted or affirmed under this License. For example, you may+not impose a license fee, royalty, or other charge for exercise of+rights granted under this License, and you may not initiate litigation+(including a cross-claim or counterclaim in a lawsuit) alleging that+any patent claim is infringed by making, using, selling, offering for+sale, or importing the Program or any portion of it.++ 11. Patents.++ A "contributor" is a copyright holder who authorizes use under this+License of the Program or a work on which the Program is based. The+work thus licensed is called the contributor's "contributor version".++ A contributor's "essential patent claims" are all patent claims+owned or controlled by the contributor, whether already acquired or+hereafter acquired, that would be infringed by some manner, permitted+by this License, of making, using, or selling its contributor version,+but do not include claims that would be infringed only as a+consequence of further modification of the contributor version. For+purposes of this definition, "control" includes the right to grant+patent sublicenses in a manner consistent with the requirements of+this License.++ Each contributor grants you a non-exclusive, worldwide, royalty-free+patent license under the contributor's essential patent claims, to+make, use, sell, offer for sale, import and otherwise run, modify and+propagate the contents of its contributor version.++ In the following three paragraphs, a "patent license" is any express+agreement or commitment, however denominated, not to enforce a patent+(such as an express permission to practice a patent or covenant not to+sue for patent infringement). To "grant" such a patent license to a+party means to make such an agreement or commitment not to enforce a+patent against the party.++ If you convey a covered work, knowingly relying on a patent license,+and the Corresponding Source of the work is not available for anyone+to copy, free of charge and under the terms of this License, through a+publicly available network server or other readily accessible means,+then you must either (1) cause the Corresponding Source to be so+available, or (2) arrange to deprive yourself of the benefit of the+patent license for this particular work, or (3) arrange, in a manner+consistent with the requirements of this License, to extend the patent+license to downstream recipients. "Knowingly relying" means you have+actual knowledge that, but for the patent license, your conveying the+covered work in a country, or your recipient's use of the covered work+in a country, would infringe one or more identifiable patents in that+country that you have reason to believe are valid.++ If, pursuant to or in connection with a single transaction or+arrangement, you convey, or propagate by procuring conveyance of, a+covered work, and grant a patent license to some of the parties+receiving the covered work authorizing them to use, propagate, modify+or convey a specific copy of the covered work, then the patent license+you grant is automatically extended to all recipients of the covered+work and works based on it.++ A patent license is "discriminatory" if it does not include within+the scope of its coverage, prohibits the exercise of, or is+conditioned on the non-exercise of one or more of the rights that are+specifically granted under this License. You may not convey a covered+work if you are a party to an arrangement with a third party that is+in the business of distributing software, under which you make payment+to the third party based on the extent of your activity of conveying+the work, and under which the third party grants, to any of the+parties who would receive the covered work from you, a discriminatory+patent license (a) in connection with copies of the covered work+conveyed by you (or copies made from those copies), or (b) primarily+for and in connection with specific products or compilations that+contain the covered work, unless you entered into that arrangement,+or that patent license was granted, prior to 28 March 2007.++ Nothing in this License shall be construed as excluding or limiting+any implied license or other defenses to infringement that may+otherwise be available to you under applicable patent law.++ 12. No Surrender of Others' Freedom.++ If conditions are imposed on you (whether by court order, agreement or+otherwise) that contradict the conditions of this License, they do not+excuse you from the conditions of this License. If you cannot convey a+covered work so as to satisfy simultaneously your obligations under this+License and any other pertinent obligations, then as a consequence you may+not convey it at all. For example, if you agree to terms that obligate you+to collect a royalty for further conveying from those to whom you convey+the Program, the only way you could satisfy both those terms and this+License would be to refrain entirely from conveying the Program.++ 13. Use with the GNU Affero General Public License.++ Notwithstanding any other provision of this License, you have+permission to link or combine any covered work with a work licensed+under version 3 of the GNU Affero General Public License into a single+combined work, and to convey the resulting work. The terms of this+License will continue to apply to the part which is the covered work,+but the special requirements of the GNU Affero General Public License,+section 13, concerning interaction through a network will apply to the+combination as such.++ 14. Revised Versions of this License.++ The Free Software Foundation may publish revised and/or new versions of+the GNU General Public License from time to time. Such new versions will+be similar in spirit to the present version, but may differ in detail to+address new problems or concerns.++ Each version is given a distinguishing version number. If the+Program specifies that a certain numbered version of the GNU General+Public License "or any later version" applies to it, you have the+option of following the terms and conditions either of that numbered+version or of any later version published by the Free Software+Foundation. If the Program does not specify a version number of the+GNU General Public License, you may choose any version ever published+by the Free Software Foundation.++ If the Program specifies that a proxy can decide which future+versions of the GNU General Public License can be used, that proxy's+public statement of acceptance of a version permanently authorizes you+to choose that version for the Program.++ Later license versions may give you additional or different+permissions. However, no additional obligations are imposed on any+author or copyright holder as a result of your choosing to follow a+later version.++ 15. Disclaimer of Warranty.++ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.++ 16. Limitation of Liability.++ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF+SUCH DAMAGES.++ 17. Interpretation of Sections 15 and 16.++ If the disclaimer of warranty and limitation of liability provided+above cannot be given local legal effect according to their terms,+reviewing courts shall apply local law that most closely approximates+an absolute waiver of all civil liability in connection with the+Program, unless a warranty or assumption of liability accompanies a+copy of the Program in return for a fee.++ END OF TERMS AND CONDITIONS++ How to Apply These Terms to Your New Programs++ If you develop a new program, and you want it to be of the greatest+possible use to the public, the best way to achieve this is to make it+free software which everyone can redistribute and change under these terms.++ To do so, attach the following notices to the program. It is safest+to attach them to the start of each source file to most effectively+state the exclusion of warranty; and each file should have at least+the "copyright" line and a pointer to where the full notice is found.++ <one line to give the program's name and a brief idea of what it does.>+ Copyright (C) <year> <name of author>++ This program is free software: you can redistribute it and/or modify+ it under the terms of the GNU General Public License as published by+ the Free Software Foundation, either version 3 of the License, or+ (at your option) any later version.++ This program is distributed in the hope that it will be useful,+ but WITHOUT ANY WARRANTY; without even the implied warranty of+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ GNU General Public License for more details.++ You should have received a copy of the GNU General Public License+ along with this program. If not, see <https://www.gnu.org/licenses/>.++Also add information on how to contact you by electronic and paper mail.++ If the program does terminal interaction, make it output a short+notice like this when it starts in an interactive mode:++ <program> Copyright (C) <year> <name of author>+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.+ This is free software, and you are welcome to redistribute it+ under certain conditions; type `show c' for details.++The hypothetical commands `show w' and `show c' should show the appropriate+parts of the General Public License. Of course, your program's commands+might be different; for a GUI interface, you would use an "about box".++ You should also get your employer (if you work as a programmer) or school,+if any, to sign a "copyright disclaimer" for the program, if necessary.+For more information on this, and how to apply and follow the GNU GPL, see+<https://www.gnu.org/licenses/>.++ The GNU General Public License does not permit incorporating your program+into proprietary programs. If your program is a subroutine library, you+may consider it more useful to permit linking proprietary applications with+the library. If this is what you want to do, use the GNU Lesser General+Public License instead of this License. But first, please read+<https://www.gnu.org/licenses/why-not-lgpl.html>.diff --git a/Package.resolved b/Package.resolvedindex c280e740..56df73cc 100644--- a/Package.resolved+++ b/Package.resolved@@ -23,8 +23,8 @@"kind" : "remoteSourceControl","location" : "https://github.com/FluidInference/FluidAudio","state" : {- "revision" : "47552dde26f79b880efff2f23ad4dab55aa914ca",- "version" : "0.8.1"+ "revision" : "9fcdf2f32cd879f494826db0e4945e8cf1187a62",+ "version" : "0.12.0"}},{@@ -50,8 +50,8 @@"kind" : "remoteSourceControl","location" : "https://github.com/PostHog/posthog-ios.git","state" : {- "revision" : "cfbae6be113616156e6840dbfb61d59593ea1db5",- "version" : "3.36.2"+ "revision" : "1ba3e8636d4f1ad9f18f5a4273e88d39a162466b",+ "version" : "3.41.1"}},{@@ -63,6 +63,33 @@"version" : "6.22.1"}},+ {+ "identity" : "swift-collections",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/apple/swift-collections.git",+ "state" : {+ "revision" : "7b847a3b7008b2dc2f47ca3110d8c782fb2e5c7e",+ "version" : "1.3.0"+ }+ },+ {+ "identity" : "swift-jinja",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/huggingface/swift-jinja.git",+ "state" : {+ "revision" : "d81197f35f41445bc10e94600795e68c6f5e94b0",+ "version" : "2.3.1"+ }+ },+ {+ "identity" : "swift-transformers",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/huggingface/swift-transformers",+ "state" : {+ "revision" : "573e5c9036c2f136b3a8a071da8e8907322403d0",+ "version" : "1.1.6"+ }+ },{"identity" : "swiftwhisper","kind" : "remoteSourceControl",diff --git a/Package.swift b/Package.swiftindex 064c7487..d9b86ef1 100644--- a/Package.swift+++ b/Package.swift@@ -10,7 +10,7 @@ let package = Package(],dependencies: [.package(url: "https://github.com/mxcl/AppUpdater.git", from: "1.0.0"),- .package(url: "https://github.com/FluidInference/FluidAudio", from: "0.7.9"),+ .package(url: "https://github.com/FluidInference/FluidAudio", from: "0.12.0"),.package(url: "https://github.com/mxcl/PromiseKit", from: "6.0.0"),.package(url: "https://github.com/MrKai77/DynamicNotchKit", from: "1.0.0"),.package(url: "https://github.com/exPHAT/SwiftWhisper.git", branch: "master"),diff --git a/README.md b/README.mdindex f102852c..fbd34492 100644--- a/README.md+++ b/README.md@@ -98,7 +98,7 @@ https://discord.gg/VUPHaKSvYV```bashgit clone https://github.com/altic-dev/Fluid-oss.gitcd Fluid-oss-open FluidVoice.xcodeproj+open Fluid.xcodeproj```Build and run in Xcode. All dependencies are managed via Swift Package Manager.@@ -120,14 +120,19 @@ Contributions are welcome! Please create an issue first to discuss any major chaopen Fluid.xcodeproj```-3. **Configure your Team ID:**- - Select the project in Xcode's navigator- - Go to "Signing & Capabilities" tab- - Select your Apple Developer Team from the dropdown- - Xcode will save this locally in `xcuserdata/` (which is gitignored)+3. **Run from Xcode (one-time signing setup):**+ - Target: `FluidVoice` → `Signing & Capabilities`+ - Enable `Automatically manage signing`+ - Pick your `Team` (Personal Team is fine)+ - This is stored in `xcuserdata/` (gitignored), so it won’t affect your PR4. **Build and run** - All dependencies are managed via Swift Package Manager+5. **Build only (no signing):**+ ```bash+ xcodebuild -project Fluid.xcodeproj -scheme Fluid -destination 'platform=macOS' build CODE_SIGNING_ALLOWED=NO+ ```+5. **(Optional) Install pre-commit hook** to prevent accidental team ID commits:```bashcp scripts/check-team-id.sh .git/hooks/pre-commit@@ -164,8 +169,46 @@ CI uses unsigned builds:xcodebuild test -project Fluid.xcodeproj -scheme Fluid -destination 'platform=macOS' CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO```+## Privacy & Analytics++FluidVoice is designed to be local-first, but it includes optional anonymous analytics, solely to keep track of FV usage and future feature development.++### What this helps with+- Feature usage patterns (for example dictation, command mode, and write mode)+- Product reliability and performance tuning+- Anonymous release health signals to prioritize fixes and improvements++### What is collected+- App version, build, and macOS version+- Low-cardinality feature/config flags (for example app mode and major settings)+- Approximate usage ranges (not exact values)+- High-level success/error outcomes++### What is not collected+- Your voice, Raw audio or transcribed text+- Selected text, prompts, or AI-generated responses+- Terminal commands or outputs+- Window titles, file names/paths, clipboard content, or typed content+- or ANYTHING personal or private information.++### How to disable+Analytics are enabled by default. You can disable or re-enable them at any time from:++`Settings → Share Anonymous Analytics`++### Why this exists+Anonymous telemetry helps us understand what breaks, where performance can be improved, and which features matter most without collecting personal content.+This helps us continue building what users want and if we should even continue developing features for you.++## License History++- Versions before **2026-02-23**: Apache License 2.0+- Versions on and after **2026-02-23**: GNU General Public License v3.0 (GPLv3)+## License-This project is licensed under the [Apache License 2.0](LICENSE).+From 2026-02-23 onward, this project is licensed under the [GNU General Public License, Version 3.0 (GPLv3)](LICENSE).++Versions published before this date were licensed under Apache License 2.0.---diff --git a/Sources/Fluid/AppDelegate.swift b/Sources/Fluid/AppDelegate.swiftindex 4eeced8c..f5b2c60c 100644--- a/Sources/Fluid/AppDelegate.swift+++ b/Sources/Fluid/AppDelegate.swift@@ -15,20 +15,29 @@ class AppDelegate: NSObject, NSApplicationDelegate {private var updateCheckTimer: Timer?func applicationDidFinishLaunching(_ notification: Notification) {+ // Bring up file logging + crash handlers immediately during launch.+ _ = FileLogger.shared+ DebugLogger.shared.info("Application launched", source: "AppDelegate")+// Initialize AppUpdater for automatic updates// Repository: https://github.com/altic-dev/Fluid-ossself.updater = AppUpdater(owner: "altic-dev", repo: "Fluid-oss")- // Request accessibility permissions for global hotkey monitoring- self.requestAccessibilityPermissions()-// Initialize app settings (dock visibility, etc.)SettingsStore.shared.initializeAppSettings()+ // Record first-open synchronously before async analytics bootstrap so+ // onboarding initialization is deterministic on brand-new installs.+ let isTrueFirstOpen = AnalyticsIdentityStore.shared.ensureFirstOpenRecorded()+ SettingsStore.shared.bootstrapOnboardingState(isTrueFirstOpen: isTrueFirstOpen)+AnalyticsService.shared.bootstrap()- let isFirstOpen = AnalyticsIdentityStore.shared.ensureFirstOpenRecorded()- if isFirstOpen {+ if SettingsStore.shared.shouldPromptAccessibilityOnLaunch {+ self.requestAccessibilityPermissions()+ }++ if isTrueFirstOpen {AnalyticsService.shared.capture(.appFirstOpen)}AnalyticsService.shared.capture(@@ -42,16 +51,59 @@ class AppDelegate: NSObject, NSApplicationDelegate {// Schedule periodic update checks every hour while app is runningself.schedulePeriodicUpdateChecks()+ // Bring the app to front on initial launch.+ // Use a few delayed retries because SwiftUI window creation can lag app launch callbacks.+ self.forceFrontOnLaunch()+// Note: App UI is designed with dark color scheme in mind// All gradients and effects are optimized for dark mode}func applicationWillTerminate(_ notification: Notification) {+ DebugLogger.shared.info("Application will terminate", source: "AppDelegate")// Clean up the update check timerself.updateCheckTimer?.invalidate()self.updateCheckTimer = nil}+ func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {+ // Ensure dock-icon reopen always foregrounds FluidVoice.+ sender.activate(ignoringOtherApps: true)++ if let mainWindow = sender.windows.first(where: { win in+ guard win.level == .normal else { return false }+ guard win.styleMask.contains(.titled) else { return false }+ return win.title == "FluidVoice" || win.title.contains("FluidVoice")+ }) {+ mainWindow.orderFrontRegardless()+ mainWindow.makeKeyAndOrderFront(nil)+ }++ return true+ }++ private func forceFrontOnLaunch() {+ for delay in [0.0, 0.12, 0.35] {+ DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in+ guard let self else { return }+ self.bringMainWindowToFront()+ }+ }+ }++ private func bringMainWindowToFront() {+ NSApp.activate(ignoringOtherApps: true)++ if let mainWindow = NSApp.windows.first(where: { win in+ guard win.level == .normal else { return false }+ guard win.styleMask.contains(.titled) else { return false }+ return win.title == "FluidVoice" || win.title.contains("FluidVoice")+ }) {+ mainWindow.orderFrontRegardless()+ mainWindow.makeKeyAndOrderFront(nil)+ }+ }+// MARK: - Periodic Update Checksprivate func schedulePeriodicUpdateChecks() {diff --git a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected]index db042f62..fc70e4e4 100644Binary files a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] and b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] differdiff --git a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected]index 7891b254..34864dc2 100644Binary files a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] and b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] differdiff --git a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected]index a544d4c0..26293eee 100644Binary files a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] and b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] differdiff --git a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected]index 3b89815d..2571fcdb 100644Binary files a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] and b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] differdiff --git a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected]index 7891b254..34864dc2 100644Binary files a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] and b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] differdiff --git a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected]index e9ccd25b..c1d8af8a 100644Binary files a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] and b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] differdiff --git a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected]index 3b89815d..2571fcdb 100644Binary files a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] and b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] differdiff --git a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected]index 1974c3e7..59d2238d 100644Binary files a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] and b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] differdiff --git a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected]index e9ccd25b..c1d8af8a 100644Binary files a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] and b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] differdiff --git a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected]index 002bbf72..17f3fc34 100644Binary files a/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] and b/Sources/Fluid/Assets.xcassets/AppIcon.appiconset/[email protected] differdiff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swiftindex 3abfc81a..1608d73b 100644--- a/Sources/Fluid/ContentView.swift+++ b/Sources/Fluid/ContentView.swift@@ -38,6 +38,18 @@ enum SidebarItem: Hashable {// NOTE: Streaming and AI response parsing is now handled by LLMClientstruct ContentView: View {+ private enum ActiveRecordingMode: String {+ case none+ case dictate+ case edit+ case command+ }++ private enum DictationOutputRoute: String {+ case normal+ case onboardingSandbox+ }+@EnvironmentObject private var appServices: AppServices@StateObject private var mouseTracker = MousePositionTracker()@StateObject private var commandModeService = CommandModeService()@@ -64,6 +76,7 @@ struct ContentView: View {@State private var isRewriteModeShortcutEnabled: Bool = SettingsStore.shared.rewriteModeShortcutEnabled@State private var isRecordingForRewrite: Bool = false // Track if current recording is for rewrite mode@State private var isRecordingForCommand: Bool = false // Track if current recording is for command mode+ @State private var activeRecordingMode: ActiveRecordingMode = .none@State private var isRecordingShortcut = false@State private var isRecordingCommandModeShortcut = false@State private var isRecordingRewriteShortcut = false@@ -134,13 +147,19 @@ struct ContentView: View {var body: some View {let layout = AnyView(- NavigationSplitView(columnVisibility: self.$columnVisibility) {- self.sidebarView- .navigationSplitViewColumnWidth(min: 220, ideal: 250, max: 300)- } detail: {- self.detailView+ Group {+ if self.settings.shouldShowOnboarding {+ self.onboardingOnlyView+ } else {+ NavigationSplitView(columnVisibility: self.$columnVisibility) {+ self.sidebarView+ .navigationSplitViewColumnWidth(min: 220, ideal: 250, max: 300)+ } detail: {+ self.detailView+ }+ .navigationSplitViewStyle(.balanced)+ }}- .navigationSplitViewStyle(.balanced))let tracked = layout.withMouseTracking(self.mouseTracker)@@ -507,11 +526,11 @@ struct ContentView: View {if !newValue {self.isRecordingCommandModeShortcut = false- if self.isRecordingForCommand {+ if self.activeRecordingMode == .command {if self.asr.isRunning {Task { await self.asr.stopWithoutTranscription() }}- self.isRecordingForCommand = false+ self.clearActiveRecordingMode()self.menuBarManager.setOverlayMode(.dictation)}}@@ -523,11 +542,11 @@ struct ContentView: View {if !newValue {self.isRecordingRewriteShortcut = false- if self.isRecordingForRewrite {+ if self.activeRecordingMode == .edit {if self.asr.isRunning {Task { await self.asr.stopWithoutTranscription() }}- self.isRecordingForRewrite = false+ self.clearActiveRecordingMode()self.rewriteModeService.clearState()self.menuBarManager.setOverlayMode(.dictation)}@@ -539,6 +558,20 @@ struct ContentView: View {self.accessibilityEnabled = trusted}}+ .onReceive(NotificationCenter.default.publisher(for: .openCustomDictionaryFromVoiceEngine)) { _ in+ self.selectedSidebarItem = .customDictionary+ }+ .toolbar {+ if !self.settings.shouldShowOnboarding {+ ToolbarItem(placement: .primaryAction) {+ Button(action: self.openIssueReportingPage) {+ Image(systemName: "ladybug.fill")+ }+ .help("Report an issue")+ .accessibilityLabel("Report an issue")+ }+ }+ }.overlay(alignment: .center) {}.alert(self.asr.errorTitle,@@ -589,6 +622,13 @@ struct ContentView: View {}}.onDisappear {+ NotchContentState.shared.onPromptModeSwitchRequested = nil+ NotchContentState.shared.onOverlayModeSwitchRequested = nil+ NotchContentState.shared.onReprocessLastRequested = nil+ NotchContentState.shared.onCopyLastRequested = nil+ NotchContentState.shared.onUndoLastAIRequested = nil+ NotchContentState.shared.onToggleAIProcessingRequested = nil+ NotchContentState.shared.onOpenPreferencesRequested = nilTask { await self.asr.stopWithoutTranscription() }// Note: Overlay lifecycle is now managed by MenuBarManager@@ -682,12 +722,7 @@ struct ContentView: View {self.menuBarManager.setOverlayMode(.command)case .rewriteMode:- // Check if in write mode (no original text) vs rewrite mode- if self.rewriteModeService.isWriteMode || self.rewriteModeService.originalText.isEmpty {- self.menuBarManager.setOverlayMode(.write)- } else {- self.menuBarManager.setOverlayMode(.rewrite)- }+ self.menuBarManager.setOverlayMode(.edit)default:// For all other views, set to dictation mode@@ -703,6 +738,7 @@ struct ContentView: View {private func handleMenuBarNavigation(_ destination: MenuBarNavigationDestination?) {guard let destination else { return }defer { menuBarManager.requestedNavigationDestination = nil }+ guard !self.settings.shouldShowOnboarding else { return }switch destination {case .preferences:@@ -716,6 +752,11 @@ struct ContentView: View {self.pendingModifierOnly = false}+ private func openIssueReportingPage() {+ guard let url = URL(string: "https://github.com/altic-dev/Fluid-oss/issues/new/choose") else { return }+ NSWorkspace.shared.open(url)+ }+private var sidebarView: some View {List(selection: self.$selectedSidebarItem) {// Priority section: Welcome (if not onboarded) or Preferences (if voice model ready)@@ -784,12 +825,6 @@ struct ContentView: View {}.listRowBackground(self.sidebarRowBackground(for: .commandMode))- NavigationLink(value: SidebarItem.rewriteMode) {- Label("Write Mode", systemImage: "pencil.and.outline")- .font(.system(size: 15, weight: .medium))- }- .listRowBackground(self.sidebarRowBackground(for: .rewriteMode))-NavigationLink(value: SidebarItem.meetingTools) {Label("File Transcription", systemImage: "doc.text.fill").font(.system(size: 15, weight: .medium))@@ -898,6 +933,32 @@ struct ContentView: View {}}+ private var onboardingOnlyView: some View {+ OnboardingFlowView(+ currentStep: Binding(+ get: { self.settings.onboardingCurrentStep },+ set: { self.settings.onboardingCurrentStep = $0 }+ ),+ accessibilityEnabled: self.accessibilityEnabled,+ markAISkipped: {+ self.settings.onboardingAISkipped = true+ self.menuBarManager.setAIProcessingEnabled(false)+ },+ markPlaygroundValidated: {+ self.settings.onboardingPlaygroundValidated = true+ self.settings.playgroundUsed = true+ self.playgroundUsed = true+ },+ finishOnboarding: {+ self.completeOnboardingIfPossible()+ },+ openAccessibilitySettings: self.openAccessibilitySettings,+ menuBarManager: self.menuBarManager,+ theme: self.theme+ )+ .environmentObject(self.appServices)+ }+// MARK: - Welcome Guideprivate var welcomeView: some View {@@ -1088,8 +1149,16 @@ struct ContentView: View {// Audio settings merged into SettingsViewprivate func refreshDevices() {- self.inputDevices = AudioDevice.listInputDevices()- self.outputDevices = AudioDevice.listOutputDevices()+ // Query CoreAudio off the main thread — during device topology changes, synchronous+ // CoreAudio calls on main can deadlock while the HAL is still settling.+ DispatchQueue.global(qos: .userInitiated).async {+ let inputs = AudioDevice.listInputDevices()+ let outputs = AudioDevice.listOutputDevices()+ DispatchQueue.main.async {+ self.inputDevices = inputs+ self.outputDevices = outputs+ }+ }}// MARK: - Model Management Functions@@ -1259,39 +1328,25 @@ struct ContentView: View {/// Build a general system prompt with voice editing commands supportprivate func buildSystemPrompt(appInfo: (name: String, bundleId: String, windowTitle: String)) -> String {- // Use selected prompt profile (if any), otherwise use the default built-in prompt- if let profile = SettingsStore.shared.selectedDictationPromptProfile {- let promptBody = SettingsStore.stripBaseDictationPrompt(from: profile.prompt)- if !promptBody.isEmpty {- AnalyticsService.shared.capture(- .customPromptUsed,- properties: self.customPromptAnalyticsProperties(- promptSource: "profile",- overrideEmpty: nil- )- )- return SettingsStore.combineBasePrompt(with: promptBody)- }- }+ _ = appInfo+ return SettingsStore.shared.effectiveSystemPrompt(for: .dictate)+ }- // Default override (including empty string to intentionally use no system prompt)- if let override = SettingsStore.shared.defaultDictationPromptOverride {- let trimmedOverride = override.trimmingCharacters(in: .whitespacesAndNewlines)- AnalyticsService.shared.capture(- .customPromptUsed,- properties: self.customPromptAnalyticsProperties(- promptSource: "default_override",- overrideEmpty: trimmedOverride.isEmpty- )- )- // Empty override means explicitly use no system prompt- guard !trimmedOverride.isEmpty else { return override }+ private var shouldTracePromptProcessing: Bool {+ self.forcePromptTraceToConsole ||+ UserDefaults.standard.bool(forKey: "EnableDebugLogs")+ }- let body = SettingsStore.stripBaseDictationPrompt(from: trimmedOverride)- return SettingsStore.combineBasePrompt(with: body)- }+ private var forcePromptTraceToConsole: Bool {+ ProcessInfo.processInfo.environment["FLUID_PROMPT_TRACE"] == "1"+ }- return SettingsStore.defaultDictationPromptText()+ private func logDictationPromptTrace(_ title: String, value: String) {+ let line = "[PromptTrace][Dictate] \(title):\n\(value)"+ if self.forcePromptTraceToConsole {+ print(line)+ }+ DebugLogger.shared.debug(line, source: "ContentView")}private func customPromptAnalyticsProperties(promptSource: String, overrideEmpty: Bool?) -> [String: Any] {@@ -1366,8 +1421,27 @@ struct ContentView: View {let provider = AppleIntelligenceProvider()let appInfo = self.recordingAppInfo ?? self.getCurrentAppInfo()let systemPrompt = self.buildSystemPrompt(appInfo: appInfo)+ if self.shouldTracePromptProcessing {+ let selectedProfile = SettingsStore.shared.selectedPromptProfile(for: .dictate)+ let selectedPromptName: String = {+ if let profile = selectedProfile {+ return profile.name.isEmpty ? "Untitled Prompt" : profile.name+ }+ return "Default Dictate"+ }()+ self.logDictationPromptTrace("Selected prompt profile", value: selectedPromptName)+ self.logDictationPromptTrace("Prompt body (custom/default body)", value: SettingsStore.shared.effectivePromptBody(for: .dictate))+ self.logDictationPromptTrace("Built-in default system prompt (baseline)", value: SettingsStore.defaultSystemPromptText(for: .dictate))+ self.logDictationPromptTrace("Final system prompt sent to model", value: systemPrompt)+ self.logDictationPromptTrace("Input transcription (Q)", value: inputText)+ self.logDictationPromptTrace("Selected context text", value: "<none (dictation mode)>")+ }DebugLogger.shared.debug("Using Apple Intelligence for transcription cleanup", source: "ContentView")- return await provider.process(systemPrompt: systemPrompt, userText: inputText)+ let output = await provider.process(systemPrompt: systemPrompt, userText: inputText)+ if self.shouldTracePromptProcessing {+ self.logDictationPromptTrace("Model answer (A)", value: output)+ }+ return output}#endifreturn inputText // Fallback if not available@@ -1391,6 +1465,25 @@ struct ContentView: View {return self.buildSystemPrompt(appInfo: appInfo)}()DebugLogger.shared.debug("Using app context for AI: app=\(appInfo.name), bundleId=\(appInfo.bundleId), title=\(appInfo.windowTitle)", source: "ContentView")+ if self.shouldTracePromptProcessing {+ let selectedProfile = SettingsStore.shared.selectedPromptProfile(for: .dictate)+ let selectedPromptName: String = {+ if let profile = selectedProfile {+ return profile.name.isEmpty ? "Untitled Prompt" : profile.name+ }+ return "Default Dictate"+ }()+ self.logDictationPromptTrace("Selected prompt profile", value: selectedPromptName)+ self.logDictationPromptTrace("Prompt body (custom/default body)", value: SettingsStore.shared.effectivePromptBody(for: .dictate))+ self.logDictationPromptTrace("Built-in default system prompt (baseline)", value: SettingsStore.defaultSystemPromptText(for: .dictate))+ self.logDictationPromptTrace("Prompt override in use", value: (overrideSystemPrompt?.isEmpty == false) ? "yes" : "no")+ if let overrideSystemPrompt, !overrideSystemPrompt.isEmpty {+ self.logDictationPromptTrace("Override system prompt", value: overrideSystemPrompt)+ }+ self.logDictationPromptTrace("Final system prompt sent to model", value: systemPrompt)+ self.logDictationPromptTrace("Input transcription (Q)", value: inputText)+ self.logDictationPromptTrace("Selected context text", value: "<none (dictation mode)>")+ }// Check if this is a reasoning model that doesn't support temperature parameterlet modelLower = derivedSelectedModel.lowercased()@@ -1450,6 +1543,13 @@ struct ContentView: View {// Log thinking if present (for debugging)if let thinking = response.thinking {DebugLogger.shared.debug("LLM thinking tokens extracted (\(thinking.count) chars)", source: "ContentView")+ if self.shouldTracePromptProcessing {+ self.logDictationPromptTrace("Model thinking", value: thinking)+ }+ }++ if self.shouldTracePromptProcessing {+ self.logDictationPromptTrace("Model answer (A)", value: response.content)}return response.content.isEmpty ? "<no content>" : response.content@@ -1465,21 +1565,20 @@ struct ContentView: View {// MARK: - Stop and Process Transcription- private func stopAndProcessTranscription() async {+ private func stopAndProcessTranscription(route: DictationOutputRoute = .normal) async {DebugLogger.shared.debug("stopAndProcessTranscription called", source: "ContentView")+ DebugLogger.shared.info("Output route selected: \(route.rawValue)", source: "ContentView")// Check if we're in rewrite or command mode- let wasRewriteMode = self.isRecordingForRewrite- let wasCommandMode = self.isRecordingForCommand+ let modeAtStop = self.activeRecordingMode+ let wasRewriteMode = modeAtStop == .edit || self.isRecordingForRewrite+ let wasCommandMode = modeAtStop == .command || self.isRecordingForCommand+ DebugLogger.shared.info(+ "Routing decision snapshot | activeMode=\(modeAtStop.rawValue) | rewrite=\(wasRewriteMode) | command=\(wasCommandMode) | overlay=\(NotchContentState.shared.mode.rawValue)",+ source: "ContentView"+ )- if wasRewriteMode {- self.isRecordingForRewrite = false- // Don't reset overlay mode here - let it stay colored until it hides- }- if wasCommandMode {- self.isRecordingForCommand = false- // Don't reset overlay mode here - let it stay colored until it hides- }+ self.clearActiveRecordingMode()// Show "Transcribing..." state before calling stop() to keep overlay visible.// The asr.stop() call performs the final transcription which can take a moment@@ -1578,6 +1677,10 @@ struct ContentView: View {finalText = await self.processTextWithAI(transcribedText)+ // Clear transient status text before leaving processing state to avoid+ // a brief non-shimmer "Refining..." preview flash.+ NotchOverlayManager.shared.updateTranscriptionText("")+// Hide processing animationself.menuBarManager.setProcessing(false)} else {@@ -1589,6 +1692,7 @@ struct ContentView: View {// Apply GAAV formatting as the FINAL step (after AI post-processing)// This ensures the user's preference for no capitalization/period is respectedfinalText = ASRService.applyGAAVFormatting(finalText)+ self.asr.finalText = finalTextDebugLogger.shared.info("Transcription finalized (chars: \(finalText.count))", source: "ContentView")@@ -1602,8 +1706,16 @@ struct ContentView: View {])+ let shouldPersistOutputs = route == .normal+ if !shouldPersistOutputs {+ DebugLogger.shared.info(+ "Sandbox route active: suppressing clipboard/history/external typing side effects",+ source: "ContentView"+ )+ }+// Save to transcription history (transcription mode only, if enabled)- if SettingsStore.shared.saveTranscriptionHistory {+ if shouldPersistOutputs, SettingsStore.shared.saveTranscriptionHistory {let appInfo = self.recordingAppInfo ?? self.getCurrentAppInfo()TranscriptionHistoryStore.shared.addEntry(rawText: transcribedText,@@ -1614,7 +1726,7 @@ struct ContentView: View {}// Copy to clipboard if enabled (happens before typing as a backup)- if SettingsStore.shared.copyTranscriptionToClipboard {+ if shouldPersistOutputs, SettingsStore.shared.copyTranscriptionToClipboard {ClipboardService.copyToClipboard(finalText)AnalyticsService.shared.capture(.outputDelivered,@@ -1629,7 +1741,7 @@ struct ContentView: View {let frontmostApp = NSWorkspace.shared.frontmostApplicationlet frontmostName = frontmostApp?.localizedName ?? "Unknown"let isFluidFrontmost = frontmostApp?.bundleIdentifier?.contains("fluid") == true- let shouldTypeExternally = !isFluidFrontmost || self.isTranscriptionFocused == false+ let shouldTypeExternally = shouldPersistOutputs && (!isFluidFrontmost || self.isTranscriptionFocused == false)DebugLogger.shared.debug("Typing decision → frontmost: \(frontmostName), fluidFrontmost: \(isFluidFrontmost), editorFocused: \(self.isTranscriptionFocused), willTypeExternally: \(shouldTypeExternally)",@@ -1669,7 +1781,8 @@ struct ContentView: View {)NotchOverlayManager.shared.hide()- } else if SettingsStore.shared.copyTranscriptionToClipboard == false,+ } else if shouldPersistOutputs,+ SettingsStore.shared.copyTranscriptionToClipboard == false,SettingsStore.shared.saveTranscriptionHistory{AnalyticsService.shared.capture(@@ -1682,6 +1795,175 @@ struct ContentView: View {}}+ private func currentDictationOutputRouteForHotkeyStop() -> DictationOutputRoute {+ let onboardingPlaygroundStep = 4+ let isOnboardingPlayground = !self.settings.onboardingCompleted &&+ self.settings.onboardingCurrentStep == onboardingPlaygroundStep+ let isDictationMode = self.activeRecordingMode == .dictate++ if isOnboardingPlayground && isDictationMode {+ return .onboardingSandbox+ }+ return .normal+ }++ private func reprocessLastDictationFromHistory() {+ guard let last = TranscriptionHistoryStore.shared.entries.first else {+ DebugLogger.shared.info("Actions: Reprocess requested but history is empty", source: "ContentView")+ return+ }++ let rawText = last.rawText.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !rawText.isEmpty else {+ DebugLogger.shared.info("Actions: Reprocess skipped because latest history raw text is empty", source: "ContentView")+ return+ }++ DebugLogger.shared.info("Actions: Reprocessing latest dictation history entry", source: "ContentView")+ Task { @MainActor in+ await self.reprocessDictationText(rawText)+ }+ }++ private func copyLastDictationFromHistory() {+ guard let last = TranscriptionHistoryStore.shared.entries.first else {+ DebugLogger.shared.info("Actions: Copy requested but history is empty", source: "ContentView")+ return+ }++ // Fallback to raw text when no processed text is available+ // (for example older entries or edge cases with AI enhancement off).+ let processed = last.processedText.trimmingCharacters(in: .whitespacesAndNewlines)+ let raw = last.rawText.trimmingCharacters(in: .whitespacesAndNewlines)+ let text = processed.isEmpty ? raw : processed+ guard !text.isEmpty else {+ DebugLogger.shared.info("Actions: Copy skipped because latest history text is empty", source: "ContentView")+ return+ }++ _ = ClipboardService.copyToClipboard(text)+ DebugLogger.shared.info("Actions: Copied latest transcription to clipboard", source: "ContentView")+ }++ private func undoLastAIProcessingFromHistory() {+ guard let last = TranscriptionHistoryStore.shared.entries.first else {+ DebugLogger.shared.info("Actions: Undo AI requested but history is empty", source: "ContentView")+ return+ }++ let rawText = last.rawText.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !rawText.isEmpty else {+ DebugLogger.shared.info("Actions: Undo AI skipped because latest history raw text is empty", source: "ContentView")+ return+ }++ guard last.wasAIProcessed else {+ DebugLogger.shared.info("Actions: Undo AI skipped because latest entry was not AI processed", source: "ContentView")+ return+ }++ DebugLogger.shared.info("Actions: Restoring latest transcription raw text (undo AI)", source: "ContentView")+ Task { @MainActor in+ await self.applyHistoryTextOutput(rawText, saveToHistory: true)+ }+ }++ private func applyHistoryTextOutput(_ text: String, saveToHistory: Bool) async {+ // Keep hotkey/recording state deterministic before applying output text.+ if self.asr.isRunning {+ DebugLogger.shared.info("Actions: stopping active recording before history action output", source: "ContentView")+ await self.asr.stopWithoutTranscription()+ }++ let finalText = ASRService.applyGAAVFormatting(text)+ let appInfo = self.getCurrentAppInfo()++ if saveToHistory, SettingsStore.shared.saveTranscriptionHistory {+ TranscriptionHistoryStore.shared.addEntry(+ rawText: text,+ processedText: finalText,+ appName: appInfo.name,+ windowTitle: appInfo.windowTitle+ )+ }++ if SettingsStore.shared.copyTranscriptionToClipboard {+ ClipboardService.copyToClipboard(finalText)+ }++ let focusedPID = TypingService.captureSystemFocusedPID()+ ?? NSWorkspace.shared.frontmostApplication?.processIdentifier+ NotchContentState.shared.recordingTargetPID = focusedPID++ let frontmostApp = NSWorkspace.shared.frontmostApplication+ let isFluidFrontmost = frontmostApp?.bundleIdentifier?.contains("fluid") == true+ let shouldTypeExternally = !isFluidFrontmost || self.isTranscriptionFocused == false+ if shouldTypeExternally {+ await self.restoreFocusToRecordingTarget()+ self.asr.typeTextToActiveField(+ finalText,+ preferredTargetPID: NotchContentState.shared.recordingTargetPID+ )+ }+ }++ private func reprocessDictationText(_ transcribedText: String) async {+ // If live recording is still active, stop it first so reprocess does not+ // leave ASR running in the background (which causes the next hotkey press+ // to behave like a stop instead of start).+ if self.asr.isRunning {+ DebugLogger.shared.info("Actions: stopping active recording before reprocess", source: "ContentView")+ await self.asr.stopWithoutTranscription()+ }++ self.setActiveRecordingMode(.dictate)+ self.menuBarManager.setProcessing(true)+ NotchOverlayManager.shared.updateTranscriptionText("Reprocessing...")+ await Task.yield()++ var finalText = transcribedText+ let shouldUseAI = DictationAIPostProcessingGate.isConfigured()+ if shouldUseAI {+ finalText = await self.processTextWithAI(transcribedText)+ }++ NotchOverlayManager.shared.updateTranscriptionText("")+ self.menuBarManager.setProcessing(false)++ finalText = ASRService.applyGAAVFormatting(finalText)+ let appInfo = self.getCurrentAppInfo()++ if SettingsStore.shared.saveTranscriptionHistory {+ TranscriptionHistoryStore.shared.addEntry(+ rawText: transcribedText,+ processedText: finalText,+ appName: appInfo.name,+ windowTitle: appInfo.windowTitle+ )+ }++ if SettingsStore.shared.copyTranscriptionToClipboard {+ ClipboardService.copyToClipboard(finalText)+ }++ let focusedPID = TypingService.captureSystemFocusedPID()+ ?? NSWorkspace.shared.frontmostApplication?.processIdentifier+ NotchContentState.shared.recordingTargetPID = focusedPID++ let frontmostApp = NSWorkspace.shared.frontmostApplication+ let isFluidFrontmost = frontmostApp?.bundleIdentifier?.contains("fluid") == true+ let shouldTypeExternally = !isFluidFrontmost || self.isTranscriptionFocused == false+ if shouldTypeExternally {+ await self.restoreFocusToRecordingTarget()+ self.asr.typeTextToActiveField(+ finalText,+ preferredTargetPID: NotchContentState.shared.recordingTargetPID+ )+ }++ self.clearActiveRecordingMode()+ }+// MARK: - Rewrite Mode Voice Processingprivate func processRewriteWithVoiceInstruction(_ instruction: String) async {@@ -1747,6 +2029,77 @@ struct ContentView: View {}}+ private func setActiveRecordingMode(_ mode: ActiveRecordingMode) {+ self.activeRecordingMode = mode+ switch mode {+ case .none, .dictate:+ self.isRecordingForCommand = false+ self.isRecordingForRewrite = false+ case .edit:+ self.isRecordingForCommand = false+ self.isRecordingForRewrite = true+ case .command:+ self.isRecordingForCommand = true+ self.isRecordingForRewrite = false+ }+ }++ private func clearActiveRecordingMode() {+ self.setActiveRecordingMode(.none)+ }++ private func handleLivePromptModeSwitch(_ mode: SettingsStore.PromptMode) {+ guard !NotchContentState.shared.isProcessing else { return }+ switch mode.normalized {+ case .dictate:+ guard self.activeRecordingMode != .dictate || NotchContentState.shared.mode != .dictation else { return }+ self.setActiveRecordingMode(.dictate)+ self.rewriteModeService.clearState()+ self.menuBarManager.setOverlayMode(.dictation)+ case .edit:+ guard self.activeRecordingMode != .edit || NotchContentState.shared.mode == .dictation else { return }+ self.setActiveRecordingMode(.edit)+ let hasOriginal = !self.rewriteModeService.originalText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty+ let hasContext = !self.rewriteModeService.selectedContextText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty+ if !hasOriginal, !hasContext {+ let captured = self.rewriteModeService.captureSelectedText()+ DebugLogger.shared.info("Live switch to Edit Text attempted context capture: \(captured)", source: "ContentView")+ if !captured {+ self.rewriteModeService.startWithoutSelection()+ }+ }+ self.menuBarManager.setOverlayMode(.edit)+ case .write, .rewrite:+ guard self.activeRecordingMode != .edit || NotchContentState.shared.mode == .dictation else { return }+ self.setActiveRecordingMode(.edit)+ let hasOriginal = !self.rewriteModeService.originalText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty+ let hasContext = !self.rewriteModeService.selectedContextText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty+ if !hasOriginal, !hasContext {+ let captured = self.rewriteModeService.captureSelectedText()+ DebugLogger.shared.info("Live switch to Edit Text attempted context capture: \(captured)", source: "ContentView")+ if !captured {+ self.rewriteModeService.startWithoutSelection()+ }+ }+ self.menuBarManager.setOverlayMode(.edit)+ }+ }++ private func handleLiveOverlayModeSwitch(_ mode: OverlayMode) {+ guard !NotchContentState.shared.isProcessing else { return }+ switch mode {+ case .dictation:+ self.handleLivePromptModeSwitch(.dictate)+ case .edit, .write, .rewrite:+ self.handleLivePromptModeSwitch(.edit)+ case .command:+ guard self.activeRecordingMode != .command || NotchContentState.shared.mode != .command else { return }+ self.rewriteModeService.clearState()+ self.setActiveRecordingMode(.command)+ self.menuBarManager.setOverlayMode(.command)+ }+ }+// MARK: - Command Mode Voice Processingprivate func processCommandWithVoice(_ command: String) async {@@ -1767,12 +2120,19 @@ struct ContentView: View {// Capture app context at start to avoid mismatches if the user switches apps mid-sessionprivate func startRecording() {+ let model = SettingsStore.shared.selectedSpeechModel+ DebugLogger.shared.info(+ "ContentView: startRecording() for model=\(model.displayName), supportsStreaming=\(model.supportsStreaming)",+ source: "ContentView"+ )+ self.setActiveRecordingMode(.dictate)+// Ensure normal dictation mode is set (command/rewrite modes set their own)if !self.isRecordingForCommand, !self.isRecordingForRewrite {self.menuBarManager.setOverlayMode(.dictation)}- if SettingsStore.shared.enableTranscriptionSounds, !self.isRecordingForCommand, !self.isRecordingForRewrite {+ if !self.isRecordingForCommand, !self.isRecordingForRewrite {TranscriptionSoundPlayer.shared.playStartSound()}@@ -1792,6 +2152,7 @@ struct ContentView: View {// Pre-load model in background while recording (avoids 10s freeze on stop)Task {do {+ DebugLogger.shared.debug("ContentView: pre-load model task started", source: "ContentView")try await self.asr.ensureAsrReady()DebugLogger.shared.debug("Model pre-loaded during recording", source: "ContentView")} catch {@@ -1915,6 +2276,44 @@ struct ContentView: View {}}+ private var onboardingVoiceModelReady: Bool {+ self.asr.isAsrReady || self.asr.modelsExistOnDisk || SettingsStore.shared.selectedSpeechModel.isInstalled+ }++ private var onboardingMicrophoneReady: Bool {+ self.asr.micStatus == .authorized+ }++ private var onboardingAccessibilityReady: Bool {+ self.accessibilityEnabled+ }++ private var onboardingAIReady: Bool {+ self.settings.onboardingAISkipped || DictationAIPostProcessingGate.isConfigured()+ }++ private var onboardingPlaygroundReady: Bool {+ self.settings.onboardingPlaygroundValidated+ }++ private var canCompleteOnboarding: Bool {+ self.onboardingVoiceModelReady &&+ self.onboardingMicrophoneReady &&+ self.onboardingAccessibilityReady &&+ self.onboardingAIReady &&+ self.onboardingPlaygroundReady+ }++ @MainActor+ private func completeOnboardingIfPossible() {+ guard self.canCompleteOnboarding else { return }++ self.settings.onboardingCompleted = true++ let isOnboarded = self.asr.isAsrReady || self.asr.modelsExistOnDisk+ self.selectedSidebarItem = isOnboarded ? .preferences : .welcome+ }+private func labelFor(status: AVAuthorizationStatus) -> String {switch status {case .authorized: return "Microphone: Authorized"@@ -1993,6 +2392,28 @@ struct ContentView: View {}private func initializeHotkeyManagerIfNeeded() {+ NotchContentState.shared.onPromptModeSwitchRequested = { mode in+ self.handleLivePromptModeSwitch(mode)+ }+ NotchContentState.shared.onOverlayModeSwitchRequested = { mode in+ self.handleLiveOverlayModeSwitch(mode)+ }+ NotchContentState.shared.onReprocessLastRequested = {+ self.reprocessLastDictationFromHistory()+ }+ NotchContentState.shared.onCopyLastRequested = {+ self.copyLastDictationFromHistory()+ }+ NotchContentState.shared.onUndoLastAIRequested = {+ self.undoLastAIProcessingFromHistory()+ }+ NotchContentState.shared.onToggleAIProcessingRequested = {+ _ = self.menuBarManager.toggleAIProcessingEnabled()+ }+ NotchContentState.shared.onOpenPreferencesRequested = {+ self.menuBarManager.openPreferencesFromUI()+ }+guard self.hotkeyManager == nil else { return }self.hotkeyManager = GlobalHotkeyManager(@@ -2003,28 +2424,49 @@ struct ContentView: View {commandModeShortcutEnabled: self.isCommandModeShortcutEnabled,rewriteModeShortcutEnabled: self.isRewriteModeShortcutEnabled,startRecordingCallback: {+ DebugLogger.shared.debug("ContentView: startRecordingCallback invoked by hotkey", source: "ContentView")self.startRecording()},+ dictationModeCallback: {+ DebugLogger.shared.info("Dictate mode triggered", source: "ContentView")+ DebugLogger.shared.debug(+ "ContentView: selected model for dictate hotkey=\(SettingsStore.shared.selectedSpeechModel.displayName)",+ source: "ContentView"+ )+ self.setActiveRecordingMode(.dictate)+ self.rewriteModeService.clearState()+ self.menuBarManager.setOverlayMode(.dictation)++ guard !self.asr.isRunning else { return }+ if SettingsStore.shared.enableTranscriptionSounds {+ TranscriptionSoundPlayer.shared.playStartSound()+ }+ Task {+ await self.asr.start()+ }+ },stopAndProcessCallback: {- await self.stopAndProcessTranscription()+ let route = self.currentDictationOutputRouteForHotkeyStop()+ DebugLogger.shared.info("Hotkey stop callback using route: \(route.rawValue)", source: "ContentView")+ await self.stopAndProcessTranscription(route: route)},commandModeCallback: {DebugLogger.shared.info("Command mode triggered", source: "ContentView")// Set flag so stopAndProcessTranscription knows to process as command- self.isRecordingForCommand = true+ self.setActiveRecordingMode(.command)// Set overlay mode to commandself.menuBarManager.setOverlayMode(.command)+ guard !self.asr.isRunning else { return }+// Start recording immediately for the commandDebugLogger.shared.info("Starting voice recording for command",source: "ContentView")- if SettingsStore.shared.enableTranscriptionSounds {- TranscriptionSoundPlayer.shared.playStartSound()- }+ TranscriptionSoundPlayer.shared.playStartSound()Task {await self.asr.start()}@@ -2043,24 +2485,33 @@ struct ContentView: View {source: "ContentView")self.rewriteModeService.startWithoutSelection()- // Set overlay mode to write (different visual)- self.menuBarManager.setOverlayMode(.write)+ // Set overlay mode to edit+ self.menuBarManager.setOverlayMode(.edit)} else {- // Text was selected - rewrite mode- self.menuBarManager.setOverlayMode(.rewrite)+ // Text was selected - edit mode (with selected context)+ self.menuBarManager.setOverlayMode(.edit)}// Set flag so stopAndProcessTranscription knows to process as rewrite- self.isRecordingForRewrite = true+ self.setActiveRecordingMode(.edit)- // Start recording immediately for the rewrite instruction (or text to improve)- DebugLogger.shared.info("Starting voice recording for rewrite/write mode", source: "ContentView")- if SettingsStore.shared.enableTranscriptionSounds {- TranscriptionSoundPlayer.shared.playStartSound()- }+ guard !self.asr.isRunning else { return }++ // Start recording immediately for the edit instruction+ DebugLogger.shared.info("Starting voice recording for edit mode", source: "ContentView")+ TranscriptionSoundPlayer.shared.playStartSound()Task {await self.asr.start()}+ },+ isDictateRecordingProvider: {+ self.activeRecordingMode == .dictate+ },+ isCommandRecordingProvider: {+ self.activeRecordingMode == .command+ },+ isRewriteRecordingProvider: {+ self.activeRecordingMode == .edit})@@ -2081,14 +2532,8 @@ struct ContentView: View {}// Reset recording mode flags- if self.isRecordingForCommand {- self.isRecordingForCommand = false- self.menuBarManager.setOverlayMode(.dictation)- handled = true- }- if self.isRecordingForRewrite {- self.isRecordingForRewrite = false- self.menuBarManager.setOverlayMode(.dictation)+ if self.activeRecordingMode != .none {+ self.clearActiveRecordingMode()handled = true}diff --git a/Sources/Fluid/Networking/AppleIntelligenceProvider.swift b/Sources/Fluid/Networking/AppleIntelligenceProvider.swiftindex c748dcec..94aa934f 100644--- a/Sources/Fluid/Networking/AppleIntelligenceProvider.swift+++ b/Sources/Fluid/Networking/AppleIntelligenceProvider.swift@@ -66,7 +66,7 @@ final class AppleIntelligenceProvider {}/// Process rewrite/write requests with conversation history- func processRewrite(messages: [(role: String, content: String)], isWriteMode: Bool) async throws -> String {+ func processRewrite(messages: [(role: String, content: String)], systemPrompt: String) async throws -> String {let session = LanguageModelSession()// Build the conversation as a single prompt since FoundationModels@@ -74,21 +74,7 @@ final class AppleIntelligenceProvider {var fullPrompt = ""// Add system context- if isWriteMode {- fullPrompt += """- You are a helpful writing assistant. The user will ask you to write or generate text for them.- Respond directly with the requested content. Be concise and helpful.- Output ONLY what they asked for - no explanations or preamble.-- """- } else {- fullPrompt += """- You are a writing assistant that rewrites text according to user instructions.- Follow the user's specific instructions for how to rewrite.- Output ONLY the rewritten text. No explanations, no quotes, no preamble.-- """- }+ fullPrompt += "\(systemPrompt)\n\n"// Add conversation historyfor message in messages {diff --git a/Sources/Fluid/Persistence/FileTranscriptionHistoryStore.swift b/Sources/Fluid/Persistence/FileTranscriptionHistoryStore.swiftnew file mode 100644index 00000000..3f31fe21--- /dev/null+++ b/Sources/Fluid/Persistence/FileTranscriptionHistoryStore.swift@@ -0,0 +1,168 @@+//+// FileTranscriptionHistoryStore.swift+// Fluid+//+// Persistence for file (meeting) transcription history so results survive navigation.+//++import Combine+import Foundation++// MARK: - File Transcription Entry Model++struct FileTranscriptionEntry: Codable, Identifiable, Equatable {+ let id: UUID+ let timestamp: Date+ let fileName: String+ let duration: TimeInterval+ let processingTime: TimeInterval+ let confidence: Float+ let text: String++ init(+ id: UUID = UUID(),+ timestamp: Date = Date(),+ fileName: String,+ duration: TimeInterval,+ processingTime: TimeInterval,+ confidence: Float,+ text: String+ ) {+ self.id = id+ self.timestamp = timestamp+ self.fileName = fileName+ self.duration = duration+ self.processingTime = processingTime+ self.confidence = confidence+ self.text = text+ }++ init(from result: TranscriptionResult) {+ self.id = result.id+ self.timestamp = result.timestamp+ self.fileName = result.fileName+ self.duration = result.duration+ self.processingTime = result.processingTime+ self.confidence = result.confidence+ self.text = result.text+ }++ /// Preview text for list display (first 80 chars)+ var previewText: String {+ let trimmed = self.text.trimmingCharacters(in: .whitespacesAndNewlines)+ if trimmed.count > 80 {+ return String(trimmed.prefix(77)) + "..."+ }+ return trimmed+ }++ /// Relative time string for display+ var relativeTimeString: String {+ let formatter = RelativeDateTimeFormatter()+ formatter.unitsStyle = .abbreviated+ return formatter.localizedString(for: self.timestamp, relativeTo: Date())+ }++ /// Full formatted date string+ var fullDateString: String {+ let formatter = DateFormatter()+ formatter.dateStyle = .medium+ formatter.timeStyle = .short+ return formatter.string(from: self.timestamp)+ }++ /// Convert to TranscriptionResult for reuse of export/copy UI+ func toTranscriptionResult() -> TranscriptionResult {+ TranscriptionResult(+ id: self.id,+ text: self.text,+ confidence: self.confidence,+ duration: self.duration,+ processingTime: self.processingTime,+ fileName: self.fileName,+ timestamp: self.timestamp+ )+ }+}++// MARK: - File Transcription History Store++@MainActor+final class FileTranscriptionHistoryStore: ObservableObject {+ static let shared = FileTranscriptionHistoryStore()++ private let defaults = UserDefaults.standard+ private let maxEntries = 50++ private enum Keys {+ static let fileTranscriptionHistory = "FileTranscriptionHistoryEntries"+ }++ @Published private(set) var entries: [FileTranscriptionEntry] = []+ @Published var selectedEntryID: UUID?++ private init() {+ self.loadEntries()+ }++ // MARK: - Public Methods++ var selectedEntry: FileTranscriptionEntry? {+ guard let id = selectedEntryID else { return nil }+ return self.entries.first(where: { $0.id == id })+ }++ /// Add a completed file transcription to history (call after successful transcribeFile).+ func addEntry(_ result: TranscriptionResult) {+ guard !result.text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return }++ let entry = FileTranscriptionEntry(from: result)+ self.entries.insert(entry, at: 0)++ if self.entries.count > self.maxEntries {+ self.entries.removeLast()+ }++ self.selectedEntryID = entry.id+ self.saveEntries()++ DebugLogger.shared.debug(+ "Added file transcription to history (total: \(self.entries.count))",+ source: "FileTranscriptionHistoryStore"+ )+ }++ func deleteEntry(id: UUID) {+ self.entries.removeAll { $0.id == id }+ if self.selectedEntryID == id {+ self.selectedEntryID = self.entries.first?.id+ }+ self.saveEntries()+ }++ func clearAll() {+ self.entries.removeAll()+ self.selectedEntryID = nil+ self.saveEntries()+ DebugLogger.shared.info("Cleared all file transcription history", source: "FileTranscriptionHistoryStore")+ }++ // MARK: - Persistence++ private func loadEntries() {+ guard let data = self.defaults.data(forKey: Keys.fileTranscriptionHistory),+ let decoded = try? JSONDecoder().decode([FileTranscriptionEntry].self, from: data)+ else {+ self.entries = []+ return+ }+ self.entries = decoded+ }++ private func saveEntries() {+ if let encoded = try? JSONEncoder().encode(self.entries) {+ self.defaults.set(encoded, forKey: Keys.fileTranscriptionHistory)+ }+ self.objectWillChange.send()+ }+}diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swiftindex d23b57da..d5d2101e 100644--- a/Sources/Fluid/Persistence/SettingsStore.swift+++ b/Sources/Fluid/Persistence/SettingsStore.swift@@ -17,134 +17,113 @@ final class SettingsStore: ObservableObject {private let keychain = KeychainService.sharedprivate init() {+ self.migrateTranscriptionStartSoundIfNeeded()+ self.ensureDebugLoggingDefaults()self.migrateProviderAPIKeysIfNeeded()self.scrubSavedProviderAPIKeys()self.migrateDictationPromptProfilesIfNeeded()+ self.normalizePromptSelectionsIfNeeded()+ self.migrateOverlayBottomOffsetTo50IfNeeded()}- // Keys- private enum Keys {- static let enableAIProcessing = "EnableAIProcessing"- static let enableDebugLogs = "EnableDebugLogs"- static let availableAIModels = "AvailableAIModels"- static let availableModelsByProvider = "AvailableModelsByProvider"- static let selectedAIModel = "SelectedAIModel"- static let selectedModelByProvider = "SelectedModelByProvider"- static let selectedProviderID = "SelectedProviderID"- static let providerAPIKeys = "ProviderAPIKeys"- static let providerAPIKeyIdentifiers = "ProviderAPIKeyIdentifiers"- static let savedProviders = "SavedProviders"- static let verifiedProviderFingerprints = "VerifiedProviderFingerprints"- static let shareAnonymousAnalytics = "ShareAnonymousAnalytics"- static let fluid1InterestCaptured = "Fluid1InterestCaptured"- static let hotkeyShortcutKey = "HotkeyShortcutKey"- static let preferredInputDeviceUID = "PreferredInputDeviceUID"- static let preferredOutputDeviceUID = "PreferredOutputDeviceUID"- static let syncAudioDevicesWithSystem = "SyncAudioDevicesWithSystem"- static let visualizerNoiseThreshold = "VisualizerNoiseThreshold"- static let launchAtStartup = "LaunchAtStartup"- static let showInDock = "ShowInDock"- static let accentColorOption = "AccentColorOption"- static let enableTranscriptionSounds = "EnableTranscriptionSounds"- static let transcriptionStartSound = "TranscriptionStartSound"- static let pressAndHoldMode = "PressAndHoldMode"- static let enableStreamingPreview = "EnableStreamingPreview"- static let enableAIStreaming = "EnableAIStreaming"- static let copyTranscriptionToClipboard = "CopyTranscriptionToClipboard"- static let autoUpdateCheckEnabled = "AutoUpdateCheckEnabled"- static let lastUpdateCheckDate = "LastUpdateCheckDate"- static let updatePromptSnoozedUntil = "UpdatePromptSnoozedUntil"- static let snoozedUpdateVersion = "SnoozedUpdateVersion"- static let playgroundUsed = "PlaygroundUsed"-- // Command Mode Keys- static let commandModeSelectedModel = "CommandModeSelectedModel"- static let commandModeSelectedProviderID = "CommandModeSelectedProviderID"- static let commandModeHotkeyShortcut = "CommandModeHotkeyShortcut"- static let commandModeConfirmBeforeExecute = "CommandModeConfirmBeforeExecute"- static let commandModeLinkedToGlobal = "CommandModeLinkedToGlobal"- static let commandModeShortcutEnabled = "CommandModeShortcutEnabled"-- // Rewrite Mode Keys- static let rewriteModeHotkeyShortcut = "RewriteModeHotkeyShortcut"- static let rewriteModeSelectedModel = "RewriteModeSelectedModel"- static let rewriteModeSelectedProviderID = "RewriteModeSelectedProviderID"- static let rewriteModeLinkedToGlobal = "RewriteModeLinkedToGlobal"+ // MARK: - Prompt Profiles (Unified)- // Model Reasoning Config Keys- static let modelReasoningConfigs = "ModelReasoningConfigs"- static let rewriteModeShortcutEnabled = "RewriteModeShortcutEnabled"- static let showThinkingTokens = "ShowThinkingTokens"+ enum PromptMode: String, Codable, CaseIterable, Identifiable {+ case dictate+ case edit+ case write // legacy persisted value (decoded as .edit)+ case rewrite // legacy persisted value (decoded as .edit)- // Stats Keys- static let userTypingWPM = "UserTypingWPM"- static let saveTranscriptionHistory = "SaveTranscriptionHistory"-- // Filler Words- static let fillerWords = "FillerWords"- static let removeFillerWordsEnabled = "RemoveFillerWordsEnabled"-- // GAAV Mode (removes capitalization and trailing punctuation)- static let gaavModeEnabled = "GAAVModeEnabled"-- // Custom Dictionary- static let customDictionaryEntries = "CustomDictionaryEntries"-- // Transcription Provider (ASR)- static let selectedTranscriptionProvider = "SelectedTranscriptionProvider"- static let whisperModelSize = "WhisperModelSize"-- // Unified Speech Model (replaces above two)- static let selectedSpeechModel = "SelectedSpeechModel"-- // Overlay Position- static let overlayPosition = "OverlayPosition"- static let overlayBottomOffset = "OverlayBottomOffset"- static let overlaySize = "OverlaySize"- static let transcriptionPreviewCharLimit = "TranscriptionPreviewCharLimit"-- // Media Playback Control- static let pauseMediaDuringTranscription = "PauseMediaDuringTranscription"+ var id: String { self.rawValue }- // Custom Dictation Prompt- static let customDictationPrompt = "CustomDictationPrompt"+ static var visiblePromptModes: [PromptMode] { [.dictate, .edit] }- // Dictation Prompt Profiles (multi-prompt system)- static let dictationPromptProfiles = "DictationPromptProfiles"- static let selectedDictationPromptID = "SelectedDictationPromptID"+ var normalized: PromptMode {+ switch self {+ case .dictate:+ return .dictate+ case .edit, .write, .rewrite:+ return .edit+ }+ }- // Default Dictation Prompt Override (optional)- // nil => use built-in default prompt- // "" => use empty system prompt- // other => use custom default prompt text- static let defaultDictationPromptOverride = "DefaultDictationPromptOverride"+ var displayName: String {+ switch self.normalized {+ case .dictate:+ return "Dictate"+ case .edit:+ return "Edit"+ case .write, .rewrite:+ return "Edit"+ }+ }++ init(from decoder: Decoder) throws {+ let container = try decoder.singleValueContainer()+ let raw = (try? container.decode(String.self).lowercased()) ?? Self.dictate.rawValue+ switch raw {+ case "dictate":+ self = .dictate+ case "edit", "write", "rewrite":+ self = .edit+ default:+ self = .dictate+ }+ }- // Streak Settings- static let weekendsDontBreakStreak = "WeekendsDontBreakStreak"+ func encode(to encoder: Encoder) throws {+ var container = encoder.singleValueContainer()+ try container.encode(self.normalized.rawValue)+ }}- // MARK: - Dictation Prompt Profiles (Multi-prompt)-struct DictationPromptProfile: Codable, Identifiable, Hashable {let id: Stringvar name: Stringvar prompt: String+ var mode: PromptMode+ var includeContext: Boolvar createdAt: Datevar updatedAt: Date+ private enum CodingKeys: String, CodingKey {+ case id+ case name+ case prompt+ case mode+ case includeContext+ case createdAt+ case updatedAt+ }+init(id: String = UUID().uuidString,name: String,prompt: String,+ mode: PromptMode = .dictate,+ includeContext: Bool = false,createdAt: Date = Date(),updatedAt: Date = Date()) {self.id = idself.name = nameself.prompt = prompt+ self.mode = mode+ self.includeContext = includeContextself.createdAt = createdAtself.updatedAt = updatedAt}++ init(from decoder: Decoder) throws {+ let container = try decoder.container(keyedBy: CodingKeys.self)+ self.id = try container.decode(String.self, forKey: .id)+ self.name = try container.decode(String.self, forKey: .name)+ self.prompt = try container.decode(String.self, forKey: .prompt)+ self.mode = try (container.decodeIfPresent(PromptMode.self, forKey: .mode) ?? .dictate).normalized+ self.includeContext = try container.decodeIfPresent(Bool.self, forKey: .includeContext) ?? false+ self.createdAt = try container.decode(Date.self, forKey: .createdAt)+ self.updatedAt = try container.decode(Date.self, forKey: .updatedAt)+ }}/// User-defined dictation prompt profiles (named system prompts for dictation cleanup).@@ -187,8 +166,85 @@ final class SettingsStore: ObservableObject {/// Convenience: currently selected profile, or nil if Default/invalid selection.var selectedDictationPromptProfile: DictationPromptProfile? {- guard let id = self.selectedDictationPromptID else { return nil }- return self.dictationPromptProfiles.first(where: { $0.id == id })+ self.selectedPromptProfile(for: .dictate)+ }++ /// Selected edit prompt profile ID. `nil` means "Default Edit".+ var selectedEditPromptID: String? {+ get {+ if let value = self.defaults.string(forKey: Keys.selectedEditPromptID),+ value.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false+ {+ return value+ }+ if let legacyRewrite = self.defaults.string(forKey: Keys.selectedRewritePromptID),+ legacyRewrite.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false+ {+ return legacyRewrite+ }+ if let legacyWrite = self.defaults.string(forKey: Keys.selectedWritePromptID),+ legacyWrite.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false+ {+ return legacyWrite+ }+ return nil+ }+ set {+ objectWillChange.send()+ if let id = newValue?.trimmingCharacters(in: .whitespacesAndNewlines), !id.isEmpty {+ self.defaults.set(id, forKey: Keys.selectedEditPromptID)+ } else {+ self.defaults.removeObject(forKey: Keys.selectedEditPromptID)+ }+ // Normalize to the new key only.+ self.defaults.removeObject(forKey: Keys.selectedWritePromptID)+ self.defaults.removeObject(forKey: Keys.selectedRewritePromptID)+ }+ }++ /// Legacy alias retained for compatibility.+ var selectedWritePromptID: String? {+ get { self.selectedEditPromptID }+ set { self.selectedEditPromptID = newValue }+ }++ /// Legacy alias retained for compatibility.+ var selectedRewritePromptID: String? {+ get { self.selectedEditPromptID }+ set { self.selectedEditPromptID = newValue }+ }++ func selectedPromptID(for mode: PromptMode) -> String? {+ switch mode.normalized {+ case .dictate:+ return self.selectedDictationPromptID+ case .edit:+ return self.selectedEditPromptID+ case .write, .rewrite:+ return self.selectedEditPromptID+ }+ }++ func setSelectedPromptID(_ id: String?, for mode: PromptMode) {+ switch mode.normalized {+ case .dictate:+ self.selectedDictationPromptID = id+ case .edit:+ self.selectedEditPromptID = id+ case .write, .rewrite:+ self.selectedEditPromptID = id+ }+ }++ func promptProfiles(for mode: PromptMode) -> [DictationPromptProfile] {+ let target = mode.normalized+ return self.dictationPromptProfiles.filter { $0.mode.normalized == target }+ }++ func selectedPromptProfile(for mode: PromptMode) -> DictationPromptProfile? {+ guard let id = self.selectedPromptID(for: mode) else { return nil }+ let target = mode.normalized+ return self.dictationPromptProfiles.first(where: { $0.id == id && $0.mode.normalized == target })}/// Optional override for the built-in default dictation system prompt.@@ -213,6 +269,67 @@ final class SettingsStore: ObservableObject {}}+ /// Optional override for the built-in default edit system prompt.+ var defaultEditPromptOverride: String? {+ get {+ if self.defaults.object(forKey: Keys.defaultEditPromptOverride) != nil {+ return self.defaults.string(forKey: Keys.defaultEditPromptOverride) ?? ""+ }+ if self.defaults.object(forKey: Keys.defaultRewritePromptOverride) != nil {+ return self.defaults.string(forKey: Keys.defaultRewritePromptOverride) ?? ""+ }+ if self.defaults.object(forKey: Keys.defaultWritePromptOverride) != nil {+ return self.defaults.string(forKey: Keys.defaultWritePromptOverride) ?? ""+ }+ return nil+ }+ set {+ objectWillChange.send()+ if let value = newValue {+ self.defaults.set(value, forKey: Keys.defaultEditPromptOverride)+ } else {+ self.defaults.removeObject(forKey: Keys.defaultEditPromptOverride)+ }+ // Normalize to the new key only.+ self.defaults.removeObject(forKey: Keys.defaultWritePromptOverride)+ self.defaults.removeObject(forKey: Keys.defaultRewritePromptOverride)+ }+ }++ /// Legacy alias retained for compatibility.+ var defaultWritePromptOverride: String? {+ get { self.defaultEditPromptOverride }+ set { self.defaultEditPromptOverride = newValue }+ }++ /// Legacy alias retained for compatibility.+ var defaultRewritePromptOverride: String? {+ get { self.defaultEditPromptOverride }+ set { self.defaultEditPromptOverride = newValue }+ }++ func defaultPromptOverride(for mode: PromptMode) -> String? {+ switch mode.normalized {+ case .dictate:+ return self.defaultDictationPromptOverride+ case .edit:+ return self.defaultEditPromptOverride+ case .write, .rewrite:+ return self.defaultEditPromptOverride+ }+ }++ func setDefaultPromptOverride(_ value: String?, for mode: PromptMode) {+ switch mode.normalized {+ case .dictate:+ self.defaultDictationPromptOverride = value+ case .edit:+ self.defaultEditPromptOverride = value+ case .write, .rewrite:+ self.defaultEditPromptOverride = value+ }+ }+/// Hidden base prompt: role/intent only (not exposed in UI).static func baseDictationPromptText() -> String {"""@@ -239,6 +356,36 @@ final class SettingsStore: ObservableObject {"""}+ /// Hidden base prompt for edit mode (role/intent only).+ static func baseEditPromptText() -> String {+ """+ You are a helpful writing assistant. The user may ask you to write new text or edit selected text.++ Output ONLY what the user requested. Do not add explanations or preamble.+ """+ }++ /// Legacy wrappers retained for compatibility.+ static func baseWritePromptText() -> String {+ self.baseEditPromptText()+ }++ /// Legacy wrappers retained for compatibility.+ static func baseRewritePromptText() -> String {+ self.baseEditPromptText()+ }++ static func basePromptText(for mode: PromptMode) -> String {+ switch mode.normalized {+ case .dictate:+ return self.baseDictationPromptText()+ case .edit:+ return self.baseEditPromptText()+ case .write, .rewrite:+ return self.baseEditPromptText()+ }+ }+/// Built-in default dictation prompt body that users may view/edit.static func defaultDictationPromptBodyText() -> String {"""@@ -262,9 +409,52 @@ final class SettingsStore: ObservableObject {"""}+ /// Built-in default edit prompt body.+ static func defaultEditPromptBodyText() -> String {+ """+ Your job:+ - If the user asks for new content, write it directly.+ - If selected context is provided, apply the instruction to that context.+ - Preserve intent and requested tone/style/format.+ - Output only the final text, without explanations.++ Example requests:+ - "Write an email to my boss asking for time off"+ - "Draft a reply saying I'll be there at 5"+ - "Rewrite this to sound more professional"+ - "Make this shorter and clearer"+ """+ }++ /// Legacy wrappers retained for compatibility.+ static func defaultWritePromptBodyText() -> String {+ self.defaultEditPromptBodyText()+ }++ /// Legacy wrappers retained for compatibility.+ static func defaultRewritePromptBodyText() -> String {+ self.defaultEditPromptBodyText()+ }++ static func defaultPromptBodyText(for mode: PromptMode) -> String {+ switch mode.normalized {+ case .dictate:+ return self.defaultDictationPromptBodyText()+ case .edit:+ return self.defaultEditPromptBodyText()+ case .write, .rewrite:+ return self.defaultEditPromptBodyText()+ }+ }+/// Join hidden base with a body, avoiding duplicate base text.static func combineBasePrompt(with body: String) -> String {- let base = self.baseDictationPromptText().trimmingCharacters(in: .whitespacesAndNewlines)+ self.combineBasePrompt(for: .dictate, with: body)+ }++ /// Join hidden base with a body for a given mode, avoiding duplicate base text.+ static func combineBasePrompt(for mode: PromptMode, with body: String) -> String {+ let base = self.basePromptText(for: mode).trimmingCharacters(in: .whitespacesAndNewlines)let trimmedBody = body.trimmingCharacters(in: .whitespacesAndNewlines)// If body already starts with base, return as-is to avoid double-prepending.@@ -280,7 +470,12 @@ final class SettingsStore: ObservableObject {/// Remove the hidden base prompt prefix if it was persisted previously.static func stripBaseDictationPrompt(from text: String) -> String {- let base = self.baseDictationPromptText().trimmingCharacters(in: .whitespacesAndNewlines)+ self.stripBasePrompt(for: .dictate, from: text)+ }++ /// Remove a hidden base prompt prefix for a given mode if it was persisted previously.+ static func stripBasePrompt(for mode: PromptMode, from text: String) -> String {+ let base = self.basePromptText(for: mode).trimmingCharacters(in: .whitespacesAndNewlines)let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)// Try exact and case-insensitive prefix removal@@ -299,7 +494,60 @@ final class SettingsStore: ObservableObject {/// Built-in default dictation system prompt shared across the app.static func defaultDictationPromptText() -> String {- self.combineBasePrompt(with: self.defaultDictationPromptBodyText())+ self.defaultSystemPromptText(for: .dictate)+ }++ static func defaultSystemPromptText(for mode: PromptMode) -> String {+ self.combineBasePrompt(for: mode, with: self.defaultPromptBodyText(for: mode))+ }++ static func contextTemplateText() -> String {+ """+ Use the following selected context to improve your response:+ {context}+ """+ }++ static func runtimeContextBlock(context: String, template: String) -> String {+ let trimmedContext = context.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !trimmedContext.isEmpty else { return "" }+ if template.contains("{context}") {+ return template.replacingOccurrences(of: "{context}", with: trimmedContext)+ }+ return "\(template)\n\(trimmedContext)"+ }++ func effectivePromptBody(for mode: PromptMode) -> String {+ if let profile = self.selectedPromptProfile(for: mode) {+ let body = Self.stripBasePrompt(for: mode, from: profile.prompt)+ if !body.isEmpty {+ return body+ }+ }++ if let override = self.defaultPromptOverride(for: mode) {+ return Self.stripBasePrompt(for: mode, from: override)+ }++ return Self.defaultPromptBodyText(for: mode)+ }++ func effectiveSystemPrompt(for mode: PromptMode) -> String {+ if let profile = self.selectedPromptProfile(for: mode) {+ let body = Self.stripBasePrompt(for: mode, from: profile.prompt)+ if !body.isEmpty {+ return Self.combineBasePrompt(for: mode, with: body)+ }+ }++ if let override = self.defaultPromptOverride(for: mode) {+ let trimmedOverride = override.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !trimmedOverride.isEmpty else { return override }+ let body = Self.stripBasePrompt(for: mode, from: trimmedOverride)+ return Self.combineBasePrompt(for: mode, with: body)+ }++ return Self.defaultSystemPromptText(for: mode)}// MARK: - Model Reasoning Configuration@@ -408,7 +656,11 @@ final class SettingsStore: ObservableObject {}var enableDebugLogs: Bool {- get { self.defaults.bool(forKey: Keys.enableDebugLogs) }+ get {+ let value = self.defaults.object(forKey: Keys.enableDebugLogs)+ if value == nil { return true }+ return self.defaults.bool(forKey: Keys.enableDebugLogs)+ }set {objectWillChange.send()self.defaults.set(newValue, forKey: Keys.enableDebugLogs)@@ -416,6 +668,13 @@ final class SettingsStore: ObservableObject {}}+ private func ensureDebugLoggingDefaults() {+ if self.defaults.object(forKey: Keys.enableDebugLogs) == nil {+ self.defaults.set(true, forKey: Keys.enableDebugLogs)+ }+ DebugLogger.shared.refreshLoggingEnabled()+ }+var selectedModel: String? {get { self.defaults.string(forKey: Keys.selectedAIModel) }set {@@ -653,7 +912,7 @@ final class SettingsStore: ObservableObject {var overlayBottomOffset: Double {get {let value = self.defaults.double(forKey: Keys.overlayBottomOffset)- return value == 0.0 ? 80.0 : value // Default to 80.0+ return value == 0.0 ? 50.0 : value // Default to 50.0}set {objectWillChange.send()@@ -738,6 +997,7 @@ final class SettingsStore: ObservableObject {}enum TranscriptionStartSound: String, CaseIterable, Identifiable {+ case nonecase fluidSfx1 = "fluid_sfx_1"case fluidSfx2 = "fluid_sfx_2"case fluidSfx3 = "fluid_sfx_3"@@ -747,6 +1007,7 @@ final class SettingsStore: ObservableObject {var displayName: String {switch self {+ case .none: return "None"case .fluidSfx1: return "Fluid SFX 1"case .fluidSfx2: return "Fluid SFX 2"case .fluidSfx3: return "Fluid SFX 3"@@ -754,8 +1015,9 @@ final class SettingsStore: ObservableObject {}}- var soundFileName: String {+ var soundFileName: String? {switch self {+ case .none: return nilcase .fluidSfx1: return "FV_start"case .fluidSfx2: return "FV_start_2"case .fluidSfx3: return "sfx_3"@@ -796,6 +1058,7 @@ final class SettingsStore: ObservableObject {var transcriptionStartSound: TranscriptionStartSound {get {+ self.migrateTranscriptionStartSoundIfNeeded()guard let raw = self.defaults.string(forKey: Keys.transcriptionStartSound),let option = TranscriptionStartSound(rawValue: raw)else {@@ -845,6 +1108,13 @@ final class SettingsStore: ObservableObject {}}+ /// Issue #162 wording: hide app from Dock and Cmd+Tab when enabled.+ /// Backed by existing `showInDock` storage to keep this change minimal.+ var hideFromDockAndAppSwitcher: Bool {+ get { !self.showInDock }+ set { self.showInDock = !newValue }+ }+var autoUpdateCheckEnabled: Bool {get {let value = self.defaults.object(forKey: Keys.autoUpdateCheckEnabled)@@ -932,6 +1202,95 @@ final class SettingsStore: ObservableObject {set { self.defaults.set(newValue, forKey: Keys.playgroundUsed) }}+ var onboardingCompleted: Bool {+ get {+ if self.defaults.object(forKey: Keys.onboardingCompleted) == nil {+ return true+ }+ return self.defaults.bool(forKey: Keys.onboardingCompleted)+ }+ set {+ objectWillChange.send()+ self.defaults.set(newValue, forKey: Keys.onboardingCompleted)+ }+ }++ var onboardingCurrentStep: Int {+ get {+ let raw = self.defaults.integer(forKey: Keys.onboardingCurrentStep)+ return max(0, min(4, raw))+ }+ set {+ objectWillChange.send()+ let clamped = max(0, min(4, newValue))+ self.defaults.set(clamped, forKey: Keys.onboardingCurrentStep)+ }+ }++ var onboardingAISkipped: Bool {+ get { self.defaults.bool(forKey: Keys.onboardingAISkipped) }+ set {+ objectWillChange.send()+ self.defaults.set(newValue, forKey: Keys.onboardingAISkipped)+ }+ }++ var onboardingPlaygroundValidated: Bool {+ get { self.defaults.bool(forKey: Keys.onboardingPlaygroundValidated) }+ set {+ objectWillChange.send()+ self.defaults.set(newValue, forKey: Keys.onboardingPlaygroundValidated)+ }+ }++ var shouldShowOnboarding: Bool {+ !self.onboardingCompleted+ }++ var shouldPromptAccessibilityOnLaunch: Bool {+ !self.shouldShowOnboarding+ }++ func bootstrapOnboardingState(isTrueFirstOpen: Bool) {+ guard self.defaults.object(forKey: Keys.onboardingCompleted) == nil else { return }++ objectWillChange.send()++ let hasLegacyUsageSignals = self.hasLegacyUsageSignals()+ let shouldShowForThisInstall = isTrueFirstOpen && !hasLegacyUsageSignals++ if shouldShowForThisInstall {+ self.defaults.set(false, forKey: Keys.onboardingCompleted)+ self.defaults.set(0, forKey: Keys.onboardingCurrentStep)+ self.defaults.set(false, forKey: Keys.onboardingAISkipped)+ self.defaults.set(false, forKey: Keys.onboardingPlaygroundValidated)+ } else {+ self.defaults.set(true, forKey: Keys.onboardingCompleted)+ self.defaults.set(0, forKey: Keys.onboardingCurrentStep)+ self.defaults.set(false, forKey: Keys.onboardingAISkipped)+ self.defaults.set(false, forKey: Keys.onboardingPlaygroundValidated)+ }+ }++ func resetOnboardingProgress() {+ objectWillChange.send()+ self.defaults.set(false, forKey: Keys.onboardingCompleted)+ self.defaults.set(0, forKey: Keys.onboardingCurrentStep)+ self.defaults.set(false, forKey: Keys.onboardingAISkipped)+ self.defaults.set(false, forKey: Keys.onboardingPlaygroundValidated)+ self.defaults.set(false, forKey: Keys.playgroundUsed)+ }++ private func hasLegacyUsageSignals() -> Bool {+ if self.defaults.object(forKey: Keys.playgroundUsed) != nil { return true }+ if self.defaults.object(forKey: Keys.hotkeyShortcutKey) != nil { return true }+ if self.defaults.object(forKey: Keys.selectedSpeechModel) != nil { return true }+ if self.defaults.object(forKey: Keys.selectedProviderID) != nil { return true }+ if self.defaults.object(forKey: Keys.customDictionaryEntries) != nil { return true }+ if !self.savedProviders.isEmpty { return true }+ return false+ }+// MARK: - Command Mode Settingsvar commandModeSelectedModel: String? {@@ -1244,6 +1603,14 @@ final class SettingsStore: ObservableObject {}}+ private func migrateTranscriptionStartSoundIfNeeded() {+ guard let legacyEnabled = self.defaults.object(forKey: Keys.enableTranscriptionSounds) as? Bool else { return }+ if legacyEnabled == false {+ self.defaults.set(TranscriptionStartSound.none.rawValue, forKey: Keys.transcriptionStartSound)+ }+ self.defaults.removeObject(forKey: Keys.enableTranscriptionSounds)+ }+private func migrateProviderAPIKeysIfNeeded() {self.defaults.removeObject(forKey: Keys.providerAPIKeyIdentifiers)@@ -1282,7 +1649,7 @@ final class SettingsStore: ObservableObject {self.customDictationPrompt = ""// If selection points to nowhere, reset to default to avoid confusion.if let id = self.selectedDictationPromptID,- self.dictationPromptProfiles.contains(where: { $0.id == id }) == false+ self.dictationPromptProfiles.contains(where: { $0.id == id && $0.mode == .dictate }) == false{self.selectedDictationPromptID = nil}@@ -1301,6 +1668,61 @@ final class SettingsStore: ObservableObject {DebugLogger.shared.info("Migrated legacy custom dictation prompt to a prompt profile", source: "SettingsStore")}+ private func normalizePromptSelectionsIfNeeded() {+ // One-time migration to unified edit keys.+ if self.defaults.object(forKey: Keys.selectedEditPromptID) == nil,+ let migratedSelectedEditID = self.selectedEditPromptID+ {+ self.defaults.set(migratedSelectedEditID, forKey: Keys.selectedEditPromptID)+ self.defaults.removeObject(forKey: Keys.selectedWritePromptID)+ self.defaults.removeObject(forKey: Keys.selectedRewritePromptID)+ }++ if self.defaults.object(forKey: Keys.defaultEditPromptOverride) == nil,+ let migratedEditOverride = self.defaultEditPromptOverride+ {+ self.defaults.set(migratedEditOverride, forKey: Keys.defaultEditPromptOverride)+ self.defaults.removeObject(forKey: Keys.defaultWritePromptOverride)+ self.defaults.removeObject(forKey: Keys.defaultRewritePromptOverride)+ }++ // Persist profile mode normalization to the new user-facing modes.+ var normalizedProfiles = self.dictationPromptProfiles+ var didChangeProfiles = false+ for idx in normalizedProfiles.indices {+ let normalizedMode = normalizedProfiles[idx].mode.normalized+ if normalizedProfiles[idx].mode != normalizedMode {+ normalizedProfiles[idx].mode = normalizedMode+ didChangeProfiles = true+ }+ }+ if didChangeProfiles {+ self.dictationPromptProfiles = normalizedProfiles+ }++ if let id = self.selectedDictationPromptID,+ self.dictationPromptProfiles.contains(where: { $0.id == id && $0.mode == .dictate }) == false+ {+ self.selectedDictationPromptID = nil+ }++ if let id = self.selectedEditPromptID,+ self.dictationPromptProfiles.contains(where: { $0.id == id && $0.mode.normalized == .edit }) == false+ {+ self.selectedEditPromptID = nil+ }+ }++ private func migrateOverlayBottomOffsetTo50IfNeeded() {+ if self.defaults.bool(forKey: Keys.overlayBottomOffsetMigratedTo50) {+ return+ }++ self.defaults.set(50.0, forKey: Keys.overlayBottomOffset)+ self.defaults.set(true, forKey: Keys.overlayBottomOffsetMigratedTo50)+ NotificationCenter.default.post(name: NSNotification.Name("OverlayOffsetChanged"), object: nil)+ }+private func scrubSavedProviderAPIKeys() {guard let data = defaults.data(forKey: Keys.savedProviders),var decoded = try? JSONDecoder().decode([SavedProvider].self, from: data) else { return }@@ -1526,6 +1948,18 @@ final class SettingsStore: ObservableObject {}}+ var vocabularyBoostingEnabled: Bool {+ get {+ let value = self.defaults.object(forKey: Keys.vocabularyBoostingEnabled)+ return value as? Bool ?? false+ }+ set {+ objectWillChange.send()+ self.defaults.set(newValue, forKey: Keys.vocabularyBoostingEnabled)+ NotificationCenter.default.post(name: .parakeetVocabularyDidChange, object: nil)+ }+ }+/// Custom dictionary entries for word replacementvar customDictionaryEntries: [CustomDictionaryEntry] {get {@@ -1549,10 +1983,15 @@ final class SettingsStore: ObservableObject {/// Unified speech recognition model selection./// Replaces the old TranscriptionProviderOption + WhisperModelSize dual-setting.enum SpeechModel: String, CaseIterable, Identifiable, Codable {+ // Temporarily disabled in UI/runtime while Parakeet word boosting work is prioritized.+ // Flip to `true` in a future round to re-enable Qwen without deleting implementation.+ static let qwenPreviewEnabled = false+// MARK: - FluidAudio Models (Apple Silicon Only)case parakeetTDT = "parakeet-tdt"case parakeetTDTv2 = "parakeet-tdt-v2"+ case qwen3Asr = "qwen3-asr"// MARK: - Apple Native@@ -1576,6 +2015,7 @@ final class SettingsStore: ObservableObject {switch self {case .parakeetTDT: return "Parakeet TDT v3 (Multilingual)"case .parakeetTDTv2: return "Parakeet TDT v2 (English Only)"+ case .qwen3Asr: return "Qwen3 ASR (Beta)"case .appleSpeech: return "Apple ASR Legacy"case .appleSpeechAnalyzer: return "Apple Speech - macOS 26+"case .whisperTiny: return "Whisper Tiny"@@ -1589,8 +2029,10 @@ final class SettingsStore: ObservableObject {var languageSupport: String {switch self {- case .parakeetTDT: return "25 Languages"+ case .parakeetTDT:+ return "25 European Languages"case .parakeetTDTv2: return "English Only (Higher Accuracy)"+ case .qwen3Asr: return "30 Languages"case .appleSpeech: return "System Languages"case .appleSpeechAnalyzer: return "EN, ES, FR, DE, IT, JA, KO, PT, ZH"case .whisperTiny, .whisperBase, .whisperSmall, .whisperMedium, .whisperLargeTurbo, .whisperLarge:@@ -1602,6 +2044,7 @@ final class SettingsStore: ObservableObject {switch self {case .parakeetTDT: return "~500 MB"case .parakeetTDTv2: return "~500 MB"+ case .qwen3Asr: return "~2.0 GB"case .appleSpeech: return "Built-in (Zero Download)"case .appleSpeechAnalyzer: return "Built-in"case .whisperTiny: return "~75 MB"@@ -1615,14 +2058,14 @@ final class SettingsStore: ObservableObject {var requiresAppleSilicon: Bool {switch self {- case .parakeetTDT, .parakeetTDTv2: return true+ case .parakeetTDT, .parakeetTDTv2, .qwen3Asr: return truedefault: return false}}var isWhisperModel: Bool {switch self {- case .parakeetTDT, .parakeetTDTv2, .appleSpeech, .appleSpeechAnalyzer: return false+ case .parakeetTDT, .parakeetTDTv2, .qwen3Asr, .appleSpeech, .appleSpeechAnalyzer: return falsedefault: return true}}@@ -1663,16 +2106,31 @@ final class SettingsStore: ObservableObject {}}+ /// Requires macOS 15 or later.+ var requiresMacOS15: Bool {+ switch self {+ case .qwen3Asr: return true+ default: return false+ }+ }+/// Returns models available for the current Mac's architecture and OSstatic var availableModels: [SpeechModel] {allCases.filter { model inif model == .whisperLargeTurbo {return false}+ if model == .qwen3Asr, !Self.qwenPreviewEnabled {+ return false+ }// Filter by Apple Silicon requirementif model.requiresAppleSilicon, !CPUArchitecture.isAppleSilicon {return false}+ // Filter by macOS 15 requirement+ if model.requiresMacOS15, #unavailable(macOS 15.0) {+ return false+ }// Filter by macOS 26 requirementif model.requiresMacOS26 {if #available(macOS 26.0, *) {@@ -1697,6 +2155,7 @@ final class SettingsStore: ObservableObject {switch self {case .parakeetTDT: return "Blazing Fast - Multilingual"case .parakeetTDTv2: return "Blazing Fast - English"+ case .qwen3Asr: return "Qwen3 - Multilingual"case .appleSpeech: return "Apple ASR Legacy"case .appleSpeechAnalyzer: return "Apple Speech - macOS 26+"case .whisperTiny: return "Fast & Light"@@ -1715,6 +2174,8 @@ final class SettingsStore: ObservableObject {return "Fast multilingual transcription with 25 languages. Best for everyday use."case .parakeetTDTv2:return "Optimized for English accuracy and fastest transcription."+ case .qwen3Asr:+ return "Qwen3 multilingual ASR via FluidAudio. Higher quality, heavier memory footprint."case .appleSpeech:return "Built-in macOS speech recognition. No download required."case .appleSpeechAnalyzer:@@ -1739,6 +2200,8 @@ final class SettingsStore: ObservableObject {switch self {case .parakeetTDT, .parakeetTDTv2:return 4.0+ case .qwen3Asr:+ return 8.0case .appleSpeech, .appleSpeechAnalyzer:return 2.0 // Built-in, minimal overheadcase .whisperTiny:@@ -1759,6 +2222,8 @@ final class SettingsStore: ObservableObject {/// Warning text for models with high memory requirements, nil if no warning neededvar memoryWarning: String? {switch self {+ case .qwen3Asr:+ return "⚠️ Requires 8GB+ RAM. Best on newer Apple Silicon Macs."case .whisperLarge:return "⚠️ Requires 10GB+ RAM. May crash on systems with limited memory."case .whisperLargeTurbo:@@ -1775,6 +2240,7 @@ final class SettingsStore: ObservableObject {switch self {case .parakeetTDT: return 5case .parakeetTDTv2: return 5+ case .qwen3Asr: return 3case .appleSpeech: return 4case .appleSpeechAnalyzer: return 4case .whisperTiny: return 4@@ -1791,6 +2257,7 @@ final class SettingsStore: ObservableObject {switch self {case .parakeetTDT: return 5case .parakeetTDTv2: return 5+ case .qwen3Asr: return 4case .appleSpeech: return 4case .appleSpeechAnalyzer: return 4case .whisperTiny: return 2@@ -1807,6 +2274,7 @@ final class SettingsStore: ObservableObject {switch self {case .parakeetTDT: return 1.0case .parakeetTDTv2: return 1.0+ case .qwen3Asr: return 0.45case .appleSpeech: return 0.60case .appleSpeechAnalyzer: return 0.85case .whisperTiny: return 0.90@@ -1823,6 +2291,7 @@ final class SettingsStore: ObservableObject {switch self {case .parakeetTDT: return 0.95case .parakeetTDTv2: return 0.98+ case .qwen3Asr: return 0.90case .appleSpeech: return 0.60case .appleSpeechAnalyzer: return 0.80case .whisperTiny: return 0.40@@ -1839,6 +2308,7 @@ final class SettingsStore: ObservableObject {switch self {case .parakeetTDT: return "FluidVoice Pick"case .parakeetTDTv2: return "FluidVoice Pick"+ case .qwen3Asr: return "Beta"case .appleSpeechAnalyzer: return "New"default: return nil}@@ -1847,7 +2317,7 @@ final class SettingsStore: ObservableObject {/// Optimization level for Apple Silicon (for display)var appleSiliconOptimized: Bool {switch self {- case .parakeetTDT, .parakeetTDTv2, .appleSpeechAnalyzer:+ case .parakeetTDT, .parakeetTDTv2, .qwen3Asr, .appleSpeechAnalyzer:return truedefault:return false@@ -1858,7 +2328,7 @@ final class SettingsStore: ObservableObject {/// Large Whisper models are too slow for streaming, so they only do final transcription on stop.var supportsStreaming: Bool {switch self {- case .whisperMedium, .whisperLargeTurbo, .whisperLarge:+ case .qwen3Asr, .whisperMedium, .whisperLargeTurbo, .whisperLarge:return false // Too slow for real-time chunk processingdefault:return true // All other models support streaming@@ -1870,6 +2340,7 @@ final class SettingsStore: ObservableObject {case nvidia = "NVIDIA"case apple = "Apple"case openai = "OpenAI"+ case qwen = "Qwen"}/// Which provider this model belongs to@@ -1879,6 +2350,8 @@ final class SettingsStore: ObservableObject {return .nvidiacase .appleSpeech, .appleSpeechAnalyzer:return .apple+ case .qwen3Asr:+ return .qwencase .whisperTiny, .whisperBase, .whisperSmall, .whisperMedium, .whisperLargeTurbo, .whisperLarge:return .openai}@@ -1900,6 +2373,15 @@ final class SettingsStore: ObservableObject {case .parakeetTDTv2:// Hardcoded path check for NVIDIA v2return Self.parakeetCacheDirectory(version: "parakeet-tdt-0.6b-v2-coreml")+ case .qwen3Asr:+ #if canImport(FluidAudio) && ENABLE_QWEN+ if #available(macOS 15.0, *) {+ return Qwen3AsrModels.modelsExist(at: Qwen3AsrModels.defaultCacheDirectory())+ }+ return false+ #else+ return false+ #endifdefault:// Whisper modelsguard let whisperFile = self.whisperModelFile else { return false }@@ -1927,6 +2409,8 @@ final class SettingsStore: ObservableObject {switch self {case .parakeetTDT, .parakeetTDTv2:return "NVIDIA"+ case .qwen3Asr:+ return "Qwen"case .appleSpeech, .appleSpeechAnalyzer:return "Apple"case .whisperTiny, .whisperBase, .whisperSmall, .whisperMedium, .whisperLargeTurbo, .whisperLarge:@@ -1947,6 +2431,8 @@ final class SettingsStore: ObservableObject {switch self {case .parakeetTDT, .parakeetTDTv2:return "#76B900"+ case .qwen3Asr:+ return "#E67E22"case .appleSpeech, .appleSpeechAnalyzer:return "#A2AAAD" // Apple Graycase .whisperTiny, .whisperBase, .whisperSmall, .whisperMedium, .whisperLargeTurbo, .whisperLarge:@@ -1982,37 +2468,6 @@ final class SettingsStore: ObservableObject {}}- /// Available Whisper model sizes- enum WhisperModelSize: String, CaseIterable, Identifiable {- case tiny = "ggml-tiny.bin"- case base = "ggml-base.bin"- case small = "ggml-small.bin"- case medium = "ggml-medium.bin"- case large = "ggml-large-v3.bin"-- var id: String { rawValue }-- var displayName: String {- switch self {- case .tiny: return "Tiny (~75 MB)"- case .base: return "Base (~142 MB)"- case .small: return "Small (~466 MB)"- case .medium: return "Medium (~1.5 GB)"- case .large: return "Large (~2.9 GB)"- }- }-- var description: String {- switch self {- case .tiny: return "Fastest, lower accuracy"- case .base: return "Good balance of speed and accuracy"- case .small: return "Better accuracy, slower"- case .medium: return "High accuracy, requires more memory"- case .large: return "Best accuracy, large download"- }- }- }-/// Selected transcription provider - defaults to "auto" which picks based on architecturevar selectedTranscriptionProvider: TranscriptionProviderOption {get {@@ -2044,7 +2499,157 @@ final class SettingsStore: ObservableObject {self.defaults.set(newValue.rawValue, forKey: Keys.whisperModelSize)}}+}+private extension SettingsStore {+ // Keys+ enum Keys {+ static let enableAIProcessing = "EnableAIProcessing"+ static let enableDebugLogs = "EnableDebugLogs"+ static let availableAIModels = "AvailableAIModels"+ static let availableModelsByProvider = "AvailableModelsByProvider"+ static let selectedAIModel = "SelectedAIModel"+ static let selectedModelByProvider = "SelectedModelByProvider"+ static let selectedProviderID = "SelectedProviderID"+ static let providerAPIKeys = "ProviderAPIKeys"+ static let providerAPIKeyIdentifiers = "ProviderAPIKeyIdentifiers"+ static let savedProviders = "SavedProviders"+ static let verifiedProviderFingerprints = "VerifiedProviderFingerprints"+ static let shareAnonymousAnalytics = "ShareAnonymousAnalytics"+ static let fluid1InterestCaptured = "Fluid1InterestCaptured"+ static let hotkeyShortcutKey = "HotkeyShortcutKey"+ static let preferredInputDeviceUID = "PreferredInputDeviceUID"+ static let preferredOutputDeviceUID = "PreferredOutputDeviceUID"+ static let syncAudioDevicesWithSystem = "SyncAudioDevicesWithSystem"+ static let visualizerNoiseThreshold = "VisualizerNoiseThreshold"+ static let launchAtStartup = "LaunchAtStartup"+ static let showInDock = "ShowInDock"+ static let accentColorOption = "AccentColorOption"+ static let enableTranscriptionSounds = "EnableTranscriptionSounds"+ static let transcriptionStartSound = "TranscriptionStartSound"+ static let pressAndHoldMode = "PressAndHoldMode"+ static let enableStreamingPreview = "EnableStreamingPreview"+ static let enableAIStreaming = "EnableAIStreaming"+ static let copyTranscriptionToClipboard = "CopyTranscriptionToClipboard"+ static let autoUpdateCheckEnabled = "AutoUpdateCheckEnabled"+ static let lastUpdateCheckDate = "LastUpdateCheckDate"+ static let updatePromptSnoozedUntil = "UpdatePromptSnoozedUntil"+ static let snoozedUpdateVersion = "SnoozedUpdateVersion"+ static let playgroundUsed = "PlaygroundUsed"+ static let onboardingCompleted = "OnboardingCompleted"+ static let onboardingCurrentStep = "OnboardingCurrentStep"+ static let onboardingAISkipped = "OnboardingAISkipped"+ static let onboardingPlaygroundValidated = "OnboardingPlaygroundValidated"++ // Command Mode Keys+ static let commandModeSelectedModel = "CommandModeSelectedModel"+ static let commandModeSelectedProviderID = "CommandModeSelectedProviderID"+ static let commandModeHotkeyShortcut = "CommandModeHotkeyShortcut"+ static let commandModeConfirmBeforeExecute = "CommandModeConfirmBeforeExecute"+ static let commandModeLinkedToGlobal = "CommandModeLinkedToGlobal"+ static let commandModeShortcutEnabled = "CommandModeShortcutEnabled"++ // Rewrite Mode Keys+ static let rewriteModeHotkeyShortcut = "RewriteModeHotkeyShortcut"+ static let rewriteModeSelectedModel = "RewriteModeSelectedModel"+ static let rewriteModeSelectedProviderID = "RewriteModeSelectedProviderID"+ static let rewriteModeLinkedToGlobal = "RewriteModeLinkedToGlobal"++ // Model Reasoning Config Keys+ static let modelReasoningConfigs = "ModelReasoningConfigs"+ static let rewriteModeShortcutEnabled = "RewriteModeShortcutEnabled"+ static let showThinkingTokens = "ShowThinkingTokens"++ // Stats Keys+ static let userTypingWPM = "UserTypingWPM"+ static let saveTranscriptionHistory = "SaveTranscriptionHistory"++ // Filler Words+ static let fillerWords = "FillerWords"+ static let removeFillerWordsEnabled = "RemoveFillerWordsEnabled"++ // GAAV Mode (removes capitalization and trailing punctuation)+ static let gaavModeEnabled = "GAAVModeEnabled"++ // Custom Dictionary+ static let customDictionaryEntries = "CustomDictionaryEntries"+ static let vocabularyBoostingEnabled = "VocabularyBoostingEnabled"++ // Transcription Provider (ASR)+ static let selectedTranscriptionProvider = "SelectedTranscriptionProvider"+ static let whisperModelSize = "WhisperModelSize"++ // Unified Speech Model (replaces above two)+ static let selectedSpeechModel = "SelectedSpeechModel"++ // Overlay Position+ static let overlayPosition = "OverlayPosition"+ static let overlayBottomOffset = "OverlayBottomOffset"+ static let overlayBottomOffsetMigratedTo50 = "OverlayBottomOffsetMigratedTo50"+ static let overlaySize = "OverlaySize"+ static let transcriptionPreviewCharLimit = "TranscriptionPreviewCharLimit"++ // Media Playback Control+ static let pauseMediaDuringTranscription = "PauseMediaDuringTranscription"++ // Custom Dictation Prompt+ static let customDictationPrompt = "CustomDictationPrompt"++ // Dictation Prompt Profiles (multi-prompt system)+ static let dictationPromptProfiles = "DictationPromptProfiles"+ static let selectedDictationPromptID = "SelectedDictationPromptID"+ static let selectedEditPromptID = "SelectedEditPromptID"+ static let selectedWritePromptID = "SelectedWritePromptID" // legacy fallback key+ static let selectedRewritePromptID = "SelectedRewritePromptID" // legacy fallback key++ // Default Dictation Prompt Override (optional)+ // nil => use built-in default prompt+ // "" => use empty system prompt+ // other => use custom default prompt text+ static let defaultDictationPromptOverride = "DefaultDictationPromptOverride"+ static let defaultEditPromptOverride = "DefaultEditPromptOverride"+ static let defaultWritePromptOverride = "DefaultWritePromptOverride" // legacy fallback key+ static let defaultRewritePromptOverride = "DefaultRewritePromptOverride" // legacy fallback key++ // Streak Settings+ static let weekendsDontBreakStreak = "WeekendsDontBreakStreak"+ }+}++extension SettingsStore {+ /// Available Whisper model sizes+ enum WhisperModelSize: String, CaseIterable, Identifiable {+ case tiny = "ggml-tiny.bin"+ case base = "ggml-base.bin"+ case small = "ggml-small.bin"+ case medium = "ggml-medium.bin"+ case large = "ggml-large-v3.bin"++ var id: String { rawValue }++ var displayName: String {+ switch self {+ case .tiny: return "Tiny (~75 MB)"+ case .base: return "Base (~142 MB)"+ case .small: return "Small (~466 MB)"+ case .medium: return "Medium (~1.5 GB)"+ case .large: return "Large (~2.9 GB)"+ }+ }++ var description: String {+ switch self {+ case .tiny: return "Fastest, lower accuracy"+ case .base: return "Good balance of speed and accuracy"+ case .small: return "Better accuracy, slower"+ case .medium: return "High accuracy, requires more memory"+ case .large: return "Best accuracy, large download"+ }+ }+ }+}++extension SettingsStore {// MARK: - Unified Speech Model Selection/// The selected speech recognition model.@@ -2055,10 +2660,20 @@ final class SettingsStore: ObservableObject {if let rawValue = defaults.string(forKey: Keys.selectedSpeechModel),let model = SpeechModel(rawValue: rawValue){+ // If Qwen was previously selected, transparently fall back while preview is disabled.+ if model == .qwen3Asr, !SpeechModel.qwenPreviewEnabled {+ return SpeechModel.defaultModel+ }// Validate model is available on this architectureif model.requiresAppleSilicon && !CPUArchitecture.isAppleSilicon {return .whisperBase}+ if model.requiresMacOS15, #unavailable(macOS 15.0) {+ return .whisperBase+ }+ if model.requiresMacOS26, #unavailable(macOS 26.0) {+ return .whisperBase+ }return model}diff --git a/Sources/Fluid/Resources/FV_start.m4a b/Sources/Fluid/Resources/FV_start.m4aindex 5115d139..902c5622 100644Binary files a/Sources/Fluid/Resources/FV_start.m4a and b/Sources/Fluid/Resources/FV_start.m4a differdiff --git a/Sources/Fluid/Resources/parakeet_custom_vocabulary.default.json b/Sources/Fluid/Resources/parakeet_custom_vocabulary.default.jsonnew file mode 100644index 00000000..6a643be0--- /dev/null+++ b/Sources/Fluid/Resources/parakeet_custom_vocabulary.default.json@@ -0,0 +1,14 @@+{+ "alpha": 2.8,+ "minCtcScore": -2.2,+ "minSimilarity": 0.72,+ "minCombinedConfidence": 0.64,+ "minTermLength": 3,+ "terms": [+ {+ "text": "FluidVoice",+ "aliases": ["fluid voice", "fluid boys"],+ "weight": 10.0+ }+ ]+}diff --git a/Sources/Fluid/Resources/sfx_3.m4a b/Sources/Fluid/Resources/sfx_3.m4aindex 128c6a69..16c249c6 100644Binary files a/Sources/Fluid/Resources/sfx_3.m4a and b/Sources/Fluid/Resources/sfx_3.m4a differdiff --git a/Sources/Fluid/Resources/sfx_4.m4a b/Sources/Fluid/Resources/sfx_4.m4aindex 7ade3208..eeb3b4ba 100644Binary files a/Sources/Fluid/Resources/sfx_4.m4a and b/Sources/Fluid/Resources/sfx_4.m4a differdiff --git a/Sources/Fluid/Services/ASRService.swift b/Sources/Fluid/Services/ASRService.swiftindex a1a57eda..c695651e 100644--- a/Sources/Fluid/Services/ASRService.swift+++ b/Sources/Fluid/Services/ASRService.swift@@ -101,6 +101,7 @@ final class ASRService: ObservableObject {@Published var isRunning: Bool = false@Published var finalText: String = ""@Published var partialTranscription: String = ""+ @Published var wordBoostStatusText: String = "Word boost: off"@Published var micStatus: AVAuthorizationStatus = .notDetermined@Published var isAsrReady: Bool = false@Published var isDownloadingModel: Bool = false@@ -112,7 +113,10 @@ final class ASRService: ObservableObject {private var isStarting: Bool = false // Guard against re-entrant start() callsprivate var downloadProgressTask: Task<Void, Never>?private var hasCompletedFirstTranscription: Bool = false // Track if model has warmed up with first transcription+ private var lastBoostHitTerm: String?+ private var hasPendingParakeetVocabularyReload: Bool = falseprivate let downloadRegistry = ModelDownloadRegistry()+ private var vocabularyChangeObserver: NSObjectProtocol?// MARK: - Error Handling@@ -160,6 +164,12 @@ final class ASRService: ObservableObject {return self.getAppleSpeechProvider()case .parakeetTDT, .parakeetTDTv2:return self.getFluidAudioProvider()+ case .qwen3Asr:+ DebugLogger.shared.warning(+ "ASRService: Qwen provider removed; falling back to FluidAudio Parakeet path",+ source: "ASRService"+ )+ return self.getFluidAudioProvider()default:return self.getWhisperProvider()}@@ -169,9 +179,14 @@ final class ASRService: ObservableObject {if let existing = fluidAudioProvider {return existing}- let provider = FluidAudioProvider()+ let provider = FluidAudioProvider(+ configureWordBoosting: SettingsStore.shared.vocabularyBoostingEnabled+ )self.fluidAudioProvider = provider- DebugLogger.shared.info("ASRService: Created FluidAudio provider", source: "ASRService")+ DebugLogger.shared.info(+ "ASRService: Created FluidAudio provider [vocabBoosting=\(SettingsStore.shared.vocabularyBoostingEnabled)]",+ source: "ASRService"+ )return provider}@@ -231,8 +246,11 @@ final class ASRService: ObservableObject {return AppleSpeechProvider()case .parakeetTDT, .parakeetTDTv2:// Create a new provider configured for the specific model- let provider = FluidAudioProvider(modelOverride: model)+ let provider = FluidAudioProvider(modelOverride: model, configureWordBoosting: false)return provider+ case .qwen3Asr:+ // Qwen support removed; route legacy requests to Parakeet v3.+ return FluidAudioProvider(modelOverride: .parakeetTDT, configureWordBoosting: false)default:// Whisper models - create provider with specific model overridelet provider = WhisperProvider(modelOverride: model)@@ -300,6 +318,8 @@ final class ASRService: ObservableObject {self.ensureReadyTask?.cancel()self.ensureReadyTask = nilself.ensureReadyProviderKey = nil+ self.lastBoostHitTerm = nil+ self.wordBoostStatusText = "Word boost: off"// Reset cached providers to force re-initialization with new settingsself.fluidAudioProvider = nil@@ -313,6 +333,9 @@ final class ASRService: ObservableObject {Task { [weak self] inguard let self = self else { return }await self.checkIfModelsExistAsync()+ await MainActor.run {+ self.refreshWordBoostStatus()+ }DebugLogger.shared.info("ASRService: Provider reset complete, will initialize '\(newModel.displayName)' on next use", source: "ASRService")}}@@ -397,6 +420,90 @@ final class ASRService: ObservableObject {// - micStatus = .notDetermined// - micPermissionGranted = false// - modelsExistOnDisk = false+ self.vocabularyChangeObserver = NotificationCenter.default.addObserver(+ forName: .parakeetVocabularyDidChange,+ object: nil,+ queue: .main+ ) { [weak self] _ in+ Task { @MainActor [weak self] in+ self?.handleParakeetVocabularyDidChange()+ }+ }+ }++ deinit {+ if let observer = self.vocabularyChangeObserver {+ NotificationCenter.default.removeObserver(observer)+ }+ }++ @MainActor+ private func handleParakeetVocabularyDidChange() {+ let model = SettingsStore.shared.selectedSpeechModel+ guard model == .parakeetTDT || model == .parakeetTDTv2 else { return }+ guard self.isRunning == false else {+ self.hasPendingParakeetVocabularyReload = true+ DebugLogger.shared.info(+ "ASRService: Vocabulary changed while recording; queued reload for when recording stops.",+ source: "ASRService"+ )+ return+ }+ self.hasPendingParakeetVocabularyReload = false+ self.resetTranscriptionProvider()+ }++ @MainActor+ private func applyPendingParakeetVocabularyReloadIfNeeded() {+ guard self.hasPendingParakeetVocabularyReload else { return }++ self.hasPendingParakeetVocabularyReload = false+ let model = SettingsStore.shared.selectedSpeechModel+ guard model == .parakeetTDT || model == .parakeetTDTv2 else { return }++ DebugLogger.shared.info(+ "ASRService: Applying queued vocabulary reload after recording stopped.",+ source: "ASRService"+ )+ self.resetTranscriptionProvider()+ }++ private func refreshWordBoostStatus() {+ let model = SettingsStore.shared.selectedSpeechModel+ guard model == .parakeetTDT || model == .parakeetTDTv2,+ let provider = self.fluidAudioProvider,+ provider.isReady+ else {+ self.wordBoostStatusText = "Word boost: off"+ return+ }++ if provider.isWordBoostingActive {+ let count = provider.boostedVocabularyTermsCount+ if let lastHit = self.lastBoostHitTerm, !lastHit.isEmpty {+ self.wordBoostStatusText = "Word boost: ON (\(count) terms) • last hit: \(lastHit)"+ } else {+ self.wordBoostStatusText = "Word boost: ON (\(count) terms) • no hit yet"+ }+ } else {+ self.wordBoostStatusText = "Word boost: ON (0 terms loaded)"+ }+ }++ private func recordWordBoostHitIfAny(transcribedText: String) {+ let model = SettingsStore.shared.selectedSpeechModel+ guard model == .parakeetTDT || model == .parakeetTDTv2,+ let provider = self.fluidAudioProvider,+ provider.isWordBoostingActive+ else { return }++ let hits = provider.detectBoostedTerms(in: transcribedText, limit: 1)+ guard let hit = hits.first else { return }+ if hit != self.lastBoostHitTerm {+ self.lastBoostHitTerm = hit+ DebugLogger.shared.info("BOOST_HIT: '\(hit)'", source: "ASRService")+ }+ self.refreshWordBoostStatus()}/// Call this AFTER the app has finished launching to complete ASR initialization.@@ -521,10 +628,12 @@ final class ASRService: ObservableObject {self.audioBuffer.clear(keepingCapacity: true) // specific optimization for restartself.partialTranscription.removeAll()self.previousFullTranscription.removeAll()+ self.lastBoostHitTerm = nilself.lastProcessedSampleCount = 0self.isProcessingChunk = falseself.skipNextChunk = falseself.audioCapturePipeline.setRecordingEnabled(true)+ self.refreshWordBoostStatus()DebugLogger.shared.debug("✅ Buffers cleared", source: "ASRService")self.isStarting = true@@ -643,6 +752,7 @@ final class ASRService: ObservableObject {DebugLogger.shared.warning("⚠️ STOP() - not running, returning empty string", source: "ASRService")return ""}+ defer { self.applyPendingParakeetVocabularyReloadIfNeeded() }// Capture media pause state before we reset it, for resuming at the endlet shouldResumeMedia = SettingsStore.shared.pauseMediaDuringTranscription && self.didPauseMediaForThisSession@@ -728,7 +838,7 @@ final class ASRService: ObservableObject {DebugLogger.shared.debug("📝 Starting transcription executor...", source: "ASRService")let result = try await transcriptionExecutor.run { [provider = self.transcriptionProvider] inDebugLogger.shared.debug("📝 Inside transcription executor closure", source: "ASRService")- let transcriptionResult = try await provider.transcribe(pcm)+ let transcriptionResult = try await provider.transcribeFinal(pcm)DebugLogger.shared.debug("📝 Transcription provider returned", source: "ASRService")return transcriptionResult}@@ -750,6 +860,7 @@ final class ASRService: ObservableObject {// Do not update self.finalText here to avoid instant binding insert in playgroundlet cleanedText = ASRService.applyCustomDictionary(ASRService.removeFillerWords(result.text))+ self.recordWordBoostHitIfAny(transcribedText: cleanedText)DebugLogger.shared.debug("After post-processing: '\(cleanedText)'", source: "ASRService")// Resume media playback if we paused it@@ -793,6 +904,7 @@ final class ASRService: ObservableObject {func stopWithoutTranscription() async {guard self.isRunning else { return }+ defer { self.applyPendingParakeetVocabularyReloadIfNeeded() }// Capture media pause state before we reset it, for resuming at the endlet shouldResumeMedia = SettingsStore.shared.pauseMediaDuringTranscription && self.didPauseMediaForThisSession@@ -813,10 +925,14 @@ final class ASRService: ObservableObject {self.engine.stop()DebugLogger.shared.debug("Engine stopped", source: "ASRService")- // Recreate engine instance to release resources (same as stop())- DebugLogger.shared.debug("🗑️ Deallocating old engine and creating fresh instance...", source: "ASRService")+ // Release old engine on a background thread — if the underlying device just died,+ // AVAudioEngine deallocation can block in CoreAudio's internal teardown.+ // No new engine is created here (it's lazy on next start()), so no overlap risk.+ let oldEngine = self.engineStorageself.engineStorage = nil- DebugLogger.shared.debug("✅ Engine instance recreated", source: "ASRService")+ if let oldEngine {+ DispatchQueue.global(qos: .utility).async { _ = oldEngine }+ }// CRITICAL FIX: Await completion of streaming task AND any pending transcriptions// This prevents use-after-free crashes (EXC_BAD_ACCESS) when clearing buffer@@ -826,9 +942,11 @@ final class ASRService: ObservableObject {self.audioBuffer.clear()self.partialTranscription.removeAll()self.previousFullTranscription.removeAll()+ self.lastBoostHitTerm = nilself.lastProcessedSampleCount = 0self.isProcessingChunk = falseself.skipNextChunk = false+ self.refreshWordBoostStatus()// Resume media playback if we paused itif shouldResumeMedia {@@ -1361,7 +1479,10 @@ final class ASRService: ObservableObject {mElement: kAudioObjectPropertyElementMain)let token: AudioObjectPropertyListenerBlock = { [weak self] _, _ in- self?.handleDefaultInputChanged()+ // Defer to next runloop pass — CoreAudio may hold an internal lock during+ // this callback, and our handler makes synchronous CoreAudio queries that+ // would deadlock waiting for the same lock.+ DispatchQueue.main.async { self?.handleDefaultInputChanged() }}let status = AudioObjectAddPropertyListenerBlock(AudioObjectID(kAudioObjectSystemObject),@@ -1396,7 +1517,10 @@ final class ASRService: ObservableObject {)let token: AudioObjectPropertyListenerBlock = { [weak self] _, _ in- self?.handleDeviceListChanged()+ // Defer to next runloop pass — CoreAudio may hold an internal lock during+ // this callback, and our handler makes synchronous CoreAudio queries that+ // would deadlock waiting for the same lock.+ DispatchQueue.main.async { self?.handleDeviceListChanged() }}let status = AudioObjectAddPropertyListenerBlock(AudioObjectID(kAudioObjectSystemObject),@@ -1428,7 +1552,7 @@ final class ASRService: ObservableObject {)let token: AudioObjectPropertyListenerBlock = { [weak self] _, _ in- self?.handleDeviceAvailabilityChanged(deviceID: deviceID)+ DispatchQueue.main.async { self?.handleDeviceAvailabilityChanged(deviceID: deviceID) }}let status = AudioObjectAddPropertyListenerBlock(deviceID,@@ -1470,71 +1594,73 @@ final class ASRService: ObservableObject {private func handleDeviceListChanged() {DebugLogger.shared.info("🔄 Device list changed - checking for new/removed devices", source: "ASRService")- // Get current device list- let currentDevices = AudioDevice.listInputDevices()- DebugLogger.shared.debug("Current input devices: \(currentDevices.map { $0.name }.joined(separator: ", "))", source: "ASRService")-- // Check if preferred device is now available (for auto-switch)- if let preferredUID = SettingsStore.shared.preferredInputDeviceUID,- let preferredDevice = currentDevices.first(where: { $0.uid == preferredUID })- {- // If we're currently using a fallback (system default), switch to preferred device+ // Perform CoreAudio queries off the main thread — during a device topology change+ // the HAL may still be settling, and synchronous queries on main can deadlock.+ let preferredUID = SettingsStore.shared.preferredInputDeviceUID+ DispatchQueue.global(qos: .userInitiated).async { [weak self] in+ let currentDevices = AudioDevice.listInputDevices()let systemDefault = AudioDevice.getDefaultInputDevice()- if let currentDevice = getCurrentlyBoundInputDevice(),- currentDevice.uid != preferredUID,- currentDevice.uid == systemDefault?.uid- {- DebugLogger.shared.info(- "🔌 Preferred device '\(preferredDevice.name)' reconnected. Auto-switching...",- source: "ASRService"- )- // If recording, restart with new device- if self.isRunning {- DebugLogger.shared.info("Recording in progress - restarting engine with preferred device", source: "ASRService")- self.restartEngineWithDevice(preferredDevice)- } else {- // Just update the binding for next recording- DebugLogger.shared.info("Not recording - updating binding for next session", source: "ASRService")- _ = self.setEngineInputDevice(- deviceID: preferredDevice.id,- deviceUID: preferredDevice.uid,- deviceName: preferredDevice.name- )+ DispatchQueue.main.async { [weak self] in+ guard let self else { return }+ let cachedUIDs = self.cachedDeviceUIDs++ DebugLogger.shared.debug("Current input devices: \(currentDevices.map { $0.name }.joined(separator: ", "))", source: "ASRService")++ // Check if preferred device is now available (for auto-switch)+ if let preferredUID,+ let preferredDevice = currentDevices.first(where: { $0.uid == preferredUID })+ {+ if let currentDevice = self.getCurrentlyBoundInputDevice(),+ currentDevice.uid != preferredUID,+ currentDevice.uid == systemDefault?.uid+ {+ DebugLogger.shared.info(+ "🔌 Preferred device '\(preferredDevice.name)' reconnected. Auto-switching...",+ source: "ASRService"+ )++ if self.isRunning {+ DebugLogger.shared.info("Recording in progress - restarting engine with preferred device", source: "ASRService")+ self.restartEngineWithDevice(preferredDevice)+ } else {+ DebugLogger.shared.info("Not recording - updating binding for next session", source: "ASRService")+ _ = self.setEngineInputDevice(+ deviceID: preferredDevice.id,+ deviceUID: preferredDevice.uid,+ deviceName: preferredDevice.name+ )+ }+ }}- }- }-- // Check for newly connected Bluetooth devices (auto-switch)- for device in currentDevices {- if device.name.localizedCaseInsensitiveContains("airpods") ||- device.name.localizedCaseInsensitiveContains("bluetooth")- {- // Check if this is a newly appeared device- let wasAvailable = self.checkDeviceWasAvailable(device.uid)- if !wasAvailable {- DebugLogger.shared.info(- "🎧 New Bluetooth device detected: '\(device.name)'. Auto-switching...",- source: "ASRService"- )- // Update preferred device setting- SettingsStore.shared.preferredInputDeviceUID = device.uid- DebugLogger.shared.debug("Updated preferred input device to: \(device.uid)", source: "ASRService")-- // If recording, restart with new device- if self.isRunning {- DebugLogger.shared.info("Recording in progress - restarting engine with new Bluetooth device", source: "ASRService")- self.restartEngineWithDevice(device)- } else {- DebugLogger.shared.info("Not recording - Bluetooth device will be used on next recording", source: "ASRService")+ // Check for newly connected Bluetooth devices (auto-switch)+ for device in currentDevices {+ if device.name.localizedCaseInsensitiveContains("airpods") ||+ device.name.localizedCaseInsensitiveContains("bluetooth")+ {+ if !cachedUIDs.contains(device.uid) {+ DebugLogger.shared.info(+ "🎧 New Bluetooth device detected: '\(device.name)'. Auto-switching...",+ source: "ASRService"+ )++ SettingsStore.shared.preferredInputDeviceUID = device.uid+ DebugLogger.shared.debug("Updated preferred input device to: \(device.uid)", source: "ASRService")++ if self.isRunning {+ DebugLogger.shared.info("Recording in progress - restarting engine with new Bluetooth device", source: "ASRService")+ self.restartEngineWithDevice(device)+ } else {+ DebugLogger.shared.info("Not recording - Bluetooth device will be used on next recording", source: "ASRService")+ }+ }}}++ self.cacheCurrentDeviceList(currentDevices)}}-- // Cache device list for next comparison- self.cacheCurrentDeviceList(currentDevices)}/// Handles device availability changes (device disconnected or reconnected)@@ -1557,29 +1683,65 @@ final class ASRService: ObservableObject {if status == noErr, isAlive == 0 {// Device disconnectedDebugLogger.shared.warning("❌ Monitored device (ID: \(deviceID)) DISCONNECTED", source: "ASRService")+ self.stopMonitoringDevice()if self.isRunning {- // Cancel recording if device disconnects during recording- DebugLogger.shared.error(- "🛑 Recording CANCELLED: Audio device disconnected during recording",+ // Instead of cancelling, try to hot-swap to another available device+ // so the recording continues seamlessly.+ DebugLogger.shared.info(+ "🔄 Device died during recording — attempting hot-swap to fallback device",source: "ASRService")- Task { @MainActor in- await self.stopWithoutTranscription()+ self.removeEngineTap()+ self.engine.stop()+ // Release dead engine on background thread (dealloc can block in CoreAudio)+ let oldEngine = self.engineStorage+ self.engineStorage = nil+ if let oldEngine {+ DispatchQueue.global(qos: .utility).async { _ = oldEngine }+ }- // Notify user- NotificationCenter.default.post(- name: NSNotification.Name("ASRServiceDeviceDisconnected"),- object: nil,- userInfo: ["errorMessage": "Recording cancelled: Audio device disconnected"]- )+ // Query available devices off-main after a short delay for CoreAudio to settle+ DispatchQueue.global(qos: .userInitiated).async { [weak self] in+ Thread.sleep(forTimeInterval: 0.3)+ let availableInputs = AudioDevice.listInputDevices()+ let defaultDevice = AudioDevice.getDefaultInputDevice()++ DispatchQueue.main.async { [weak self] in+ guard let self, self.isRunning else { return }++ guard let fallback = defaultDevice ?? availableInputs.first else {+ DebugLogger.shared.error("🛑 No fallback device — cancelling recording", source: "ASRService")+ Task { @MainActor in+ await self.stopWithoutTranscription()+ NotificationCenter.default.post(+ name: NSNotification.Name("ASRServiceDeviceDisconnected"),+ object: nil,+ userInfo: ["errorMessage": "Recording cancelled: No audio device available"]+ )+ }+ return+ }++ DebugLogger.shared.info("🔄 Hot-swapping to: '\(fallback.name)'", source: "ASRService")+ do {+ try self.configureSession()+ _ = self.setEngineInputDevice(+ deviceID: fallback.id, deviceUID: fallback.uid, deviceName: fallback.name+ )+ try self.startEngine()+ try self.setupEngineTap()+ self.startMonitoringDevice(fallback.id)+ DebugLogger.shared.info("✅ Hot-swap successful — recording continues with '\(fallback.name)'", source: "ASRService")+ } catch {+ DebugLogger.shared.error("❌ Hot-swap failed: \(error)", source: "ASRService")+ Task { @MainActor in await self.stopWithoutTranscription() }+ }+ }}} else {DebugLogger.shared.info("Not recording - device disconnect handled gracefully", source: "ASRService")- // Just stop monitoring - don't try to set engine device when engine may not exist- self.stopMonitoringDevice()- DebugLogger.shared.info("✅ Stopped monitoring disconnected device", source: "ASRService")}} else if status == noErr, isAlive != 0 {DebugLogger.shared.info("✅ Device (ID: \(deviceID)) is still alive", source: "ASRService")@@ -1659,10 +1821,6 @@ final class ASRService: ObservableObject {// Device caching for change detectionprivate var cachedDeviceUIDs: Set<String> = []- private func checkDeviceWasAvailable(_ uid: String) -> Bool {- return self.cachedDeviceUIDs.contains(uid)- }-private func cacheCurrentDeviceList(_ devices: [AudioDevice.Device]) {self.cachedDeviceUIDs = Set(devices.map { $0.uid })}@@ -1694,6 +1852,11 @@ final class ASRService: ObservableObject {func ensureAsrReady(progressHandler: ((Double) -> Void)?) async throws {let provider = self.transcriptionProviderlet providerKey = "\(type(of: provider)):\(provider.name)"+ let model = SettingsStore.shared.selectedSpeechModel+ DebugLogger.shared.info(+ "ensureAsrReady() requested for model=\(model.id) [supportsStreaming=\(model.supportsStreaming)] provider=\(providerKey)",+ source: "ASRService"+ )// Single-flight: if a prepare is already running for this provider, await it.if let task = ensureReadyTask, ensureReadyProviderKey == providerKey {@@ -1718,9 +1881,15 @@ final class ASRService: ObservableObject {}private func performEnsureAsrReady(provider: TranscriptionProvider, externalProgressHandler: ((Double) -> Void)? = nil) async throws {+ DebugLogger.shared.debug(+ "ensureAsrReady(begin): provider=\(provider.name), providerReady=\(provider.isReady), isAsrReady=\(self.isAsrReady), isRunning=\(self.isRunning)",+ source: "ASRService"+ )+// Check if already readyif self.isAsrReady, provider.isReady {DebugLogger.shared.debug("ASR already ready with loaded models, skipping initialization", source: "ASRService")+ self.refreshWordBoostStatus()return}@@ -1733,11 +1902,13 @@ final class ASRService: ObservableObject {let totalStartTime = Date()do {+ let initializationStart = Date()DebugLogger.shared.info("=== ASR INITIALIZATION START ===", source: "ASRService")- DebugLogger.shared.info("Using provider: \(provider.name)", source: "ASRService")+ DebugLogger.shared.info("Using provider: \(provider.name) [providerReady=\(provider.isReady)]", source: "ASRService")let modelsAlreadyCached = provider.modelsExistOnDisk()DebugLogger.shared.info("Models already cached on disk: \(modelsAlreadyCached)", source: "ASRService")+ DebugLogger.shared.debug("Model cache lookup complete in \(String(format: "%.3f", Date().timeIntervalSince(totalStartTime)))s", source: "ASRService")// Suppress stderr noise during model loading (ALWAYS restore, even on failure).let originalStderr = dup(STDERR_FILENO)@@ -1773,7 +1944,7 @@ final class ASRService: ObservableObject {self.isDownloadingModel = trueself.isLoadingModel = falseself.downloadProgress = nil- self.startParakeetDownloadProgressMonitor()+ self.stopDownloadProgressMonitor()DebugLogger.shared.info("⬇️ DOWNLOADING model...", source: "ASRService")}}@@ -1781,14 +1952,18 @@ final class ASRService: ObservableObject {// Use the transcription provider to prepare modelslet downloadStartTime = Date()DebugLogger.shared.info("Calling transcriptionProvider.prepare()...", source: "ASRService")- try await provider.prepare(progressHandler: { [weak self] progress in- DispatchQueue.main.async {- let clamped = max(0.0, min(1.0, progress))- self?.downloadProgress = clamped- // Also call external progress handler if provided- externalProgressHandler?(clamped)+ try await self.prepareProviderWithRecovery(+ provider: provider,+ modelsAlreadyCached: modelsAlreadyCached,+ progressHandler: { [weak self] progress in+ DispatchQueue.main.async {+ let clamped = max(0.0, min(1.0, progress))+ let monotonic = max(self?.downloadProgress ?? 0.0, clamped)+ self?.downloadProgress = monotonic+ externalProgressHandler?(monotonic)+ }}- })+ )let downloadDuration = Date().timeIntervalSince(downloadStartTime)DebugLogger.shared.info("✓ Provider preparation completed in \(String(format: "%.1f", downloadDuration)) seconds", source: "ASRService")@@ -1806,11 +1981,12 @@ final class ASRService: ObservableObject {self.modelsExistOnDisk = true}- let totalDuration = Date().timeIntervalSince(totalStartTime)+ let totalDuration = Date().timeIntervalSince(initializationStart)DebugLogger.shared.info("=== ASR INITIALIZATION COMPLETE ===", source: "ASRService")DebugLogger.shared.info("Total initialization time: \(String(format: "%.1f", totalDuration)) seconds", source: "ASRService")self.isAsrReady = true+ self.refreshWordBoostStatus()} catch {DebugLogger.shared.error("ASR initialization failed with error: \(error)", source: "ASRService")DebugLogger.shared.error("Error details: \(error.localizedDescription)", source: "ASRService")@@ -1824,6 +2000,65 @@ final class ASRService: ObservableObject {}}+ private func prepareProviderWithRecovery(+ provider: TranscriptionProvider,+ modelsAlreadyCached: Bool,+ progressHandler: @escaping (Double) -> Void+ ) async throws {+ let start = Date()+ var firstError: Error?+ do {+ try await provider.prepare(progressHandler: progressHandler)+ DebugLogger.shared.info(+ "ASRService: Provider '\(provider.name)' prepared successfully in \(String(format: "%.2f", Date().timeIntervalSince(start)))s",+ source: "ASRService"+ )+ return+ } catch {+ firstError = error+ DebugLogger.shared.error("ASRService: First prepare attempt for \(provider.name) failed after \(String(format: "%.2f", Date().timeIntervalSince(start)))s", source: "ASRService")+ DebugLogger.shared.warning(+ "ASRService: First prepare failed for \(provider.name): \(error). " ++ "Attempting a single recovery by clearing provider cache.",+ source: "ASRService"+ )+ }++ guard modelsAlreadyCached else {+ DebugLogger.shared.error(+ "ASRService: Provider cache was empty; recovery retry disabled after first failure for \(provider.name).",+ source: "ASRService"+ )+ throw NSError(+ domain: "ASRService",+ code: -2000,+ userInfo: [NSLocalizedDescriptionKey: "Provider preparation failed: \(self.errorSummary(from: firstError))"]+ )+ }++ do {+ DebugLogger.shared.info("ASRService: Clearing provider cache before retry for \(provider.name)", source: "ASRService")+ try await provider.clearCache()+ } catch {+ DebugLogger.shared.warning(+ "ASRService: Provider cache clear failed for \(provider.name): \(error)",+ source: "ASRService"+ )+ }++ // One strict retry. If this fails, we let the caller handle the error.+ try await provider.prepare(progressHandler: progressHandler)+ DebugLogger.shared.info(+ "ASRService: Provider '\(provider.name)' prepared successfully after cache-clear retry",+ source: "ASRService"+ )+ }++ private func errorSummary(from error: Error?) -> String {+ if let error { return error.localizedDescription }+ return "Unknown error"+ }+private func startParakeetDownloadProgressMonitor() {let model = SettingsStore.shared.selectedSpeechModelguard model == .parakeetTDT || model == .parakeetTDTv2 else { return }@@ -2058,7 +2293,7 @@ final class ASRService: ObservableObject {do {DebugLogger.shared.debug("Streaming chunk starting transcription (samples: \(chunk.count)) using \(self.transcriptionProvider.name)", source: "ASRService")let result = try await transcriptionExecutor.run { [provider = self.transcriptionProvider] in- try await provider.transcribe(chunk)+ try await provider.transcribeStreaming(chunk)}let duration = Date().timeIntervalSince(startTime)@@ -2068,6 +2303,7 @@ final class ASRService: ObservableObject {)let rawText = result.text.trimmingCharacters(in: .whitespacesAndNewlines)let newText = ASRService.applyCustomDictionary(ASRService.removeFillerWords(rawText))+ self.recordWordBoostHitIfAny(transcribedText: newText)// Mark first transcription as complete to clear loading stateif !self.hasCompletedFirstTranscription {diff --git a/Sources/Fluid/Services/DebugLogger.swift b/Sources/Fluid/Services/DebugLogger.swiftindex bcf4fd99..c6fbc480 100644--- a/Sources/Fluid/Services/DebugLogger.swift+++ b/Sources/Fluid/Services/DebugLogger.swift@@ -19,7 +19,13 @@ class DebugLogger: ObservableObject {}// Delay access to SettingsStore until after initial singleton setup// Use UserDefaults directly to avoid the circular dependency- let enabled = UserDefaults.standard.bool(forKey: "EnableDebugLogs")+ let defaults = UserDefaults.standard+ let enabled: Bool+ if defaults.object(forKey: "EnableDebugLogs") == nil {+ enabled = true+ } else {+ enabled = defaults.bool(forKey: "EnableDebugLogs")+ }self._loggingEnabledCache = enabledreturn enabled}@@ -69,28 +75,28 @@ class DebugLogger: ObservableObject {/// Refresh the cached logging setting (call after SettingsStore is fully initialized)func refreshLoggingEnabled() {- self._loggingEnabledCache = UserDefaults.standard.bool(forKey: "EnableDebugLogs")+ let defaults = UserDefaults.standard+ if defaults.object(forKey: "EnableDebugLogs") == nil {+ self._loggingEnabledCache = true+ } else {+ self._loggingEnabledCache = defaults.bool(forKey: "EnableDebugLogs")+ }}func log(_ message: String, level: LogLevel = .info, source: String = "App") {let loggingEnabled = self.loggingEnabled- // If logging is disabled, we drop all logs except errors which are always printed to console- if !loggingEnabled, level != .error {- return- }-self.queue.async {let timestamp = Date()let timestampString = Self.logFormatter.string(from: timestamp)let formattedLine = self.formatLogLine(timestamp: timestampString, level: level, source: source, message: message)- // Always write to FileLogger and Console if we reach this point (either logging is enabled OR it's an error)+ // Always persist diagnostics so issues can be debugged even if UI debug mode is off.FileLogger.shared.append(line: formattedLine)print(formattedLine)- // Only update the UI logs if logging is enabled (don't show errors in UI if debug is off)+ // UI log panel still respects the in-app debug toggle.guard loggingEnabled else { return }let entry = LogEntry(diff --git a/Sources/Fluid/Services/FileLogger.swift b/Sources/Fluid/Services/FileLogger.swiftindex e4b298a5..ec2bd002 100644--- a/Sources/Fluid/Services/FileLogger.swift+++ b/Sources/Fluid/Services/FileLogger.swift@@ -1,3 +1,4 @@+import Darwinimport Foundation/// A lightweight file-backed logger that mirrors in-app debug logs to disk for diagnostics.@@ -9,38 +10,47 @@ final class FileLogger {private let logDirectory: URLprivate let logFileURL: URLprivate let backupLogURL: URL+ private let legacyLogFileURL: URL+ private let legacyBackupLogURL: URLprivate let maxLogFileSize: UInt64 = 1 * 1024 * 1024 // 1 MB limit per log fileprivate let maxLogFileAge: TimeInterval = 72 * 60 * 60 // Rotate every 72 hours+ private static var crashFileDescriptor: Int32 = -1+ private static var crashHandlersInstalled = false+ private static let sigAbrtLine = Array("[CRASH] Fatal signal SIGABRT\n".utf8)+ private static let sigIllLine = Array("[CRASH] Fatal signal SIGILL\n".utf8)+ private static let sigSegvLine = Array("[CRASH] Fatal signal SIGSEGV\n".utf8)+ private static let sigBusLine = Array("[CRASH] Fatal signal SIGBUS\n".utf8)+ private static let sigTrapLine = Array("[CRASH] Fatal signal SIGTRAP\n".utf8)+ private static let sigUnknownLine = Array("[CRASH] Fatal signal UNKNOWN\n".utf8)private init() {let baseDirectory = self.fileManager.urls(for: .libraryDirectory, in: .userDomainMask).first ?? URL(fileURLWithPath: NSTemporaryDirectory())self.logDirectory = baseDirectory.appendingPathComponent("Logs/Fluid", isDirectory: true)- self.logFileURL = self.logDirectory.appendingPathComponent("fluid.log", isDirectory: false)- self.backupLogURL = self.logDirectory.appendingPathComponent("fluid.log.1", isDirectory: false)+ self.logFileURL = self.logDirectory.appendingPathComponent("Fluid.log", isDirectory: false)+ self.backupLogURL = self.logDirectory.appendingPathComponent("Fluid.log.1", isDirectory: false)+ self.legacyLogFileURL = self.logDirectory.appendingPathComponent("fluid.log", isDirectory: false)+ self.legacyBackupLogURL = self.logDirectory.appendingPathComponent("fluid.log.1", isDirectory: false)self.queue.sync {self.createLogDirectoryIfNeeded()+ self.migrateLegacyLogFilesIfNeeded()self.rotateIfNeeded(force: false)+ self.prepareCrashLogging()+ self.appendRunMetadata()}+ self.installCrashHandlersIfNeeded()}func append(line: String) {self.queue.async { [weak self] inguard let self = self else { return }- self.createLogDirectoryIfNeeded()- self.rotateIfNeeded(force: false)- let data = (line + "\n").data(using: .utf8) ?? Data()- if !self.fileManager.fileExists(atPath: self.logFileURL.path) {- self.fileManager.createFile(atPath: self.logFileURL.path, contents: data)- } else if let handle = try? FileHandle(forWritingTo: self.logFileURL) {- do {- try handle.seekToEnd()- try handle.write(contentsOf: data)- try handle.close()- } catch {- try? handle.close()- }- }+ self.appendUnlocked(line: line)+ }+ }++ func appendSync(line: String) {+ self.queue.sync {+ self.appendUnlocked(line: line)}}@@ -59,6 +69,53 @@ final class FileLogger {}}+ private func migrateLegacyLogFilesIfNeeded() {+ if !self.fileManager.fileExists(atPath: self.logFileURL.path),+ self.fileManager.fileExists(atPath: self.legacyLogFileURL.path)+ {+ try? self.fileManager.moveItem(at: self.legacyLogFileURL, to: self.logFileURL)+ }++ if !self.fileManager.fileExists(atPath: self.backupLogURL.path),+ self.fileManager.fileExists(atPath: self.legacyBackupLogURL.path)+ {+ try? self.fileManager.moveItem(at: self.legacyBackupLogURL, to: self.backupLogURL)+ }+ }++ private func appendUnlocked(line: String) {+ self.createLogDirectoryIfNeeded()+ self.rotateIfNeeded(force: false)+ let data = (line + "\n").data(using: .utf8) ?? Data()+ if !self.fileManager.fileExists(atPath: self.logFileURL.path) {+ self.fileManager.createFile(atPath: self.logFileURL.path, contents: data)+ self.prepareCrashLogging()+ return+ }+ guard let handle = try? FileHandle(forWritingTo: self.logFileURL) else {+ self.prepareCrashLogging()+ return+ }+ do {+ try handle.seekToEnd()+ try handle.write(contentsOf: data)+ try handle.close()+ } catch {+ try? handle.close()+ }+ self.prepareCrashLogging()+ }++ private func appendRunMetadata() {+ let bundle = Bundle.main+ let appVersion = bundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "unknown"+ let build = bundle.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "unknown"+ let osVersion = ProcessInfo.processInfo.operatingSystemVersionString+ let pid = ProcessInfo.processInfo.processIdentifier+ self.appendUnlocked(line: "[RUN] PID=\(pid) AppVersion=\(appVersion) Build=\(build) OS=\(osVersion)")+ self.appendUnlocked(line: "[RUN] Processed by \(Bundle.main.bundleIdentifier ?? "unknown")")+ }+private func rotateIfNeeded(force: Bool) {guard self.fileManager.fileExists(atPath: self.logFileURL.path) else { return }@@ -83,5 +140,64 @@ final class FileLogger {// Move current log to backup and create a fresh filetry? self.fileManager.moveItem(at: self.logFileURL, to: self.backupLogURL)self.fileManager.createFile(atPath: self.logFileURL.path, contents: nil)+ self.prepareCrashLogging()+ }++ private func prepareCrashLogging() {+ if Self.crashFileDescriptor >= 0 {+ close(Self.crashFileDescriptor)+ Self.crashFileDescriptor = -1+ }+ Self.crashFileDescriptor = open(self.logFileURL.path, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)+ }++ private func installCrashHandlersIfNeeded() {+ guard !Self.crashHandlersInstalled else { return }+ Self.crashHandlersInstalled = true++ NSSetUncaughtExceptionHandler { exception in+ let line = "[CRASH] Uncaught exception \(exception.name.rawValue): \(exception.reason ?? "Unknown reason")"+ FileLogger.writeCrashLineDirect(line)+ if !exception.callStackSymbols.isEmpty {+ FileLogger.writeCrashLineDirect("[CRASH] Stack: \(exception.callStackSymbols.joined(separator: " | "))")+ }+ }++ signal(SIGABRT, fileLoggerSignalHandler)+ signal(SIGILL, fileLoggerSignalHandler)+ signal(SIGSEGV, fileLoggerSignalHandler)+ signal(SIGBUS, fileLoggerSignalHandler)+ signal(SIGTRAP, fileLoggerSignalHandler)}++ static func writeCrashSignalLine(_ signalNumber: Int32) {+ guard self.crashFileDescriptor >= 0 else { return }+ let bytes: [UInt8]+ switch signalNumber {+ case SIGABRT: bytes = Self.sigAbrtLine+ case SIGILL: bytes = Self.sigIllLine+ case SIGSEGV: bytes = Self.sigSegvLine+ case SIGBUS: bytes = Self.sigBusLine+ case SIGTRAP: bytes = Self.sigTrapLine+ default: bytes = Self.sigUnknownLine+ }+ bytes.withUnsafeBytes { rawBuffer in+ guard let baseAddress = rawBuffer.baseAddress else { return }+ _ = write(Self.crashFileDescriptor, baseAddress, rawBuffer.count)+ }+ }++ static func writeCrashLineDirect(_ line: String) {+ guard self.crashFileDescriptor >= 0 else { return }+ let message = line.hasSuffix("\n") ? line : "\(line)\n"+ message.withCString { ptr in+ _ = write(Self.crashFileDescriptor, ptr, strlen(ptr))+ }+ }+}++private func fileLoggerSignalHandler(_ signalNumber: Int32) {+ FileLogger.writeCrashSignalLine(signalNumber)+ signal(signalNumber, SIG_DFL)+ raise(signalNumber)}diff --git a/Sources/Fluid/Services/FluidAudioProvider.swift b/Sources/Fluid/Services/FluidAudioProvider.swiftindex 14850bd0..5274f5fe 100644--- a/Sources/Fluid/Services/FluidAudioProvider.swift+++ b/Sources/Fluid/Services/FluidAudioProvider.swift@@ -2,6 +2,18 @@ import Foundation#if arch(arm64)import FluidAudio+private actor DownloadProgressSink {+ private let handler: ((Double) -> Void)?++ init(handler: ((Double) -> Void)?) {+ self.handler = handler+ }++ func emit(_ progress: Double) {+ self.handler?(progress)+ }+}+/// TranscriptionProvider implementation using FluidAudio (optimized for Apple Silicon)/// This wraps the existing FluidAudio-based ASR for use on Apple Silicon Macs.final class FluidAudioProvider: TranscriptionProvider {@@ -13,23 +25,56 @@ final class FluidAudioProvider: TranscriptionProvider {true}- private var asrManager: AsrManager?+ private var streamingAsrManager: AsrManager?+ private var finalAsrManager: AsrManager?private(set) var isReady: Bool = false+ private(set) var isWordBoostingActive: Bool = false+ private(set) var boostedVocabularyTermsCount: Int = 0+ private var boostedTermLookup: [String] = []/// Optional model override - if set, uses this model instead of the global setting./// Used for downloading specific models without changing the active selection.var modelOverride: SettingsStore.SpeechModel?+ private let configureWordBoosting: Bool- init(modelOverride: SettingsStore.SpeechModel? = nil) {+ init(modelOverride: SettingsStore.SpeechModel? = nil, configureWordBoosting: Bool = true) {self.modelOverride = modelOverride+ self.configureWordBoosting = configureWordBoosting}func prepare(progressHandler: ((Double) -> Void)? = nil) async throws {guard self.isReady == false else { return }let selectedModel = self.modelOverride ?? SettingsStore.shared.selectedSpeechModel- DebugLogger.shared.info("FluidAudioProvider: Starting model preparation for \(selectedModel.displayName)", source: "FluidAudioProvider")+ let modelVersion: String = selectedModel == .parakeetTDTv2 ? "v2" : "v3"+ let cacheDirectory = AsrModels.defaultCacheDirectory().deletingLastPathComponent()+ DebugLogger.shared.info(+ "FluidAudioProvider: Starting model preparation for \(selectedModel.displayName) [version=\(modelVersion)]",+ source: "FluidAudioProvider"+ )+ DebugLogger.shared.debug("FluidAudioProvider: target cache directory=\(cacheDirectory.path)", source: "FluidAudioProvider")+ let progressSink = DownloadProgressSink(handler: progressHandler)+ await progressSink.emit(0.05)+ // AsrModels.downloadAndLoad() is a single await without granular callbacks.+ // Emit synthetic incremental progress so the UI updates smoothly during long downloads.+ let progressTicker = Task(priority: .utility) {+ var stagedProgress = 0.05+ let stageCap = 0.82+ while !Task.isCancelled {+ try? await Task.sleep(nanoseconds: 250_000_000)+ if Task.isCancelled { break }+ if stagedProgress >= stageCap { continue }++ let remaining = stageCap - stagedProgress+ let step = max(0.008, remaining * 0.12)+ stagedProgress = min(stageCap, stagedProgress + step)+ await progressSink.emit(stagedProgress)+ }+ }+ defer { progressTicker.cancel() }++ let loadStart = Date()// Download and load modelslet models: AsrModelsif selectedModel == .parakeetTDTv2 {@@ -39,18 +84,80 @@ final class FluidAudioProvider: TranscriptionProvider {// Default to v3 (Multilingual)models = try await AsrModels.downloadAndLoad(version: .v3)}+ progressTicker.cancel()+ DebugLogger.shared.debug(+ "FluidAudioProvider: Models downloadAndLoad returned in \(String(format: "%.2f", Date().timeIntervalSince(loadStart)))s",+ source: "FluidAudioProvider"+ )+ await progressSink.emit(0.88)++ // Streaming manager: lightweight, no vocab boosting → avoids CTC/ANE contention+ // that causes intermittent SIGTRAP crashes during streaming inference.+ let streamingManager = AsrManager(config: ASRConfig.default)+ try await streamingManager.initialize(models: models)+ DebugLogger.shared.debug("FluidAudioProvider: Streaming AsrManager initialized", source: "FluidAudioProvider")+ await progressSink.emit(0.94)++ self.isWordBoostingActive = false+ self.boostedVocabularyTermsCount = 0+ self.boostedTermLookup = []++ // Final manager: separate instance with vocab boosting for end-of-recording rescoring.+ // Shares the same underlying MLModel objects (reference types) so memory overhead+ // is only the decoder state (~100KB).+ let finalManager: AsrManager+ if self.configureWordBoosting {+ do {+ if let vocabBundle = try await ParakeetVocabularyStore.shared.loadTokenizedVocabularyBundle() {+ DebugLogger.shared.debug(+ "FluidAudioProvider: Vocabulary bundle loaded with \(vocabBundle.vocabulary.terms.count) terms",+ source: "FluidAudioProvider"+ )+ let boostedManager = AsrManager(config: ASRConfig.default)+ try await boostedManager.initialize(models: models)+ try await boostedManager.configureVocabularyBoosting(+ vocabulary: vocabBundle.vocabulary,+ ctcModels: vocabBundle.ctcModels+ )+ self.isWordBoostingActive = true+ self.boostedVocabularyTermsCount = vocabBundle.vocabulary.terms.count+ self.boostedTermLookup = Self.makeBoostedTermLookup(from: vocabBundle.vocabulary.terms)+ DebugLogger.shared.info(+ "FluidAudioProvider: Enabled vocabulary boosting with \(self.boostedVocabularyTermsCount) terms (final only)",+ source: "FluidAudioProvider"+ )+ finalManager = boostedManager+ } else {+ DebugLogger.shared.debug("FluidAudioProvider: No vocabulary boost terms found; using base ASR manager", source: "FluidAudioProvider")+ finalManager = streamingManager+ }+ } catch {+ DebugLogger.shared.warning("FluidAudioProvider: Failed to configure vocabulary boosting: \(error)", source: "FluidAudioProvider")+ finalManager = streamingManager+ }+ } else {+ DebugLogger.shared.debug("FluidAudioProvider: Word boosting disabled by configuration", source: "FluidAudioProvider")+ finalManager = streamingManager+ }- // Initialize AsrManager- let manager = AsrManager(config: ASRConfig.default)- try await manager.initialize(models: models)- self.asrManager = manager+ self.streamingAsrManager = streamingManager+ self.finalAsrManager = finalManager+ await progressSink.emit(0.98)self.isReady = true- DebugLogger.shared.info("FluidAudioProvider: Models ready", source: "FluidAudioProvider")+ await progressSink.emit(1.0)+ DebugLogger.shared.info(+ "FluidAudioProvider: Models ready [isWordBoostingActive=\(self.isWordBoostingActive), terms=\(self.boostedVocabularyTermsCount)]",+ source: "FluidAudioProvider"+ )}func transcribe(_ samples: [Float]) async throws -> ASRTranscriptionResult {- guard let manager = asrManager else {+ try await self.transcribeFinal(samples)+ }++ func transcribeStreaming(_ samples: [Float]) async throws -> ASRTranscriptionResult {+ guard let manager = self.streamingAsrManager else {throw NSError(domain: "FluidAudioProvider",code: -1,@@ -62,6 +169,33 @@ final class FluidAudioProvider: TranscriptionProvider {return ASRTranscriptionResult(text: result.text, confidence: result.confidence)}+ func transcribeFinal(_ samples: [Float]) async throws -> ASRTranscriptionResult {+ guard let manager = self.finalAsrManager ?? self.streamingAsrManager else {+ throw NSError(+ domain: "FluidAudioProvider",+ code: -1,+ userInfo: [NSLocalizedDescriptionKey: "ASR manager not initialized"]+ )+ }++ // If the boosted final manager fails, fall back to the unboosted streaming+ // manager so the user still gets a transcription (just without CTC rescoring).+ do {+ let result = try await manager.transcribe(samples, source: AudioSource.microphone)+ return ASRTranscriptionResult(text: result.text, confidence: result.confidence)+ } catch {+ guard let fallback = self.streamingAsrManager, fallback !== manager else {+ throw error+ }+ DebugLogger.shared.warning(+ "FluidAudioProvider: Boosted final transcription failed (\(error.localizedDescription)), retrying without vocab boost",+ source: "FluidAudioProvider"+ )+ let result = try await fallback.transcribe(samples, source: AudioSource.microphone)+ return ASRTranscriptionResult(text: result.text, confidence: result.confidence)+ }+ }+func modelsExistOnDisk() -> Bool {let baseCacheDir = AsrModels.defaultCacheDirectory().deletingLastPathComponent()let selectedModel = self.modelOverride ?? SettingsStore.shared.selectedSpeechModel@@ -78,7 +212,12 @@ final class FluidAudioProvider: TranscriptionProvider {func clearCache() async throws {let baseCacheDir = AsrModels.defaultCacheDirectory().deletingLastPathComponent()let selectedModel = self.modelOverride ?? SettingsStore.shared.selectedSpeechModel+ DebugLogger.shared.info(+ "FluidAudioProvider: clearCache called for \(selectedModel.displayName)",+ source: "FluidAudioProvider"+ )+ let start = Date()if selectedModel == .parakeetTDTv2 {// Clear v2 cache onlylet v2CacheDir = baseCacheDir.appendingPathComponent("parakeet-tdt-0.6b-v2-coreml")@@ -95,14 +234,70 @@ final class FluidAudioProvider: TranscriptionProvider {}}+ DebugLogger.shared.debug(+ "FluidAudioProvider: clearCache completed in \(String(format: "%.3f", Date().timeIntervalSince(start)))s",+ source: "FluidAudioProvider"+ )+self.isReady = false- self.asrManager = nil+ self.streamingAsrManager = nil+ self.finalAsrManager = nil+ self.isWordBoostingActive = false+ self.boostedVocabularyTermsCount = 0+ self.boostedTermLookup = []}/// Provides direct access to the underlying AsrManager for advanced use cases/// (e.g., MeetingTranscriptionService sharing)var underlyingManager: AsrManager? {- return self.asrManager+ return self.streamingAsrManager+ }++ func detectBoostedTerms(in text: String, limit: Int = 2) -> [String] {+ guard self.isWordBoostingActive, !self.boostedTermLookup.isEmpty else { return [] }+ let normalizedText = " \(Self.normalizeForLookup(text)) "+ guard normalizedText.count > 2 else { return [] }++ var hits: [String] = []+ hits.reserveCapacity(min(limit, 2))+ for candidate in self.boostedTermLookup where normalizedText.contains(" \(candidate) ") {+ hits.append(candidate)+ if hits.count >= limit {+ break+ }+ }+ return hits+ }++ private static func makeBoostedTermLookup(from terms: [CustomVocabularyTerm]) -> [String] {+ var unique: Set<String> = []+ unique.reserveCapacity(terms.count * 2)+ for term in terms {+ let normalized = self.normalizeForLookup(term.text)+ if !normalized.isEmpty {+ unique.insert(normalized)+ }+ for alias in term.aliases ?? [] {+ let normalizedAlias = self.normalizeForLookup(alias)+ if !normalizedAlias.isEmpty {+ unique.insert(normalizedAlias)+ }+ }+ }+ return unique.sorted { lhs, rhs in+ if lhs.count == rhs.count {+ return lhs < rhs+ }+ return lhs.count > rhs.count+ }+ }++ private static func normalizeForLookup(_ text: String) -> String {+ let lowercase = text.lowercased()+ let words = lowercase+ .components(separatedBy: CharacterSet.alphanumerics.inverted)+ .filter { !$0.isEmpty }+ return words.joined(separator: " ")}}#else@@ -111,8 +306,10 @@ final class FluidAudioProvider: TranscriptionProvider {let name = "FluidAudio (Apple Silicon ONLY)"var isAvailable: Bool { false }var isReady: Bool { false }+ private(set) var isWordBoostingActive: Bool = false+ private(set) var boostedVocabularyTermsCount: Int = 0- init(modelOverride: SettingsStore.SpeechModel? = nil) {+ init(modelOverride: SettingsStore.SpeechModel? = nil, configureWordBoosting: Bool = true) {// Intel stub - parameter ignored}@@ -131,5 +328,9 @@ final class FluidAudioProvider: TranscriptionProvider {userInfo: [NSLocalizedDescriptionKey: "FluidAudio is not supported on Intel Macs"])}++ func detectBoostedTerms(in text: String, limit: Int = 2) -> [String] {+ []+ }}#endifdiff --git a/Sources/Fluid/Services/GlobalHotkeyManager.swift b/Sources/Fluid/Services/GlobalHotkeyManager.swiftindex 24bbf4d2..b25f6bd4 100644--- a/Sources/Fluid/Services/GlobalHotkeyManager.swift+++ b/Sources/Fluid/Services/GlobalHotkeyManager.swift@@ -1,27 +1,33 @@import AppKitimport Foundation-@MainActor-final class GlobalHotkeyManager: NSObject {- private final class HotkeyState: @unchecked Sendable {- private let lock = NSLock()- var isKeyPressed = false- var isCommandModeKeyPressed = false- var isRewriteKeyPressed = false- var modifierOnlyKeyDown = false- var otherKeyPressedDuringModifier = false- var modifierPressStartTime: Date?- var pendingHoldModeStart: Task<Void, Never>?- var pendingHoldModeType: HoldModeType?-- func withLock<T>(_ block: () -> T) -> T {- self.lock.lock()- defer { self.lock.unlock() }- return block()- }+private enum HotkeyHoldModeType {+ case transcription+ case commandMode+ case rewriteMode+}++private final class HotkeyState: @unchecked Sendable {+ private let lock = NSLock()+ var isKeyPressed = false+ var isCommandModeKeyPressed = false+ var isRewriteKeyPressed = false+ var modifierOnlyKeyDown = false+ var otherKeyPressedDuringModifier = false+ var modifierPressStartTime: Date?+ var pendingHoldModeStart: Task<Void, Never>?+ var pendingHoldModeType: HotkeyHoldModeType?++ func withLock<T>(_ block: () -> T) -> T {+ self.lock.lock()+ defer { self.lock.unlock() }+ return block()}+}- private let state = HotkeyState()+@MainActor+final class GlobalHotkeyManager: NSObject {+ private nonisolated(unsafe) var state = HotkeyState()private nonisolated(unsafe) var eventTap: CFMachPort?private nonisolated(unsafe) var runLoopSource: CFRunLoopSource?private let asrService: ASRService@@ -31,9 +37,13 @@ final class GlobalHotkeyManager: NSObject {private var commandModeShortcutEnabled: Boolprivate var rewriteModeShortcutEnabled: Boolprivate var startRecordingCallback: (() async -> Void)?+ private var dictationModeCallback: (() async -> Void)?private var stopAndProcessCallback: (() async -> Void)?private var commandModeCallback: (() async -> Void)?private var rewriteModeCallback: (() async -> Void)?+ private var isDictateRecordingProvider: (() -> Bool)?+ private var isCommandRecordingProvider: (() -> Bool)?+ private var isRewriteRecordingProvider: (() -> Bool)?private var cancelCallback: (() -> Bool)? // Returns true if handledprivate var pressAndHoldMode: Bool = SettingsStore.shared.pressAndHoldMode@@ -75,17 +85,11 @@ final class GlobalHotkeyManager: NSObject {}// Tracks which mode's pending start is active (for cancellation on key combos)- private nonisolated var pendingHoldModeType: HoldModeType? {+ private nonisolated var pendingHoldModeType: HotkeyHoldModeType? {get { self.state.withLock { self.state.pendingHoldModeType } }set { self.state.withLock { self.state.pendingHoldModeType = newValue } }}- private enum HoldModeType {- case transcription- case commandMode- case rewriteMode- }-// Busy flag to prevent race conditions during stop processingprivate var isProcessingStop = false@@ -104,9 +108,13 @@ final class GlobalHotkeyManager: NSObject {commandModeShortcutEnabled: Bool,rewriteModeShortcutEnabled: Bool,startRecordingCallback: (() async -> Void)? = nil,+ dictationModeCallback: (() async -> Void)? = nil,stopAndProcessCallback: (() async -> Void)? = nil,commandModeCallback: (() async -> Void)? = nil,- rewriteModeCallback: (() async -> Void)? = nil+ rewriteModeCallback: (() async -> Void)? = nil,+ isDictateRecordingProvider: (() -> Bool)? = nil,+ isCommandRecordingProvider: (() -> Bool)? = nil,+ isRewriteRecordingProvider: (() -> Bool)? = nil) {self.asrService = asrServiceself.shortcut = shortcut@@ -115,9 +123,13 @@ final class GlobalHotkeyManager: NSObject {self.commandModeShortcutEnabled = commandModeShortcutEnabledself.rewriteModeShortcutEnabled = rewriteModeShortcutEnabledself.startRecordingCallback = startRecordingCallback+ self.dictationModeCallback = dictationModeCallbackself.stopAndProcessCallback = stopAndProcessCallbackself.commandModeCallback = commandModeCallbackself.rewriteModeCallback = rewriteModeCallback+ self.isDictateRecordingProvider = isDictateRecordingProvider+ self.isCommandRecordingProvider = isCommandRecordingProvider+ self.isRewriteRecordingProvider = isRewriteRecordingProvidersuper.init()self.initializeWithDelay()@@ -366,8 +378,13 @@ final class GlobalHotkeyManager: NSObject {} else {// Toggle mode: press to start, press again to stopif self.asrService.isRunning {- DebugLogger.shared.info("Command mode shortcut pressed while recording - stopping", source: "GlobalHotkeyManager")- self.stopRecordingIfNeeded()+ if self.isCommandRecordingProvider?() ?? false {+ DebugLogger.shared.info("Command mode shortcut pressed in Command mode - stopping", source: "GlobalHotkeyManager")+ self.stopRecordingIfNeeded()+ } else {+ DebugLogger.shared.info("Command mode shortcut pressed while recording - switching mode", source: "GlobalHotkeyManager")+ self.triggerCommandMode()+ }} else {DebugLogger.shared.info("Command mode shortcut triggered - starting", source: "GlobalHotkeyManager")self.triggerCommandMode()@@ -389,8 +406,13 @@ final class GlobalHotkeyManager: NSObject {} else {// Toggle mode: press to start, press again to stopif self.asrService.isRunning {- DebugLogger.shared.info("Rewrite mode shortcut pressed while recording - stopping", source: "GlobalHotkeyManager")- self.stopRecordingIfNeeded()+ if self.isRewriteRecordingProvider?() ?? false {+ DebugLogger.shared.info("Rewrite mode shortcut pressed in Edit mode - stopping", source: "GlobalHotkeyManager")+ self.stopRecordingIfNeeded()+ } else {+ DebugLogger.shared.info("Rewrite mode shortcut pressed while recording - switching mode", source: "GlobalHotkeyManager")+ self.triggerRewriteMode()+ }} else {DebugLogger.shared.info("Rewrite mode shortcut triggered - starting", source: "GlobalHotkeyManager")self.triggerRewriteMode()@@ -405,10 +427,50 @@ final class GlobalHotkeyManager: NSObject {if self.pressAndHoldMode {if !self.isKeyPressed {self.isKeyPressed = true- self.startRecordingIfNeeded()+ if self.asrService.isRunning {+ let isSameMode = self.isDictateRecordingProvider?() ?? false+ DebugLogger.shared.debug(+ "GlobalHotkeyManager: dictation hold-press path",+ source: "GlobalHotkeyManager"+ )+ DebugLogger.shared.info(+ "Hotkey route | pressed=dictate | active=\(isSameMode ? "dictate" : "other") | asrRunning=true | action=\(isSameMode ? "stop" : "switch")",+ source: "GlobalHotkeyManager"+ )+ if !isSameMode {+ self.triggerDictationMode()+ }+ } else {+ DebugLogger.shared.info(+ "Hotkey route | pressed=dictate | active=none | asrRunning=false | action=start",+ source: "GlobalHotkeyManager"+ )+ self.startRecordingIfNeeded()+ }}} else {- self.toggleRecording()+ if self.asrService.isRunning {+ let isSameMode = self.isDictateRecordingProvider?() ?? false+ DebugLogger.shared.debug(+ "GlobalHotkeyManager: dictation tap path while already running",+ source: "GlobalHotkeyManager"+ )+ DebugLogger.shared.info(+ "Hotkey route | pressed=dictate | active=\(isSameMode ? "dictate" : "other") | asrRunning=true | action=\(isSameMode ? "stop" : "switch")",+ source: "GlobalHotkeyManager"+ )+ if isSameMode {+ self.stopRecordingIfNeeded()+ } else {+ self.triggerDictationMode()+ }+ } else {+ DebugLogger.shared.info(+ "Hotkey route | pressed=dictate | active=none | asrRunning=false | action=start",+ source: "GlobalHotkeyManager"+ )+ self.triggerDictationMode()+ }}return nil}@@ -498,8 +560,13 @@ final class GlobalHotkeyManager: NSObject {} else if wasCleanPress {// Toggle mode: only trigger on release if no other key was pressedif self.asrService.isRunning {- DebugLogger.shared.info("Command mode modifier released (toggle) - stopping", source: "GlobalHotkeyManager")- self.stopRecordingIfNeeded()+ if self.isCommandRecordingProvider?() ?? false {+ DebugLogger.shared.info("Command mode modifier released (toggle, same mode) - stopping", source: "GlobalHotkeyManager")+ self.stopRecordingIfNeeded()+ } else {+ DebugLogger.shared.info("Command mode modifier released (toggle, switch mode) - switching", source: "GlobalHotkeyManager")+ self.triggerCommandMode()+ }} else {DebugLogger.shared.info("Command mode modifier released (toggle) - starting", source: "GlobalHotkeyManager")self.triggerCommandMode()@@ -572,8 +639,13 @@ final class GlobalHotkeyManager: NSObject {} else if wasCleanPress {// Toggle mode: only trigger on release if no other key was pressedif self.asrService.isRunning {- DebugLogger.shared.info("Rewrite mode modifier released (toggle) - stopping", source: "GlobalHotkeyManager")- self.stopRecordingIfNeeded()+ if self.isRewriteRecordingProvider?() ?? false {+ DebugLogger.shared.info("Rewrite mode modifier released (toggle, same mode) - stopping", source: "GlobalHotkeyManager")+ self.stopRecordingIfNeeded()+ } else {+ DebugLogger.shared.info("Rewrite mode modifier released (toggle, switch mode) - switching", source: "GlobalHotkeyManager")+ self.triggerRewriteMode()+ }} else {DebugLogger.shared.info("Rewrite mode modifier released (toggle) - starting", source: "GlobalHotkeyManager")self.triggerRewriteMode()@@ -637,7 +709,24 @@ final class GlobalHotkeyManager: NSObject {}} else if wasCleanPress {// Toggle mode: only trigger on release if no other key was pressed- self.toggleRecording()+ if self.asrService.isRunning {+ let isSameMode = self.isDictateRecordingProvider?() ?? false+ DebugLogger.shared.info(+ "Hotkey route | pressed=dictate(mod) | active=\(isSameMode ? "dictate" : "other") | asrRunning=true | action=\(isSameMode ? "stop" : "switch")",+ source: "GlobalHotkeyManager"+ )+ if isSameMode {+ self.stopRecordingIfNeeded()+ } else {+ self.triggerDictationMode()+ }+ } else {+ DebugLogger.shared.info(+ "Hotkey route | pressed=dictate(mod) | active=none | asrRunning=false | action=start",+ source: "GlobalHotkeyManager"+ )+ self.triggerDictationMode()+ }} else {DebugLogger.shared.debug("Transcription modifier released but another key was pressed - ignoring", source: "GlobalHotkeyManager")}@@ -656,6 +745,10 @@ final class GlobalHotkeyManager: NSObject {Task { @MainActor [weak self] inguard let self = self else { return }DebugLogger.shared.info("Command mode hotkey triggered", source: "GlobalHotkeyManager")+ DebugLogger.shared.debug(+ "GlobalHotkeyManager: command callback path, isRunning=\(self.asrService.isRunning), isReady=\(self.asrService.isAsrReady)",+ source: "GlobalHotkeyManager"+ )await self.commandModeCallback?()}}@@ -664,10 +757,42 @@ final class GlobalHotkeyManager: NSObject {Task { @MainActor [weak self] inguard let self = self else { return }DebugLogger.shared.info("Rewrite mode hotkey triggered", source: "GlobalHotkeyManager")+ DebugLogger.shared.debug(+ "GlobalHotkeyManager: rewrite callback path, isRunning=\(self.asrService.isRunning), isReady=\(self.asrService.isAsrReady)",+ source: "GlobalHotkeyManager"+ )await self.rewriteModeCallback?()}}+ private func triggerDictationMode() {+ Task { @MainActor [weak self] in+ guard let self = self else { return }+ let model = SettingsStore.shared.selectedSpeechModel+ DebugLogger.shared.info("Dictate mode hotkey triggered", source: "GlobalHotkeyManager")+ DebugLogger.shared.debug(+ "GlobalHotkeyManager: dictate callback path, isRunning=\(self.asrService.isRunning), isReady=\(self.asrService.isAsrReady), model=\(model.displayName)",+ source: "GlobalHotkeyManager"+ )+ if let callback = self.dictationModeCallback {+ DebugLogger.shared.debug("GlobalHotkeyManager: invoking dictationModeCallback", source: "GlobalHotkeyManager")+ await callback()+ } else if let startCallback = self.startRecordingCallback {+ DebugLogger.shared.debug(+ "GlobalHotkeyManager: dictationModeCallback missing; invoking fallback callback",+ source: "GlobalHotkeyManager"+ )+ await startCallback()+ } else {+ DebugLogger.shared.warning(+ "GlobalHotkeyManager: dictation callbacks missing; invoking ASRService.start directly",+ source: "GlobalHotkeyManager"+ )+ await self.asrService.start()+ }+ }+ }+func enablePressAndHoldMode(_ enable: Bool) {self.pressAndHoldMode = enableif !enable, self.isKeyPressed {@@ -839,7 +964,5 @@ final class GlobalHotkeyManager: NSObject {initializationTask?.cancel()healthCheckTask?.cancel()cleanupEventTap()-- DebugLogger.shared.info("Deinitialized and cleaned up", source: "GlobalHotkeyManager")}}diff --git a/Sources/Fluid/Services/MediaPlaybackService.swift b/Sources/Fluid/Services/MediaPlaybackService.swiftindex d5ae048c..72160960 100644--- a/Sources/Fluid/Services/MediaPlaybackService.swift+++ b/Sources/Fluid/Services/MediaPlaybackService.swift@@ -25,11 +25,40 @@ final class MediaPlaybackService {////// - Returns: `true` if we successfully paused playback, `false` if nothing was playing/// or if we couldn't determine playback state.+ ///+ /// - Note: Uses a local one-shot gate to protect against `MediaRemoteAdapter`+ /// firing the `getTrackInfo` callback more than once, which would otherwise+ /// crash with `EXC_BREAKPOINT` (SIGTRAP) due to double-resume of a+ /// `CheckedContinuation`.func pauseIfPlaying() async -> Bool {return await withCheckedContinuation { continuation in+ let resumeLock = NSLock()+ var didResume = false++ func resumeOnce(_ value: Bool) {+ var shouldResume = false++ resumeLock.lock()+ if !didResume {+ didResume = true+ shouldResume = true+ }+ resumeLock.unlock()++ guard shouldResume else {+ DebugLogger.shared.warning(+ "MediaPlaybackService: Suppressed duplicate resume (MediaRemoteAdapter callback fired more than once)",+ source: "MediaPlaybackService"+ )+ return+ }++ continuation.resume(returning: value)+ }+self.mediaController.getTrackInfo { [weak self] trackInfo inguard let self = self else {- continuation.resume(returning: false)+ resumeOnce(false)return}@@ -39,7 +68,7 @@ final class MediaPlaybackService {"MediaPlaybackService: No track info available, nothing to pause",source: "MediaPlaybackService")- continuation.resume(returning: false)+ resumeOnce(false)return}@@ -73,13 +102,13 @@ final class MediaPlaybackService {source: "MediaPlaybackService")self.mediaController.pause()- continuation.resume(returning: true)+ resumeOnce(true)} else {DebugLogger.shared.debug("MediaPlaybackService: Media is not playing, no action needed",source: "MediaPlaybackService")- continuation.resume(returning: false)+ resumeOnce(false)}}}diff --git a/Sources/Fluid/Services/MeetingTranscriptionService.swift b/Sources/Fluid/Services/MeetingTranscriptionService.swiftindex 22a93710..7f7539d6 100644--- a/Sources/Fluid/Services/MeetingTranscriptionService.swift+++ b/Sources/Fluid/Services/MeetingTranscriptionService.swift@@ -5,17 +5,56 @@ import Foundation/// Result of a transcription operationstruct TranscriptionResult: Identifiable, Sendable, Codable {- let id = UUID()+ let id: UUIDlet text: Stringlet confidence: Floatlet duration: TimeIntervallet processingTime: TimeIntervallet fileName: String- let timestamp: Date = .init()+ let timestamp: Date++ init(+ id: UUID = UUID(),+ text: String,+ confidence: Float,+ duration: TimeInterval,+ processingTime: TimeInterval,+ fileName: String,+ timestamp: Date = Date()+ ) {+ self.id = id+ self.text = text+ self.confidence = confidence+ self.duration = duration+ self.processingTime = processingTime+ self.fileName = fileName+ self.timestamp = timestamp+ }enum CodingKeys: String, CodingKey {case text, confidence, duration, processingTime, fileName, timestamp}++ init(from decoder: Decoder) throws {+ let c = try decoder.container(keyedBy: CodingKeys.self)+ self.id = UUID()+ self.text = try c.decode(String.self, forKey: .text)+ self.confidence = try c.decode(Float.self, forKey: .confidence)+ self.duration = try c.decode(TimeInterval.self, forKey: .duration)+ self.processingTime = try c.decode(TimeInterval.self, forKey: .processingTime)+ self.fileName = try c.decode(String.self, forKey: .fileName)+ self.timestamp = try c.decode(Date.self, forKey: .timestamp)+ }++ func encode(to encoder: Encoder) throws {+ var c = encoder.container(keyedBy: CodingKeys.self)+ try c.encode(self.text, forKey: .text)+ try c.encode(self.confidence, forKey: .confidence)+ try c.encode(self.duration, forKey: .duration)+ try c.encode(self.processingTime, forKey: .processingTime)+ try c.encode(self.fileName, forKey: .fileName)+ try c.encode(self.timestamp, forKey: .timestamp)+ }}/// Service for transcribing complete audio/video files with optional speaker diarization@@ -28,7 +67,7 @@ final class MeetingTranscriptionService: ObservableObject {@Published var error: String?@Published var result: TranscriptionResult?- // Share the ASR service instance to avoid loading models twice+ /// Share the ASR service instance to avoid loading models twiceprivate let asrService: ASRServiceinit(asrService: ASRService) {@@ -258,6 +297,7 @@ final class MeetingTranscriptionService: ObservableObject {)self.result = result+ FileTranscriptionHistoryStore.shared.addEntry(result)return result} catch let error as TranscriptionError {diff --git a/Sources/Fluid/Services/MenuBarManager.swift b/Sources/Fluid/Services/MenuBarManager.swiftindex 4513989b..3ed1adc8 100644--- a/Sources/Fluid/Services/MenuBarManager.swift+++ b/Sources/Fluid/Services/MenuBarManager.swift@@ -17,6 +17,7 @@ final class MenuBarManager: ObservableObject {// Cached menu items to avoid rebuilding entire menuprivate var statusMenuItem: NSMenuItem?private var aiMenuItem: NSMenuItem?+ private var rollbackMenuItem: NSMenuItem?// References to app stateprivate weak var asrService: ASRService?@@ -352,6 +353,18 @@ final class MenuBarManager: ObservableObject {menu.addItem(.separator())+ let rollbackMenuItem = NSMenuItem(+ title: "Rollback to Previous Version...",+ action: #selector(rollbackToPreviousVersion(_:)),+ keyEquivalent: ""+ )+ rollbackMenuItem.target = self+ rollbackMenuItem.isEnabled = SimpleUpdater.shared.hasRollbackBackup()+ menu.addItem(rollbackMenuItem)+ self.rollbackMenuItem = rollbackMenuItem++ menu.addItem(.separator())+// Quitlet quitItem = NSMenuItem(title: "Quit Fluid Voice",@@ -385,16 +398,36 @@ final class MenuBarManager: ObservableObject {// Update AI toggle textlet aiTitle = self.aiProcessingEnabled ? "Disable AI Processing" : "Enable AI Processing"self.aiMenuItem?.title = aiTitle++ // Update rollback availability text+ self.rollbackMenuItem?.isEnabled = SimpleUpdater.shared.hasRollbackBackup()}- @objc private func toggleAIProcessing() {- self.aiProcessingEnabled.toggle()- // Persist and broadcast change- SettingsStore.shared.enableAIProcessing = self.aiProcessingEnabled- // If a ContentView has bound to MenuBarManager, its onChange sync will mirror this+ /// Centralized entry point to update AI post-processing enablement.+ /// Use this instead of writing `aiProcessingEnabled` directly so all state stays in sync.+ func setAIProcessingEnabled(_ enabled: Bool) {+ guard self.aiProcessingEnabled != enabled else {+ // Ensure menu text stays correct even if caller repeats the same value.+ self.updateMenu()+ return+ }+ self.aiProcessingEnabled = enabled+ SettingsStore.shared.enableAIProcessing = enabledself.updateMenu()}+ /// Toggle AI post-processing and return the new value.+ @discardableResult+ func toggleAIProcessingEnabled() -> Bool {+ let next = !self.aiProcessingEnabled+ self.setAIProcessingEnabled(next)+ return next+ }++ @objc private func toggleAIProcessing() {+ _ = self.toggleAIProcessingEnabled()+ }+@objc private func checkForUpdates(_ sender: Any?) {DebugLogger.shared.info("🔎 Menu action: Check for Updates…", source: "MenuBarManager")@@ -429,6 +462,109 @@ final class MenuBarManager: ObservableObject {}}+ @objc private func rollbackToPreviousVersion(_ sender: Any?) {+ let availableVersion = SimpleUpdater.shared.latestRollbackVersion() ?? ""+ guard !availableVersion.isEmpty else {+ let msg = NSAlert()+ msg.messageText = "No rollback backup found"+ msg.informativeText = "No previous version backup is available on this device."+ msg.alertStyle = .informational+ msg.addButton(withTitle: "Get Previous Builds")+ msg.addButton(withTitle: "Cancel")+ if msg.runModal() == .alertFirstButtonReturn {+ self.openPreviousBuildPicker()+ }+ return+ }++ let confirm = NSAlert()+ confirm.messageText = "Rollback to \(availableVersion)?"+ confirm.informativeText = "This will restore the backup and relaunch FluidVoice."+ confirm.alertStyle = .warning+ confirm.addButton(withTitle: "Rollback")+ confirm.addButton(withTitle: "Cancel")++ guard confirm.runModal() == .alertFirstButtonReturn else { return }++ Task { @MainActor in+ do {+ try await SimpleUpdater.shared.rollbackToLatestBackup()+ let success = NSAlert()+ success.messageText = "Rollback Successful"+ success.informativeText = "Rolled back to \(availableVersion). FluidVoice will relaunch shortly."+ success.alertStyle = .informational+ success.addButton(withTitle: "Report Bug")+ success.addButton(withTitle: "OK")+ let response = success.runModal()+ if response == .alertFirstButtonReturn {+ self.openIssueReportingPage()+ }+ } catch {+ let fail = NSAlert()+ fail.messageText = "Rollback Failed"+ fail.informativeText = error.localizedDescription+ fail.alertStyle = .critical+ fail.addButton(withTitle: "OK")+ fail.runModal()+ }+ }+ }++ private func openIssueReportingPage() {+ guard let url = URL(string: "https://github.com/altic-dev/Fluid-oss/issues/new/choose") else { return }+ NSWorkspace.shared.open(url)+ }++ private func openPreviousBuildPicker() {+ Task { @MainActor in+ do {+ let options = try await SimpleUpdater.shared.fetchRecentReleaseBuildOptions(+ owner: "altic-dev",+ repo: "Fluid-oss",+ limit: 3+ )+ self.presentPreviousBuildPicker(options)+ } catch {+ self.openAllReleasesPage()+ }+ }+ }++ private func presentPreviousBuildPicker(_ options: [SimpleUpdater.ReleaseBuildOption]) {+ guard !options.isEmpty else {+ self.openAllReleasesPage()+ return+ }++ let picker = NSAlert()+ picker.messageText = "Download Previous Build"+ picker.informativeText = "Choose one of the latest release builds to install manually."+ picker.alertStyle = .informational++ for option in options {+ picker.addButton(withTitle: option.version)+ }+ picker.addButton(withTitle: "All Releases")+ picker.addButton(withTitle: "Cancel")++ let response = picker.runModal()+ let first = NSApplication.ModalResponse.alertFirstButtonReturn.rawValue+ let index = response.rawValue - first++ if index >= 0, index < options.count {+ NSWorkspace.shared.open(options[index].url)+ return+ }+ if index == options.count {+ self.openAllReleasesPage()+ }+ }++ private func openAllReleasesPage() {+ guard let url = URL(string: "https://github.com/altic-dev/Fluid-oss/releases") else { return }+ NSWorkspace.shared.open(url)+ }+@objc private func openMainWindow() {// First, unhide the app if it's hiddenif NSApp.isHidden {@@ -444,7 +580,7 @@ final class MenuBarManager: ObservableObject {if let window = hostedWindow, window.isReleasedWhenClosed == false {self.ensureUsableMainWindow(window)window.animationBehavior = .none- window.makeKeyAndOrderFront(nil)+ self.bringToFront(window)} else if let window = NSApp.windows.first(where: { win in// Only normal app windows (exclude overlays/panels/menus)guard win.level == .normal else { return false }@@ -457,7 +593,7 @@ final class MenuBarManager: ObservableObject {}) {self.ensureUsableMainWindow(window)window.animationBehavior = .none- window.makeKeyAndOrderFront(nil)+ self.bringToFront(window)self.hostedWindow = window} else {// If there is no suitable window (or it's minimized), create a fresh one.@@ -466,6 +602,9 @@ final class MenuBarManager: ObservableObject {// Final attempt: ensure app is active and visibleNSApp.activate(ignoringOtherApps: true)+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.08) {+ NSApp.activate(ignoringOtherApps: true)+ }}@objc private func openPreferences() {@@ -483,6 +622,11 @@ final class MenuBarManager: ObservableObject {}}+ /// Public entry-point for non-menu UI surfaces (e.g. overlay controls) to open Preferences.+ func openPreferencesFromUI() {+ self.openPreferences()+ }+/// Create and present a fresh main window hosting `ContentView`private func createAndShowMainWindow() {// Build the SwiftUI root view with required environment@@ -506,11 +650,14 @@ final class MenuBarManager: ObservableObject {window.isReleasedWhenClosed = falsewindow.contentViewController = hostingControllerwindow.setFrame(self.defaultWindowFrame(), display: false)- window.makeKeyAndOrderFront(nil)+ self.bringToFront(window)self.hostedWindow = window// Bring app to front in case we're running as an accessory app (no Dock)NSApp.activate(ignoringOtherApps: true)+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.08) {+ NSApp.activate(ignoringOtherApps: true)+ }}private func ensureUsableMainWindow(_ window: NSWindow) {@@ -534,4 +681,10 @@ final class MenuBarManager: ObservableObject {)return NSRect(origin: origin, size: size)}++ private func bringToFront(_ window: NSWindow) {+ // Keep ordering explicit to avoid "opened but behind other apps" behavior.+ window.orderFrontRegardless()+ window.makeKeyAndOrderFront(nil)+ }}diff --git a/Sources/Fluid/Services/NotchOverlayManager.swift b/Sources/Fluid/Services/NotchOverlayManager.swiftindex e650c252..5f0c355d 100644--- a/Sources/Fluid/Services/NotchOverlayManager.swift+++ b/Sources/Fluid/Services/NotchOverlayManager.swift@@ -14,6 +14,7 @@ import SwiftUIenum OverlayMode: String {case dictation = "Dictation"+ case edit = "Edit"case rewrite = "Rewrite"case write = "Write"case command = "Command"@@ -190,9 +191,9 @@ final class NotchOverlayManager {}self.lastAudioPublisher = audioLevelPublisher- self.currentMode = mode+ self.currentMode = self.normalizedOverlayMode(mode)- BottomOverlayWindowController.shared.show(audioPublisher: audioLevelPublisher, mode: mode)+ BottomOverlayWindowController.shared.show(audioPublisher: audioLevelPublisher, mode: self.currentMode)self.isBottomOverlayVisible = true}@@ -209,10 +210,11 @@ final class NotchOverlayManager {let currentGeneration = self.generationself.state = .showing- self.currentMode = mode+ self.currentMode = self.normalizedOverlayMode(mode)// Update shared content state immediately- NotchContentState.shared.mode = mode+ NotchContentState.shared.mode = self.currentMode+ self.syncPromptPickerMode(for: self.currentMode)NotchContentState.shared.updateTranscription("")// Create notch with SwiftUI views@@ -293,8 +295,22 @@ final class NotchOverlayManager {func setMode(_ mode: OverlayMode) {// Always update NotchContentState to ensure UI stays in sync// (can get out of sync during show/hide transitions)- self.currentMode = mode- NotchContentState.shared.mode = mode+ let normalized = self.normalizedOverlayMode(mode)+ self.currentMode = normalized+ NotchContentState.shared.mode = normalized+ self.syncPromptPickerMode(for: normalized)+ }++ func switchLiveOverlayMode(to promptMode: SettingsStore.PromptMode) {+ guard !NotchContentState.shared.isProcessing else { return }+ switch promptMode.normalized {+ case .dictate:+ self.setMode(.dictation)+ case .edit:+ self.setMode(.edit)+ case .write, .rewrite:+ self.setMode(.edit)+ }}func updateTranscriptionText(_ text: String) {@@ -405,6 +421,26 @@ final class NotchOverlayManager {self.commandOutputState = .visible}+ private func syncPromptPickerMode(for mode: OverlayMode) {+ switch mode {+ case .dictation:+ NotchContentState.shared.promptPickerMode = .dictate+ case .edit, .write, .rewrite:+ NotchContentState.shared.promptPickerMode = .edit+ case .command:+ break+ }+ }++ private func normalizedOverlayMode(_ mode: OverlayMode) -> OverlayMode {+ switch mode {+ case .write, .rewrite:+ return .edit+ case .dictation, .edit, .command:+ return mode+ }+ }+/// Hide expanded command output notch - force close regardless of hover statefunc hideExpandedCommandOutput() {self.commandOutputGeneration &+= 1diff --git a/Sources/Fluid/Services/ParakeetVocabularyStore.swift b/Sources/Fluid/Services/ParakeetVocabularyStore.swiftnew file mode 100644index 00000000..1480f65c--- /dev/null+++ b/Sources/Fluid/Services/ParakeetVocabularyStore.swift@@ -0,0 +1,409 @@+import Foundation+#if arch(arm64)+import FluidAudio+#endif++/// JSON-backed store for Parakeet vocabulary boosting terms.+/// Persists to Application Support so it survives app updates and can be user-edited.+final class ParakeetVocabularyStore {+ static let shared = ParakeetVocabularyStore()++ struct VocabularyConfig: Codable, Sendable {+ struct Term: Codable, Hashable, Sendable {+ let text: String+ let weight: Float?+ let aliases: [String]++ init(text: String, weight: Float?, aliases: [String] = []) {+ self.text = text+ self.weight = weight+ self.aliases = aliases+ }++ private enum CodingKeys: String, CodingKey {+ case text+ case weight+ case aliases+ }++ init(from decoder: Decoder) throws {+ let container = try decoder.container(keyedBy: CodingKeys.self)+ self.text = try container.decode(String.self, forKey: .text)+ self.weight = try container.decodeIfPresent(Float.self, forKey: .weight)+ self.aliases = try container.decodeIfPresent([String].self, forKey: .aliases) ?? []+ }++ func encode(to encoder: Encoder) throws {+ var container = encoder.container(keyedBy: CodingKeys.self)+ try container.encode(self.text, forKey: .text)+ try container.encodeIfPresent(self.weight, forKey: .weight)+ if !self.aliases.isEmpty {+ try container.encode(self.aliases, forKey: .aliases)+ }+ }+ }++ let alpha: Float?+ let minCtcScore: Float?+ let minSimilarity: Float?+ let minCombinedConfidence: Float?+ let minTermLength: Int?+ let terms: [Term]+ }++ struct ResolvedConfig: Sendable {+ let alpha: Float+ let minCtcScore: Float+ let minSimilarity: Float+ let minCombinedConfidence: Float+ let minTermLength: Int+ let terms: [VocabularyConfig.Term]+ }++ enum StoreError: LocalizedError {+ case invalidJSON(String)+ case applicationSupportUnavailable++ var errorDescription: String? {+ switch self {+ case let .invalidJSON(details):+ return "Invalid vocabulary JSON: \(details)"+ case .applicationSupportUnavailable:+ return "Could not access Application Support directory."+ }+ }+ }++ private enum Defaults {+ // Balanced defaults to reduce over-biasing while still improving rare terms.+ static let alpha: Float = 2.8+ static let minCtcScore: Float = -2.2+ static let minSimilarity: Float = 0.72+ static let minCombinedConfidence: Float = 0.64+ static let minTermLength: Int = 3+ static let maxTerms: Int = 256+ }++ private let fileName = "parakeet_custom_vocabulary.json"+ private let appSupportFolder = "FluidVoice"++ private init() {}++ func vocabularyFileURL() throws -> URL {+ guard let base = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first else {+ throw StoreError.applicationSupportUnavailable+ }+ let directory = base.appendingPathComponent(self.appSupportFolder, isDirectory: true)+ DebugLogger.shared.debug(+ "ParakeetVocabularyStore: app support directory=\(directory.path)",+ source: "ParakeetVocabularyStore"+ )+ try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)+ return directory.appendingPathComponent(self.fileName)+ }++ @discardableResult+ func ensureVocabularyFileExists() throws -> URL {+ let url = try self.vocabularyFileURL()+ DebugLogger.shared.debug("ParakeetVocabularyStore: checking vocabulary file \(url.path)", source: "ParakeetVocabularyStore")+ guard !FileManager.default.fileExists(atPath: url.path) else { return url }++ if let bundled = Bundle.main.url(forResource: "parakeet_custom_vocabulary.default", withExtension: "json"),+ let bundledText = try? String(contentsOf: bundled, encoding: .utf8)+ {+ try bundledText.write(to: url, atomically: true, encoding: .utf8)+ } else {+ try Self.defaultTemplateJSON().write(to: url, atomically: true, encoding: .utf8)+ }+ return url+ }++ func loadRawJSON() throws -> String {+ let url = try self.ensureVocabularyFileExists()+ DebugLogger.shared.debug("ParakeetVocabularyStore: loading raw JSON from \(url.path)", source: "ParakeetVocabularyStore")+ return try String(contentsOf: url, encoding: .utf8)+ }++ func validateJSON(_ json: String) throws -> VocabularyConfig {+ let data = Data(json.utf8)+ do {+ return try JSONDecoder().decode(VocabularyConfig.self, from: data)+ } catch {+ throw StoreError.invalidJSON(error.localizedDescription)+ }+ }++ func saveRawJSON(_ json: String) throws {+ _ = try self.validateJSON(json)+ let url = try self.ensureVocabularyFileExists()+ try json.write(to: url, atomically: true, encoding: .utf8)+ NotificationCenter.default.post(name: .parakeetVocabularyDidChange, object: nil)+ }++ /// Loads only the user-managed boost terms from storage.+ /// Tuning parameters remain backend-managed defaults unless explicitly present in the file.+ func loadUserBoostTerms() throws -> [VocabularyConfig.Term] {+ let rawJSON = try self.loadRawJSON()+ let parsed = try self.validateJSON(rawJSON)+ return Self.normalizeUserTerms(parsed.terms, maxTerms: Defaults.maxTerms)+ }++ /// Saves user-managed boost terms while keeping tuning backend-controlled.+ func saveUserBoostTerms(_ terms: [VocabularyConfig.Term]) throws {+ let normalizedTerms = Self.normalizeUserTerms(terms, maxTerms: Defaults.maxTerms)+ // Keep tuning backend-controlled so users only manage words in UI.+ let config = VocabularyConfig(+ alpha: Defaults.alpha,+ minCtcScore: Defaults.minCtcScore,+ minSimilarity: Defaults.minSimilarity,+ minCombinedConfidence: Defaults.minCombinedConfidence,+ minTermLength: Defaults.minTermLength,+ terms: normalizedTerms+ )++ let encoder = JSONEncoder()+ encoder.outputFormatting = [.prettyPrinted, .sortedKeys]+ let data = try encoder.encode(config)+ guard let text = String(data: data, encoding: .utf8) else {+ throw StoreError.invalidJSON("Failed to encode boost terms.")+ }++ let url = try self.ensureVocabularyFileExists()+ try text.write(to: url, atomically: true, encoding: .utf8)+ NotificationCenter.default.post(name: .parakeetVocabularyDidChange, object: nil)+ }++ func hasAnyBoostTerms() -> Bool {+ (try? self.loadResolvedConfig())?.terms.isEmpty == false+ }++ func loadResolvedConfig() throws -> ResolvedConfig {+ let rawJSON = try self.loadRawJSON()+ let parsed = (try? self.validateJSON(rawJSON)) ?? VocabularyConfig(+ alpha: nil,+ minCtcScore: nil,+ minSimilarity: nil,+ minCombinedConfidence: nil,+ minTermLength: nil,+ terms: []+ )+ DebugLogger.shared.debug(+ "ParakeetVocabularyStore: loaded base config terms=\(parsed.terms.count)",+ source: "ParakeetVocabularyStore"+ )++ let mergedTerms = self.mergeAndNormalizeTerms(jsonTerms: parsed.terms, dictionaryEntries: SettingsStore.shared.customDictionaryEntries)+ DebugLogger.shared.debug(+ "ParakeetVocabularyStore: merged terms=\(mergedTerms.count), dictionaryEntries=\(SettingsStore.shared.customDictionaryEntries.count)",+ source: "ParakeetVocabularyStore"+ )++ return ResolvedConfig(+ // Backend-tuned values: avoid stale/aggressive values from old JSON files.+ alpha: Defaults.alpha,+ minCtcScore: Defaults.minCtcScore,+ minSimilarity: Defaults.minSimilarity,+ minCombinedConfidence: Defaults.minCombinedConfidence,+ minTermLength: Defaults.minTermLength,+ terms: mergedTerms+ )+ }++ private func mergeAndNormalizeTerms(+ jsonTerms: [VocabularyConfig.Term],+ dictionaryEntries: [SettingsStore.CustomDictionaryEntry]+ ) -> [VocabularyConfig.Term] {+ DebugLogger.shared.debug(+ "ParakeetVocabularyStore: merge input jsonTerms=\(jsonTerms.count), dictionaryEntries=\(dictionaryEntries.count)",+ source: "ParakeetVocabularyStore"+ )+ var mergedByText: [String: VocabularyConfig.Term] = [:]++ func normalizeAliases(_ aliases: [String], excluding text: String) -> [String] {+ let normalized = aliases+ .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }+ .filter { !$0.isEmpty }+ .filter { $0.caseInsensitiveCompare(text) != .orderedSame }+ let deduped = Array(Set(normalized.map { $0.lowercased() })).sorted()+ return deduped+ }++ func upsert(_ term: VocabularyConfig.Term) {+ let normalizedText = term.text.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !normalizedText.isEmpty else { return }+ let key = normalizedText.lowercased()++ if let existing = mergedByText[key] {+ let combinedAliases = Array(Set(existing.aliases + term.aliases)).sorted()+ let combinedWeight = max(existing.weight ?? 0, term.weight ?? 0)+ mergedByText[key] = VocabularyConfig.Term(+ text: existing.text,+ weight: combinedWeight > 0 ? combinedWeight : nil,+ aliases: combinedAliases+ )+ return+ }++ mergedByText[key] = VocabularyConfig.Term(+ text: normalizedText,+ weight: term.weight,+ aliases: normalizeAliases(term.aliases, excluding: normalizedText)+ )+ }++ for term in jsonTerms {+ upsert(term)+ }++ for entry in dictionaryEntries {+ let replacement = entry.replacement.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !replacement.isEmpty else { continue }+ let aliases = entry.triggers+ .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }+ .filter { !$0.isEmpty }+ upsert(VocabularyConfig.Term(text: replacement, weight: 8.0, aliases: aliases))+ }++ let merged = mergedByText.values.sorted { lhs, rhs in+ lhs.text.localizedCaseInsensitiveCompare(rhs.text) == .orderedAscending+ }+ DebugLogger.shared.debug(+ "ParakeetVocabularyStore: merge output count=\(merged.count)",+ source: "ParakeetVocabularyStore"+ )+ return merged+ }++ private static func normalizeUserTerms(_ terms: [VocabularyConfig.Term], maxTerms: Int) -> [VocabularyConfig.Term] {+ var seen: Set<String> = []+ var normalized: [VocabularyConfig.Term] = []+ normalized.reserveCapacity(min(terms.count, maxTerms))++ for term in terms {+ let text = term.text.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !text.isEmpty else { continue }++ let key = text.lowercased()+ guard !seen.contains(key) else { continue }+ seen.insert(key)++ let aliases = term.aliases+ .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }+ .filter { !$0.isEmpty }+ .filter { $0.caseInsensitiveCompare(text) != .orderedSame }++ let dedupedAliases = Array(Set(aliases.map { $0.lowercased() })).sorted()+ normalized.append(+ VocabularyConfig.Term(+ text: text,+ weight: term.weight,+ aliases: dedupedAliases+ )+ )++ if normalized.count >= maxTerms {+ break+ }+ }++ return normalized+ }++ static func defaultTemplateJSON() -> String {+ """+ {+ "alpha": 2.8,+ "minCtcScore": -2.2,+ "minSimilarity": 0.72,+ "minCombinedConfidence": 0.64,+ "minTermLength": 3,+ "terms": [+ {+ "text": "FluidVoice",+ "aliases": ["fluid voice", "fluid boys"],+ "weight": 10.0+ }+ ]+ }+ """+ }+}++extension Notification.Name {+ static let parakeetVocabularyDidChange = Notification.Name("ParakeetVocabularyDidChange")+}++#if arch(arm64)+extension ParakeetVocabularyStore {+ /// Creates tokenized vocabulary + CTC models for FluidAudio vocabulary boosting.+ func loadTokenizedVocabularyBundle(+ maxTerms: Int = 256+ ) async throws -> (vocabulary: CustomVocabularyContext, ctcModels: CtcModels)? {+ let resolved = try self.loadResolvedConfig()+ DebugLogger.shared.debug("ParakeetVocabularyStore: resolved vocabulary term count=\(resolved.terms.count)", source: "ParakeetVocabularyStore")+ guard !resolved.terms.isEmpty else {+ DebugLogger.shared.debug("ParakeetVocabularyStore: no resolved terms; returning nil bundle", source: "ParakeetVocabularyStore")+ return nil+ }++ let cappedLimit = min(maxTerms, Defaults.maxTerms)+ DebugLogger.shared.debug(+ "ParakeetVocabularyStore: maxTerms=\(maxTerms), cappedLimit=\(cappedLimit)",+ source: "ParakeetVocabularyStore"+ )+ // Keep high-priority terms when capping large vocab sets.+ let prioritizedTerms = resolved.terms.sorted { lhs, rhs in+ let lhsWeight = lhs.weight ?? 0+ let rhsWeight = rhs.weight ?? 0+ if lhsWeight == rhsWeight {+ return lhs.text.localizedCaseInsensitiveCompare(rhs.text) == .orderedAscending+ }+ return lhsWeight > rhsWeight+ }+ let cappedTerms = Array(prioritizedTerms.prefix(cappedLimit))+ DebugLogger.shared.debug(+ "ParakeetVocabularyStore: capped terms count=\(cappedTerms.count)",+ source: "ParakeetVocabularyStore"+ )+ let ctcModels = try await CtcModels.downloadAndLoad(variant: .ctc110m)+ DebugLogger.shared.debug(+ "ParakeetVocabularyStore: ctc model loaded variant=\(ctcModels.variant)",+ source: "ParakeetVocabularyStore"+ )+ let ctcTokenizer = try await CtcTokenizer.load(from: CtcModels.defaultCacheDirectory(for: ctcModels.variant))++ let tokenizedTerms: [CustomVocabularyTerm] = cappedTerms.compactMap { term in+ let tokens = ctcTokenizer.encode(term.text)+ guard !tokens.isEmpty else { return nil }+ return CustomVocabularyTerm(+ text: term.text,+ weight: term.weight,+ aliases: term.aliases,+ tokenIds: nil,+ ctcTokenIds: tokens+ )+ }++ DebugLogger.shared.debug("ParakeetVocabularyStore: tokenized term count=\(tokenizedTerms.count)", source: "ParakeetVocabularyStore")+ guard !tokenizedTerms.isEmpty else {+ DebugLogger.shared.debug("ParakeetVocabularyStore: tokenization produced empty list; returning nil bundle", source: "ParakeetVocabularyStore")+ return nil+ }++ let vocabulary = CustomVocabularyContext(+ terms: tokenizedTerms,+ alpha: resolved.alpha,+ minCtcScore: resolved.minCtcScore,+ minSimilarity: resolved.minSimilarity,+ minCombinedConfidence: resolved.minCombinedConfidence,+ minTermLength: resolved.minTermLength+ )+ DebugLogger.shared.debug(+ "ParakeetVocabularyStore: prepared tokenized vocabulary with \(vocabulary.terms.count) terms",+ source: "ParakeetVocabularyStore"+ )++ return (vocabulary, ctcModels)+ }+}+#endifdiff --git a/Sources/Fluid/Services/RewriteModeService.swift b/Sources/Fluid/Services/RewriteModeService.swiftindex 24920287..3005e075 100644--- a/Sources/Fluid/Services/RewriteModeService.swift+++ b/Sources/Fluid/Services/RewriteModeService.swift@@ -1,10 +1,12 @@import AppKitimport Combine+import CryptoKitimport Foundation@MainActorfinal class RewriteModeService: ObservableObject {@Published var originalText: String = ""+ @Published var selectedContextText: String = ""@Published var rewrittenText: String = ""@Published var streamingThinkingText: String = "" // Real-time thinking tokens for UI@Published var isProcessing = false@@ -14,6 +16,24 @@ final class RewriteModeService: ObservableObject {private let textSelectionService = TextSelectionService.sharedprivate let typingService = TypingService()private var thinkingBuffer: [String] = [] // Buffer thinking tokens+ private var forcePromptTraceToConsole: Bool {+ ProcessInfo.processInfo.environment["FLUID_PROMPT_TRACE"] == "1"+ }++ private var diagnosticsEnabled: Bool {+ if ProcessInfo.processInfo.environment["FLUID_REWRITE_DIAGNOSTICS"] == "1" {+ return true+ }+ return UserDefaults.standard.bool(forKey: "RewriteModeDiagnosticsEnabled")+ }++ private var shouldTracePromptProcessing: Bool {+ if let explicit = UserDefaults.standard.object(forKey: "RewriteModePromptTraceEnabled") as? Bool {+ return explicit+ }+ // Default OFF to avoid logging prompt/context content in normal usage.+ return false+ }struct Message: Identifiable, Equatable {let id = UUID()@@ -29,9 +49,13 @@ final class RewriteModeService: ObservableObject {func captureSelectedText() -> Bool {if let text = textSelectionService.getSelectedText(), !text.isEmpty {self.originalText = text+ self.selectedContextText = textself.rewrittenText = ""self.conversationHistory = []self.isWriteMode = false+ if self.shouldTracePromptProcessing {+ self.logPromptTrace("Captured selected context", value: text)+ }return true}return false@@ -40,9 +64,13 @@ final class RewriteModeService: ObservableObject {/// Start rewrite mode without selected text - user will provide text via voicefunc startWithoutSelection() {self.originalText = ""+ self.selectedContextText = ""self.rewrittenText = ""self.conversationHistory = []self.isWriteMode = true+ if self.shouldTracePromptProcessing {+ self.logPromptTrace("Starting edit with no selected context", value: "<empty>")+ }}/// Set the original text directly (from voice input when no text was selected)@@ -54,6 +82,9 @@ final class RewriteModeService: ObservableObject {func processRewriteRequest(_ prompt: String) async {let startTime = Date()+ self.appendDiagnosticLog(+ "processRewriteRequest start | promptChars=\(prompt.count) | hadOriginal=\(!self.originalText.isEmpty) | contextChars=\(self.selectedContextText.count)"+ )// If no original text, we're in "Write Mode" - generate content based on user's requestif self.originalText.isEmpty {self.originalText = prompt@@ -64,17 +95,23 @@ final class RewriteModeService: ObservableObject {} else {// Rewrite Mode: User has selected text and is giving instructionsself.isWriteMode = false+ let hasContext = !self.selectedContextText.trimmingCharacters(in: .whitespacesAndNewlines).isEmptyif self.conversationHistory.isEmpty {- let rewritePrompt = """- Here is the text to rewrite:-- "\(originalText)"-- User's instruction: \(prompt)-- Rewrite the text according to the instruction. Output ONLY the rewritten text, nothing else.- """+ let rewritePrompt: String+ if hasContext {+ rewritePrompt = """+ User's instruction: \(prompt)++ Apply the instruction to the selected context. Output ONLY the rewritten text, nothing else.+ """+ } else {+ rewritePrompt = """+ User's instruction: \(prompt)++ Output ONLY the requested text, nothing else.+ """+ }self.conversationHistory.append(Message(role: .user, content: rewritePrompt))} else {// Follow-up request@@ -91,6 +128,9 @@ final class RewriteModeService: ObservableObject {self.conversationHistory.append(Message(role: .assistant, content: response))self.rewrittenText = responseself.isProcessing = false+ self.appendDiagnosticLog(+ "processRewriteRequest success | writeMode=\(self.isWriteMode) | outputChars=\(response.count) | latency=\(String(format: "%.2fs", Date().timeIntervalSince(startTime)))"+ )AnalyticsService.shared.capture(.rewriteRunCompleted,@@ -103,6 +143,9 @@ final class RewriteModeService: ObservableObject {} catch {self.conversationHistory.append(Message(role: .assistant, content: "Error: \(error.localizedDescription)"))self.isProcessing = false+ self.appendDiagnosticLog(+ "processRewriteRequest failure | writeMode=\(self.isWriteMode) | error=\(error.localizedDescription)"+ )AnalyticsService.shared.capture(.rewriteRunCompleted,@@ -131,6 +174,7 @@ final class RewriteModeService: ObservableObject {func clearState() {self.originalText = ""+ self.selectedContextText = ""self.rewrittenText = ""self.streamingThinkingText = ""self.conversationHistory = []@@ -142,8 +186,56 @@ final class RewriteModeService: ObservableObject {private func callLLM(messages: [Message], isWriteMode: Bool) async throws -> String {let settings = SettingsStore.shared- // Use Write Mode's independent provider/model settings- let providerID = settings.rewriteModeSelectedProviderID+ let promptMode: SettingsStore.PromptMode = .edit+ let selectedProfile = settings.selectedPromptProfile(for: promptMode)+ let selectedPromptName: String = {+ if let profile = selectedProfile {+ return profile.name.isEmpty ? "Untitled Prompt" : profile.name+ }+ return "Default Edit"+ }()+ let promptBody = settings.effectivePromptBody(for: promptMode)+ let builtInDefaultPrompt = SettingsStore.defaultSystemPromptText(for: promptMode)+ let systemPromptBeforeContext = settings.effectiveSystemPrompt(for: promptMode)+ // Use global provider/model when linked, otherwise use Edit Mode's independent settings.+ let providerID: String = {+ if settings.rewriteModeLinkedToGlobal {+ let globalProvider = settings.selectedProviderID+ if self.isProviderVerified(globalProvider, settings: settings) {+ return globalProvider+ }+ return settings.rewriteModeSelectedProviderID+ }+ return settings.rewriteModeSelectedProviderID+ }()++ var systemPrompt = systemPromptBeforeContext+ let contextText = self.selectedContextText.trimmingCharacters(in: .whitespacesAndNewlines)+ var contextBlock = ""+ contextBlock = SettingsStore.runtimeContextBlock(+ context: self.selectedContextText,+ template: SettingsStore.contextTemplateText()+ )+ if !contextBlock.isEmpty {+ systemPrompt = "\(systemPrompt)\n\n\(contextBlock)"+ DebugLogger.shared.debug("Injected selected-text context into \(promptMode.rawValue) prompt", source: "RewriteModeService")+ }++ if self.shouldTracePromptProcessing {+ let messageDump = messages.map {+ let role = ($0.role == .user) ? "user" : "assistant"+ return "[\(role)]\n\($0.content)"+ }.joined(separator: "\n\n")+ self.logPromptTrace("Mode", value: isWriteMode ? "Edit (write)" : "Edit (rewrite)")+ self.logPromptTrace("Selected prompt profile", value: selectedPromptName)+ self.logPromptTrace("Prompt body (custom/default body)", value: promptBody)+ self.logPromptTrace("Built-in default system prompt (baseline)", value: builtInDefaultPrompt)+ self.logPromptTrace("System prompt before context", value: systemPromptBeforeContext)+ self.logPromptTrace("Selected context text", value: contextText.isEmpty ? "<empty>" : contextText)+ self.logPromptTrace("Context block injected", value: contextBlock.isEmpty ? "<none>" : contextBlock)+ self.logPromptTrace("Final system prompt sent to model", value: systemPrompt)+ self.logPromptTrace("Conversation input (Q/history)", value: messageDump.isEmpty ? "<empty>" : messageDump)+ }// Route to Apple Intelligence if selectedif providerID == "apple-intelligence" {@@ -152,8 +244,12 @@ final class RewriteModeService: ObservableObject {let provider = AppleIntelligenceProvider()let messageTuples = messages.map { (role: $0.role == .user ? "user" : "assistant", content: $0.content) }- DebugLogger.shared.debug("Using Apple Intelligence for rewrite mode", source: "RewriteModeService")- return try await provider.processRewrite(messages: messageTuples, isWriteMode: isWriteMode)+ DebugLogger.shared.debug("Using Apple Intelligence for edit mode", source: "RewriteModeService")+ let output = try await provider.processRewrite(messages: messageTuples, systemPrompt: systemPrompt)+ if self.shouldTracePromptProcessing {+ self.logPromptTrace("Model answer (A)", value: output)+ }+ return output}#endifthrow NSError(@@ -163,7 +259,27 @@ final class RewriteModeService: ObservableObject {)}- let model = settings.rewriteModeSelectedModel ?? "gpt-4.1"+ let model: String = {+ if settings.rewriteModeLinkedToGlobal {+ let key: String+ if ModelRepository.shared.isBuiltIn(providerID) {+ key = providerID+ } else if providerID.hasPrefix("custom:") {+ key = providerID+ } else {+ key = "custom:\(providerID)"+ }+ return settings.selectedModelByProvider[key]+ ?? settings.selectedModel+ ?? "gpt-4.1"+ }+ return settings.rewriteModeSelectedModel ?? "gpt-4.1"+ }()+ self.appendDiagnosticLog(+ "LLM config | writeMode=\(isWriteMode) | linkedToGlobal=\(settings.rewriteModeLinkedToGlobal) | " ++ "provider=\(providerID) | model=\(model) | profile=\(selectedPromptName) | " ++ "contextChars=\(contextText.count) | contextInjected=\(!contextBlock.isEmpty)"+ )let apiKey = settings.getAPIKey(for: providerID) ?? ""let baseURL: String@@ -175,36 +291,6 @@ final class RewriteModeService: ObservableObject {baseURL = ModelRepository.shared.defaultBaseURL(for: "openai")}- // Different system prompts for each mode- let systemPrompt: String- if isWriteMode {- // Write Mode: Generate content based on user's request- systemPrompt = """- You are a helpful writing assistant. The user will ask you to write or generate text for them.-- Examples of requests:- - "Write an email to my boss asking for time off"- - "Draft a reply saying I'll be there at 5"- - "Write a professional summary for LinkedIn"- - "Answer this: what is the capital of France"-- Respond directly with the requested content. Be concise and helpful.- Output ONLY what they asked for - no explanations or preamble.- """- } else {- // Rewrite Mode: Transform selected text based on instructions- systemPrompt = """- You are a writing assistant that rewrites text according to user instructions. The user has selected existing text and wants you to transform it.-- Your job:- - Follow the user's specific instructions for how to rewrite- - Maintain the core meaning unless asked to change it- - Apply the requested style, tone, or format changes-- Output ONLY the rewritten text. No explanations, no quotes around the text, no preamble.- """- }-// Build messages array for LLMClientvar apiMessages: [[String: Any]] = [["role": "system", "content": systemPrompt],@@ -214,8 +300,9 @@ final class RewriteModeService: ObservableObject {apiMessages.append(["role": msg.role == .user ? "user" : "assistant", "content": msg.content])}- // Check streaming setting- let enableStreaming = settings.enableAIStreaming+ // Edit Text mode does not need token-by-token UI updates.+ // Keep this non-streaming to reduce CPU/battery churn on smaller devices.+ let enableStreaming = false// Reasoning models (o1, o3, gpt-5) don't support temperature parameter at alllet isReasoningModel = settings.isReasoningModel(model)@@ -263,7 +350,7 @@ final class RewriteModeService: ObservableObject {}}- DebugLogger.shared.info("Using LLMClient for Write/Rewrite (streaming=\(enableStreaming))", source: "RewriteModeService")+ DebugLogger.shared.info("Using LLMClient for Edit mode (streaming=\(enableStreaming))", source: "RewriteModeService")// Clear streaming buffers before startingif enableStreaming {@@ -281,13 +368,71 @@ final class RewriteModeService: ObservableObject {// Log thinking if present (for debugging)if let thinking = response.thinking {DebugLogger.shared.debug("LLM thinking tokens extracted (\(thinking.count) chars)", source: "RewriteModeService")+ if self.shouldTracePromptProcessing {+ self.logPromptTrace("Model thinking", value: thinking)+ }}DebugLogger.shared.debug("Response complete. Content length: \(response.content.count)", source: "RewriteModeService")+ if self.shouldTracePromptProcessing {+ self.logPromptTrace("Model answer (A)", value: response.content)+ }// For non-streaming, we return the content directly// For streaming, rewrittenText is already updated via callback,// but we return the final content for consistencyreturn response.content}++ private func logPromptTrace(_ title: String, value: String) {+ let line = "[PromptTrace][Edit] \(title):\n\(value)"+ if self.forcePromptTraceToConsole {+ print(line)+ }+ self.appendDiagnosticLog(line)+ }++ private func appendDiagnosticLog(_ message: String) {+ guard self.diagnosticsEnabled || self.forcePromptTraceToConsole else { return }+ let line = "[RewriteModeService] \(message)"+ FileLogger.shared.append(line: line)+ DebugLogger.shared.debug(line, source: "RewriteModeService")+ }++ private func providerKey(for providerID: String) -> String {+ if ModelRepository.shared.isBuiltIn(providerID) { return providerID }+ if providerID.hasPrefix("custom:") { return providerID }+ return "custom:\(providerID)"+ }++ private func providerBaseURL(for providerID: String, settings: SettingsStore) -> String {+ if let saved = settings.savedProviders.first(where: { $0.id == providerID }) {+ return saved.baseURL.trimmingCharacters(in: .whitespacesAndNewlines)+ }+ if ModelRepository.shared.isBuiltIn(providerID) {+ return ModelRepository.shared.defaultBaseURL(for: providerID).trimmingCharacters(in: .whitespacesAndNewlines)+ }+ return ""+ }++ private func providerFingerprint(baseURL: String, apiKey: String) -> String? {+ let trimmedBase = baseURL.trimmingCharacters(in: .whitespacesAndNewlines)+ let trimmedKey = apiKey.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !trimmedBase.isEmpty else { return nil }+ let input = "\(trimmedBase)|\(trimmedKey)"+ let digest = SHA256.hash(data: Data(input.utf8))+ return digest.map { String(format: "%02x", $0) }.joined()+ }++ private func isProviderVerified(_ providerID: String, settings: SettingsStore) -> Bool {+ let key = self.providerKey(for: providerID)+ guard let stored = settings.verifiedProviderFingerprints[key] else { return false }+ if providerID == "apple-intelligence" {+ return stored == "apple-intelligence"+ }+ let baseURL = self.providerBaseURL(for: providerID, settings: settings)+ let apiKey = settings.getAPIKey(for: providerID) ?? ""+ let current = self.providerFingerprint(baseURL: baseURL, apiKey: apiKey)+ return current == stored+ }}diff --git a/Sources/Fluid/Services/SimpleUpdater.swift b/Sources/Fluid/Services/SimpleUpdater.swiftindex 16edc263..9a456f3f 100644--- a/Sources/Fluid/Services/SimpleUpdater.swift+++ b/Sources/Fluid/Services/SimpleUpdater.swift@@ -12,6 +12,8 @@ enum SimpleUpdateError: Error, LocalizedError {case unzipFailedcase notAnAppBundlecase codesignMismatch+ case rollbackUnavailable+ case rollbackRestoreFailedvar errorDescription: String? {switch self {@@ -24,6 +26,8 @@ enum SimpleUpdateError: Error, LocalizedError {case .unzipFailed: return "Failed to extract the update archive."case .notAnAppBundle: return "Extracted content does not contain an app bundle."case .codesignMismatch: return "Downloaded app’s code signature does not match current app."+ case .rollbackUnavailable: return "No rollback backup is available."+ case .rollbackRestoreFailed: return "Failed to restore a previous version."}}}@@ -41,12 +45,94 @@ struct GHRelease: Decodable {let body: String?let name: String?let published_at: String?+ let html_url: URL?}@MainActorfinal class SimpleUpdater {+ struct ReleaseBuildOption {+ let version: String+ let url: URL+ }+static let shared = SimpleUpdater()private init() {}++ private let fileManager = FileManager.default+ private let maxRollbackBackups = 3+ private let rollbackBackupDirectoryName = "RollbackBackups"++ private var installedAppName: String {+ return Bundle.main.bundleURL.deletingPathExtension().lastPathComponent+ }++ func hasRollbackBackup() -> Bool {+ return !self.availableRollbackBackups().isEmpty+ }++ func latestRollbackVersion() -> String? {+ guard let latest = self.latestRollbackBackup() else { return nil }+ return self.versionString(for: latest)+ }++ func rollbackToLatestBackup() async throws {+ guard let rollbackBundleURL = self.latestRollbackBackup() else {+ throw SimpleUpdateError.rollbackUnavailable+ }++ self.createRollbackBackup(beforeRollback: true)++ do {+ try self.performSwapAndRelaunch(+ installedAppURL: Bundle.main.bundleURL,+ downloadedAppURL: rollbackBundleURL+ )+ DebugLogger.shared.info(+ "SimpleUpdater: Rolled back to \(rollbackBundleURL.lastPathComponent)",+ source: "SimpleUpdater"+ )+ } catch {+ throw SimpleUpdateError.rollbackRestoreFailed+ }+ }++ func fetchRecentReleaseBuildOptions(owner: String, repo: String, limit: Int = 3) async throws -> [ReleaseBuildOption] {+ guard let releasesURL = URL(string: "https://api.github.com/repos/\(owner)/\(repo)/releases") else {+ throw SimpleUpdateError.invalidURL+ }++ let (data, response) = try await URLSession.shared.data(from: releasesURL)+ guard let http = response as? HTTPURLResponse, (200..<300).contains(http.statusCode) else {+ throw SimpleUpdateError.invalidResponse+ }++ let releases: [GHRelease]+ do {+ releases = try JSONDecoder().decode([GHRelease].self, from: data)+ } catch {+ throw SimpleUpdateError.jsonDecoding+ }++ let count = max(1, limit)+ let stableReleases = releases.filter { !$0.prerelease }.prefix(count)++ return stableReleases.map { release in+ let zipAsset = release.assets.first {+ $0.content_type == "application/zip" ||+ $0.content_type == "application/x-zip-compressed" ||+ $0.name.lowercased().hasSuffix(".zip")+ }+ let fallbackTagURL = URL(string: "https://github.com/\(owner)/\(repo)/releases/tag/\(release.tag_name)")+ let fallbackReleasesURL = URL(string: "https://github.com/\(owner)/\(repo)/releases")+ let url = zipAsset?.browser_download_url ??+ release.html_url ??+ fallbackTagURL ??+ fallbackReleasesURL ??+ URL(fileURLWithPath: "/")+ return ReleaseBuildOption(version: release.tag_name, url: url)+ }+ }+// Allowed Apple Developer Team IDs for code-sign validation// Configured per your request; restrict to your actual Team ID only.private let allowedTeamIDs: Set<String> = [@@ -141,14 +227,15 @@ final class SimpleUpdater {let latestTag = latest.tag_namelet latestVersion = self.parseVersion(latestTag)+ let currentBundle = Bundle.main// up to dateif !self.isVersion(latestVersion, greaterThan: current) {throw PMKError.cancelled // mimic AppUpdater semantics for up-to-date}- // Find asset matching: "{repo-lower}-{version-no-v}.*" and zip preferred- let verString = self.versionString(latestVersion)- let prefix = "\(repo.lowercased())-\(verString)"+ // Find asset matching: "{repo-lower}-{version-from-tag}.*" and zip preferred+ let rawVersion = latestTag.hasPrefix("v") ? String(latestTag.dropFirst()) : latestTag+ let prefix = "\(repo.lowercased())-\(rawVersion)"let asset = latest.assets.first { asset inlet base = (asset.name as NSString).deletingPathExtension.lowercased()return (base == prefix) &&@@ -188,7 +275,6 @@ final class SimpleUpdater {}// Validate code signing identity matches (skip in DEBUG for easier local testing)- let currentBundle = Bundle.main#if DEBUG// In Debug builds the local app is typically signed with a development cert, while// releases are signed with Developer ID. Skip strict check to enable testing.@@ -230,12 +316,116 @@ final class SimpleUpdater {}#endif+ self.createRollbackBackup(beforeRollback: false)+// Replace and relaunchtry self.performSwapAndRelaunch(installedAppURL: currentBundle.bundleURL, downloadedAppURL: extractedBundleURL)}// MARK: - Helpers+ private func rollbackRootDirectory() -> URL {+ let base = self.fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask).first+ let support = base ?? URL(fileURLWithPath: NSTemporaryDirectory())+ return support+ .appendingPathComponent("Fluid", isDirectory: true)+ .appendingPathComponent(self.rollbackBackupDirectoryName, isDirectory: true)+ .appendingPathComponent(self.installedAppName, isDirectory: true)+ }++ private func availableRollbackBackups() -> [URL] {+ let backupDir = self.rollbackRootDirectory()+ guard self.fileManager.fileExists(atPath: backupDir.path) else { return [] }++ let urls: [URL]+ do {+ urls = try self.fileManager.contentsOfDirectory(+ at: backupDir,+ includingPropertiesForKeys: [.contentModificationDateKey],+ options: [.skipsHiddenFiles]+ )+ } catch {+ return []+ }++ return urls+ .filter { $0.pathExtension == "app" }+ .compactMap { url in+ (try? url.resourceValues(forKeys: [.contentModificationDateKey]))?.contentModificationDate.map { (url, $0) }+ }+ .sorted { $0.1 > $1.1 }+ .map { $0.0 }+ }++ private func latestRollbackBackup() -> URL? {+ return self.availableRollbackBackups().first+ }++ private func versionString(for appURL: URL) -> String? {+ guard let bundle = Bundle(url: appURL) else { return nil }+ return bundle.infoDictionary?["CFBundleShortVersionString"] as? String+ }++ private func sanitizeVersion(_ version: String) -> String {+ return version+ .replacingOccurrences(of: "/", with: "_")+ .replacingOccurrences(of: ":", with: "_")+ .replacingOccurrences(of: " ", with: "_")+ }++ private func createRollbackBackup(beforeRollback: Bool) {+ let currentAppVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "unknown"+ let appURL = Bundle.main.bundleURL+ let backupRoot = self.rollbackRootDirectory()++ do {+ try self.fileManager.createDirectory(+ at: backupRoot,+ withIntermediateDirectories: true+ )+ } catch {+ DebugLogger.shared.warning("SimpleUpdater: Failed to create rollback backup folder: \(error.localizedDescription)", source: "SimpleUpdater")+ return+ }++ let timestamp = Int(Date().timeIntervalSince1970)+ let safeVersion = self.sanitizeVersion(currentAppVersion)+ let backupName = beforeRollback+ ? "\(self.installedAppName)-\(safeVersion)-rollback-\(timestamp).app"+ : "\(self.installedAppName)-\(safeVersion)-\(timestamp).app"+ let backupURL = backupRoot.appendingPathComponent(backupName)++ do {+ try self.fileManager.copyItem(at: appURL, to: backupURL)+ self.pruneRollbackBackups()+ DebugLogger.shared.info(+ "SimpleUpdater: Created rollback backup at \(backupURL.path)",+ source: "SimpleUpdater"+ )+ } catch {+ DebugLogger.shared.warning(+ "SimpleUpdater: Failed to create rollback backup: \(error.localizedDescription)",+ source: "SimpleUpdater"+ )+ }+ }++ private func pruneRollbackBackups() {+ let backups = self.availableRollbackBackups()+ guard backups.count > self.maxRollbackBackups else { return }++ for oldBackup in backups.dropFirst(self.maxRollbackBackups) {+ do {+ try self.fileManager.removeItem(at: oldBackup)+ } catch {+ DebugLogger.shared.warning(+ "SimpleUpdater: Failed to remove old rollback backup \(oldBackup.lastPathComponent): \(error.localizedDescription)",+ source: "SimpleUpdater"+ )+ }+ }+ }+private func parseVersion(_ s: String) -> [Int] {var t = s.hasPrefix("v") ? String(s.dropFirst()) : sdiff --git a/Sources/Fluid/Services/TextSelectionService.swift b/Sources/Fluid/Services/TextSelectionService.swiftindex 8d6fa174..601a06f9 100644--- a/Sources/Fluid/Services/TextSelectionService.swift+++ b/Sources/Fluid/Services/TextSelectionService.swift@@ -9,29 +9,40 @@ final class TextSelectionService {/// Attempts to get the currently selected text using Accessibility APIsfunc getSelectedText() -> String? {+ self.diag("Selection capture start")+// Check accessibility permissionsguard AXIsProcessTrusted() else {DebugLogger.shared.error("Accessibility permissions not granted", source: "TextSelectionService")+ self.diag("Selection capture failed: Accessibility permissions not granted")return nil}// 1. Try to get the system-wide focused elementif let focusedElement = getFocusedElement() {if let text = getSelectedText(from: focusedElement) {+ self.diag("Selection capture success via system focused element (chars=\(text.count))")return text}+ self.diag("System focused element returned no selected text")}// 2. Fallback: Try to find focused element in frontmost appif let frontmostApp = NSWorkspace.shared.frontmostApplication {+ self.diag("Trying frontmost app fallback: \(frontmostApp.bundleIdentifier ?? frontmostApp.localizedName ?? "unknown") pid=\(frontmostApp.processIdentifier)")let appElement = AXUIElementCreateApplication(frontmostApp.processIdentifier)if let focusedElement = getFocusedElement(from: appElement) {if let text = getSelectedText(from: focusedElement) {+ self.diag("Selection capture success via frontmost app focused element (chars=\(text.count))")return text}+ self.diag("Frontmost app focused element returned no selected text")+ } else {+ self.diag("Frontmost app fallback could not resolve focused element")}}+ self.diag("Selection capture failed: no selected text found")return nil}@@ -68,13 +79,86 @@ final class TextSelectionService {let result = AXUIElementCopyAttributeValue(element, kAXSelectedTextAttribute as CFString, &value)if result == .success, let text = value as? String {+ self.diag("kAXSelectedTextAttribute succeeded (chars=\(text.count))")return text}- // Fallback: If no text is selected, some apps might return the value attribute- // But for "rewrite selected", we strictly want selected text.- // We could optionally return all text if we wanted to rewrite the whole field.+ self.diag("kAXSelectedTextAttribute unavailable (\(self.describe(result))) - trying selected range fallback")- return nil+ // Fallback: reconstruct selected text from selected range + full value for apps+ // that don't expose kAXSelectedTextAttribute directly.+ var selectedRangeRef: CFTypeRef?+ let rangeResult = AXUIElementCopyAttributeValue(element, kAXSelectedTextRangeAttribute as CFString, &selectedRangeRef)+ guard rangeResult == .success, let axRange = selectedRangeRef else {+ self.diag("kAXSelectedTextRangeAttribute unavailable (\(self.describe(rangeResult)))")+ return nil+ }++ guard CFGetTypeID(axRange) == AXValueGetTypeID() else {+ self.diag("kAXSelectedTextRangeAttribute returned non-AXValue")+ return nil+ }++ let axValue = unsafeBitCast(axRange, to: AXValue.self)++ var range = CFRange()+ let gotRange = AXValueGetValue(axValue, .cfRange, &range)+ guard gotRange else {+ self.diag("AXValueGetValue(.cfRange) failed")+ return nil+ }++ guard range.location != kCFNotFound, range.length > 0 else {+ self.diag("Selected range empty (location=\(range.location), length=\(range.length))")+ return nil+ }++ var fullValueRef: CFTypeRef?+ let valueResult = AXUIElementCopyAttributeValue(element, kAXValueAttribute as CFString, &fullValueRef)+ guard valueResult == .success, let fullText = fullValueRef as? String else {+ self.diag("kAXValueAttribute unavailable for range extraction (\(self.describe(valueResult)))")+ return nil+ }++ let nsText = fullText as NSString+ guard range.location >= 0,+ range.length > 0,+ range.location + range.length <= nsText.length+ else {+ self.diag("Selected range out of bounds (textLen=\(nsText.length), location=\(range.location), length=\(range.length))")+ return nil+ }++ let extracted = nsText.substring(with: NSRange(location: range.location, length: range.length))+ self.diag("Selected range extraction succeeded (chars=\(extracted.count))")+ return extracted+ }++ private func describe(_ error: AXError) -> String {+ switch error {+ case .success: return "success"+ case .failure: return "failure"+ case .illegalArgument: return "illegalArgument"+ case .invalidUIElement: return "invalidUIElement"+ case .invalidUIElementObserver: return "invalidUIElementObserver"+ case .cannotComplete: return "cannotComplete"+ case .attributeUnsupported: return "attributeUnsupported"+ case .actionUnsupported: return "actionUnsupported"+ case .notificationUnsupported: return "notificationUnsupported"+ case .notImplemented: return "notImplemented"+ case .notificationAlreadyRegistered: return "notificationAlreadyRegistered"+ case .notificationNotRegistered: return "notificationNotRegistered"+ case .apiDisabled: return "apiDisabled"+ case .noValue: return "noValue"+ case .parameterizedAttributeUnsupported: return "parameterizedAttributeUnsupported"+ case .notEnoughPrecision: return "notEnoughPrecision"+ @unknown default: return "unknown(\(error.rawValue))"+ }+ }++ private func diag(_ message: String) {+ let line = "[TextSelectionService] \(message)"+ FileLogger.shared.append(line: line)+ DebugLogger.shared.debug(line, source: "TextSelectionService")}}diff --git a/Sources/Fluid/Services/TranscriptionProvider.swift b/Sources/Fluid/Services/TranscriptionProvider.swiftindex f3ed9bca..46393a6a 100644--- a/Sources/Fluid/Services/TranscriptionProvider.swift+++ b/Sources/Fluid/Services/TranscriptionProvider.swift@@ -37,6 +37,14 @@ protocol TranscriptionProvider {/// - Returns: Transcription result with text and confidencefunc transcribe(_ samples: [Float]) async throws -> ASRTranscriptionResult+ /// Transcribe audio for live streaming updates.+ /// Providers can use faster/lighter paths than final transcription when needed.+ func transcribeStreaming(_ samples: [Float]) async throws -> ASRTranscriptionResult++ /// Transcribe audio for final output when recording stops.+ /// Providers can use higher-quality passes (e.g., vocabulary rescoring) here.+ func transcribeFinal(_ samples: [Float]) async throws -> ASRTranscriptionResult+/// Check if models exist on disk (without loading them)func modelsExistOnDisk() -> Bool@@ -48,6 +56,13 @@ protocol TranscriptionProvider {extension TranscriptionProvider {func modelsExistOnDisk() -> Bool { return false }func clearCache() async throws {}+ func transcribeStreaming(_ samples: [Float]) async throws -> ASRTranscriptionResult {+ try await self.transcribe(samples)+ }++ func transcribeFinal(_ samples: [Float]) async throws -> ASRTranscriptionResult {+ try await self.transcribe(samples)+ }}// MARK: - Architecture Detectiondiff --git a/Sources/Fluid/Services/TranscriptionSoundPlayer.swift b/Sources/Fluid/Services/TranscriptionSoundPlayer.swiftindex af8da231..c1eefc58 100644--- a/Sources/Fluid/Services/TranscriptionSoundPlayer.swift+++ b/Sources/Fluid/Services/TranscriptionSoundPlayer.swift@@ -11,7 +11,8 @@ final class TranscriptionSoundPlayer {func playStartSound() {let selected = SettingsStore.shared.transcriptionStartSound- self.play(soundName: selected.soundFileName)+ guard let soundName = selected.soundFileName else { return }+ self.play(soundName: soundName)}private func play(soundName: String) {diff --git a/Sources/Fluid/Services/TypingService.swift b/Sources/Fluid/Services/TypingService.swiftindex d836c2ff..1c3c4666 100644--- a/Sources/Fluid/Services/TypingService.swift+++ b/Sources/Fluid/Services/TypingService.swift@@ -113,6 +113,26 @@ final class TypingService {self.log("[TypingService] insertTextInstantly called with \(text.count) characters")self.log("[TypingService] Attempting to type text: \"\(text.prefix(50))\(text.count > 50 ? "..." : "")\"")+ if text.utf16.count > Self.cgEventUnicodeLimit {+ self.log("[TypingService] Text exceeds CGEvent limit (\(text.utf16.count) UTF-16 units), using clipboard insertion")+ if self.insertTextViaClipboard(text) {+ self.log("[TypingService] SUCCESS: Clipboard insertion completed (long text path)")+ return+ }+ self.log("[TypingService] Clipboard failed for long text, trying character-by-character")+ for (index, char) in text.enumerated() {+ if index % 10 == 0 {+ self.log("[TypingService] Typing character \(index + 1)/\(text.count)")+ }+ self.typeCharacter(char)+ usleep(1000)+ }+ self.log("[TypingService] Character-by-character typing completed")+ return+ }++ // Short text: use the normal cascade (CGEvent bulk is safe for <= cgEventUnicodeLimit)+// Preferred: target a specific PID when provided (e.g., the app that was focused when recording started).if let preferredTargetPID, preferredTargetPID > 0 {self.log("[TypingService] Trying CGEvent insertion targeting preferred PID \(preferredTargetPID)")@@ -155,7 +175,6 @@ final class TypingService {}// Secondary: Try Accessibility insertion into the actual focused element- // This is useful for some native apps or when direct event posting failsself.log("[TypingService] Trying Accessibility focused-element insertion")if self.insertTextViaAccessibility(text) {self.log("[TypingService] SUCCESS: Accessibility insertion completed")@@ -190,6 +209,8 @@ final class TypingService {self.log("[TypingService] Character-by-character typing completed")}+ private static let cgEventUnicodeLimit = 200+private func insertTextBulkInstant(_ text: String, targetPID: pid_t) -> Bool {self.log("[TypingService] Starting INSTANT bulk CGEvent insertion (NO CLIPBOARD) to PID \(targetPID)")@@ -198,10 +219,14 @@ final class TypingService {return false}- // Convert entire text to UTF16let utf16Array = Array(text.utf16)self.log("[TypingService] Converting \(text.count) characters to CGEvents (UTF16 count \(utf16Array.count))")+ guard utf16Array.count <= Self.cgEventUnicodeLimit else {+ self.log("[TypingService] Text too long for single CGEvent (\(utf16Array.count) UTF-16 units > \(Self.cgEventUnicodeLimit)), falling back")+ return false+ }+guard let keyDown = CGEvent(keyboardEventSource: nil, virtualKey: 0, keyDown: true),let keyUp = CGEvent(keyboardEventSource: nil, virtualKey: 0, keyDown: false)else {@@ -224,6 +249,12 @@ final class TypingService {self.log("[TypingService] Starting INSTANT bulk CGEvent insertion via HID (NO PID)")let utf16Array = Array(text.utf16)++ guard utf16Array.count <= Self.cgEventUnicodeLimit else {+ self.log("[TypingService] Text too long for single HID CGEvent (\(utf16Array.count) > \(Self.cgEventUnicodeLimit)), falling back")+ return false+ }+guard let keyDown = CGEvent(keyboardEventSource: nil, virtualKey: 0, keyDown: true),let keyUp = CGEvent(keyboardEventSource: nil, virtualKey: 0, keyDown: false)else {diff --git a/Sources/Fluid/UI/AISettings/AIEnhancementSettingsView.swift b/Sources/Fluid/UI/AISettings/AIEnhancementSettingsView.swiftindex fd1ec663..20a49e8e 100644--- a/Sources/Fluid/UI/AISettings/AIEnhancementSettingsView.swift+++ b/Sources/Fluid/UI/AISettings/AIEnhancementSettingsView.swift@@ -10,6 +10,7 @@ struct AIEnhancementSettingsView: View {@State var fluid1InterestEmail: String = ""@State var fluid1InterestErrorMessage: String = ""@State var fluid1InterestIsSubmitting: Bool = false+ @State var hoveredPromptCardKey: String? = nilvar body: some View {self.aiConfigurationCarddiff --git a/Sources/Fluid/UI/AISettings/AIEnhancementSettingsViewModel.swift b/Sources/Fluid/UI/AISettings/AIEnhancementSettingsViewModel.swiftindex 19a46e8e..f76d6147 100644--- a/Sources/Fluid/UI/AISettings/AIEnhancementSettingsViewModel.swift+++ b/Sources/Fluid/UI/AISettings/AIEnhancementSettingsViewModel.swift@@ -15,8 +15,9 @@ final class AIEnhancementSettingsViewModel: ObservableObject {@Published var enableAIProcessing: Bool {didSet {guard self.enableAIProcessing != oldValue else { return }- self.settings.enableAIProcessing = self.enableAIProcessing- self.menuBarManager.aiProcessingEnabled = self.enableAIProcessing+ // Route through MenuBarManager so all UI surfaces (menu, settings, future overlay)+ // share one callable code path.+ self.menuBarManager.setAIProcessingEnabled(self.enableAIProcessing)}}@@ -35,6 +36,7 @@ final class AIEnhancementSettingsViewModel: ObservableObject {@Published var showingAddModel: Bool = false@Published var newModelName: String = ""@Published var isFetchingModels: Bool = false+ @Published var refreshingProviderID: String? = nil@Published var fetchModelsError: String? = nil// Reasoning Configuration@@ -99,9 +101,12 @@ final class AIEnhancementSettingsViewModel: ObservableObject {// Dictation Prompt Profiles UI@Published var dictationPromptProfiles: [SettingsStore.DictationPromptProfile] = []@Published var selectedDictationPromptID: String? = nil+ @Published var selectedEditPromptID: String? = nil@Published var promptEditorMode: PromptEditorMode? = nil@Published var draftPromptName: String = ""@Published var draftPromptText: String = ""+ @Published var draftPromptMode: SettingsStore.PromptMode = .dictate+ @Published var draftIncludeContext: Bool = false@Published var promptEditorSessionID: UUID = .init()// Prompt Deletion UI@@ -136,6 +141,7 @@ final class AIEnhancementSettingsViewModel: ObservableObject {self.savedProviders = self.settings.savedProvidersself.dictationPromptProfiles = self.settings.dictationPromptProfilesself.selectedDictationPromptID = self.settings.selectedDictationPromptID+ self.selectedEditPromptID = self.settings.selectedEditPromptID// Normalize provider keysvar normalized: [String: [String]] = [:]@@ -913,9 +919,13 @@ final class AIEnhancementSettingsViewModel: ObservableObject {}func fetchModelsForCurrentProvider() async {+ self.refreshingProviderID = self.selectedProviderIDself.isFetchingModels = trueself.fetchModelsError = nil- defer { self.isFetchingModels = false }+ defer {+ self.isFetchingModels = false+ self.refreshingProviderID = nil+ }let baseURL = self.openAIBaseURLlet key = self.providerKey(for: self.selectedProviderID)@@ -965,6 +975,81 @@ final class AIEnhancementSettingsViewModel: ObservableObject {}}+ func models(for providerID: String) -> [String] {+ let key = self.providerKey(for: providerID)+ if let cached = self.availableModelsByProvider[key], !cached.isEmpty {+ return cached+ }+ if let saved = self.savedProviders.first(where: { $0.id == providerID }), !saved.models.isEmpty {+ return saved.models+ }+ if ModelRepository.shared.isBuiltIn(providerID) {+ return ModelRepository.shared.defaultModels(for: providerID)+ }+ return []+ }++ func fetchModels(for providerID: String) async {+ let baseURL = self.providerBaseURL(for: providerID)+ let key = self.providerKey(for: providerID)+ let apiKey = self.providerAPIKeys[key] ?? self.providerAPIKeys[providerID]++ self.refreshingProviderID = providerID+ self.isFetchingModels = true+ self.fetchModelsError = nil+ defer {+ self.isFetchingModels = false+ self.refreshingProviderID = nil+ }++ do {+ let models = try await ModelRepository.shared.fetchModels(+ for: providerID,+ baseURL: baseURL,+ apiKey: apiKey+ )++ await MainActor.run {+ guard !models.isEmpty else {+ self.fetchModelsError = "No models returned from API"+ return+ }++ self.availableModelsByProvider[key] = models+ self.settings.availableModelsByProvider = self.availableModelsByProvider+ self.fetchedModelsProviders.insert(key)++ if providerID == self.selectedProviderID {+ self.availableModels = models+ if !models.contains(self.selectedModel) {+ self.selectedModel = models.first ?? ""+ }+ }++ let selectedForProvider = self.selectedModelByProvider[key] ?? ""+ if !models.contains(selectedForProvider), let first = models.first {+ self.selectedModelByProvider[key] = first+ self.settings.selectedModelByProvider = self.selectedModelByProvider+ }++ if let providerIndex = self.savedProviders.firstIndex(where: { $0.id == providerID }) {+ let updatedProvider = SettingsStore.SavedProvider(+ id: self.savedProviders[providerIndex].id,+ name: self.savedProviders[providerIndex].name,+ baseURL: self.savedProviders[providerIndex].baseURL,+ models: models+ )+ self.savedProviders[providerIndex] = updatedProvider+ self.saveSavedProviders()+ }+ }+ } catch {+ await MainActor.run {+ self.fetchModelsError = error.localizedDescription+ }+ }+ }+private func providerBaseURL(for providerID: String) -> String {if providerID == self.selectedProviderID {return self.openAIBaseURL.trimmingCharacters(in: .whitespacesAndNewlines)@@ -1135,9 +1220,9 @@ final class AIEnhancementSettingsViewModel: ObservableObject {}/// Combine a user-visible body with the hidden base prompt to ensure role/intent is always present.- func combinedDraftPrompt(_ text: String) -> String {- let body = SettingsStore.stripBaseDictationPrompt(from: text)- return SettingsStore.combineBasePrompt(with: body)+ func combinedDraftPrompt(_ text: String, mode: SettingsStore.PromptMode) -> String {+ let body = SettingsStore.stripBasePrompt(for: mode, from: text)+ return SettingsStore.combineBasePrompt(for: mode, with: body)}func requestDeletePrompt(_ profile: SettingsStore.DictationPromptProfile) {@@ -1164,12 +1249,15 @@ final class AIEnhancementSettingsViewModel: ObservableObject {self.settings.dictationPromptProfiles = profiles// If the deleted profile was active, reset to Default- if self.settings.selectedDictationPromptID == id {- self.settings.selectedDictationPromptID = nil+ if let deleted = self.dictationPromptProfiles.first(where: { $0.id == id }),+ self.settings.selectedPromptID(for: deleted.mode) == id+ {+ self.settings.setSelectedPromptID(nil, for: deleted.mode)}self.dictationPromptProfiles = profilesself.selectedDictationPromptID = self.settings.selectedDictationPromptID+ self.selectedEditPromptID = self.settings.selectedEditPromptIDself.clearPendingDeletePrompt()}@@ -1178,27 +1266,34 @@ final class AIEnhancementSettingsViewModel: ObservableObject {DictationAIPostProcessingGate.isConfigured()}- func openDefaultPromptViewer() {- self.draftPromptName = "Default"- if let override = self.settings.defaultDictationPromptOverride {- self.draftPromptText = SettingsStore.stripBaseDictationPrompt(from: override)+ func openDefaultPromptViewer(for mode: SettingsStore.PromptMode) {+ let normalizedMode = mode.normalized+ self.draftPromptMode = normalizedMode+ self.draftIncludeContext = (normalizedMode == .edit)+ self.draftPromptName = "Default \(normalizedMode.displayName)"+ if let override = self.settings.defaultPromptOverride(for: normalizedMode) {+ self.draftPromptText = SettingsStore.stripBasePrompt(for: normalizedMode, from: override)} else {- self.draftPromptText = SettingsStore.defaultDictationPromptBodyText()+ self.draftPromptText = SettingsStore.defaultPromptBodyText(for: normalizedMode)}self.promptEditorSessionID = UUID()- self.promptEditorMode = .defaultPrompt+ self.promptEditorMode = .defaultPrompt(mode: normalizedMode)}- func openNewPromptEditor() {+ func openNewPromptEditor(prefillMode: SettingsStore.PromptMode = .edit) {+ self.draftPromptMode = prefillMode.normalized+ self.draftIncludeContext = (self.draftPromptMode == .edit)self.draftPromptName = "New Prompt"self.draftPromptText = ""self.promptEditorSessionID = UUID()- self.promptEditorMode = .newPrompt+ self.promptEditorMode = .newPrompt(prefillMode: self.draftPromptMode)}func openEditor(for profile: SettingsStore.DictationPromptProfile) {+ self.draftPromptMode = profile.mode.normalized+ self.draftIncludeContext = (self.draftPromptMode == .edit) ? true : profile.includeContextself.draftPromptName = profile.name- self.draftPromptText = SettingsStore.stripBaseDictationPrompt(from: profile.prompt)+ self.draftPromptText = SettingsStore.stripBasePrompt(for: self.draftPromptMode, from: profile.prompt)self.promptEditorSessionID = UUID()self.promptEditorMode = .edit(promptID: profile.id)}@@ -1207,20 +1302,23 @@ final class AIEnhancementSettingsViewModel: ObservableObject {self.promptEditorMode = nilself.draftPromptName = ""self.draftPromptText = ""+ self.draftPromptMode = .dictate+ self.draftIncludeContext = falseself.promptTest.deactivate()}func savePromptEditor(mode: PromptEditorMode) {// Default prompt is non-deletable; save it via the optional override (empty is allowed).if mode.isDefault {- let body = SettingsStore.stripBaseDictationPrompt(from: self.draftPromptText)- self.settings.defaultDictationPromptOverride = body+ let body = SettingsStore.stripBasePrompt(for: self.draftPromptMode, from: self.draftPromptText)+ self.settings.setDefaultPromptOverride(body, for: self.draftPromptMode)self.closePromptEditor()return}let name = self.draftPromptName.trimmingCharacters(in: .whitespacesAndNewlines)- let promptBody = SettingsStore.stripBaseDictationPrompt(from: self.draftPromptText)+ let promptBody = SettingsStore.stripBasePrompt(for: self.draftPromptMode, from: self.draftPromptText)+ let includeContext = (self.draftPromptMode.normalized == .edit) ? true : self.draftIncludeContextvar profiles = self.settings.dictationPromptProfileslet now = Date()@@ -1228,19 +1326,68 @@ final class AIEnhancementSettingsViewModel: ObservableObject {if let id = mode.editingPromptID,let idx = profiles.firstIndex(where: { $0.id == id }){+ let previous = profiles[idx]var updated = profiles[idx]updated.name = nameupdated.prompt = promptBody+ updated.mode = self.draftPromptMode.normalized+ updated.includeContext = includeContextupdated.updatedAt = nowprofiles[idx] = updated++ if previous.mode != updated.mode,+ self.settings.selectedPromptID(for: previous.mode) == id+ {+ self.settings.setSelectedPromptID(nil, for: previous.mode)+ }} else {- let newProfile = SettingsStore.DictationPromptProfile(name: name, prompt: promptBody, createdAt: now, updatedAt: now)+ let newProfile = SettingsStore.DictationPromptProfile(+ name: name,+ prompt: promptBody,+ mode: self.draftPromptMode.normalized,+ includeContext: includeContext,+ createdAt: now,+ updatedAt: now+ )profiles.append(newProfile)}self.settings.dictationPromptProfiles = profilesself.dictationPromptProfiles = profilesself.selectedDictationPromptID = self.settings.selectedDictationPromptID+ self.selectedEditPromptID = self.settings.selectedEditPromptIDself.closePromptEditor()}++ func selectedPromptID(for mode: SettingsStore.PromptMode) -> String? {+ switch mode.normalized {+ case .dictate:+ return self.selectedDictationPromptID+ case .edit:+ return self.selectedEditPromptID+ case .write, .rewrite:+ return self.selectedEditPromptID+ }+ }++ func setSelectedPromptID(_ id: String?, for mode: SettingsStore.PromptMode) {+ self.settings.setSelectedPromptID(id, for: mode.normalized)+ self.selectedDictationPromptID = self.settings.selectedDictationPromptID+ self.selectedEditPromptID = self.settings.selectedEditPromptID+ }++ func hasDefaultPromptOverride(for mode: SettingsStore.PromptMode) -> Bool {+ self.settings.defaultPromptOverride(for: mode.normalized) != nil+ }++ func resetDefaultPromptOverride(for mode: SettingsStore.PromptMode) {+ self.settings.setDefaultPromptOverride(nil, for: mode.normalized)+ }++ func defaultPromptBodyPreview(for mode: SettingsStore.PromptMode) -> String {+ if let override = self.settings.defaultPromptOverride(for: mode) {+ return SettingsStore.stripBasePrompt(for: mode, from: override)+ }+ return SettingsStore.defaultPromptBodyText(for: mode)+ }}diff --git a/Sources/Fluid/UI/AISettings/VoiceEngineSettingsViewModel.swift b/Sources/Fluid/UI/AISettings/VoiceEngineSettingsViewModel.swiftindex 16a405ee..884f5724 100644--- a/Sources/Fluid/UI/AISettings/VoiceEngineSettingsViewModel.swift+++ b/Sources/Fluid/UI/AISettings/VoiceEngineSettingsViewModel.swift@@ -129,13 +129,18 @@ final class VoiceEngineSettingsViewModel: ObservableObject {Task { @MainActor in// Only update progress if we're still downloading this specific modelguard let self, self.downloadingModel?.id == downloadingModelId else { return }- self.downloadProgress = progress+ self.downloadProgress = max(self.downloadProgress, progress)}})DebugLogger.shared.info("Model download completed: \(model.displayName)", source: "VoiceEngineVM")} catch {DebugLogger.shared.error("Failed to download model \(model.displayName): \(error)", source: "VoiceEngineVM")+ await MainActor.run {+ self.asr.errorTitle = "Model Download Failed"+ self.asr.errorMessage = error.localizedDescription+ self.asr.showError = true+ }}// Clear downloading state@@ -190,6 +195,8 @@ final class VoiceEngineSettingsViewModel: ObservableObject {return "Parakeet TDT v3 uses CoreML and Neural Engine for fastest transcription (25 languages) on Apple Silicon."case .parakeetTDTv2:return "Parakeet TDT v2 is an English-only model optimized for accuracy and consistency on Apple Silicon."+ case .qwen3Asr:+ return "Qwen3 ASR is a multilingual FluidAudio model with strong quality, but higher memory usage. Requires macOS 15+."default:return "Whisper models support 99 languages and work on any Mac."}diff --git a/Sources/Fluid/UI/AISettingsView+AIConfiguration.swift b/Sources/Fluid/UI/AISettingsView+AIConfiguration.swiftindex bb6ca057..2a262c01 100644--- a/Sources/Fluid/UI/AISettingsView+AIConfiguration.swift+++ b/Sources/Fluid/UI/AISettingsView+AIConfiguration.swift@@ -44,6 +44,18 @@ extension AIEnhancementSettingsView {.cornerRadius(6)}+ func aiOnboardingInfoRow(_ body: String) -> some View {+ HStack(alignment: .top, spacing: 8) {+ Circle()+ .fill(self.theme.palette.accent.opacity(0.9))+ .frame(width: 5, height: 5)+ .padding(.top, 5)+ Text(body)+ .font(.caption)+ .foregroundStyle(.secondary)+ }+ }+// MARK: - AI Configuration Cardvar aiConfigurationCard: some View {@@ -70,6 +82,16 @@ extension AIEnhancementSettingsView {Divider().background(self.theme.palette.separator.opacity(0.5))+ VStack(alignment: .leading, spacing: 8) {+ Text("FluidVoice can clean up or rewrite your transcription using AI.")+ .font(.caption)+ .foregroundStyle(.secondary)++ self.aiOnboardingInfoRow("Local models run on your Mac. Examples: Ollama and LM Studio.")+ self.aiOnboardingInfoRow("Cloud models use a provider of your choice. Examples: OpenAI, Anthropic, Groq, and OpenRouter.")+ self.aiOnboardingInfoRow("If you do not want to choose right now, FluidVoice still works without AI.")+ }+HStack(spacing: 12) {VStack(alignment: .leading, spacing: 2) {Text("Providers")@@ -750,13 +772,24 @@ extension AIEnhancementSettingsView {return AnyView(VStack(alignment: .leading, spacing: 10) {if isApple {- HStack(spacing: 10) {- Image(systemName: "lock.shield.fill")- .font(.system(size: 14))- .foregroundStyle(Color.fluidGreen)- Text("Apple Intelligence runs on-device and does not require an API key.")- .font(.system(size: 13))- .foregroundStyle(.secondary)+ VStack(alignment: .leading, spacing: 10) {+ HStack(spacing: 10) {+ Image(systemName: "lock.shield.fill")+ .font(.system(size: 14))+ .foregroundStyle(Color.fluidGreen)+ Text("Apple Intelligence runs on-device and does not require an API key.")+ .font(.system(size: 13))+ .foregroundStyle(.secondary)+ }++ HStack(spacing: 10) {+ Image(systemName: "exclamationmark.triangle.fill")+ .font(.system(size: 14))+ .foregroundStyle(.orange)+ Text("Output quality can be poor and inconsistent. Use it at your discretion.")+ .font(.system(size: 13, weight: .medium))+ .foregroundStyle(.secondary)+ }}.padding(12).frame(maxWidth: .infinity, alignment: .leading)@@ -1281,13 +1314,15 @@ extension AIEnhancementSettingsView {Image(systemName: "text.bubble.fill").font(.system(size: 12, weight: .medium)).foregroundStyle(self.theme.palette.accent)- VStack(alignment: .leading, spacing: 2) {+ HStack(alignment: .firstTextBaseline, spacing: 0) {Text("Prompts & Advanced").font(.system(size: 14, weight: .semibold))- Text("Choose how to process your speech — email, code, terminal, and more")+ Text(" - Choose how to process your speech — email, code, terminal, and more").font(.caption).foregroundStyle(.secondary)}+ .lineLimit(1)+ .truncationMode(.tail)}self.advancedSettingsCarddiff --git a/Sources/Fluid/UI/AISettingsView+AdvancedSettings.swift b/Sources/Fluid/UI/AISettingsView+AdvancedSettings.swiftindex e0db09cd..a692c6ea 100644--- a/Sources/Fluid/UI/AISettingsView+AdvancedSettings.swift+++ b/Sources/Fluid/UI/AISettingsView+AdvancedSettings.swift@@ -14,74 +14,38 @@ extension AIEnhancementSettingsView {var advancedSettingsCard: some View {ThemedCard(style: .prominent, hoverEffect: false) {VStack(alignment: .leading, spacing: 12) {- // Header- HStack {- Image(systemName: "gearshape.2.fill")- .font(.title3)- .foregroundStyle(self.theme.palette.accent)- Text("Advanced")- .font(.headline)- .fontWeight(.semibold)- Spacer()- }-- // Dictation Prompts (multi-prompt system)VStack(alignment: .leading, spacing: 10) {HStack {- VStack(alignment: .leading, spacing: 2) {- Text("Dictation Prompts")+ HStack(alignment: .firstTextBaseline, spacing: 0) {+ Text("Prompt Profiles").font(.system(size: 15, weight: .semibold)).foregroundStyle(self.theme.palette.primaryText)- Text("Create multiple named system prompts for AI dictation cleanup. Select which one is active.")+ Text(" - Pick one prompt for Dictate and one for Edit Text.").font(.system(size: 13)).foregroundStyle(self.theme.palette.secondaryText)}+ .lineLimit(1)+ .truncationMode(.tail)Spacer()Button("+ Add Prompt") {- self.viewModel.openNewPromptEditor()+ self.viewModel.openNewPromptEditor(prefillMode: .edit)}.buttonStyle(CompactButtonStyle(isReady: true)).frame(minWidth: AISettingsLayout.actionMinWidth, minHeight: AISettingsLayout.controlHeight)}- // Default prompt card- self.promptProfileCard(- title: "Default",- subtitle: self.viewModel.promptPreview(- self.settings.defaultDictationPromptOverride.map {- SettingsStore.stripBaseDictationPrompt(from: $0)- } ?? SettingsStore.defaultDictationPromptBodyText()- ),- isSelected: self.viewModel.selectedDictationPromptID == nil,- onUse: {- self.settings.selectedDictationPromptID = nil- self.viewModel.selectedDictationPromptID = nil- },- onOpen: { self.viewModel.openDefaultPromptViewer() }- )+ ViewThatFits(in: .horizontal) {+ HStack(alignment: .top, spacing: 12) {+ ForEach(SettingsStore.PromptMode.visiblePromptModes) { mode in+ self.promptModeSection(mode: mode)+ .frame(maxWidth: .infinity, alignment: .topLeading)+ }+ }- // User prompt cards- let profiles = self.viewModel.dictationPromptProfiles- if profiles.isEmpty {- Text("No custom prompts yet. Click “+ Add Prompt” to create one.")- .font(.caption)- .foregroundStyle(.secondary)- .padding(.horizontal, 4)- } else {- ForEach(profiles) { profile in- self.promptProfileCard(- title: profile.name.isEmpty ? "Untitled Prompt" : profile.name,- subtitle: profile.prompt.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty- ? "Empty prompt (uses Default)"- : self.viewModel.promptPreview(SettingsStore.stripBaseDictationPrompt(from: profile.prompt)),- isSelected: self.viewModel.selectedDictationPromptID == profile.id,- onUse: {- self.settings.selectedDictationPromptID = profile.id- self.viewModel.selectedDictationPromptID = profile.id- },- onOpen: { self.viewModel.openEditor(for: profile) },- onDelete: { self.viewModel.requestDeletePrompt(profile) }- )+ VStack(spacing: 14) {+ ForEach(SettingsStore.PromptMode.visiblePromptModes) { mode in+ self.promptModeSection(mode: mode)+ }}}}@@ -95,33 +59,48 @@ extension AIEnhancementSettingsView {}func promptProfileCard(+ cardKey: String,title: String,subtitle: String,+ mode: SettingsStore.PromptMode,isSelected: Bool,onUse: @escaping () -> Void,- onOpen: @escaping () -> Void,+ onManage: @escaping () -> Void,+ onResetDefault: (() -> Void)? = nil,+ canResetDefault: Bool = false,onDelete: (() -> Void)? = nil) -> some View {- HStack(alignment: .top, spacing: 10) {- Button(action: onOpen) {+ let tone = self.modeAccentColor(mode)+ let selectedStrokeOpacity: Double = mode.normalized == .dictate ? 0.52 : 0.38+ let isHovering = self.hoveredPromptCardKey == cardKey+ return HStack(alignment: .center, spacing: 10) {+ RoundedRectangle(cornerRadius: 1.5, style: .continuous)+ .fill(isHovering ? tone.opacity(0.5) : .clear)+ .frame(width: 3, height: 34)++ Button(action: onUse) {VStack(alignment: .leading, spacing: 4) {- HStack(spacing: 8) {+ HStack(alignment: .firstTextBaseline, spacing: 8) {Text(title).font(.system(size: 14, weight: .semibold)).foregroundStyle(self.theme.palette.primaryText)- if isSelected {- Text("Active")+ if mode.normalized == .edit {+ Text("Context: Auto").font(.caption2)- .padding(.horizontal, 8)- .padding(.vertical, 3)- .background(RoundedRectangle(cornerRadius: 6, style: .continuous).fill(Color.fluidGreen.opacity(0.18)))- .foregroundStyle(Color.fluidGreen)+ .padding(.horizontal, 6)+ .padding(.vertical, 2)+ .background(+ RoundedRectangle(cornerRadius: 5, style: .continuous)+ .fill(tone.opacity(0.12))+ )+ .foregroundStyle(tone)}}Text(subtitle).font(.caption).foregroundStyle(.secondary)- .lineLimit(2)+ .lineLimit(1)+ .truncationMode(.tail).multilineTextAlignment(.leading)}.frame(maxWidth: .infinity, alignment: .leading)@@ -131,48 +110,422 @@ extension AIEnhancementSettingsView {Spacer(minLength: 8)- HStack(spacing: 8) {- Button("Use") { onUse() }- .buttonStyle(CompactButtonStyle())- .frame(minWidth: AISettingsLayout.promptActionMinWidth, minHeight: AISettingsLayout.controlHeight)- .disabled(isSelected)-- if let onDelete {- Button(action: { onDelete() }) {- HStack(spacing: 4) { Image(systemName: "trash"); Text("Delete") }- .font(.caption)+ HStack(spacing: 10) {+ Image(systemName: isSelected ? "checkmark.circle.fill" : "circle")+ .font(.system(size: 15, weight: .semibold))+ .foregroundStyle(isSelected ? tone : self.theme.palette.secondaryText.opacity(0.35))+ .frame(width: 18, height: 18)++ Menu {+ Button("Edit Prompt") { onManage() }+ if mode == .edit {+ Divider()+ Text("Selected text context is added automatically when text is selected.")+ }+ if let onDelete {+ Divider()+ Button(role: .destructive, action: { onDelete() }) {+ Label("Delete Prompt", systemImage: "trash")+ }+ } else if let onResetDefault {+ Divider()+ Button("Reset to Built-in Default", role: .destructive) { onResetDefault() }+ .disabled(!canResetDefault)}- .buttonStyle(CompactButtonStyle(foreground: .red, borderColor: .red.opacity(0.6)))- .frame(minWidth: AISettingsLayout.promptActionMinWidth, minHeight: AISettingsLayout.controlHeight)+ } label: {+ Image(systemName: "ellipsis.circle")+ .font(.system(size: 14, weight: .semibold))+ .frame(width: AISettingsLayout.controlHeight, height: AISettingsLayout.controlHeight)}+ .buttonStyle(.plain)+ .foregroundStyle(self.theme.palette.secondaryText)}}.padding(12).background(RoundedRectangle(cornerRadius: 12, style: .continuous)- .fill(self.theme.palette.cardBackground.opacity(0.7))+ .fill(self.theme.palette.cardBackground.opacity(0.64))+ .overlay(+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .fill(isHovering ? tone.opacity(mode.normalized == .dictate ? 0.06 : 0.045) : .clear)+ ).overlay(RoundedRectangle(cornerRadius: 12, style: .continuous)- .stroke(isSelected ? self.theme.palette.accent.opacity(0.55) : self.theme.palette.cardBorder.opacity(0.35), lineWidth: 1)+ .stroke(isHovering ? tone.opacity(selectedStrokeOpacity) : self.theme.palette.cardBorder.opacity(0.3), lineWidth: 1)+ )+ )+ .onHover { hovering in+ if hovering {+ self.hoveredPromptCardKey = cardKey+ } else if self.hoveredPromptCardKey == cardKey {+ self.hoveredPromptCardKey = nil+ }+ }+ .animation(.easeOut(duration: 0.1), value: isHovering)+ }++ @ViewBuilder+ private func promptModeSection(mode: SettingsStore.PromptMode) -> some View {+ let customProfiles = self.viewModel.dictationPromptProfiles+ .filter { $0.mode.normalized == mode }+ let tone = self.modeAccentColor(mode)++ VStack(alignment: .leading, spacing: 8) {+ HStack(spacing: 8) {+ Image(systemName: self.modeSymbol(mode))+ .font(.system(size: 11, weight: .semibold))+ .foregroundStyle(.white.opacity(0.95))+ .frame(width: 20, height: 20)+ .background(Circle().fill(tone.opacity(mode.normalized == .dictate ? 0.85 : 0.65)))+ HStack(alignment: .firstTextBaseline, spacing: 0) {+ Text(mode.normalized == .dictate ? "Dictate Mode" : "Edit Text Mode")+ .font(.system(size: 13, weight: .semibold))+ .foregroundStyle(self.theme.palette.primaryText)+ Text(" - \(self.promptSectionDescription(for: mode))")+ .font(.caption)+ .foregroundStyle(self.theme.palette.secondaryText)+ }+ .lineLimit(1)+ .truncationMode(.tail)+ }+ .padding(.horizontal, 2)++ if mode.normalized == .edit {+ self.editModeProviderModelRow+ }++ self.promptProfileCard(+ cardKey: "\(mode.normalized.rawValue)-default",+ title: "Default \(self.friendlyModeName(mode))",+ subtitle: self.viewModel.promptPreview(self.viewModel.defaultPromptBodyPreview(for: mode)),+ mode: mode,+ isSelected: self.viewModel.selectedPromptID(for: mode) == nil,+ onUse: {+ self.viewModel.setSelectedPromptID(nil, for: mode)+ },+ onManage: { self.viewModel.openDefaultPromptViewer(for: mode) },+ onResetDefault: { self.viewModel.resetDefaultPromptOverride(for: mode) },+ canResetDefault: self.viewModel.hasDefaultPromptOverride(for: mode)+ )++ if customProfiles.isEmpty {+ Text("No custom \(self.friendlyModeName(mode).lowercased()) prompts yet.")+ .font(.caption2)+ .foregroundStyle(.secondary)+ .padding(.horizontal, 4)+ } else {+ ForEach(customProfiles) { profile in+ self.promptProfileCard(+ cardKey: "\(profile.mode.normalized.rawValue)-\(profile.id)",+ title: profile.name.isEmpty ? "Untitled Prompt" : profile.name,+ subtitle: SettingsStore.stripBasePrompt(for: profile.mode, from: profile.prompt).isEmpty+ ? "Empty prompt (uses Default)"+ : self.viewModel.promptPreview(SettingsStore.stripBasePrompt(for: profile.mode, from: profile.prompt)),+ mode: profile.mode,+ isSelected: self.viewModel.selectedPromptID(for: profile.mode) == profile.id,+ onUse: {+ self.viewModel.setSelectedPromptID(profile.id, for: profile.mode)+ },+ onManage: { self.viewModel.openEditor(for: profile) },+ onDelete: { self.viewModel.requestDeletePrompt(profile) }+ )+ }+ }+ }+ .padding(12)+ .background(+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .fill(+ LinearGradient(+ colors: [+ tone.opacity(mode.normalized == .dictate ? 0.14 : 0.08),+ self.theme.palette.contentBackground.opacity(0.28),+ ],+ startPoint: .topLeading,+ endPoint: .bottomTrailing+ )+ )+ .overlay(+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .stroke(tone.opacity(mode.normalized == .dictate ? 0.34 : 0.22), lineWidth: 1)+ )+ )+ }++ private var editModeProviderModelRow: some View {+ let verified = self.editModeVerifiedProviders++ return VStack(alignment: .leading, spacing: 8) {+ HStack(alignment: .center, spacing: 12) {+ Text("Edit mode model selection (optional)")+ .font(.system(size: 12, weight: .semibold))+ .foregroundStyle(self.theme.palette.secondaryText)+ .lineLimit(1)+ .layoutPriority(1)+ .frame(maxWidth: .infinity, alignment: .leading)+ }++ if verified.isEmpty {+ HStack(spacing: 8) {+ Image(systemName: "info.circle")+ .font(.system(size: 12))+ .foregroundStyle(.secondary)+ Text("No verified providers yet. Verify a provider above to enable Edit Text model selection.")+ .font(.caption)+ .foregroundStyle(.secondary)+ }+ .padding(10)+ .background(+ RoundedRectangle(cornerRadius: 10, style: .continuous)+ .fill(self.theme.palette.cardBackground.opacity(0.45))+ .overlay(+ RoundedRectangle(cornerRadius: 10, style: .continuous)+ .stroke(self.theme.palette.cardBorder.opacity(0.25), lineWidth: 1)+ ))+ } else {+ let providerID = self.activeEditModeProviderID+ let models = self.viewModel.models(for: providerID)+ HStack(alignment: .center, spacing: 12) {+ Toggle("Sync with AI Enhancement model", isOn: self.editModeLinkedToGlobalBinding)+ .toggleStyle(.checkbox)+ .font(.caption)+ .foregroundStyle(.secondary)+ .fixedSize(horizontal: true, vertical: false)+ .onChange(of: self.settings.rewriteModeLinkedToGlobal) { _, linked in+ if linked {+ self.syncEditModeToGlobalSelection()+ } else {+ self.normalizeEditModeProviderSelection()+ }+ }++ HStack(alignment: .center, spacing: 10) {+ Text("Provider")+ .font(.caption)+ .foregroundStyle(.secondary)++ Picker("", selection: self.editModeProviderBinding) {+ ForEach(verified) { provider in+ Text(provider.name).tag(provider.id)+ }+ }+ .pickerStyle(.menu)+ .labelsHidden()+ .frame(width: 170)+ .disabled(self.settings.rewriteModeLinkedToGlobal)++ Text("Model")+ .font(.caption)+ .foregroundStyle(.secondary)++ SearchableModelPicker(+ models: models,+ selectedModel: self.editModeModelBinding(for: providerID),+ onRefresh: { await self.viewModel.fetchModels(for: providerID) },+ isRefreshing: self.viewModel.refreshingProviderID == providerID,+ refreshEnabled: !self.settings.rewriteModeLinkedToGlobal && self.canFetchModels(for: providerID),+ selectionEnabled: !self.settings.rewriteModeLinkedToGlobal && !models.isEmpty,+ controlWidth: 190,+ controlHeight: 28+ )+ .disabled(self.settings.rewriteModeLinkedToGlobal)+ }+ .frame(maxWidth: .infinity, alignment: .trailing)+ .opacity(self.settings.rewriteModeLinkedToGlobal ? 0.65 : 1)+ }+ .padding(10)+ .background(+ RoundedRectangle(cornerRadius: 10, style: .continuous)+ .fill(self.theme.palette.cardBackground.opacity(0.45))+ .overlay(+ RoundedRectangle(cornerRadius: 10, style: .continuous)+ .stroke(self.theme.palette.cardBorder.opacity(0.25), lineWidth: 1)+ )+ )+ .onAppear {+ self.normalizeEditModeProviderSelection()+ }+ }+ }+ .padding(.horizontal, 2)+ .onAppear {+ self.ensureDefaultEditModeSyncState()+ }+ }++ private var editModeVerifiedProviders: [AIEnhancementSettingsViewModel.ProviderItemData] {+ self.viewModel.cachedVerifiedProviderItems.sorted { lhs, rhs in+ lhs.name.localizedCaseInsensitiveCompare(rhs.name) == .orderedAscending+ }+ }++ private var editModeSelectedProviderID: String {+ let current = self.settings.rewriteModeSelectedProviderID+ if self.editModeVerifiedProviders.contains(where: { $0.id == current }) {+ return current+ }+ return self.editModeVerifiedProviders.first?.id ?? current+ }++ private var activeEditModeProviderID: String {+ if self.settings.rewriteModeLinkedToGlobal {+ let global = self.viewModel.selectedProviderID+ if self.editModeVerifiedProviders.contains(where: { $0.id == global }) {+ return global+ }+ return self.editModeSelectedProviderID+ }+ return self.editModeSelectedProviderID+ }++ private var editModeLinkedToGlobalBinding: Binding<Bool> {+ Binding(+ get: { self.settings.rewriteModeLinkedToGlobal },+ set: { self.settings.rewriteModeLinkedToGlobal = $0 }+ )+ }++ private var editModeProviderBinding: Binding<String> {+ Binding(+ get: { self.activeEditModeProviderID },+ set: { newProviderID in+ guard !self.settings.rewriteModeLinkedToGlobal else { return }+ self.settings.rewriteModeSelectedProviderID = newProviderID+ let models = self.viewModel.models(for: newProviderID)+ let current = self.settings.rewriteModeSelectedModel ?? ""+ if !models.contains(current) {+ self.settings.rewriteModeSelectedModel = models.first+ }+ })}+ private func editModeModelBinding(for providerID: String) -> Binding<String> {+ Binding(+ get: {+ if self.settings.rewriteModeLinkedToGlobal {+ let key = self.viewModel.providerKey(for: providerID)+ return self.settings.selectedModelByProvider[key]+ ?? self.settings.selectedModel+ ?? self.viewModel.models(for: providerID).first+ ?? ""+ }+ return self.settings.rewriteModeSelectedModel ?? self.viewModel.models(for: providerID).first ?? ""+ },+ set: { newModel in+ guard !self.settings.rewriteModeLinkedToGlobal else { return }+ self.settings.rewriteModeSelectedModel = newModel+ }+ )+ }++ private func normalizeEditModeProviderSelection() {+ guard let first = self.editModeVerifiedProviders.first else { return }+ let current = self.settings.rewriteModeSelectedProviderID+ if !self.editModeVerifiedProviders.contains(where: { $0.id == current }) {+ self.settings.rewriteModeSelectedProviderID = first.id+ }++ let providerID = self.settings.rewriteModeSelectedProviderID+ let models = self.viewModel.models(for: providerID)+ let currentModel = self.settings.rewriteModeSelectedModel ?? ""+ if !models.contains(currentModel) {+ self.settings.rewriteModeSelectedModel = models.first+ }+ }++ private func syncEditModeToGlobalSelection() {+ let global = self.viewModel.selectedProviderID+ let providerID: String+ if self.editModeVerifiedProviders.contains(where: { $0.id == global }) {+ providerID = global+ } else if let fallback = self.editModeVerifiedProviders.first?.id {+ providerID = fallback+ } else {+ providerID = global+ }+ self.settings.rewriteModeSelectedProviderID = providerID++ let key = self.viewModel.providerKey(for: providerID)+ let model = self.settings.selectedModelByProvider[key]+ ?? self.settings.selectedModel+ ?? self.viewModel.models(for: providerID).first+ self.settings.rewriteModeSelectedModel = model+ }++ private func ensureDefaultEditModeSyncState() {+ // If no persisted value exists yet, default Sync to ON.+ if UserDefaults.standard.object(forKey: "RewriteModeLinkedToGlobal") == nil {+ self.settings.rewriteModeLinkedToGlobal = true+ self.syncEditModeToGlobalSelection()+ }+ }++ private func canFetchModels(for providerID: String) -> Bool {+ let key = self.viewModel.providerKey(for: providerID)+ let apiKey = self.viewModel.providerAPIKeys[key] ?? ""+ let hasAPIKey = !apiKey.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty++ let baseURL: String+ if let saved = self.viewModel.savedProviders.first(where: { $0.id == providerID }) {+ baseURL = saved.baseURL+ } else {+ baseURL = ModelRepository.shared.defaultBaseURL(for: providerID)+ }+ let trimmedBaseURL = baseURL.trimmingCharacters(in: .whitespacesAndNewlines)+ let isLocal = self.viewModel.isLocalEndpoint(trimmedBaseURL)++ return isLocal ? !trimmedBaseURL.isEmpty : (hasAPIKey && !trimmedBaseURL.isEmpty)+ }++ private func promptSectionDescription(for mode: SettingsStore.PromptMode) -> String {+ switch mode {+ case .dictate:+ return "No selected-text context - Process raw voice text - clean, write into email, convert terminal commands, translate etc."+ case .edit, .write, .rewrite:+ return "Uses selected text as context (when text is selected) - Edit or rewrite selected text - answer questions, summarize, convert to bullets etc."+ }+ }++ private func modeAccentColor(_ mode: SettingsStore.PromptMode) -> Color {+ _ = mode+ return Color.fluidGreen+ }++ private func modeSymbol(_ mode: SettingsStore.PromptMode) -> String {+ switch mode.normalized {+ case .dictate:+ return "mic.fill"+ case .edit, .write, .rewrite:+ return "square.and.pencil"+ }+ }++ private func friendlyModeName(_ mode: SettingsStore.PromptMode) -> String {+ switch mode.normalized {+ case .dictate:+ return "Dictate"+ case .edit, .write, .rewrite:+ return "Edit Text"+ }+ }+func promptEditorSheet(mode: PromptEditorMode) -> some View {VStack(spacing: 14) {HStack {VStack(alignment: .leading, spacing: 2) {Text({switch mode {- case .defaultPrompt: return "Default Dictation Prompt"- case .newPrompt: return "New Dictation Prompt"- case .edit: return "Edit Dictation Prompt"+ case let .defaultPrompt(promptMode): return "Default \(self.friendlyModeName(promptMode)) Prompt"+ case let .newPrompt(prefillMode): return "New \(self.friendlyModeName(prefillMode)) Prompt"+ case .edit: return "Edit Prompt"}}()).font(.headline)Text(mode.isDefault? "This is the built-in prompt. Create a custom prompt to override it."- : "Name and prompt text are used as the system prompt for dictation cleanup."+ : "Prompt text is appended to the hidden base prompt for the selected mode.").font(.caption).foregroundStyle(.secondary)@@ -180,6 +533,19 @@ extension AIEnhancementSettingsView {Spacer()}+ VStack(alignment: .leading, spacing: 8) {+ Text("Mode")+ .font(.caption)+ .foregroundStyle(.secondary)+ Picker("Mode", selection: self.$viewModel.draftPromptMode) {+ ForEach(SettingsStore.PromptMode.visiblePromptModes) { mode in+ Text(self.friendlyModeName(mode)).tag(mode)+ }+ }+ .pickerStyle(.segmented)+ .disabled(mode.isDefault)+ }+VStack(alignment: .leading, spacing: 8) {Text("Name").font(.caption)@@ -210,81 +576,26 @@ extension AIEnhancementSettingsView {)).onChange(of: self.viewModel.draftPromptText) { _, newValue in- let combined = self.viewModel.combinedDraftPrompt(newValue)+ guard self.viewModel.draftPromptMode == .dictate else { return }+ let combined = self.viewModel.combinedDraftPrompt(newValue, mode: self.viewModel.draftPromptMode)self.promptTest.updateDraftPromptText(combined)}}- // MARK: - Test Mode-- VStack(alignment: .leading, spacing: 8) {- HStack(spacing: 8) {- Image(systemName: "waveform")- .foregroundStyle(self.theme.palette.accent)- Text("Test")- .font(.subheadline)- .fontWeight(.semibold)- Spacer()- }-- let hotkeyDisplay = self.settings.hotkeyShortcut.displayString- let canTest = self.viewModel.isAIPostProcessingConfiguredForDictation()-- Toggle(isOn: Binding(- get: { self.promptTest.isActive },- set: { enabled in- if enabled {- let combined = self.viewModel.combinedDraftPrompt(self.viewModel.draftPromptText)- self.promptTest.activate(draftPromptText: combined)- } else {- self.promptTest.deactivate()- }- }- )) {- Text("Enable Test Mode (Hotkey: \(hotkeyDisplay))")+ if self.viewModel.draftPromptMode != .dictate {+ VStack(alignment: .leading, spacing: 8) {+ Text("Selected text is added automatically when text is selected.").font(.caption)- }- .toggleStyle(.switch)- .disabled(!canTest)+ .foregroundStyle(self.theme.palette.secondaryText)- if !canTest {- Text("Testing is disabled because AI post-processing is not configured.")- .font(.caption2)- .foregroundStyle(.secondary)- } else if self.promptTest.isActive {- Text("Press the hotkey to start/stop recording. The transcription will be post-processed using your draft prompt and shown below (nothing will be typed into other apps).")+ Text("Context block added automatically:").font(.caption2).foregroundStyle(.secondary)- }-- if self.promptTest.isActive {- if self.promptTest.isProcessing {- HStack(spacing: 8) {- ProgressView().controlSize(.small).fixedSize()- Text("Processing…")- .font(.caption)- .foregroundStyle(.secondary)- }- }- if !self.promptTest.lastError.isEmpty {- Text(self.promptTest.lastError)- .font(.caption2)- .foregroundStyle(.red)- .textSelection(.enabled)- }-- VStack(alignment: .leading, spacing: 6) {- Text("Raw transcription")- .font(.caption2)- .foregroundStyle(.secondary)- TextEditor(text: Binding(- get: { self.promptTest.lastTranscriptionText },- set: { _ in }- ))- .font(.system(.caption, design: .monospaced))- .frame(minHeight: 70)- .scrollContentBackground(.hidden)+ Text(SettingsStore.contextTemplateText())+ .font(.system(.caption2, design: .monospaced))+ .padding(8)+ .frame(maxWidth: .infinity, alignment: .leading).background(RoundedRectangle(cornerRadius: 8, style: .continuous).fill(self.theme.palette.contentBackground.opacity(0.7))@@ -293,39 +604,127 @@ extension AIEnhancementSettingsView {.stroke(self.theme.palette.cardBorder.opacity(0.35), lineWidth: 1)))+ }+ }++ // MARK: - Test Mode++ if self.viewModel.draftPromptMode == .dictate {+ VStack(alignment: .leading, spacing: 8) {+ HStack(spacing: 8) {+ Image(systemName: "waveform")+ .foregroundStyle(self.theme.palette.accent)+ Text("Test")+ .font(.subheadline)+ .fontWeight(.semibold)+ Spacer()}- VStack(alignment: .leading, spacing: 6) {- Text("Post-processed output")+ let hotkeyDisplay = self.settings.hotkeyShortcut.displayString+ let canTest = self.viewModel.isAIPostProcessingConfiguredForDictation()++ Toggle(isOn: Binding(+ get: { self.promptTest.isActive },+ set: { enabled in+ if enabled {+ let combined = self.viewModel.combinedDraftPrompt(self.viewModel.draftPromptText, mode: self.viewModel.draftPromptMode)+ self.promptTest.activate(draftPromptText: combined)+ } else {+ self.promptTest.deactivate()+ }+ }+ )) {+ Text("Enable Test Mode (Hotkey: \(hotkeyDisplay))")+ .font(.caption)+ }+ .toggleStyle(.switch)+ .disabled(!canTest)++ if !canTest {+ Text("Testing is disabled because AI post-processing is not configured.").font(.caption2).foregroundStyle(.secondary)- TextEditor(text: Binding(- get: { self.promptTest.lastOutputText },- set: { _ in }- ))- .font(.system(.caption, design: .monospaced))- .frame(minHeight: 110)- .scrollContentBackground(.hidden)- .background(- RoundedRectangle(cornerRadius: 8, style: .continuous)- .fill(self.theme.palette.contentBackground.opacity(0.7))- .overlay(- RoundedRectangle(cornerRadius: 8, style: .continuous)- .stroke(self.theme.palette.cardBorder.opacity(0.35), lineWidth: 1)- )- )+ } else if self.promptTest.isActive {+ Text("Press the hotkey to start/stop recording. The transcription will be post-processed using your draft prompt and shown below (nothing will be typed into other apps).")+ .font(.caption2)+ .foregroundStyle(.secondary)+ }++ if self.promptTest.isActive {+ if self.promptTest.isProcessing {+ HStack(spacing: 8) {+ ProgressView().controlSize(.small).fixedSize()+ Text("Processing…")+ .font(.caption)+ .foregroundStyle(.secondary)+ }+ }++ if !self.promptTest.lastError.isEmpty {+ Text(self.promptTest.lastError)+ .font(.caption2)+ .foregroundStyle(.red)+ .textSelection(.enabled)+ }++ VStack(alignment: .leading, spacing: 6) {+ Text("Raw transcription")+ .font(.caption2)+ .foregroundStyle(.secondary)+ TextEditor(text: Binding(+ get: { self.promptTest.lastTranscriptionText },+ set: { _ in }+ ))+ .font(.system(.caption, design: .monospaced))+ .frame(minHeight: 70)+ .scrollContentBackground(.hidden)+ .background(+ RoundedRectangle(cornerRadius: 8, style: .continuous)+ .fill(self.theme.palette.contentBackground.opacity(0.7))+ .overlay(+ RoundedRectangle(cornerRadius: 8, style: .continuous)+ .stroke(self.theme.palette.cardBorder.opacity(0.35), lineWidth: 1)+ )+ )+ }++ VStack(alignment: .leading, spacing: 6) {+ Text("Post-processed output")+ .font(.caption2)+ .foregroundStyle(.secondary)+ TextEditor(text: Binding(+ get: { self.promptTest.lastOutputText },+ set: { _ in }+ ))+ .font(.system(.caption, design: .monospaced))+ .frame(minHeight: 110)+ .scrollContentBackground(.hidden)+ .background(+ RoundedRectangle(cornerRadius: 8, style: .continuous)+ .fill(self.theme.palette.contentBackground.opacity(0.7))+ .overlay(+ RoundedRectangle(cornerRadius: 8, style: .continuous)+ .stroke(self.theme.palette.cardBorder.opacity(0.35), lineWidth: 1)+ )+ )+ }}}+ .padding(12)+ .background(+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .fill(self.theme.palette.accent.opacity(0.06))+ .overlay(+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .stroke(self.theme.palette.cardBorder.opacity(0.5), lineWidth: 1)+ )+ )+ } else if self.promptTest.isActive {+ Text("Prompt test mode is available only for Dictate prompts.")+ .font(.caption2)+ .foregroundStyle(.secondary)+ .onAppear { self.promptTest.deactivate() }}- .padding(12)- .background(- RoundedRectangle(cornerRadius: 12, style: .continuous)- .fill(self.theme.palette.accent.opacity(0.06))- .overlay(- RoundedRectangle(cornerRadius: 12, style: .continuous)- .stroke(self.theme.palette.cardBorder.opacity(0.5), lineWidth: 1)- )- )HStack(spacing: 10) {Button(mode.isDefault ? "Close" : "Cancel") {@@ -368,12 +767,12 @@ extension AIEnhancementSettingsView {}}- func openDefaultPromptViewer() {- self.viewModel.openDefaultPromptViewer()+ func openDefaultPromptViewer(for mode: SettingsStore.PromptMode) {+ self.viewModel.openDefaultPromptViewer(for: mode)}- func openNewPromptEditor() {- self.viewModel.openNewPromptEditor()+ func openNewPromptEditor(prefillMode: SettingsStore.PromptMode = .edit) {+ self.viewModel.openNewPromptEditor(prefillMode: prefillMode)}func openEditor(for profile: SettingsStore.DictationPromptProfile) {diff --git a/Sources/Fluid/UI/AISettingsView+SpeechRecognition.swift b/Sources/Fluid/UI/AISettingsView+SpeechRecognition.swiftindex 5f9bfb02..1f482650 100644--- a/Sources/Fluid/UI/AISettingsView+SpeechRecognition.swift+++ b/Sources/Fluid/UI/AISettingsView+SpeechRecognition.swift@@ -11,8 +11,13 @@ extension VoiceEngineSettingsView {// MARK: - Speech Recognition Cardvar speechRecognitionCard: some View {- let activeModel = self.settings.selectedSpeechModel- let otherModels = self.viewModel.filteredSpeechModels.filter { $0 != activeModel }+ let selectedModel = self.settings.selectedSpeechModel+ let activeModel = selectedModel.isInstalled ? selectedModel : nil+ let hasActiveModel = activeModel != nil+ let otherModels = self.viewModel.filteredSpeechModels.filter { model in+ guard let activeModel else { return true }+ return model != activeModel+ }return ThemedCard(hoverEffect: false) {VStack(alignment: .leading, spacing: 14) {@@ -102,18 +107,30 @@ extension VoiceEngineSettingsView {// Active + Other models listVStack(alignment: .leading, spacing: 10) {- VStack(alignment: .leading, spacing: 6) {- Text("Active Model")- .font(.callout)- .fontWeight(.semibold)- .foregroundStyle(.secondary)- self.speechModelCard(for: activeModel)+ if let activeModel {+ VStack(alignment: .leading, spacing: 6) {+ Text("Active Model")+ .font(.callout)+ .fontWeight(.semibold)+ .foregroundStyle(.secondary)+ self.speechModelCard(for: activeModel)+ }+ } else {+ VStack(alignment: .leading, spacing: 6) {+ Text("Active Model")+ .font(.callout)+ .fontWeight(.semibold)+ .foregroundStyle(.secondary)+ Label("No active model yet. Download and activate one below.", systemImage: "arrow.down.circle")+ .font(.caption)+ .foregroundStyle(.secondary)+ }}Divider().padding(.vertical, 2)VStack(alignment: .leading, spacing: 6) {- Text("Other Models")+ Text(hasActiveModel ? "Other Models" : "Available Models").font(.callout).fontWeight(.semibold).foregroundStyle(.secondary)@@ -147,108 +164,144 @@ extension VoiceEngineSettingsView {/// Stats panel showing speed/accuracy bars that animate when model changesvar modelStatsPanel: some View {let model = self.viewModel.previewSpeechModel+ let supportsParakeetCustomWords = model == .parakeetTDT || model == .parakeetTDTv2++ return VStack(alignment: .leading, spacing: 12) {+ HStack(alignment: .center, spacing: 20) {+ VStack(alignment: .leading, spacing: 8) {+ VStack(alignment: .leading, spacing: 4) {+ HStack {+ Text(model.humanReadableName)+ .font(.system(size: 16, weight: .bold))+ .foregroundStyle(self.theme.palette.primaryText)++ if let badge = model.badgeText {+ Text(badge)+ .font(.caption2)+ .fontWeight(.semibold)+ .padding(.horizontal, 6)+ .padding(.vertical, 2)+ .background(Capsule().fill(badge == "FluidVoice Pick" ? .cyan.opacity(0.2) : .orange.opacity(0.2)))+ .foregroundStyle(badge == "FluidVoice Pick" ? .cyan : .orange)+ }- return HStack(alignment: .center, spacing: 20) {- VStack(alignment: .leading, spacing: 8) {- VStack(alignment: .leading, spacing: 4) {- HStack {- Text(model.humanReadableName)- .font(.system(size: 16, weight: .bold))- .foregroundStyle(self.theme.palette.primaryText)-- if let badge = model.badgeText {- Text(badge)- .font(.caption2)- .fontWeight(.semibold)- .padding(.horizontal, 6)- .padding(.vertical, 2)- .background(Capsule().fill(badge == "FluidVoice Pick" ? .cyan.opacity(0.2) : .orange.opacity(0.2)))- .foregroundStyle(badge == "FluidVoice Pick" ? .cyan : .orange)+ Spacer()}- Spacer()+ Text(model.cardDescription)+ .font(.system(size: 13))+ .foregroundStyle(.secondary)+ .lineLimit(2)}- Text(model.cardDescription)- .font(.system(size: 13))- .foregroundStyle(.secondary)- .lineLimit(2)- }+ HStack(spacing: 8) {+ Label(model.downloadSize, systemImage: "internaldrive")+ .font(.caption2)+ .foregroundStyle(.secondary)- HStack(spacing: 8) {- Label(model.downloadSize, systemImage: "internaldrive")- .font(.caption2)- .foregroundStyle(.secondary)+ if model.requiresAppleSilicon {+ Text("Apple Silicon")+ .font(.caption2)+ .padding(.horizontal, 6)+ .padding(.vertical, 2)+ .background(Capsule().fill(self.theme.palette.accent.opacity(0.2)))+ .foregroundStyle(self.theme.palette.accent)+ }- if model.requiresAppleSilicon {- Text("Apple Silicon")+ Text(model.languageSupport).font(.caption2).padding(.horizontal, 6).padding(.vertical, 2)- .background(Capsule().fill(self.theme.palette.accent.opacity(0.2)))- .foregroundStyle(self.theme.palette.accent)- }+ .background(Capsule().fill(.quaternary))+ .foregroundStyle(.secondary)- Text(model.languageSupport)- .font(.caption2)- .padding(.horizontal, 6)- .padding(.vertical, 2)- .background(Capsule().fill(.quaternary))- .foregroundStyle(.secondary)+ Spacer()+ }- Spacer()+ // Memory warning for large models+ if let memoryWarning = model.memoryWarning {+ HStack(spacing: 6) {+ Image(systemName: "exclamationmark.triangle.fill")+ .font(.caption2)+ .foregroundStyle(.orange)+ Text(memoryWarning)+ .font(.caption2)+ .foregroundStyle(.orange)+ }+ .padding(.horizontal, 8)+ .padding(.vertical, 4)+ .background(+ RoundedRectangle(cornerRadius: 6)+ .fill(.orange.opacity(0.1))+ .overlay(+ RoundedRectangle(cornerRadius: 6)+ .stroke(.orange.opacity(0.3), lineWidth: 1)+ )+ )+ }}+ .frame(maxWidth: .infinity, alignment: .leading)++ HStack(spacing: 16) {+ LiquidBar(+ fillPercent: model.speedPercent,+ color: .yellow,+ secondaryColor: .orange,+ icon: "bolt.fill",+ label: "Speed"+ )- // Memory warning for large models- if let memoryWarning = model.memoryWarning {- HStack(spacing: 6) {- Image(systemName: "exclamationmark.triangle.fill")- .font(.caption2)- .foregroundStyle(.orange)- Text(memoryWarning)- .font(.caption2)- .foregroundStyle(.orange)- }- .padding(.horizontal, 8)- .padding(.vertical, 4)- .background(- RoundedRectangle(cornerRadius: 6)- .fill(.orange.opacity(0.1))- .overlay(- RoundedRectangle(cornerRadius: 6)- .stroke(.orange.opacity(0.3), lineWidth: 1)- )+ LiquidBar(+ fillPercent: model.accuracyPercent,+ color: Color.fluidGreen,+ secondaryColor: .cyan,+ icon: "target",+ label: "Accuracy")}+ .frame(width: 140, alignment: .center)+ .animation(.spring(response: 0.5, dampingFraction: 0.7), value: model.id)}- .frame(maxWidth: .infinity, alignment: .leading)- HStack(spacing: 16) {- LiquidBar(- fillPercent: model.speedPercent,- color: .yellow,- secondaryColor: .orange,- icon: "bolt.fill",- label: "Speed"- )+ if supportsParakeetCustomWords {+ HStack(alignment: .center, spacing: 10) {+ Image(systemName: "checkmark.seal.fill")+ .font(.caption)+ .foregroundStyle(Color.fluidGreen)++ Text("Custom Words supported on Parakeet. Teach names, product terms, and uncommon words for better accuracy.")+ .font(.caption)+ .foregroundStyle(.secondary)+ .lineLimit(3)++ Spacer(minLength: 8)- LiquidBar(- fillPercent: model.accuracyPercent,- color: Color.fluidGreen,- secondaryColor: .cyan,- icon: "target",- label: "Accuracy"+ Button("Open Custom Dictionary") {+ NotificationCenter.default.post(name: .openCustomDictionaryFromVoiceEngine, object: nil)+ }+ .buttonStyle(.borderedProminent)+ .tint(Color.fluidGreen)+ .controlSize(.small)+ }+ .padding(.horizontal, 10)+ .padding(.vertical, 8)+ .background(+ RoundedRectangle(cornerRadius: 8)+ .fill(Color.fluidGreen.opacity(0.10))+ .overlay(+ RoundedRectangle(cornerRadius: 8)+ .stroke(Color.fluidGreen.opacity(0.30), lineWidth: 1)+ ))}- .frame(width: 140, alignment: .center)- .animation(.spring(response: 0.5, dampingFraction: 0.7), value: model.id)}.padding(.vertical, 6)}func speechModelCard(for model: SettingsStore.SpeechModel) -> some View {let isSelected = self.viewModel.previewSpeechModel == model- let isActive = self.viewModel.isActiveSpeechModel(model)+ let isConfiguredActive = self.viewModel.isActiveSpeechModel(model)+ let isActive = isConfiguredActive && model.isInstalledreturn HStack(alignment: .top, spacing: 10) {Circle()@@ -302,23 +355,43 @@ extension VoiceEngineSettingsView {if self.viewModel.downloadingModel == model {// This specific model is currently being downloadedVStack(alignment: .trailing, spacing: 4) {- ProgressView(value: self.viewModel.downloadProgress)- .progressViewStyle(.linear)- .frame(width: 90)- Text("\(Int(self.viewModel.downloadProgress * 100))%")- .font(.caption2)- .foregroundStyle(.secondary)- }- } else if (self.viewModel.asr.isDownloadingModel || self.viewModel.asr.isLoadingModel) && isActive && !self.viewModel.asr.isAsrReady {- // Active model is loading/downloading (for Activate flow)- VStack(alignment: .trailing, spacing: 4) {- if let progress = self.viewModel.asr.downloadProgress, self.viewModel.asr.isDownloadingModel {- ProgressView(value: progress)+ if self.viewModel.downloadProgress >= 0.82 {+ HStack(spacing: 6) {+ ProgressView()+ .controlSize(.mini)+ Text("Finalizing…")+ .font(.caption2)+ .foregroundStyle(.secondary)+ }+ } else {+ ProgressView(value: self.viewModel.downloadProgress).progressViewStyle(.linear).frame(width: 90)- Text("\(Int(progress * 100))%")+ Text("\(Int(self.viewModel.downloadProgress * 100))%").font(.caption2).foregroundStyle(.secondary)+ }+ }+ } else if (self.viewModel.asr.isDownloadingModel || self.viewModel.asr.isLoadingModel) && isConfiguredActive && !self.viewModel.asr.isAsrReady {+ // Active model is loading/downloading (for Activate flow)+ VStack(alignment: .trailing, spacing: 4) {+ if let progress = self.viewModel.asr.downloadProgress, self.viewModel.asr.isDownloadingModel {+ if progress >= 0.82 {+ HStack(spacing: 6) {+ ProgressView()+ .controlSize(.mini)+ Text("Finalizing…")+ .font(.caption2)+ .foregroundStyle(.secondary)+ }+ } else {+ ProgressView(value: progress)+ .progressViewStyle(.linear)+ .frame(width: 90)+ Text("\(Int(progress * 100))%")+ .font(.caption2)+ .foregroundStyle(.secondary)+ }} else {ProgressView().controlSize(.mini)@@ -330,7 +403,7 @@ extension VoiceEngineSettingsView {}} else if model.isInstalled {HStack(spacing: 8) {- if isActive {+ if isConfiguredActive {let isLoading = (self.viewModel.asr.isLoadingModel || self.viewModel.asr.isDownloadingModel) && !self.viewModel.asr.isAsrReadyText(isLoading ? "Loading…" : "Active").font(.caption2)@@ -416,9 +489,18 @@ extension VoiceEngineSettingsView {if (self.viewModel.asr.isDownloadingModel || self.viewModel.asr.isLoadingModel) && !self.viewModel.asr.isAsrReady {HStack(spacing: 8) {ProgressView().controlSize(.small).fixedSize()- Text(self.viewModel.asr.isLoadingModel ? "Loading model…" : "Downloading…")- .font(.caption)- .foregroundStyle(.secondary)+ if self.viewModel.asr.isDownloadingModel,+ let progress = self.viewModel.asr.downloadProgress,+ progress >= 0.82+ {+ Text("Finalizing download and loading model…")+ .font(.caption)+ .foregroundStyle(.secondary)+ } else {+ Text(self.viewModel.asr.isLoadingModel ? "Loading model…" : "Downloading…")+ .font(.caption)+ .foregroundStyle(.secondary)+ }}} else if self.viewModel.asr.isAsrReady {Image(systemName: "checkmark.circle.fill").foregroundStyle(Color.fluidGreen).font(.caption)@@ -546,3 +628,7 @@ extension VoiceEngineSettingsView {return nil}}++extension Notification.Name {+ static let openCustomDictionaryFromVoiceEngine = Notification.Name("OpenCustomDictionaryFromVoiceEngine")+}diff --git a/Sources/Fluid/UI/AISettingsView.swift b/Sources/Fluid/UI/AISettingsView.swiftindex 56895088..d60268ba 100644--- a/Sources/Fluid/UI/AISettingsView.swift+++ b/Sources/Fluid/UI/AISettingsView.swift@@ -15,14 +15,14 @@ enum AIConnectionStatus {}enum PromptEditorMode: Identifiable, Equatable {- case defaultPrompt- case newPrompt+ case defaultPrompt(mode: SettingsStore.PromptMode)+ case newPrompt(prefillMode: SettingsStore.PromptMode)case edit(promptID: String)var id: String {switch self {- case .defaultPrompt: return "default"- case .newPrompt: return "new"+ case let .defaultPrompt(mode): return "default:\(mode.rawValue)"+ case let .newPrompt(prefillMode): return "new:\(prefillMode.rawValue)"case let .edit(promptID): return "edit:\(promptID)"}}@@ -36,6 +36,14 @@ enum PromptEditorMode: Identifiable, Equatable {if case let .edit(promptID) = self { return promptID }return nil}++ var mode: SettingsStore.PromptMode? {+ switch self {+ case let .defaultPrompt(mode): return mode+ case let .newPrompt(prefillMode): return prefillMode+ case .edit: return nil+ }+ }}enum ModelSortOption: String, CaseIterable, Identifiable {diff --git a/Sources/Fluid/UI/CustomDictionaryView.swift b/Sources/Fluid/UI/CustomDictionaryView.swiftindex 693740d9..957a656f 100644--- a/Sources/Fluid/UI/CustomDictionaryView.swift+++ b/Sources/Fluid/UI/CustomDictionaryView.swift@@ -11,23 +11,30 @@ import SwiftUIstruct CustomDictionaryView: View {@Environment(\.theme) private var theme@State private var entries: [SettingsStore.CustomDictionaryEntry] = SettingsStore.shared.customDictionaryEntries+ @State private var boostTerms: [ParakeetVocabularyStore.VocabularyConfig.Term] = []@State private var showAddSheet = false@State private var editingEntry: SettingsStore.CustomDictionaryEntry?+ @State private var showAddBoostSheet = false+ @State private var editingBoostTerm: EditableBoostTerm?// Collapsible section states- @State private var isOfflineSectionExpanded = true- @State private var isAISectionExpanded = false+ @State private var isOfflineSectionExpanded = false+ @State private var isAISectionExpanded = true++ @State private var boostStatusMessage = "Add custom words for better Parakeet recognition."+ @State private var boostHasError = false+ @State private var vocabBoostingEnabled: Bool = SettingsStore.shared.vocabularyBoostingEnabledvar body: some View {ScrollView(.vertical, showsIndicators: false) {VStack(alignment: .leading, spacing: 16) {self.pageHeader- // Section 1: Offline/Instant Replacement- self.offlineReplacementSection-- // Section 2: AI Post-Processing (Coming Soon)+ // Section 1: Custom Words (Parakeet)self.aiPostProcessingSection++ // Section 2: Instant Replacement+ self.offlineReplacementSection}.padding(20)}@@ -48,6 +55,25 @@ struct CustomDictionaryView: View {}}}+ .sheet(isPresented: self.$showAddBoostSheet) {+ AddBoostTermSheet(existingTerms: self.existingBoostTerms()) { newTerm in+ self.boostTerms.append(newTerm)+ self.saveBoostTerms()+ }+ }+ .sheet(item: self.$editingBoostTerm) { editable in+ EditBoostTermSheet(+ term: editable.term,+ existingTerms: self.existingBoostTerms(excludingIndex: editable.index)+ ) { updatedTerm in+ guard self.boostTerms.indices.contains(editable.index) else { return }+ self.boostTerms[editable.index] = updatedTerm+ self.saveBoostTerms()+ }+ }+ .onAppear {+ self.loadBoostTerms()+ }}// MARK: - Page Header@@ -63,13 +89,13 @@ struct CustomDictionaryView: View {.fontWeight(.semibold)}- Text("Improve transcription accuracy by defining word replacements. Choose between instant offline replacement or AI-powered context-aware corrections.")+ Text("Improve transcription accuracy with Custom Words for names and product terms, plus Instant Replacement for simple find-and-replace.").font(.subheadline).foregroundStyle(.secondary)}}- // MARK: - Section 1: Offline Replacement+ // MARK: - Section 2: Offline Replacementprivate var offlineReplacementSection: some View {ThemedCard(hoverEffect: false) {@@ -203,7 +229,7 @@ struct CustomDictionaryView: View {}}- // MARK: - Section 2: AI Post-Processing+ // MARK: - Section 1: Custom Words (Parakeet)private var aiPostProcessingSection: some View {ThemedCard(hoverEffect: false) {@@ -220,22 +246,34 @@ struct CustomDictionaryView: View {.foregroundStyle(.secondary).frame(width: 16)- Text("AI Post-Processing")+ Text("Custom Words (Parakeet)").font(.headline)- // AI badge- Text("AI")+ Text("PARAKEET").font(.caption2.weight(.semibold)).padding(.horizontal, 6).padding(.vertical, 2)- .background(RoundedRectangle(cornerRadius: 4).fill(.purple.opacity(0.2)))- .foregroundStyle(.purple)+ .background(RoundedRectangle(cornerRadius: 4).fill(self.theme.palette.accent.opacity(0.2)))+ .foregroundStyle(self.theme.palette.accent)- Text("COMING SOON")+ Text("\(self.boostTerms.count)").font(.caption2.weight(.medium))- .foregroundStyle(.tertiary)+ .padding(.horizontal, 6)+ .padding(.vertical, 2)+ .background(Capsule().fill(.quaternary))+ .foregroundStyle(.secondary)Spacer()++ if self.isAISectionExpanded && !self.boostTerms.isEmpty {+ Button {+ self.showAddBoostSheet = true+ } label: {+ Image(systemName: "plus")+ }+ .buttonStyle(.bordered)+ .controlSize(.small)+ }}.contentShape(Rectangle())}@@ -245,33 +283,105 @@ struct CustomDictionaryView: View {Divider().padding(.vertical, 12)- // DescriptionVStack(alignment: .leading, spacing: 12) {- Text("Context-aware corrections powered by your AI provider. The AI will understand context and apply intelligent replacements.")+ Text("Add names, product words, and uncommon terms in a simple form.").font(.caption).foregroundStyle(.secondary)- // Planned features- VStack(alignment: .leading, spacing: 6) {- Label("Context-aware replacements", systemImage: "brain.head.profile")- Label("Learns from your corrections", systemImage: "sparkles")- Label("Works with technical jargon", systemImage: "wrench.and.screwdriver")- Label("Requires AI provider API key", systemImage: "key")+ Text("Words from Instant Replacement are also used here automatically.")+ .font(.caption2)+ .foregroundStyle(.secondary)++ Text("Applies when using a Parakeet voice engine.")+ .font(.caption2)+ .foregroundStyle(.secondary)++ HStack {+ Toggle(isOn: self.$vocabBoostingEnabled) {+ VStack(alignment: .leading, spacing: 2) {+ Text("Vocabulary Boosting")+ .font(.subheadline.weight(.medium))+ Text("Uses a secondary ML model to improve recognition of custom words. Disable if you experience issues.")+ .font(.caption2)+ .foregroundStyle(.secondary)+ }+ }+ .toggleStyle(.switch)+ .controlSize(.small)+ .onChange(of: self.vocabBoostingEnabled) { _, newValue in+ SettingsStore.shared.vocabularyBoostingEnabled = newValue+ }+ }+ .padding(10)+ .background(+ RoundedRectangle(cornerRadius: 8)+ .fill(self.theme.palette.contentBackground.opacity(0.6))+ )++ if self.boostTerms.isEmpty {+ VStack(spacing: 10) {+ Image(systemName: "waveform.and.magnifyingglass")+ .font(.system(size: 28))+ .foregroundStyle(.tertiary)+ Text("No custom words yet")+ .font(.subheadline)+ .foregroundStyle(.secondary)+ Button {+ self.showAddBoostSheet = true+ } label: {+ HStack(spacing: 4) {+ Image(systemName: "plus")+ Text("Add Custom Word")+ }+ }+ .buttonStyle(.borderedProminent)+ .tint(self.theme.palette.accent)+ .controlSize(.small)+ }+ .frame(maxWidth: .infinity)+ .padding(.vertical, 16)+ } else {+ VStack(spacing: 8) {+ ForEach(Array(self.boostTerms.enumerated()), id: \.offset) { index, term in+ BoostTermRow(+ term: term,+ onEdit: {+ self.editingBoostTerm = EditableBoostTerm(index: index, term: term)+ },+ onDelete: {+ self.deleteBoostTerm(at: index)+ }+ )+ }+ }++ HStack {+ Button {+ self.showAddBoostSheet = true+ } label: {+ Label("Add Word", systemImage: "plus")+ }+ .buttonStyle(.borderedProminent)+ .tint(self.theme.palette.accent)+ .controlSize(.small)++ Spacer()+ }}- .font(.caption)- .foregroundStyle(.secondary)- // Coming soon messageHStack {- Image(systemName: "hammer.fill")- .foregroundStyle(.orange)- Text("This feature is under development")+ Image(systemName: self.boostHasError ? "xmark.circle.fill" : "checkmark.circle.fill")+ .foregroundStyle(self.boostHasError ? .red : .secondary)+ Text(self.boostStatusMessage).font(.caption)- .foregroundStyle(.secondary)+ .foregroundStyle(self.boostHasError ? .red : .secondary)}.padding(10).frame(maxWidth: .infinity, alignment: .leading)- .background(RoundedRectangle(cornerRadius: 8).fill(.orange.opacity(0.1)))+ .background(+ RoundedRectangle(cornerRadius: 8)+ .fill(self.boostHasError ? Color.red.opacity(0.08) : self.theme.palette.contentBackground.opacity(0.6))+ )}}}@@ -285,6 +395,36 @@ struct CustomDictionaryView: View {SettingsStore.shared.customDictionaryEntries = self.entries// Invalidate cached regex patterns so changes take effect immediatelyASRService.invalidateDictionaryCache()+ NotificationCenter.default.post(name: .parakeetVocabularyDidChange, object: nil)+ }++ private func loadBoostTerms() {+ do {+ self.boostTerms = try ParakeetVocabularyStore.shared.loadUserBoostTerms()+ self.boostStatusMessage = "Loaded \(self.boostTerms.count) custom words."+ self.boostHasError = false+ } catch {+ self.boostTerms = []+ self.boostStatusMessage = "Couldn't load custom words: \(error.localizedDescription)"+ self.boostHasError = true+ }+ }++ private func saveBoostTerms() {+ do {+ try ParakeetVocabularyStore.shared.saveUserBoostTerms(self.boostTerms)+ self.boostStatusMessage = "Saved \(self.boostTerms.count) custom words."+ self.boostHasError = false+ } catch {+ self.boostStatusMessage = "Couldn't save custom words: \(error.localizedDescription)"+ self.boostHasError = true+ }+ }++ private func deleteBoostTerm(at index: Int) {+ guard self.boostTerms.indices.contains(index) else { return }+ self.boostTerms.remove(at: index)+ self.saveBoostTerms()}private func deleteEntry(_ entry: SettingsStore.CustomDictionaryEntry) {@@ -302,6 +442,285 @@ struct CustomDictionaryView: View {}return triggers}++ private func existingBoostTerms(excludingIndex: Int? = nil) -> Set<String> {+ var terms: Set<String> = []+ for (index, term) in self.boostTerms.enumerated() where index != excludingIndex {+ terms.insert(term.text.lowercased())+ }+ return terms+ }+}++private struct EditableBoostTerm: Identifiable {+ let id = UUID()+ let index: Int+ let term: ParakeetVocabularyStore.VocabularyConfig.Term+}++private enum BoostStrengthPreset: String, CaseIterable, Identifiable {+ case mild = "Mild"+ case balanced = "Balanced"+ case strong = "Strong"++ var id: String { self.rawValue }++ var weight: Float {+ switch self {+ case .mild: return 5.0+ case .balanced: return 10.0+ case .strong: return 13.0+ }+ }++ var hint: String {+ switch self {+ case .mild: return "Very light nudge with minimal impact."+ case .balanced: return "Best default for most names and product terms."+ case .strong: return "Use when this word should win more often in noisy audio."+ }+ }++ static func nearest(for weight: Float) -> Self {+ if weight < 8.5 { return .mild }+ if weight > 11.5 { return .strong }+ return .balanced+ }+}++// MARK: - Boost Term Row++struct BoostTermRow: View {+ let term: ParakeetVocabularyStore.VocabularyConfig.Term+ let onEdit: () -> Void+ let onDelete: () -> Void++ @Environment(\.theme) private var theme++ var body: some View {+ HStack(alignment: .center, spacing: 12) {+ VStack(alignment: .leading, spacing: 4) {+ Text(self.term.text)+ .font(.callout.weight(.medium))+ .foregroundStyle(self.theme.palette.accent)+ }++ Spacer()++ if let weight = self.term.weight {+ Text("\(BoostStrengthPreset.nearest(for: weight).rawValue) priority")+ .font(.caption2.weight(.semibold))+ .padding(.horizontal, 6)+ .padding(.vertical, 3)+ .background(Capsule().fill(.quaternary))+ .foregroundStyle(.secondary)+ }++ HStack(spacing: 6) {+ Button {+ self.onEdit()+ } label: {+ Image(systemName: "pencil")+ .font(.caption2)+ }+ .buttonStyle(.bordered)+ .controlSize(.mini)++ Button(role: .destructive) {+ self.onDelete()+ } label: {+ Image(systemName: "trash")+ .font(.caption2)+ }+ .buttonStyle(.bordered)+ .controlSize(.mini)+ }+ }+ .padding(10)+ .background(RoundedRectangle(cornerRadius: 8).fill(.quaternary.opacity(0.5)))+ }+}++// MARK: - Add Boost Term Sheet++struct AddBoostTermSheet: View {+ @Environment(\.dismiss) private var dismiss++ let existingTerms: Set<String>+ let onSave: (ParakeetVocabularyStore.VocabularyConfig.Term) -> Void++ @State private var termText = ""+ @State private var strength: BoostStrengthPreset = .balanced++ private var normalizedTerm: String {+ self.termText.trimmingCharacters(in: .whitespacesAndNewlines)+ }++ private var isDuplicate: Bool {+ self.existingTerms.contains(self.normalizedTerm.lowercased())+ }++ private var canSave: Bool {+ !self.normalizedTerm.isEmpty && !self.isDuplicate+ }++ var body: some View {+ ScrollView(.vertical, showsIndicators: false) {+ VStack(alignment: .leading, spacing: 14) {+ Text("Add Custom Word")+ .font(.headline)++ VStack(alignment: .leading, spacing: 6) {+ Text("Preferred Word or Phrase")+ .font(.subheadline.weight(.medium))+ TextField("FluidVoice", text: self.$termText)+ .textFieldStyle(.roundedBorder)+ .onSubmit { self.saveIfValid() }+ }++ VStack(alignment: .leading, spacing: 6) {+ Text("Word Priority")+ .font(.subheadline.weight(.medium))+ Picker("Word Priority", selection: self.$strength) {+ ForEach(BoostStrengthPreset.allCases) { preset in+ Text(preset.rawValue).tag(preset)+ }+ }+ .pickerStyle(.segmented)+ Text(self.strength.hint)+ .font(.caption2)+ .foregroundStyle(.secondary)+ }++ if self.isDuplicate {+ Text("This term already exists.")+ .font(.caption)+ .foregroundStyle(.orange)+ }++ HStack {+ Button("Cancel") { self.dismiss() }+ .buttonStyle(.bordered)+ Spacer()+ Button("Save") { self.saveIfValid() }+ .buttonStyle(.borderedProminent)+ .disabled(!self.canSave)+ .keyboardShortcut(.return, modifiers: [])+ }+ }+ }+ .padding(20)+ .frame(minWidth: 420, idealWidth: 460, maxWidth: 520)+ .frame(minHeight: 300, idealHeight: 340, maxHeight: 460)+ .onAppear {+ // Always start new entries at the recommended default.+ self.termText = ""+ self.strength = .balanced+ }+ }++ private func saveIfValid() {+ guard self.canSave else { return }+ self.onSave(+ ParakeetVocabularyStore.VocabularyConfig.Term(+ text: self.normalizedTerm,+ weight: self.strength.weight,+ aliases: []+ )+ )+ self.dismiss()+ }+}++// MARK: - Edit Boost Term Sheet++struct EditBoostTermSheet: View {+ @Environment(\.dismiss) private var dismiss++ let term: ParakeetVocabularyStore.VocabularyConfig.Term+ let existingTerms: Set<String>+ let onSave: (ParakeetVocabularyStore.VocabularyConfig.Term) -> Void++ @State private var termText = ""+ @State private var strength: BoostStrengthPreset = .balanced++ private var normalizedTerm: String {+ self.termText.trimmingCharacters(in: .whitespacesAndNewlines)+ }++ private var isDuplicate: Bool {+ self.existingTerms.contains(self.normalizedTerm.lowercased())+ }++ private var canSave: Bool {+ !self.normalizedTerm.isEmpty && !self.isDuplicate+ }++ var body: some View {+ ScrollView(.vertical, showsIndicators: false) {+ VStack(alignment: .leading, spacing: 14) {+ Text("Edit Custom Word")+ .font(.headline)++ VStack(alignment: .leading, spacing: 6) {+ Text("Preferred Word or Phrase")+ .font(.subheadline.weight(.medium))+ TextField("FluidVoice", text: self.$termText)+ .textFieldStyle(.roundedBorder)+ .onSubmit { self.saveIfValid() }+ }++ VStack(alignment: .leading, spacing: 6) {+ Text("Word Priority")+ .font(.subheadline.weight(.medium))+ Picker("Word Priority", selection: self.$strength) {+ ForEach(BoostStrengthPreset.allCases) { preset in+ Text(preset.rawValue).tag(preset)+ }+ }+ .pickerStyle(.segmented)+ Text(self.strength.hint)+ .font(.caption2)+ .foregroundStyle(.secondary)+ }++ if self.isDuplicate {+ Text("This term already exists.")+ .font(.caption)+ .foregroundStyle(.orange)+ }++ HStack {+ Button("Cancel") { self.dismiss() }+ .buttonStyle(.bordered)+ Spacer()+ Button("Save") { self.saveIfValid() }+ .buttonStyle(.borderedProminent)+ .disabled(!self.canSave)+ .keyboardShortcut(.return, modifiers: [])+ }+ }+ }+ .padding(20)+ .frame(minWidth: 420, idealWidth: 460, maxWidth: 520)+ .frame(minHeight: 300, idealHeight: 340, maxHeight: 460)+ .onAppear {+ self.termText = self.term.text+ self.strength = BoostStrengthPreset.nearest(for: self.term.weight ?? BoostStrengthPreset.balanced.weight)+ }+ }++ private func saveIfValid() {+ guard self.canSave else { return }+ self.onSave(+ ParakeetVocabularyStore.VocabularyConfig.Term(+ text: self.normalizedTerm,+ weight: self.strength.weight,+ aliases: self.term.aliases+ )+ )+ self.dismiss()+ }}// MARK: - Dictionary Entry Rowdiff --git a/Sources/Fluid/UI/MeetingTranscriptionView.swift b/Sources/Fluid/UI/MeetingTranscriptionView.swiftindex cbad4101..dc7a95c3 100644--- a/Sources/Fluid/UI/MeetingTranscriptionView.swift+++ b/Sources/Fluid/UI/MeetingTranscriptionView.swift@@ -4,6 +4,7 @@ import UniformTypeIdentifiersstruct MeetingTranscriptionView: View {let asrService: ASRService@StateObject private var transcriptionService: MeetingTranscriptionService+ @ObservedObject private var fileHistoryStore = FileTranscriptionHistoryStore.shared@State private var selectedFileURL: URL?@Environment(\.theme) private var theme@@ -14,8 +15,11 @@ struct MeetingTranscriptionView: View {@State private var showingFilePicker = false@State private var showingExportDialog = false+ @State private var exportResult: TranscriptionResult?@State private var exportFormat: ExportFormat = .text@State private var showingCopyConfirmation = false+ @State private var isDropTargeted = false+ @State private var dropErrorMessage: String?enum ExportFormat: String, CaseIterable {case text = "Text (.txt)"@@ -68,6 +72,18 @@ struct MeetingTranscriptionView: View {if let error = transcriptionService.error {self.errorCard(error: error)}++ // Drop error (unsupported file type)+ if let message = self.dropErrorMessage {+ self.dropErrorCard(message: message)+ }++ // Recent transcriptions (persisted history)+ if !self.fileHistoryStore.entries.isEmpty {+ Divider()+ .padding(.vertical, 8)+ self.recentTranscriptionsSection+ }}.padding(24)}@@ -87,6 +103,24 @@ struct MeetingTranscriptionView: View {.transition(.move(edge: .top).combined(with: .opacity))}}+ .fileExporter(+ isPresented: self.$showingExportDialog,+ document: TranscriptionDocument(+ result: self.exportResult ?? TranscriptionResult(text: "", confidence: 0, duration: 0, processingTime: 0, fileName: "transcript"),+ format: self.exportFormat,+ service: self.transcriptionService+ ),+ contentType: self.exportFormat == .text ? .plainText : .json,+ defaultFilename: "\((self.exportResult?.fileName).map { "\($0)_transcript" } ?? "transcript").\(self.exportFormat.fileExtension)"+ ) { exportCompletion in+ switch exportCompletion {+ case .success:+ DebugLogger.shared.info("File exported successfully", source: "MeetingTranscriptionView")+ case let .failure(error):+ DebugLogger.shared.error("Export failed: \(error)", source: "MeetingTranscriptionView")+ }+ self.exportResult = nil+ }}// MARK: - File Selection Card@@ -147,7 +181,7 @@ struct MeetingTranscriptionView: View {.disabled(self.transcriptionService.isTranscribing)} else {- // File picker button+ // File picker button – whole area is tappable; supports drag-and-dropButton(action: {self.showingFilePicker = true}) {@@ -164,6 +198,7 @@ struct MeetingTranscriptionView: View {}.frame(maxWidth: .infinity).padding(32)+ .contentShape(Rectangle())}.buttonStyle(.plain).background(@@ -174,9 +209,14 @@ struct MeetingTranscriptionView: View {.stroke(self.theme.palette.cardBorder.opacity(0.45), lineWidth: 1)))- .overlay(RoundedRectangle(cornerRadius: 12)- .strokeBorder(style: StrokeStyle(lineWidth: 2, dash: [8]))- .foregroundColor(Color.fluidGreen.opacity(0.3)))+ .overlay(+ RoundedRectangle(cornerRadius: 12)+ .strokeBorder(style: StrokeStyle(lineWidth: 2, dash: [8]))+ .foregroundColor(Color.fluidGreen.opacity(self.isDropTargeted ? 0.7 : 0.3))+ )+ .onDrop(of: [.fileURL], isTargeted: self.$isDropTargeted) { providers in+ self.handleDrop(providers: providers)+ }}}.fileImporter(@@ -265,6 +305,7 @@ struct MeetingTranscriptionView: View {.help("Copy to clipboard")Button(action: {+ self.exportResult = resultself.showingExportDialog = true}) {Image(systemName: "square.and.arrow.up")@@ -303,23 +344,146 @@ struct MeetingTranscriptionView: View {.stroke(self.theme.palette.cardBorder.opacity(0.45), lineWidth: 1)))- .fileExporter(- isPresented: self.$showingExportDialog,- document: TranscriptionDocument(- result: result,- format: self.exportFormat,- service: self.transcriptionService- ),- contentType: self.exportFormat == .text ? .plainText : .json,- defaultFilename: "\(result.fileName)_transcript.\(self.exportFormat.fileExtension)"- ) { result in- switch result {- case .success:- DebugLogger.shared.info("File exported successfully", source: "MeetingTranscriptionView")- case let .failure(error):- DebugLogger.shared.error("Export failed: \(error)", source: "MeetingTranscriptionView")+ }++ // MARK: - Recent Transcriptions Section++ private var recentTranscriptionsSection: some View {+ VStack(alignment: .leading, spacing: 16) {+ HStack {+ Text("Recent transcriptions")+ .font(.headline)+ Spacer()+ if !self.fileHistoryStore.entries.isEmpty {+ Button("Clear all") {+ self.fileHistoryStore.clearAll()+ }+ .buttonStyle(.plain)+ .foregroundColor(.secondary)+ .font(.caption)+ }+ }++ VStack(spacing: 8) {+ ForEach(self.fileHistoryStore.entries) { entry in+ self.recentEntryRow(entry: entry)+ }+ }++ if let entry = self.fileHistoryStore.selectedEntry {+ self.historyDetailCard(entry: entry)+ }+ }+ }++ private func recentEntryRow(entry: FileTranscriptionEntry) -> some View {+ let isSelected = self.fileHistoryStore.selectedEntryID == entry.id+ return Button(action: {+ self.fileHistoryStore.selectedEntryID = entry.id+ }) {+ HStack {+ Image(systemName: "doc.text.fill")+ .font(.body)+ .foregroundColor(Color.fluidGreen)+ .frame(width: 24)++ VStack(alignment: .leading, spacing: 2) {+ Text(entry.fileName)+ .font(.system(size: 14, weight: .medium))+ .lineLimit(1)+ Text(entry.relativeTimeString)+ .font(.caption)+ .foregroundColor(.secondary)+ Text(entry.previewText)+ .font(.caption)+ .foregroundColor(.secondary)+ .lineLimit(1)+ }++ Spacer()++ if isSelected {+ Image(systemName: "chevron.right.circle.fill")+ .foregroundColor(Color.fluidGreen)+ }+ }+ .padding(12)+ .background(+ RoundedRectangle(cornerRadius: 8, style: .continuous)+ .fill(self.theme.palette.cardBackground)+ .overlay(+ RoundedRectangle(cornerRadius: 8, style: .continuous)+ .stroke(isSelected ? Color.fluidGreen.opacity(0.5) : self.theme.palette.cardBorder.opacity(0.3), lineWidth: isSelected ? 2 : 1)+ )+ )+ }+ .buttonStyle(.plain)+ }++ private func historyDetailCard(entry: FileTranscriptionEntry) -> some View {+ let result = entry.toTranscriptionResult()+ return VStack(alignment: .leading, spacing: 16) {+ HStack {+ VStack(alignment: .leading, spacing: 4) {+ Text("From history")+ .font(.headline)+ HStack(spacing: 16) {+ Label("\(String(format: "%.1f", entry.duration))s", systemImage: "clock")+ Label("\(String(format: "%.0f%%", entry.confidence * 100))", systemImage: "checkmark.circle")+ Label(entry.fullDateString, systemImage: "calendar")+ }+ .font(.caption)+ .foregroundColor(.secondary)+ }+ Spacer()+ HStack(spacing: 8) {+ Button(action: { self.copyToClipboard(entry.text) }) {+ Image(systemName: "doc.on.doc")+ }+ .help("Copy to clipboard")+ Button(action: {+ self.exportResult = result+ self.showingExportDialog = true+ }) {+ Image(systemName: "square.and.arrow.up")+ }+ .help("Export transcription")+ Button(action: {+ self.fileHistoryStore.deleteEntry(id: entry.id)+ }) {+ Image(systemName: "trash")+ }+ .help("Remove from history")+ }+ .buttonStyle(.borderless)}+ Divider()+ ScrollView {+ Text(entry.text)+ .font(.body)+ .textSelection(.enabled)+ .frame(maxWidth: .infinity, alignment: .leading)+ .padding()+ }+ .frame(maxHeight: 300)+ .background(+ RoundedRectangle(cornerRadius: 8, style: .continuous)+ .fill(self.theme.palette.contentBackground)+ .overlay(+ RoundedRectangle(cornerRadius: 8, style: .continuous)+ .stroke(self.theme.palette.cardBorder.opacity(0.45), lineWidth: 1)+ )+ )}+ .padding()+ .background(+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .fill(self.theme.palette.cardBackground)+ .overlay(+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .stroke(self.theme.palette.cardBorder.opacity(0.45), lineWidth: 1)+ )+ )}// MARK: - Error Card@@ -350,8 +514,64 @@ struct MeetingTranscriptionView: View {)}+ // MARK: - Drop Error Card++ private func dropErrorCard(message: String) -> some View {+ HStack {+ Image(systemName: "exclamationmark.triangle.fill")+ .foregroundColor(.red)++ Text(message)+ .font(.subheadline)++ Spacer()++ Button("Dismiss") {+ self.dropErrorMessage = nil+ }+ .buttonStyle(.borderless)+ }+ .padding()+ .background(+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .fill(Color.red.opacity(0.12))+ .overlay(+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .stroke(Color.red.opacity(0.4), lineWidth: 1)+ )+ )+ }+// MARK: - Helper Functions+ private static let supportedFileExtensions = ["wav", "mp3", "m4a", "aac", "flac", "aiff", "caf", "mp4", "mov"]++ private static let dropErrorCopy = "Accepted file types: WAV, MP3, M4A, MP4, MOV, and more."++ private func handleDrop(providers: [NSItemProvider]) -> Bool {+ guard let provider = providers.first else { return false }+ provider.loadItem(forTypeIdentifier: UTType.fileURL.identifier, options: nil) { item, _ in+ let url: URL? = (item as? URL) ?? (item as? Data).flatMap { URL(dataRepresentation: $0, relativeTo: nil) }+ guard let url = url else { return }+ let ext = url.pathExtension.lowercased()+ guard Self.supportedFileExtensions.contains(ext) else {+ DispatchQueue.main.async {+ self.dropErrorMessage = Self.dropErrorCopy+ DispatchQueue.main.asyncAfter(deadline: .now() + 3) {+ self.dropErrorMessage = nil+ }+ }+ return+ }+ DispatchQueue.main.async {+ self.selectedFileURL = url+ self.transcriptionService.reset()+ self.dropErrorMessage = nil+ }+ }+ return true+ }+private func transcribeFile() async {guard let fileURL = selectedFileURL else { return }@@ -393,7 +613,9 @@ struct MeetingTranscriptionView: View {// MARK: - Document for Exportstruct TranscriptionDocument: FileDocument {- static var readableContentTypes: [UTType] { [.plainText, .json] }+ static var readableContentTypes: [UTType] {+ [.plainText, .json]+ }let result: TranscriptionResultlet format: MeetingTranscriptionView.ExportFormatdiff --git a/Sources/Fluid/UI/SettingsView.swift b/Sources/Fluid/UI/SettingsView.swiftindex 6e903d7c..3c3dd95a 100644--- a/Sources/Fluid/UI/SettingsView.swift+++ b/Sources/Fluid/UI/SettingsView.swift@@ -45,6 +45,8 @@ struct SettingsView: View {@State private var showAnalyticsPrivacy: Bool = false@State private var pendingAnalyticsValue: Bool? = nil@State private var showAreYouSureToStopAnalytics: Bool = false+ @State private var rollbackVersion: String = ""+ @State private var isRollingBack: Bool = falselet hotkeyManager: GlobalHotkeyManager?let menuBarManager: MenuBarManager@@ -94,6 +96,10 @@ struct SettingsView: View {)}+ private var currentAppVersion: String {+ Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "Unknown"+ }+var body: some View {ScrollView(.vertical, showsIndicators: false) {VStack(spacing: 16) {@@ -118,14 +124,14 @@ struct SettingsView: View {)Divider().opacity(0.2)- // Show in Dock+ // Hide from Dock & App Switcherself.settingsToggleRow(- title: "Show in Dock",- description: "Display FluidVoice icon in the Dock",+ title: "Hide from Dock & App Switcher",+ description: "Keep FluidVoice in the menu bar only (hides Dock icon and Cmd+Tab entry)",footnote: "Note: May require app restart to take effect.",isOn: Binding(- get: { SettingsStore.shared.showInDock },- set: { SettingsStore.shared.showInDock = $0 }+ get: { SettingsStore.shared.hideFromDockAndAppSwitcher },+ set: { SettingsStore.shared.hideFromDockAndAppSwitcher = $0 }))Divider().opacity(0.2)@@ -180,38 +186,27 @@ struct SettingsView: View {}Divider().opacity(0.2)- self.settingsToggleRow(- title: "Transcription Sounds",- description: "Play a short sound when dictation or command recording starts.",- isOn: Binding(- get: { SettingsStore.shared.enableTranscriptionSounds },- set: { SettingsStore.shared.enableTranscriptionSounds = $0 }- )- )-- if SettingsStore.shared.enableTranscriptionSounds {- HStack {- VStack(alignment: .leading, spacing: 2) {- Text("Start Sound")- .font(.body)- Text("Choose which sound plays when recording starts.")- .font(.subheadline)- .foregroundStyle(.secondary)- }+ HStack {+ VStack(alignment: .leading, spacing: 2) {+ Text("Transcription Sounds")+ .font(.body)+ Text("Choose which sound plays when recording starts. Select None to disable.")+ .font(.subheadline)+ .foregroundStyle(.secondary)+ }- Spacer()+ Spacer()- Picker("", selection: Binding(- get: { SettingsStore.shared.transcriptionStartSound },- set: { SettingsStore.shared.transcriptionStartSound = $0 }- )) {- ForEach(SettingsStore.TranscriptionStartSound.allCases) { option in- Text(option.displayName).tag(option)- }+ Picker("", selection: Binding(+ get: { SettingsStore.shared.transcriptionStartSound },+ set: { SettingsStore.shared.transcriptionStartSound = $0 }+ )) {+ ForEach(SettingsStore.TranscriptionStartSound.allCases) { option in+ Text(option.displayName).tag(option)}- .pickerStyle(.menu)- .frame(width: 170, alignment: .trailing)}+ .pickerStyle(.menu)+ .frame(width: 170, alignment: .trailing)}Divider().opacity(0.2)@@ -243,6 +238,10 @@ struct SettingsView: View {.font(.caption).foregroundStyle(.tertiary)}++ Text("Current version: \(self.currentAppVersion)")+ .font(.caption)+ .foregroundStyle(.tertiary)}// Update Buttons@@ -285,8 +284,78 @@ struct SettingsView: View {}.buttonStyle(.bordered).controlSize(.regular)++ Button(self.rollbackVersion.isEmpty ? "Rollback" : "Rollback to \(self.rollbackVersion)") {+ guard !self.isRollingBack else { return }++ let infoText = self.rollbackVersion.isEmpty ? "your previously installed version" : self.rollbackVersion+ let targetVersion = self.rollbackVersion+ let confirm = NSAlert()+ confirm.messageText = "Rollback to \(infoText)?"+ confirm.informativeText = "This will restore a previous app version and relaunch FluidVoice."+ confirm.alertStyle = .warning+ confirm.addButton(withTitle: "Rollback")+ confirm.addButton(withTitle: "Cancel")++ guard confirm.runModal() == .alertFirstButtonReturn else { return }++ self.isRollingBack = true+ Task {+ defer {+ Task { @MainActor in+ self.isRollingBack = false+ }+ }++ do {+ try await SimpleUpdater.shared.rollbackToLatestBackup()+ await MainActor.run {+ let success = NSAlert()+ success.messageText = "Rollback Successful"+ success.informativeText = "Rolled back to \(targetVersion). FluidVoice will relaunch shortly."+ success.alertStyle = .informational+ success.addButton(withTitle: "Report Bug")+ success.addButton(withTitle: "OK")+ let response = success.runModal()+ if response == .alertFirstButtonReturn {+ self.openIssueReportingPage()+ }+ }+ } catch {+ await MainActor.run {+ let fail = NSAlert()+ fail.messageText = "Rollback Failed"+ fail.informativeText = error.localizedDescription+ fail.alertStyle = .critical+ fail.addButton(withTitle: "OK")+ fail.runModal()+ self.refreshRollbackState()+ }+ }+ }+ }+ .buttonStyle(.bordered)+ .controlSize(.regular)+ .disabled(self.rollbackVersion.isEmpty || self.isRollingBack)+ .opacity(self.isRollingBack ? 0.7 : 1.0)++ Button("Get Previous Builds") {+ self.openPreviousBuildPicker()+ }+ .buttonStyle(.bordered)+ .controlSize(.regular)}.padding(.top, 12)++ if self.rollbackVersion.isEmpty {+ Text("No rollback backup found.")+ .font(.caption)+ .foregroundStyle(.secondary)+ } else {+ Text("Rollback target: \(self.rollbackVersion)")+ .font(.caption)+ .foregroundStyle(.secondary)+ }}}.padding(16)@@ -445,8 +514,8 @@ struct SettingsView: View {self.shortcutRow(icon: "pencil.and.outline",iconColor: .secondary,- title: "Write Mode",- description: "Select text and speak how to rewrite, or write new content",+ title: "Edit Mode",+ description: "Select text and speak how to edit, or generate new content",shortcut: self.rewriteShortcut,isRecording: self.isRecordingRewriteShortcut,isEnabled: self.$rewriteShortcutEnabled,@@ -795,10 +864,10 @@ struct SettingsView: View {.padding(16)}- // Visualization Sensitivity Card+ // Overlay Settings CardThemedCard(style: .standard) {VStack(alignment: .leading, spacing: 14) {- Label("Visualization", systemImage: "waveform")+ Label("Overlay", systemImage: "waveform").font(.headline).foregroundStyle(.primary)@@ -980,8 +1049,8 @@ struct SettingsView: View {VStack(alignment: .leading, spacing: 8) {self.settingsToggleRow(- title: "Enable Debug Logs",- description: "Capture and show detailed app activity.",+ title: "Show Debug Logs in App",+ description: "File logs are always collected for diagnostics.",isOn: Binding(get: { SettingsStore.shared.enableDebugLogs },set: { SettingsStore.shared.enableDebugLogs = $0 }@@ -1006,6 +1075,26 @@ struct SettingsView: View {Text("The debug log contains detailed information about app operations and can help with troubleshooting.").font(.caption).foregroundStyle(.secondary)+ Text("Crash diagnostics are written to Library/Logs/Fluid/Fluid.log by default.")+ .font(.caption)+ .foregroundStyle(.secondary)++ #if DEBUG+ Divider().padding(.vertical, 8)++ Button(role: .destructive) {+ self.settings.resetOnboardingProgress()+ DebugLogger.shared.info("Developer action: onboarding reset", source: "SettingsView")+ } label: {+ Label("Reset Onboarding (Dev)", systemImage: "arrow.counterclockwise")+ }+ .buttonStyle(.bordered)+ .controlSize(.regular)++ Text("Developer-only action. Immediately re-enters first-run onboarding flow.")+ .font(.caption)+ .foregroundStyle(.secondary)+ #endif}}.padding(16)@@ -1083,6 +1172,7 @@ struct SettingsView: View {// This avoids the CoreAudio/SwiftUI AttributeGraph race condition that causes EXC_BAD_ACCESS.self.cachedDefaultInputName = AudioDevice.getDefaultInputDevice()?.name ?? ""self.cachedDefaultOutputName = AudioDevice.getDefaultOutputDevice()?.name ?? ""+ self.refreshRollbackState()}}.onChange(of: self.visualizerNoiseThreshold) { _, newValue in@@ -1090,6 +1180,65 @@ struct SettingsView: View {}}+ private func refreshRollbackState() {+ self.rollbackVersion = SimpleUpdater.shared.latestRollbackVersion() ?? ""+ }++ private func openIssueReportingPage() {+ guard let url = URL(string: "https://github.com/altic-dev/Fluid-oss/issues/new/choose") else { return }+ NSWorkspace.shared.open(url)+ }++ private func openPreviousBuildPicker() {+ Task { @MainActor in+ do {+ let options = try await SimpleUpdater.shared.fetchRecentReleaseBuildOptions(+ owner: "altic-dev",+ repo: "Fluid-oss",+ limit: 3+ )+ self.presentPreviousBuildPicker(options)+ } catch {+ self.openAllReleasesPage()+ }+ }+ }++ private func presentPreviousBuildPicker(_ options: [SimpleUpdater.ReleaseBuildOption]) {+ guard !options.isEmpty else {+ self.openAllReleasesPage()+ return+ }++ let picker = NSAlert()+ picker.messageText = "Download Previous Build"+ picker.informativeText = "No local rollback backup was found. Choose a recent release build:"+ picker.alertStyle = .informational++ for option in options {+ picker.addButton(withTitle: option.version)+ }+ picker.addButton(withTitle: "All Releases")+ picker.addButton(withTitle: "Cancel")++ let response = picker.runModal()+ let first = NSApplication.ModalResponse.alertFirstButtonReturn.rawValue+ let index = response.rawValue - first++ if index >= 0, index < options.count {+ NSWorkspace.shared.open(options[index].url)+ return+ }+ if index == options.count {+ self.openAllReleasesPage()+ }+ }++ private func openAllReleasesPage() {+ guard let url = URL(string: "https://github.com/altic-dev/Fluid-oss/releases") else { return }+ NSWorkspace.shared.open(url)+ }+private func applyAnalyticsConsentChange(_ enabled: Bool) {SettingsStore.shared.shareAnonymousAnalytics = enabledAnalyticsService.shared.setEnabled(enabled)diff --git a/Sources/Fluid/UI/WelcomeView.swift b/Sources/Fluid/UI/WelcomeView.swiftindex 11a87bfb..fbf25cf5 100644--- a/Sources/Fluid/UI/WelcomeView.swift+++ b/Sources/Fluid/UI/WelcomeView.swift@@ -63,9 +63,9 @@ struct WelcomeView: View {: "Download the AI model for offline voice transcription (~500MB)"),status: (self.asr.isAsrReady || self.asr.modelsExistOnDisk) ? .completed : .pending,action: {- self.selectedSidebarItem = .aiEnhancements+ self.selectedSidebarItem = .voiceEngine},- actionButtonTitle: "Go to AI Settings",+ actionButtonTitle: "Go to Voice Engine",showActionButton: !(self.asr.isAsrReady || self.asr.modelsExistOnDisk))@@ -215,11 +215,11 @@ struct WelcomeView: View {}.frame(maxWidth: .infinity)- // Write Mode+ // Edit ModeThemedCard(style: .standard) {VStack(alignment: .leading, spacing: 12) {HStack(spacing: 8) {- Label("Write Mode", systemImage: "pencil.and.outline")+ Label("Edit Mode", systemImage: "pencil.and.outline").font(.headline).foregroundStyle(.blue)@@ -227,20 +227,20 @@ struct WelcomeView: View {Spacer()- Button("Open") {- self.selectedSidebarItem = .rewriteMode+ Button("Open AI Settings") {+ self.selectedSidebarItem = .aiEnhancements}.buttonStyle(.bordered).controlSize(.small)}- Text("AI-powered writing assistant. Write fresh content or rewrite selected text with voice.")+ Text("AI-powered editing assistant. Write fresh content or edit selected text with voice.").font(.subheadline).foregroundStyle(.secondary)VStack(alignment: .leading, spacing: 10) {VStack(alignment: .leading, spacing: 6) {- Text("To Write Fresh")+ Text("Create New Text").font(.subheadline.weight(.medium)).foregroundStyle(.blue)@@ -257,7 +257,7 @@ struct WelcomeView: View {}VStack(alignment: .leading, spacing: 6) {- Text("To Rewrite/Edit")+ Text("Edit Selected Text").font(.subheadline.weight(.medium)).foregroundStyle(.blue)@@ -325,6 +325,24 @@ struct WelcomeView: View {}}+ if self.settings.selectedSpeechModel == .parakeetTDT || self.settings.selectedSpeechModel == .parakeetTDTv2 {+ HStack(spacing: 6) {+ Image(systemName: "text.magnifyingglass")+ .font(.caption)+ .foregroundStyle(self.theme.palette.accent)+ Text(self.asr.wordBoostStatusText)+ .font(.caption)+ .foregroundStyle(.secondary)+ .lineLimit(1)+ }+ .padding(.horizontal, 10)+ .padding(.vertical, 6)+ .background(+ RoundedRectangle(cornerRadius: 8)+ .fill(self.theme.palette.contentBackground.opacity(0.6))+ )+ }+VStack(alignment: .leading, spacing: 12) {// Recording ControlVStack(spacing: 10) {@@ -514,3 +532,957 @@ struct WelcomeView: View {}}}++struct OnboardingFlowView: View {+ @EnvironmentObject var appServices: AppServices+ private var asr: ASRService { self.appServices.asr }+ @ObservedObject private var settings = SettingsStore.shared++ @Binding var currentStep: Int+ let accessibilityEnabled: Bool+ let markAISkipped: () -> Void+ let markPlaygroundValidated: () -> Void+ let finishOnboarding: () -> Void+ let openAccessibilitySettings: () -> Void+ let menuBarManager: MenuBarManager+ let theme: AppTheme++ @State private var preferredLanguageChoice: PreferredLanguageChoice = .englishOnly++ private enum PreferredLanguageChoice: String, CaseIterable, Identifiable {+ case englishOnly+ case multipleLanguages+ case other++ var id: String { self.rawValue }++ var title: String {+ switch self {+ case .englishOnly:+ return "English only"+ case .multipleLanguages:+ return "Multiple languages"+ case .other:+ return "Other"+ }+ }++ var subtitle: String {+ switch self {+ case .englishOnly:+ return "Uses Parakeet TDT v2"+ case .multipleLanguages:+ return "Uses Parakeet TDT v3"+ case .other:+ return "Choose a different model manually"+ }+ }+ }++ private enum Step: Int, CaseIterable {+ case voiceModel = 0+ case microphone = 1+ case accessibility = 2+ case aiEnhancement = 3+ case playground = 4++ var title: String {+ switch self {+ case .voiceModel:+ return "Download Voice Model"+ case .microphone:+ return "Grant Microphone Access"+ case .accessibility:+ return "Enable Accessibility"+ case .aiEnhancement:+ return "Set Up AI Enhancement"+ case .playground:+ return "Run Playground Test"+ }+ }++ var subtitle: String {+ switch self {+ case .voiceModel:+ return CPUArchitecture.isAppleSilicon+ ? "Choose the best voice model for how you speak. Download it once to continue."+ : "Recommended for your Mac: Whisper. Download it once to continue."+ case .microphone:+ return "Allow FluidVoice to capture audio from your microphone."+ case .accessibility:+ return "Allow FluidVoice to type transcriptions into other apps."+ case .aiEnhancement:+ return "Optional: Configure AI post-processing or skip this step."+ case .playground:+ return "Record a quick sample to validate your setup before finishing."+ }+ }+ }++ private var step: Step {+ Step(rawValue: self.currentStep) ?? .voiceModel+ }++ private var progressValue: Double {+ Double(self.step.rawValue + 1) / Double(Step.allCases.count)+ }++ private var recommendedOnboardingModel: SettingsStore.SpeechModel {+ if CPUArchitecture.isAppleSilicon {+ switch self.preferredLanguageChoice {+ case .englishOnly:+ return .parakeetTDTv2+ case .multipleLanguages, .other:+ return .parakeetTDT+ }+ }+ return .whisperBase+ }++ private var recommendedOnboardingModelDisplayName: String {+ self.recommendedOnboardingModel.displayName+ }++ private var recommendedModelReasonText: String {+ if CPUArchitecture.isAppleSilicon {+ switch self.preferredLanguageChoice {+ case .englishOnly:+ return "Best if you mainly speak English. Lower complexity and tuned for English dictation."+ case .multipleLanguages:+ return "Best if you switch languages. Broader support with Parakeet TDT v3."+ case .other:+ return "Choose a different model below if neither of the default language paths fits."+ }+ }+ return "Best for Intel Macs: dependable Whisper quality with broad compatibility."+ }++ private var onboardingModelOptions: [SettingsStore.SpeechModel] {+ let candidates: [SettingsStore.SpeechModel] = CPUArchitecture.isAppleSilicon+ ? [.parakeetTDT, .parakeetTDTv2, .whisperBase, .whisperSmall]+ : [.whisperBase, .whisperTiny, .whisperSmall, .whisperMedium]++ var seenModelIDs = Set<String>()+ return candidates.filter { model in+ guard SettingsStore.SpeechModel.availableModels.contains(model) else { return false }+ return seenModelIDs.insert(model.id).inserted+ }+ }++ private var onboardingAlternativeModels: [SettingsStore.SpeechModel] {+ let filtered = self.onboardingModelOptions.filter { $0 != self.recommendedOnboardingModel }+ guard self.preferredLanguageChoice == .other, self.shouldShowLanguageChoice else {+ return filtered+ }+ return filtered.filter { model in+ model != .parakeetTDT && model != .parakeetTDTv2+ }+ }++ private var shouldShowLanguageChoice: Bool {+ CPUArchitecture.isAppleSilicon+ }++ private var showsMappedRecommendedModel: Bool {+ !self.shouldShowLanguageChoice || self.preferredLanguageChoice != .other+ }++ private var shouldShowAlternativeModels: Bool {+ !self.shouldShowLanguageChoice || self.preferredLanguageChoice == .other+ }++ private var parakeetV3LanguageNames: String {+ "Bulgarian, Croatian, Czech, Danish, Dutch, English, Estonian, Finnish, French, German, Greek, Hungarian, Italian, Latvian, Lithuanian, Maltese, Polish, Portuguese, Romanian, Slovak, Slovenian, Spanish, Swedish, Russian, and Ukrainian"+ }++ private var isRecommendedModelSelected: Bool {+ self.isOnboardingModelSelected(self.recommendedOnboardingModel)+ }++ private var isRecommendedModelDownloaded: Bool {+ self.isOnboardingModelDownloaded(self.recommendedOnboardingModel)+ }++ private var isPreparingRecommendedModel: Bool {+ self.isPreparingOnboardingModel(self.recommendedOnboardingModel)+ }++ private var isRecommendedModelReady: Bool {+ self.isOnboardingModelReady(self.recommendedOnboardingModel)+ }++ private var isVoiceModelReady: Bool {+ self.isOnboardingModelReady(self.settings.selectedSpeechModel)+ }++ private var isMicrophoneReady: Bool {+ self.asr.micStatus == .authorized+ }++ private var isAccessibilityReady: Bool {+ self.accessibilityEnabled+ }++ private var isAIReady: Bool {+ self.settings.onboardingAISkipped || DictationAIPostProcessingGate.isConfigured()+ }++ private var isPlaygroundReady: Bool {+ self.settings.onboardingPlaygroundValidated+ }++ private var onboardingShortcutDisplay: String {+ let display = self.settings.hotkeyShortcut.displayString.trimmingCharacters(in: .whitespacesAndNewlines)+ return display.isEmpty ? "your shortcut" : display+ }++ private var canContinue: Bool {+ switch self.step {+ case .voiceModel:+ return self.isVoiceModelReady+ case .microphone:+ return self.isMicrophoneReady+ case .accessibility:+ return self.isAccessibilityReady+ case .aiEnhancement:+ return self.isAIReady+ case .playground:+ return self.isPlaygroundReady+ }+ }++ private var primaryButtonTitle: String {+ switch self.step {+ case .playground:+ return "Finish Setup"+ default:+ return "Continue"+ }+ }++ var body: some View {+ VStack(spacing: 0) {+ self.header+ Divider()+ self.stepContent+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)+ Divider()+ self.footer+ }+ .background {+ ZStack {+ self.theme.palette.windowBackground+ .opacity(0.98)+ .ignoresSafeArea()++ Rectangle()+ .fill(self.theme.materials.window)+ .opacity(0.75)+ .ignoresSafeArea()+ }+ }+ .onAppear {+ self.syncPreferredLanguageChoiceWithSelectedModel()+ Task { @MainActor in+ self.asr.micStatus = AVCaptureDevice.authorizationStatus(for: .audio)+ await self.asr.checkIfModelsExistAsync()+ }+ }+ .onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in+ self.asr.micStatus = AVCaptureDevice.authorizationStatus(for: .audio)+ }+ }++ private var header: some View {+ VStack(alignment: .leading, spacing: 12) {+ Text("Welcome to FluidVoice")+ .font(.title2.weight(.bold))+ .foregroundStyle(self.theme.palette.primaryText)++ Text(self.step.subtitle)+ .font(.subheadline)+ .foregroundStyle(self.theme.palette.secondaryText)++ HStack {+ Text("Step \(self.step.rawValue + 1) of \(Step.allCases.count)")+ .font(.caption.weight(.semibold))+ .foregroundStyle(.secondary)+ Spacer()+ Text(self.step.title)+ .font(.caption.weight(.semibold))+ .foregroundStyle(self.theme.palette.accent)+ }++ ProgressView(value: self.progressValue)+ .tint(self.theme.palette.accent)+ }+ .padding(24)+ }++ @ViewBuilder+ private var stepContent: some View {+ switch self.step {+ case .voiceModel:+ self.voiceModelStep+ case .microphone:+ self.microphoneStep+ case .accessibility:+ self.accessibilityStep+ case .aiEnhancement:+ self.aiEnhancementStep+ case .playground:+ self.playgroundStep+ }+ }++ private var voiceModelStep: some View {+ ScrollView {+ VStack(alignment: .leading, spacing: 16) {+ ThemedCard(style: .standard) {+ VStack(alignment: .leading, spacing: 14) {+ if self.shouldShowLanguageChoice {+ VStack(alignment: .leading, spacing: 10) {+ Text("Preferred language")+ .font(.body.weight(.semibold))+ .foregroundStyle(self.theme.palette.primaryText)++ Text("Pick the path that matches how you usually speak. You can change models later.")+ .font(.caption)+ .foregroundStyle(.secondary)++ HStack(spacing: 10) {+ ForEach(PreferredLanguageChoice.allCases) { option in+ self.preferredLanguageOptionCard(for: option)+ }+ }+ }++ Divider().padding(.vertical, 2)+ }++ HStack(spacing: 10) {+ Image(systemName: self.isVoiceModelReady ? "checkmark.circle.fill" : "cpu")+ .foregroundStyle(self.isVoiceModelReady ? Color.fluidGreen : self.theme.palette.accent)++ VStack(alignment: .leading, spacing: 3) {+ Text(self.recommendedModelHeadline)+ .font(.body.weight(.semibold))+ .foregroundStyle(self.theme.palette.primaryText)++ Text(self.recommendedModelReasonText)+ .font(.caption)+ .foregroundStyle(.secondary)+ }++ Spacer()+ }++ if self.showsMappedRecommendedModel {+ HStack(spacing: 10) {+ Label(self.recommendedOnboardingModel.downloadSize, systemImage: "internaldrive")+ .font(.caption)+ .foregroundStyle(.secondary)++ Text(self.recommendedOnboardingModel.languageSupport)+ .font(.caption)+ .foregroundStyle(.secondary)+ }++ if self.recommendedOnboardingModel == .parakeetTDT {+ Text("Supported languages: \(self.parakeetV3LanguageNames)")+ .font(.caption2)+ .foregroundStyle(.secondary)+ }+ }++ if self.isPreparingRecommendedModel {+ VStack(alignment: .leading, spacing: 6) {+ if self.asr.isDownloadingModel, let progress = self.asr.downloadProgress {+ if progress >= 0.82 {+ HStack(spacing: 8) {+ ProgressView()+ .controlSize(.small)+ Text("Finalizing download and loading model…")+ .font(.caption)+ .foregroundStyle(.secondary)+ }+ } else {+ ProgressView(value: progress)+ .tint(self.theme.palette.accent)+ Text("Downloading \(Int(progress * 100))%")+ .font(.caption)+ .foregroundStyle(.secondary)+ }+ } else {+ HStack(spacing: 8) {+ ProgressView()+ .controlSize(.small)+ Text("Loading model…")+ .font(.caption)+ .foregroundStyle(.secondary)+ }+ }+ }+ }++ HStack(spacing: 10) {+ if self.isRecommendedModelReady {+ Label(+ "Model downloaded and loaded",+ systemImage: "checkmark.seal.fill"+ )+ .font(.caption.weight(.semibold))+ .foregroundStyle(Color.fluidGreen)+ } else if self.isRecommendedModelDownloaded {+ Label(+ self.isRecommendedModelSelected ? "Model downloaded. Click to finish loading." : "Model downloaded",+ systemImage: "arrow.triangle.2.circlepath"+ )+ .font(.caption.weight(.semibold))+ .foregroundStyle(.secondary)+ } else {+ Label("Model not downloaded yet", systemImage: "arrow.down.circle")+ .font(.caption.weight(.semibold))+ .foregroundStyle(.secondary)+ }++ Spacer()++ if self.preferredLanguageChoice == .other && self.shouldShowLanguageChoice {+ Text("Choose a model from the options below.")+ .font(.caption.weight(.semibold))+ .foregroundStyle(.secondary)+ } else {+ Button(self.onboardingModelActionButtonTitle(for: self.recommendedOnboardingModel)) {+ self.prepareOnboardingModel(self.recommendedOnboardingModel)+ }+ .buttonStyle(.borderedProminent)+ .tint(self.theme.palette.accent)+ .disabled(self.asr.isRunning || self.isPreparingRecommendedModel || self.isRecommendedModelReady)+ }+ }++ if self.isVoiceModelReady && !self.isRecommendedModelSelected && self.preferredLanguageChoice != .other {+ Text("A different model is already configured. You can continue, or switch to the recommended model.")+ .font(.caption)+ .foregroundStyle(.secondary)+ }++ if self.shouldShowAlternativeModels && !self.onboardingAlternativeModels.isEmpty {+ Divider().padding(.vertical, 2)++ Text("Other popular options")+ .font(.subheadline.weight(.semibold))+ .foregroundStyle(self.theme.palette.primaryText)++ VStack(spacing: 8) {+ ForEach(Array(self.onboardingAlternativeModels.prefix(3))) { model in+ self.onboardingModelOptionRow(for: model)+ }+ }+ }++ Text("You can switch models later in Voice Engine settings.")+ .font(.caption)+ .foregroundStyle(.secondary)+ }+ .padding(16)+ }+ }+ .padding(24)+ }+ }++ private var microphoneStep: some View {+ ScrollView {+ VStack(alignment: .leading, spacing: 16) {+ ThemedCard(style: .standard) {+ VStack(alignment: .leading, spacing: 14) {+ HStack(spacing: 10) {+ Circle()+ .fill(self.isMicrophoneReady ? Color.fluidGreen : self.theme.palette.warning)+ .frame(width: 10, height: 10)++ Text(self.isMicrophoneReady ? "Microphone access granted" : "Microphone access required")+ .font(.body.weight(.medium))+ .foregroundStyle(self.isMicrophoneReady ? .primary : self.theme.palette.warning)++ Spacer()++ if !self.isMicrophoneReady {+ Button(self.microphoneActionButtonTitle) {+ self.handleMicrophoneAction()+ }+ .buttonStyle(.borderedProminent)+ .tint(self.theme.palette.accent)+ }+ }++ if !self.isMicrophoneReady {+ VStack(alignment: .leading, spacing: 6) {+ Text("How to enable microphone access")+ .font(.caption.weight(.semibold))+ .foregroundStyle(.secondary)++ if self.asr.micStatus == .notDetermined {+ Text("1. Click \"Grant Access\"")+ Text("2. Choose \"Allow\" in the system dialog")+ } else {+ Text("1. Click \"Open Settings\"")+ Text("2. Find FluidVoice in the microphone list")+ Text("3. Toggle FluidVoice on")+ }+ }+ .font(.caption)+ .foregroundStyle(.secondary)+ }+ }+ .padding(16)+ }+ }+ .padding(24)+ }+ }++ private var accessibilityStep: some View {+ ScrollView {+ VStack(alignment: .leading, spacing: 16) {+ ThemedCard(style: .standard) {+ VStack(alignment: .leading, spacing: 14) {+ HStack(spacing: 10) {+ Circle()+ .fill(self.isAccessibilityReady ? Color.fluidGreen : self.theme.palette.warning)+ .frame(width: 10, height: 10)++ Text(self.isAccessibilityReady ? "Accessibility enabled" : "Accessibility permission required")+ .font(.body.weight(.medium))+ .foregroundStyle(self.isAccessibilityReady ? .primary : self.theme.palette.warning)++ Spacer()++ if !self.isAccessibilityReady {+ Button("Enable Accessibility") {+ self.openAccessibilitySettings()+ }+ .buttonStyle(.borderedProminent)+ .tint(self.theme.palette.accent)+ }+ }++ if !self.isAccessibilityReady {+ VStack(alignment: .leading, spacing: 6) {+ Text("How to enable accessibility")+ .font(.caption.weight(.semibold))+ .foregroundStyle(.secondary)+ Text("1. Click \"Enable Accessibility\"")+ Text("2. Add or enable FluidVoice in Accessibility")+ Text("3. Return here and continue")+ }+ .font(.caption)+ .foregroundStyle(.secondary)+ }+ }+ .padding(16)+ }+ }+ .padding(24)+ }+ }++ private var aiEnhancementStep: some View {+ VStack(alignment: .leading, spacing: 10) {+ HStack(spacing: 8) {+ Image(systemName: self.isAIReady ? "checkmark.circle.fill" : "sparkles")+ .foregroundStyle(self.isAIReady ? Color.fluidGreen : self.theme.palette.accent)+ Text(self.isAIReady+ ? "AI enhancement is ready (or skipped)"+ : "Configure AI enhancement or skip to continue")+ .font(.subheadline.weight(.medium))+ .foregroundStyle(self.isAIReady ? Color.fluidGreen : .secondary)+ }+ .padding(.horizontal, 24)+ .padding(.top, 16)++ AIEnhancementSettingsScreen(menuBarManager: self.menuBarManager, theme: self.theme)+ }+ }++ private var playgroundStep: some View {+ ScrollView {+ VStack(alignment: .leading, spacing: 16) {+ ThemedCard(style: .standard) {+ VStack(alignment: .leading, spacing: 14) {+ HStack {+ Text("Quick Playground Test")+ .font(.headline)+ Spacer()+ if self.asr.isRunning {+ Text("Recording...")+ .font(.caption.weight(.semibold))+ .foregroundStyle(.red)+ }+ }++ VStack(alignment: .leading, spacing: 8) {+ Text("Press Start Recording or use \(self.onboardingShortcutDisplay), then stop and confirm your text appears below.")+ .font(.caption)+ .foregroundStyle(.secondary)++ Button(self.asr.isRunning ? "Stop Recording" : "Start Recording") {+ self.togglePlaygroundRecording()+ }+ .buttonStyle(PremiumButtonStyle(isRecording: self.asr.isRunning))+ .disabled(self.asr.micStatus != .authorized)+ }++ TextEditor(text: Binding(+ get: { self.asr.finalText },+ set: { self.asr.finalText = $0 }+ ))+ .font(.body)+ .frame(height: 170)+ .padding(10)+ .background(+ RoundedRectangle(cornerRadius: 8, style: .continuous)+ .fill(self.theme.palette.cardBackground)+ .overlay(+ RoundedRectangle(cornerRadius: 8, style: .continuous)+ .stroke(self.theme.palette.cardBorder.opacity(0.6), lineWidth: 1)+ )+ )+ .scrollContentBackground(.hidden)++ if self.isPlaygroundReady {+ HStack(spacing: 6) {+ Image(systemName: "checkmark.circle.fill")+ .foregroundStyle(Color.fluidGreen)+ Text("Playground test passed. You can finish setup.")+ .font(.caption)+ .foregroundStyle(.secondary)+ }+ } else {+ Text("Record a short sample with the button or your hotkey and confirm transcription appears here.")+ .font(.caption)+ .foregroundStyle(.secondary)+ }+ }+ .padding(16)+ }+ }+ .padding(24)+ }+ .onChange(of: self.asr.finalText) { _, newValue in+ if !newValue.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {+ self.markPlaygroundValidated()+ }+ }+ }++ private var footer: some View {+ HStack(spacing: 10) {+ if self.step.rawValue > 0 {+ Button("Back") {+ self.goBack()+ }+ .buttonStyle(.bordered)+ }++ Spacer()++ if self.step == .aiEnhancement {+ Button("Skip this step") {+ self.markAISkipped()+ self.goNext()+ }+ .buttonStyle(.bordered)+ }++ Button(self.primaryButtonTitle) {+ self.handlePrimaryAction()+ }+ .buttonStyle(.borderedProminent)+ .tint(self.theme.palette.accent)+ .disabled(!self.canContinue)+ }+ .padding(20)+ }++ private var microphoneActionButtonTitle: String {+ switch self.asr.micStatus {+ case .notDetermined:+ return "Grant Access"+ case .denied, .restricted:+ return "Open Settings"+ default:+ return "Grant Access"+ }+ }++ private func isOnboardingModelSelected(_ model: SettingsStore.SpeechModel) -> Bool {+ self.settings.selectedSpeechModel == model+ }++ private func isOnboardingModelReady(_ model: SettingsStore.SpeechModel) -> Bool {+ self.isOnboardingModelSelected(model) && model.isInstalled && self.asr.isAsrReady+ }++ private func isOnboardingModelDownloaded(_ model: SettingsStore.SpeechModel) -> Bool {+ model.isInstalled || (self.isOnboardingModelSelected(model) && (self.asr.isAsrReady || self.asr.modelsExistOnDisk))+ }++ private func isPreparingOnboardingModel(_ model: SettingsStore.SpeechModel) -> Bool {+ self.isOnboardingModelSelected(model) && (self.asr.isDownloadingModel || (self.asr.isLoadingModel && !self.asr.isAsrReady))+ }++ private func onboardingModelActionButtonTitle(for model: SettingsStore.SpeechModel) -> String {+ let isSelected = self.isOnboardingModelSelected(model)+ let isDownloaded = self.isOnboardingModelDownloaded(model)+ let isReady = self.isOnboardingModelReady(model)++ if self.isPreparingOnboardingModel(model) {+ return self.asr.isLoadingModel ? "Loading..." : "Downloading..."+ }+ if isReady {+ return "Ready"+ }+ if isDownloaded {+ return isSelected ? "Load" : "Use"+ }+ return "Use & Download"+ }++ private func prepareOnboardingModel(_ model: SettingsStore.SpeechModel, preserveManualChoice: Bool = false) {+ guard !self.asr.isRunning else { return }++ self.selectOnboardingModel(model, preserveManualChoice: preserveManualChoice)++ Task { @MainActor in+ do {+ try await self.asr.ensureAsrReady()+ } catch {+ DebugLogger.shared.error("Failed to prepare onboarding voice model \(model.displayName): \(error)", source: "OnboardingFlowView")+ }+ await self.asr.checkIfModelsExistAsync()+ }+ }++ private func onboardingModelOptionRow(for model: SettingsStore.SpeechModel) -> some View {+ let isSelected = self.isOnboardingModelSelected(model)+ let isDownloaded = self.isOnboardingModelDownloaded(model)+ let isPreparing = self.isPreparingOnboardingModel(model)+ let isReady = self.isOnboardingModelReady(model)++ return Button {+ self.selectOnboardingModel(model, preserveManualChoice: true)+ } label: {+ VStack(alignment: .leading, spacing: 8) {+ HStack(alignment: .top, spacing: 10) {+ VStack(alignment: .leading, spacing: 4) {+ Text(model.displayName)+ .font(.callout.weight(.semibold))+ .foregroundStyle(self.theme.palette.primaryText)++ Text(model.cardDescription)+ .font(.caption)+ .foregroundStyle(.secondary)+ .lineLimit(2)++ HStack(spacing: 10) {+ Label(model.downloadSize, systemImage: "internaldrive")+ .font(.caption2)+ .foregroundStyle(.secondary)+ Text(model.languageSupport)+ .font(.caption2)+ .foregroundStyle(.secondary)+ }++ if model == .parakeetTDT {+ Text("Supported languages: \(self.parakeetV3LanguageNames)")+ .font(.caption2)+ .foregroundStyle(.secondary)+ }+ }++ Spacer(minLength: 8)++ Button(self.onboardingModelActionButtonTitle(for: model)) {+ self.prepareOnboardingModel(model, preserveManualChoice: true)+ }+ .buttonStyle(.bordered)+ .controlSize(.small)+ .disabled(self.asr.isRunning || isPreparing || isReady)+ }++ if isPreparing {+ if self.asr.isDownloadingModel, let progress = self.asr.downloadProgress {+ if progress >= 0.82 {+ HStack(spacing: 6) {+ ProgressView()+ .controlSize(.mini)+ Text("Finalizing...")+ .font(.caption2)+ .foregroundStyle(.secondary)+ }+ } else {+ ProgressView(value: progress)+ .tint(self.theme.palette.accent)+ Text("Downloading \(Int(progress * 100))%")+ .font(.caption2)+ .foregroundStyle(.secondary)+ }+ } else {+ Text("Loading model...")+ .font(.caption2)+ .foregroundStyle(.secondary)+ }+ } else if isReady {+ Label("Downloaded and loaded", systemImage: "checkmark.circle.fill")+ .font(.caption2.weight(.semibold))+ .foregroundStyle(Color.fluidGreen)+ } else if isDownloaded {+ Label(isSelected ? "Downloaded. Click Load to finish." : "Downloaded", systemImage: "arrow.triangle.2.circlepath")+ .font(.caption2.weight(.semibold))+ .foregroundStyle(.secondary)+ }+ }+ .padding(10)+ .background(+ RoundedRectangle(cornerRadius: 10, style: .continuous)+ .fill(self.theme.palette.cardBackground.opacity(isSelected ? 0.82 : 0.55))+ .overlay(+ RoundedRectangle(cornerRadius: 10, style: .continuous)+ .stroke(+ isSelected ? self.theme.palette.accent.opacity(0.45) : self.theme.palette.cardBorder.opacity(0.32),+ lineWidth: 1+ )+ )+ )+ }+ .buttonStyle(.plain)+ }++ private func selectOnboardingModel(_ model: SettingsStore.SpeechModel, preserveManualChoice: Bool = false) {+ if self.settings.selectedSpeechModel != model {+ self.settings.selectedSpeechModel = model+ self.asr.resetTranscriptionProvider()+ }+ if preserveManualChoice, self.preferredLanguageChoice == .other {+ return+ }+ self.syncPreferredLanguageChoiceWithSelectedModel()+ }++ private var recommendedModelHeadline: String {+ if self.shouldShowLanguageChoice {+ switch self.preferredLanguageChoice {+ case .englishOnly:+ return "English only uses \(self.recommendedOnboardingModelDisplayName)"+ case .multipleLanguages:+ return "Multiple languages uses \(self.recommendedOnboardingModelDisplayName)"+ case .other:+ return "Other languages or workflows"+ }+ }++ return "Recommended for this Mac: \(self.recommendedOnboardingModelDisplayName)"+ }++ private func preferredLanguageOptionCard(for option: PreferredLanguageChoice) -> some View {+ let isSelected = self.preferredLanguageChoice == option++ return Button {+ self.preferredLanguageChoice = option+ } label: {+ VStack(alignment: .leading, spacing: 6) {+ HStack(spacing: 6) {+ Text(option.title)+ .font(.callout.weight(.semibold))+ .foregroundStyle(self.theme.palette.primaryText)++ if option != .other {+ Text("FluidVoice Recommended")+ .font(.caption2.weight(.semibold))+ .padding(.horizontal, 6)+ .padding(.vertical, 2)+ .background(Capsule().fill(self.theme.palette.accent.opacity(0.18)))+ .foregroundStyle(self.theme.palette.accent)+ }+ }++ Text(option.subtitle)+ .font(.caption)+ .foregroundStyle(.secondary)+ .multilineTextAlignment(.leading)+ }+ .frame(maxWidth: .infinity, alignment: .leading)+ .padding(12)+ .background(+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .fill(self.theme.palette.cardBackground.opacity(isSelected ? 0.82 : 0.55))+ .overlay(+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .stroke(+ isSelected ? self.theme.palette.accent.opacity(0.55) : self.theme.palette.cardBorder.opacity(0.32),+ lineWidth: 1+ )+ )+ )+ }+ .buttonStyle(.plain)+ }++ private func syncPreferredLanguageChoiceWithSelectedModel() {+ guard self.shouldShowLanguageChoice else { return }++ switch self.settings.selectedSpeechModel {+ case .parakeetTDTv2:+ self.preferredLanguageChoice = .englishOnly+ case .parakeetTDT:+ self.preferredLanguageChoice = .multipleLanguages+ default:+ self.preferredLanguageChoice = .other+ }+ }++ private func handleMicrophoneAction() {+ if self.asr.micStatus == .notDetermined {+ self.asr.requestMicAccess()+ } else {+ self.asr.openSystemSettingsForMic()+ }+ }++ private func goBack() {+ self.currentStep = max(0, self.currentStep - 1)+ }++ private func goNext() {+ self.currentStep = min(Step.allCases.count - 1, self.currentStep + 1)+ }++ private func handlePrimaryAction() {+ if self.step == .playground {+ if !self.settings.onboardingPlaygroundValidated {+ self.markPlaygroundValidated()+ }+ self.finishOnboarding()+ return+ }+ self.goNext()+ }++ private func togglePlaygroundRecording() {+ Task { @MainActor in+ if self.asr.isRunning {+ let transcribed = await self.asr.stop()+ self.asr.finalText = ASRService.applyGAAVFormatting(transcribed)+ if !self.asr.finalText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {+ self.markPlaygroundValidated()+ }+ } else {+ self.asr.finalText = ""+ await self.asr.start()+ }+ }+ }+}diff --git a/Sources/Fluid/Views/BottomOverlayView.swift b/Sources/Fluid/Views/BottomOverlayView.swiftindex da980019..da8b74ef 100644--- a/Sources/Fluid/Views/BottomOverlayView.swift+++ b/Sources/Fluid/Views/BottomOverlayView.swift@@ -9,6 +9,19 @@ import AppKitimport Combineimport SwiftUI+private enum OverlayShortcutResolver {+ static func shortcutDisplay(for mode: OverlayMode, settings: SettingsStore = .shared) -> String {+ switch mode {+ case .dictation:+ return settings.hotkeyShortcut.displayString+ case .edit, .write, .rewrite:+ return settings.rewriteModeHotkeyShortcut.displayString+ case .command:+ return settings.commandModeHotkeyShortcut.displayString+ }+ }+}+// MARK: - Bottom Overlay Window Controller@MainActor@@ -18,6 +31,8 @@ final class BottomOverlayWindowController {private var window: NSPanel?private var audioSubscription: AnyCancellable?private var pendingResizeWorkItem: DispatchWorkItem?+ private var localMouseDownMonitor: Any?+ private var globalMouseDownMonitor: Any?private init() {NotificationCenter.default.addObserver(forName: NSNotification.Name("OverlayOffsetChanged"), object: nil, queue: .main) { [weak self] _ in@@ -27,7 +42,7 @@ final class BottomOverlayWindowController {}NotificationCenter.default.addObserver(forName: NSNotification.Name("OverlaySizeChanged"), object: nil, queue: .main) { [weak self] _ inTask { @MainActor [weak self] in- self?.updateSizeAndPosition()+ self?.scheduleSizeAndPositionUpdate(after: 0)}}}@@ -36,9 +51,17 @@ final class BottomOverlayWindowController {self.pendingResizeWorkItem?.cancel()self.pendingResizeWorkItem = nilBottomOverlayPromptMenuController.shared.hide()+ BottomOverlayModeMenuController.shared.hide()+ BottomOverlayActionsMenuController.shared.hide()+ self.ensureMouseDownMonitors()// Update mode in content stateNotchContentState.shared.mode = mode+ switch mode {+ case .dictation: NotchContentState.shared.promptPickerMode = .dictate+ case .edit, .write, .rewrite: NotchContentState.shared.promptPickerMode = .edit+ case .command: break+ }NotchContentState.shared.updateTranscription("")NotchContentState.shared.bottomOverlayAudioLevel = 0@@ -75,7 +98,10 @@ final class BottomOverlayWindowController {self.audioSubscription = nilself.pendingResizeWorkItem?.cancel()self.pendingResizeWorkItem = nil+ self.removeMouseDownMonitors()BottomOverlayPromptMenuController.shared.hide()+ BottomOverlayModeMenuController.shared.hide()+ BottomOverlayActionsMenuController.shared.hide()// Reset stateNotchContentState.shared.setProcessing(false)@@ -88,8 +114,8 @@ final class BottomOverlayWindowController {context.duration = 0.2context.timingFunction = CAMediaTimingFunction(name: .easeIn)window.animator().alphaValue = 0- } completionHandler: { [weak self] in- self?.window?.orderOut(nil)+ } completionHandler: {+ window.orderOut(nil)}}@@ -98,6 +124,10 @@ final class BottomOverlayWindowController {}func refreshSizeForContent() {+ self.scheduleSizeAndPositionUpdate()+ }++ private func scheduleSizeAndPositionUpdate(after delay: TimeInterval = 0.03) {self.pendingResizeWorkItem?.cancel()// Debounce rapid streaming updates to avoid resize thrash.@@ -105,7 +135,7 @@ final class BottomOverlayWindowController {self?.updateSizeAndPosition()}self.pendingResizeWorkItem = resizeWorkItem- DispatchQueue.main.asyncAfter(deadline: .now() + 0.03, execute: resizeWorkItem)+ DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: resizeWorkItem)}/// Update window size based on current SwiftUI content and re-position@@ -167,6 +197,52 @@ final class BottomOverlayWindowController {self.window = panel}+ private func ensureMouseDownMonitors() {+ if self.localMouseDownMonitor == nil {+ self.localMouseDownMonitor = NSEvent.addLocalMonitorForEvents(matching: [.leftMouseDown, .rightMouseDown]) { [weak self] event in+ let clickPoint: NSPoint+ if let window = event.window {+ clickPoint = window.convertPoint(toScreen: event.locationInWindow)+ } else {+ clickPoint = NSEvent.mouseLocation+ }++ Task { @MainActor [weak self] in+ self?.dismissMenusForClick(screenPoint: clickPoint)+ }+ return event+ }+ }++ if self.globalMouseDownMonitor == nil {+ self.globalMouseDownMonitor = NSEvent.addGlobalMonitorForEvents(matching: [.leftMouseDown, .rightMouseDown]) { [weak self] _ in+ let clickPoint = NSEvent.mouseLocation+ Task { @MainActor [weak self] in+ self?.dismissMenusForClick(screenPoint: clickPoint)+ }+ }+ }+ }++ private func removeMouseDownMonitors() {+ if let monitor = self.localMouseDownMonitor {+ NSEvent.removeMonitor(monitor)+ self.localMouseDownMonitor = nil+ }+ if let monitor = self.globalMouseDownMonitor {+ NSEvent.removeMonitor(monitor)+ self.globalMouseDownMonitor = nil+ }+ }++ @MainActor+ private func dismissMenusForClick(screenPoint: NSPoint) {+ guard self.window?.isVisible == true else { return }+ BottomOverlayPromptMenuController.shared.dismissIfNeeded(for: screenPoint)+ BottomOverlayModeMenuController.shared.dismissIfNeeded(for: screenPoint)+ BottomOverlayActionsMenuController.shared.dismissIfNeeded(for: screenPoint)+ }+private func positionWindow() {// Safe check for window and screen availabilityguard let window = window else { return }@@ -229,7 +305,7 @@ final class BottomOverlayPromptMenuController {self.selectorFrameInScreen = selectorFrameInScreenself.parentWindow = parentWindowself.menuMaxWidth = resolvedMaxWidth- self.menuGap = max(menuGap, 2)+ self.menuGap = max(menuGap, 0)if self.menuWindow?.isVisible == true {if widthChanged {@@ -241,13 +317,19 @@ final class BottomOverlayPromptMenuController {}func selectorHoverChanged(_ hovering: Bool) {- self.isHoveringSelector = hovering- self.updateVisibility()+ // Hover-open disabled: menu is click/tap driven.}func menuHoverChanged(_ hovering: Bool) {- self.isHoveringMenu = hovering- self.updateVisibility()+ // Hover-open disabled: menu is click/tap driven.+ }++ func toggleFromTap() {+ if self.menuWindow?.isVisible == true {+ self.hide()+ return+ }+ self.showMenuIfPossible()}func hide() {@@ -267,6 +349,15 @@ final class BottomOverlayPromptMenuController {self.menuWindow?.orderOut(nil)}+ func dismissIfNeeded(for screenPoint: NSPoint) {+ guard self.menuWindow?.isVisible == true else { return }+ let insideMenu = self.menuWindow?.frame.contains(screenPoint) ?? false+ let insideSelector = self.selectorFrameInScreen.contains(screenPoint)+ if !insideMenu, !insideSelector {+ self.hide()+ }+ }+private func updateVisibility() {let shouldShow = self.isHoveringSelector || self.isHoveringMenu@@ -353,6 +444,7 @@ final class BottomOverlayPromptMenuController {panel.animationBehavior = .nonelet contentView = BottomOverlayPromptMenuView(+ promptMode: self.resolvedPromptMode(),maxWidth: self.menuMaxWidth,onHoverChanged: { [weak self] hovering inself?.menuHoverChanged(hovering)@@ -377,6 +469,7 @@ final class BottomOverlayPromptMenuController {private func updateMenuContent() {let rootView = BottomOverlayPromptMenuView(+ promptMode: self.resolvedPromptMode(),maxWidth: self.menuMaxWidth,onHoverChanged: { [weak self] hovering inself?.menuHoverChanged(hovering)@@ -388,6 +481,17 @@ final class BottomOverlayPromptMenuController {self.hostingView?.rootView = rootView}+ private func resolvedPromptMode() -> SettingsStore.PromptMode {+ switch NotchContentState.shared.mode {+ case .dictation:+ return .dictate+ case .edit, .write, .rewrite:+ return .edit+ case .command:+ return NotchContentState.shared.promptPickerMode.normalized+ }+ }+private func attachToParentWindowIfNeeded() {guard let menuWindow = self.menuWindow else { return }@@ -408,7 +512,7 @@ final class BottomOverlayPromptMenuController {guard fittingSize.width > 0, fittingSize.height > 0 else { return }let preferredX = self.selectorFrameInScreen.midX - (fittingSize.width / 2)- let preferredY = self.selectorFrameInScreen.minY - self.menuGap - fittingSize.height+ let preferredY = self.selectorFrameInScreen.maxY + self.menuGaplet screen = self.parentWindow?.screen?? NSScreen.screens.first(where: { $0.frame.contains(NSPoint(x: self.selectorFrameInScreen.midX, y: self.selectorFrameInScreen.midY)) })@@ -450,211 +554,1078 @@ final class BottomOverlayPromptMenuController {}}-private struct BottomOverlayPromptMenuView: View {- @ObservedObject private var settings = SettingsStore.shared+@MainActor+final class BottomOverlayModeMenuController {+ static let shared = BottomOverlayModeMenuController()- let maxWidth: CGFloat- let onHoverChanged: (Bool) -> Void- let onDismissRequested: () -> Void+ private var menuWindow: NSPanel?+ private var hostingView: NSHostingView<BottomOverlayModeMenuView>?+ private var selectorFrameInScreen: CGRect = .zero+ private weak var parentWindow: NSWindow?+ private var menuMaxWidth: CGFloat = 220+ private var menuGap: CGFloat = 6- var body: some View {- VStack(alignment: .leading, spacing: 0) {- Button(action: {- self.settings.selectedDictationPromptID = nil- self.restoreTypingTargetApp()- self.onDismissRequested()- }) {- HStack {- Text("Default")- Spacer()- if self.settings.selectedDictationPromptID == nil {- Image(systemName: "checkmark")- .font(.system(size: 10, weight: .semibold))- }- }- }- .buttonStyle(.plain)- .padding(.vertical, 4)+ private var isHoveringSelector = false+ private var isHoveringMenu = false+ private var pendingShowWorkItem: DispatchWorkItem?+ private var pendingHideWorkItem: DispatchWorkItem?+ private var pendingPositionWorkItem: DispatchWorkItem?- if !self.settings.dictationPromptProfiles.isEmpty {- Divider()- .padding(.vertical, 4)+ private init() {}- ForEach(self.settings.dictationPromptProfiles) { profile in- Button(action: {- self.settings.selectedDictationPromptID = profile.id- self.restoreTypingTargetApp()- self.onDismissRequested()- }) {- HStack {- Text(profile.name.isEmpty ? "Untitled" : profile.name)- Spacer()- if self.settings.selectedDictationPromptID == profile.id {- Image(systemName: "checkmark")- .font(.system(size: 10, weight: .semibold))- }- }- }- .buttonStyle(.plain)- .padding(.vertical, 4)- }+ func updateAnchor(selectorFrameInScreen: CGRect, parentWindow: NSWindow?, maxWidth: CGFloat, menuGap: CGFloat) {+ guard selectorFrameInScreen.width > 0, selectorFrameInScreen.height > 0 else { return }++ let resolvedMaxWidth = max(maxWidth, 120)+ let widthChanged = abs(self.menuMaxWidth - resolvedMaxWidth) > 0.5++ self.selectorFrameInScreen = selectorFrameInScreen+ self.parentWindow = parentWindow+ self.menuMaxWidth = resolvedMaxWidth+ self.menuGap = max(menuGap, 0)++ if self.menuWindow?.isVisible == true {+ if widthChanged {+ self.updateMenuContent()}- }- .padding(.horizontal, 8)- .padding(.vertical, 6)- .background(Color.black)- .cornerRadius(8)- .overlay(- RoundedRectangle(cornerRadius: 8)- .stroke(Color.white.opacity(0.12), lineWidth: 1)- )- .frame(maxWidth: self.maxWidth)- .onHover { hovering in- self.onHoverChanged(hovering)+ self.attachToParentWindowIfNeeded()+ self.scheduleMenuPositionUpdate()}}- private func restoreTypingTargetApp() {- let pid = NotchContentState.shared.recordingTargetPID- DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {- if let pid { _ = TypingService.activateApp(pid: pid) }- }+ func selectorHoverChanged(_ hovering: Bool) {+ // Hover-open disabled: menu is click/tap driven.}-}--private struct PromptSelectorAnchorReader: NSViewRepresentable {- let onFrameChange: (CGRect, NSWindow?) -> Void- func makeNSView(context: Context) -> AnchorReportingView {- let view = AnchorReportingView()- view.onFrameChange = self.onFrameChange- return view+ func menuHoverChanged(_ hovering: Bool) {+ // Hover-open disabled: menu is click/tap driven.}- func updateNSView(_ nsView: AnchorReportingView, context: Context) {- nsView.onFrameChange = self.onFrameChange+ func toggleFromTap() {+ if self.menuWindow?.isVisible == true {+ self.hide()+ return+ }+ self.showMenuIfPossible()}- final class AnchorReportingView: NSView {- var onFrameChange: ((CGRect, NSWindow?) -> Void)?- private var windowObservers: [NSObjectProtocol] = []- private var lastReportedFrameInScreen: CGRect = .null- private weak var lastReportedWindow: NSWindow?-- override func viewDidMoveToWindow() {- super.viewDidMoveToWindow()- self.installWindowObservers()- self.reportFrame(force: true)- }+ func hide() {+ self.pendingShowWorkItem?.cancel()+ self.pendingShowWorkItem = nil+ self.pendingHideWorkItem?.cancel()+ self.pendingHideWorkItem = nil+ self.pendingPositionWorkItem?.cancel()+ self.pendingPositionWorkItem = nil- override func layout() {- super.layout()- self.reportFrame()- }+ self.isHoveringSelector = false+ self.isHoveringMenu = false- deinit {- self.cleanup()+ if let menuWindow = self.menuWindow, let parent = menuWindow.parent {+ parent.removeChildWindow(menuWindow)}+ self.menuWindow?.orderOut(nil)+ }- func cleanup() {- for observer in self.windowObservers {- NotificationCenter.default.removeObserver(observer)- }- self.windowObservers.removeAll()+ func dismissIfNeeded(for screenPoint: NSPoint) {+ guard self.menuWindow?.isVisible == true else { return }+ let insideMenu = self.menuWindow?.frame.contains(screenPoint) ?? false+ let insideSelector = self.selectorFrameInScreen.contains(screenPoint)+ if !insideMenu, !insideSelector {+ self.hide()}+ }- private func installWindowObservers() {- self.cleanup()- guard let window = self.window else { return }+ private func updateVisibility() {+ let shouldShow = self.isHoveringSelector || self.isHoveringMenu- let center = NotificationCenter.default- self.windowObservers.append(- center.addObserver(forName: NSWindow.didMoveNotification, object: window, queue: .main) { [weak self] _ in- self?.reportFrame()- }- )- self.windowObservers.append(- center.addObserver(forName: NSWindow.didResizeNotification, object: window, queue: .main) { [weak self] _ in- self?.reportFrame()- }- )- self.windowObservers.append(- center.addObserver(forName: NSWindow.didChangeScreenNotification, object: window, queue: .main) { [weak self] _ in- self?.reportFrame()- }- )- }+ if shouldShow {+ self.pendingHideWorkItem?.cancel()+ self.pendingHideWorkItem = nil- func reportFrame(force: Bool = false) {- guard let window = self.window else {- if force || !self.lastReportedFrameInScreen.isNull {- self.lastReportedFrameInScreen = .null- self.lastReportedWindow = nil- self.onFrameChange?(CGRect.zero, nil)- }+ if self.menuWindow?.isVisible == true {+ self.scheduleMenuPositionUpdate()return}- let frameInWindow = self.convert(self.bounds, to: nil)- let frameInScreen = window.convertToScreen(frameInWindow)- let frameTolerance: CGFloat = 0.5- let hasLastFrame = !self.lastReportedFrameInScreen.isNull- let frameChanged = !hasLastFrame ||- abs(frameInScreen.origin.x - self.lastReportedFrameInScreen.origin.x) > frameTolerance ||- abs(frameInScreen.origin.y - self.lastReportedFrameInScreen.origin.y) > frameTolerance ||- abs(frameInScreen.size.width - self.lastReportedFrameInScreen.size.width) > frameTolerance ||- abs(frameInScreen.size.height - self.lastReportedFrameInScreen.size.height) > frameTolerance- let windowChanged = self.lastReportedWindow !== window+ self.pendingShowWorkItem?.cancel()+ let showTask = DispatchWorkItem { [weak self] in+ self?.showMenuIfPossible()+ }+ self.pendingShowWorkItem = showTask+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.04, execute: showTask)+ return+ }- guard force || frameChanged || windowChanged else { return }+ self.pendingShowWorkItem?.cancel()+ self.pendingShowWorkItem = nil- self.lastReportedFrameInScreen = frameInScreen- self.lastReportedWindow = window- self.onFrameChange?(frameInScreen, window)+ self.pendingHideWorkItem?.cancel()+ let hideTask = DispatchWorkItem { [weak self] in+ self?.hideIfNotHovered()}+ self.pendingHideWorkItem = hideTask+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.16, execute: hideTask)}-}-// MARK: - Bottom Overlay SwiftUI View+ private func hideIfNotHovered() {+ guard !self.isHoveringSelector, !self.isHoveringMenu else { return }+ self.pendingPositionWorkItem?.cancel()+ self.pendingPositionWorkItem = nil+ if let menuWindow = self.menuWindow, let parent = menuWindow.parent {+ parent.removeChildWindow(menuWindow)+ }+ self.menuWindow?.orderOut(nil)+ }-struct BottomOverlayView: View {- @ObservedObject private var contentState = NotchContentState.shared- @ObservedObject private var appServices = AppServices.shared- @ObservedObject private var settings = SettingsStore.shared- @Environment(\.theme) private var theme+ private func scheduleMenuPositionUpdate() {+ guard self.pendingPositionWorkItem == nil else { return }- struct LayoutConstants {- let hPadding: CGFloat- let vPadding: CGFloat- let waveformWidth: CGFloat- let waveformHeight: CGFloat- let iconSize: CGFloat- let transFontSize: CGFloat- let modeFontSize: CGFloat- let cornerRadius: CGFloat- let barCount: Int- let barWidth: CGFloat- let barSpacing: CGFloat- let minBarHeight: CGFloat- let maxBarHeight: CGFloat+ let task = DispatchWorkItem { [weak self] in+ guard let self else { return }+ self.pendingPositionWorkItem = nil+ self.updateMenuSizeAndPosition()+ }- static func get(for size: SettingsStore.OverlaySize) -> LayoutConstants {- switch size {- case .small:- return LayoutConstants(- hPadding: 14,- vPadding: 8,- waveformWidth: 90,- waveformHeight: 20,- iconSize: 16,- transFontSize: 11,- modeFontSize: 10,+ self.pendingPositionWorkItem = task+ DispatchQueue.main.async(execute: task)+ }++ private func showMenuIfPossible() {+ guard self.selectorFrameInScreen.width > 0, self.selectorFrameInScreen.height > 0 else { return }++ self.createWindowIfNeeded()+ self.updateMenuContent()+ self.attachToParentWindowIfNeeded()+ self.updateMenuSizeAndPosition()+ self.menuWindow?.orderFrontRegardless()+ }++ private func createWindowIfNeeded() {+ guard self.menuWindow == nil else { return }++ let panel = NSPanel(+ contentRect: .zero,+ styleMask: [.borderless, .nonactivatingPanel],+ backing: .buffered,+ defer: false+ )++ panel.isFloatingPanel = true+ panel.level = .floating+ panel.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]+ panel.isOpaque = false+ panel.backgroundColor = .clear+ panel.hasShadow = false+ panel.isMovableByWindowBackground = false+ panel.hidesOnDeactivate = false+ panel.animationBehavior = .none++ let contentView = BottomOverlayModeMenuView(+ maxWidth: self.menuMaxWidth,+ onHoverChanged: { [weak self] hovering in+ self?.menuHoverChanged(hovering)+ },+ onDismissRequested: { [weak self] in+ self?.hide()+ }+ )++ let hostingView = NSHostingView(rootView: contentView)+ let fittingSize = hostingView.fittingSize+ hostingView.frame = NSRect(origin: .zero, size: fittingSize)+ hostingView.wantsLayer = true+ hostingView.layer?.backgroundColor = .clear++ panel.setContentSize(fittingSize)+ panel.contentView = hostingView++ self.hostingView = hostingView+ self.menuWindow = panel+ }++ private func updateMenuContent() {+ let rootView = BottomOverlayModeMenuView(+ maxWidth: self.menuMaxWidth,+ onHoverChanged: { [weak self] hovering in+ self?.menuHoverChanged(hovering)+ },+ onDismissRequested: { [weak self] in+ self?.hide()+ }+ )+ self.hostingView?.rootView = rootView+ }++ private func attachToParentWindowIfNeeded() {+ guard let menuWindow = self.menuWindow else { return }++ if let currentParent = menuWindow.parent, currentParent !== self.parentWindow {+ currentParent.removeChildWindow(menuWindow)+ }++ if let parentWindow = self.parentWindow, menuWindow.parent !== parentWindow {+ parentWindow.addChildWindow(menuWindow, ordered: .above)+ }+ }++ private func updateMenuSizeAndPosition() {+ guard let menuWindow = self.menuWindow, let hostingView = self.hostingView else { return }+ guard self.selectorFrameInScreen.width > 0, self.selectorFrameInScreen.height > 0 else { return }++ let fittingSize = hostingView.fittingSize+ guard fittingSize.width > 0, fittingSize.height > 0 else { return }++ let preferredX = self.selectorFrameInScreen.midX - (fittingSize.width / 2)+ let preferredY = self.selectorFrameInScreen.maxY + self.menuGap++ let screen = self.parentWindow?.screen+ ?? NSScreen.screens.first(where: { $0.frame.contains(NSPoint(x: self.selectorFrameInScreen.midX, y: self.selectorFrameInScreen.midY)) })+ ?? NSScreen.main++ var targetX = preferredX+ var targetY = preferredY++ if let screen {+ let visible = screen.visibleFrame+ let horizontalInset: CGFloat = 8+ let verticalInset: CGFloat = 8++ if fittingSize.width < visible.width - (horizontalInset * 2) {+ targetX = max(visible.minX + horizontalInset, min(preferredX, visible.maxX - fittingSize.width - horizontalInset))+ } else {+ targetX = visible.minX + horizontalInset+ }++ if fittingSize.height < visible.height - (verticalInset * 2) {+ targetY = max(visible.minY + verticalInset, min(preferredY, visible.maxY - fittingSize.height - verticalInset))+ } else {+ targetY = visible.minY + verticalInset+ }+ }++ let targetFrame = NSRect(x: targetX, y: targetY, width: fittingSize.width, height: fittingSize.height)+ let currentFrame = menuWindow.frame+ let frameTolerance: CGFloat = 0.5+ let isSameFrame =+ abs(currentFrame.origin.x - targetFrame.origin.x) <= frameTolerance &&+ abs(currentFrame.origin.y - targetFrame.origin.y) <= frameTolerance &&+ abs(currentFrame.size.width - targetFrame.size.width) <= frameTolerance &&+ abs(currentFrame.size.height - targetFrame.size.height) <= frameTolerance++ if !isSameFrame {+ menuWindow.setFrame(targetFrame, display: false)+ }+ }+}++@MainActor+final class BottomOverlayActionsMenuController {+ static let shared = BottomOverlayActionsMenuController()++ private var menuWindow: NSPanel?+ private var hostingView: NSHostingView<BottomOverlayActionsMenuView>?+ private var selectorFrameInScreen: CGRect = .zero+ private weak var parentWindow: NSWindow?+ private var menuMaxWidth: CGFloat = 220+ private var menuGap: CGFloat = 6++ private var isHoveringSelector = false+ private var isHoveringMenu = false+ private var pendingShowWorkItem: DispatchWorkItem?+ private var pendingHideWorkItem: DispatchWorkItem?+ private var pendingPositionWorkItem: DispatchWorkItem?++ private init() {}++ func updateAnchor(selectorFrameInScreen: CGRect, parentWindow: NSWindow?, maxWidth: CGFloat, menuGap: CGFloat) {+ guard selectorFrameInScreen.width > 0, selectorFrameInScreen.height > 0 else { return }++ let resolvedMaxWidth = max(maxWidth, 120)+ let widthChanged = abs(self.menuMaxWidth - resolvedMaxWidth) > 0.5++ self.selectorFrameInScreen = selectorFrameInScreen+ self.parentWindow = parentWindow+ self.menuMaxWidth = resolvedMaxWidth+ self.menuGap = max(menuGap, 0)++ if self.menuWindow?.isVisible == true {+ if widthChanged {+ self.updateMenuContent()+ }+ self.attachToParentWindowIfNeeded()+ self.scheduleMenuPositionUpdate()+ }+ }++ func selectorHoverChanged(_ hovering: Bool) {+ // Hover-open disabled: menu is click/tap driven.+ }++ func menuHoverChanged(_ hovering: Bool) {+ // Hover-open disabled: menu is click/tap driven.+ }++ func toggleFromTap() {+ if self.menuWindow?.isVisible == true {+ self.hide()+ return+ }+ self.showMenuIfPossible()+ }++ func hide() {+ self.pendingShowWorkItem?.cancel()+ self.pendingShowWorkItem = nil+ self.pendingHideWorkItem?.cancel()+ self.pendingHideWorkItem = nil+ self.pendingPositionWorkItem?.cancel()+ self.pendingPositionWorkItem = nil++ self.isHoveringSelector = false+ self.isHoveringMenu = false++ if let menuWindow = self.menuWindow, let parent = menuWindow.parent {+ parent.removeChildWindow(menuWindow)+ }+ self.menuWindow?.orderOut(nil)+ }++ func dismissIfNeeded(for screenPoint: NSPoint) {+ guard self.menuWindow?.isVisible == true else { return }+ let insideMenu = self.menuWindow?.frame.contains(screenPoint) ?? false+ let insideSelector = self.selectorFrameInScreen.contains(screenPoint)+ if !insideMenu, !insideSelector {+ self.hide()+ }+ }++ private func updateVisibility() {+ let shouldShow = self.isHoveringSelector || self.isHoveringMenu++ if shouldShow {+ self.pendingHideWorkItem?.cancel()+ self.pendingHideWorkItem = nil++ if self.menuWindow?.isVisible == true {+ self.scheduleMenuPositionUpdate()+ return+ }++ self.pendingShowWorkItem?.cancel()+ let showTask = DispatchWorkItem { [weak self] in+ self?.showMenuIfPossible()+ }+ self.pendingShowWorkItem = showTask+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.04, execute: showTask)+ return+ }++ self.pendingShowWorkItem?.cancel()+ self.pendingShowWorkItem = nil++ self.pendingHideWorkItem?.cancel()+ let hideTask = DispatchWorkItem { [weak self] in+ self?.hideIfNotHovered()+ }+ self.pendingHideWorkItem = hideTask+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.16, execute: hideTask)+ }++ private func hideIfNotHovered() {+ guard !self.isHoveringSelector, !self.isHoveringMenu else { return }+ self.pendingPositionWorkItem?.cancel()+ self.pendingPositionWorkItem = nil+ if let menuWindow = self.menuWindow, let parent = menuWindow.parent {+ parent.removeChildWindow(menuWindow)+ }+ self.menuWindow?.orderOut(nil)+ }++ private func scheduleMenuPositionUpdate() {+ guard self.pendingPositionWorkItem == nil else { return }++ let task = DispatchWorkItem { [weak self] in+ guard let self else { return }+ self.pendingPositionWorkItem = nil+ self.updateMenuSizeAndPosition()+ }++ self.pendingPositionWorkItem = task+ DispatchQueue.main.async(execute: task)+ }++ private func showMenuIfPossible() {+ guard self.selectorFrameInScreen.width > 0, self.selectorFrameInScreen.height > 0 else { return }++ self.createWindowIfNeeded()+ self.updateMenuContent()+ self.attachToParentWindowIfNeeded()+ self.updateMenuSizeAndPosition()+ self.menuWindow?.orderFrontRegardless()+ }++ private func createWindowIfNeeded() {+ guard self.menuWindow == nil else { return }++ let panel = NSPanel(+ contentRect: .zero,+ styleMask: [.borderless, .nonactivatingPanel],+ backing: .buffered,+ defer: false+ )++ panel.isFloatingPanel = true+ panel.level = .floating+ panel.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]+ panel.isOpaque = false+ panel.backgroundColor = .clear+ panel.hasShadow = false+ panel.isMovableByWindowBackground = false+ panel.hidesOnDeactivate = false+ panel.animationBehavior = .none++ let contentView = BottomOverlayActionsMenuView(+ maxWidth: self.menuMaxWidth,+ onHoverChanged: { [weak self] hovering in+ self?.menuHoverChanged(hovering)+ },+ onDismissRequested: { [weak self] in+ self?.hide()+ }+ )++ let hostingView = NSHostingView(rootView: contentView)+ let fittingSize = hostingView.fittingSize+ hostingView.frame = NSRect(origin: .zero, size: fittingSize)+ hostingView.wantsLayer = true+ hostingView.layer?.backgroundColor = .clear++ panel.setContentSize(fittingSize)+ panel.contentView = hostingView++ self.hostingView = hostingView+ self.menuWindow = panel+ }++ private func updateMenuContent() {+ let rootView = BottomOverlayActionsMenuView(+ maxWidth: self.menuMaxWidth,+ onHoverChanged: { [weak self] hovering in+ self?.menuHoverChanged(hovering)+ },+ onDismissRequested: { [weak self] in+ self?.hide()+ }+ )+ self.hostingView?.rootView = rootView+ }++ private func attachToParentWindowIfNeeded() {+ guard let menuWindow = self.menuWindow else { return }++ if let currentParent = menuWindow.parent, currentParent !== self.parentWindow {+ currentParent.removeChildWindow(menuWindow)+ }++ if let parentWindow = self.parentWindow, menuWindow.parent !== parentWindow {+ parentWindow.addChildWindow(menuWindow, ordered: .above)+ }+ }++ private func updateMenuSizeAndPosition() {+ guard let menuWindow = self.menuWindow, let hostingView = self.hostingView else { return }+ guard self.selectorFrameInScreen.width > 0, self.selectorFrameInScreen.height > 0 else { return }++ let fittingSize = hostingView.fittingSize+ guard fittingSize.width > 0, fittingSize.height > 0 else { return }++ let preferredX = self.selectorFrameInScreen.midX - (fittingSize.width / 2)+ let preferredY = self.selectorFrameInScreen.maxY + self.menuGap++ let screen = self.parentWindow?.screen+ ?? NSScreen.screens.first(where: { $0.frame.contains(NSPoint(x: self.selectorFrameInScreen.midX, y: self.selectorFrameInScreen.midY)) })+ ?? NSScreen.main++ var targetX = preferredX+ var targetY = preferredY++ if let screen {+ let visible = screen.visibleFrame+ let horizontalInset: CGFloat = 8+ let verticalInset: CGFloat = 8++ if fittingSize.width < visible.width - (horizontalInset * 2) {+ targetX = max(visible.minX + horizontalInset, min(preferredX, visible.maxX - fittingSize.width - horizontalInset))+ } else {+ targetX = visible.minX + horizontalInset+ }++ if fittingSize.height < visible.height - (verticalInset * 2) {+ targetY = max(visible.minY + verticalInset, min(preferredY, visible.maxY - fittingSize.height - verticalInset))+ } else {+ targetY = visible.minY + verticalInset+ }+ }++ let targetFrame = NSRect(x: targetX, y: targetY, width: fittingSize.width, height: fittingSize.height)+ let currentFrame = menuWindow.frame+ let frameTolerance: CGFloat = 0.5+ let isSameFrame =+ abs(currentFrame.origin.x - targetFrame.origin.x) <= frameTolerance &&+ abs(currentFrame.origin.y - targetFrame.origin.y) <= frameTolerance &&+ abs(currentFrame.size.width - targetFrame.size.width) <= frameTolerance &&+ abs(currentFrame.size.height - targetFrame.size.height) <= frameTolerance++ if !isSameFrame {+ menuWindow.setFrame(targetFrame, display: false)+ }+ }+}++private struct BottomOverlayModeMenuView: View {+ @ObservedObject private var contentState = NotchContentState.shared+ @ObservedObject private var settings = SettingsStore.shared++ let maxWidth: CGFloat+ let onHoverChanged: (Bool) -> Void+ let onDismissRequested: () -> Void++ @State private var hoveredRowID: String?++ private var normalizedOverlayMode: OverlayMode {+ switch self.contentState.mode {+ case .dictation:+ return .dictation+ case .edit, .write, .rewrite:+ return .edit+ case .command:+ return .command+ }+ }++ private func rowBackground(isSelected: Bool, rowID: String) -> some View {+ let isHovered = self.hoveredRowID == rowID+ let fillColor: Color+ if isSelected {+ fillColor = Color.white.opacity(0.28)+ } else if isHovered {+ fillColor = Color.white.opacity(0.20)+ } else {+ fillColor = Color.clear+ }++ let strokeColor: Color+ if isSelected {+ strokeColor = Color.white.opacity(0.38)+ } else if isHovered {+ strokeColor = Color.white.opacity(0.24)+ } else {+ strokeColor = Color.clear+ }++ return RoundedRectangle(cornerRadius: 7)+ .fill(fillColor)+ .overlay(+ RoundedRectangle(cornerRadius: 7)+ .stroke(strokeColor, lineWidth: 1)+ )+ }++ @ViewBuilder+ private func modeRow(_ title: String, mode: OverlayMode, rowID: String) -> some View {+ let isSelected = self.normalizedOverlayMode == mode+ let shortcut = OverlayShortcutResolver.shortcutDisplay(for: mode, settings: self.settings)++ Button(action: {+ guard !self.contentState.isProcessing else { return }+ self.contentState.onOverlayModeSwitchRequested?(mode)+ self.onDismissRequested()+ }) {+ HStack(alignment: .center, spacing: 8) {+ Text(title)+ .font(.system(size: 15, weight: .semibold))+ Spacer()+ if !shortcut.isEmpty {+ Text(shortcut)+ .font(.system(size: 11, weight: .semibold))+ .foregroundStyle(.white.opacity(0.7))+ .padding(.horizontal, 6)+ .padding(.vertical, 2)+ .background(Color.white.opacity(0.08))+ .clipShape(Capsule())+ }+ if isSelected {+ Image(systemName: "checkmark")+ .font(.system(size: 10, weight: .semibold))+ }+ }+ .padding(.horizontal, 8)+ .padding(.vertical, 6)+ .background(self.rowBackground(isSelected: isSelected, rowID: rowID))+ }+ .buttonStyle(.plain)+ .onHover { hovering in+ self.hoveredRowID = hovering ? rowID : nil+ }+ }++ var body: some View {+ VStack(alignment: .leading, spacing: 0) {+ self.modeRow("Dictate", mode: .dictation, rowID: "dictate")+ self.modeRow("Edit", mode: .edit, rowID: "edit")++ Divider()+ .padding(.vertical, 4)++ self.modeRow("Command", mode: .command, rowID: "command")+ }+ .padding(.horizontal, 8)+ .padding(.vertical, 4)+ .background(Color.black)+ .cornerRadius(8)+ .overlay(+ RoundedRectangle(cornerRadius: 8)+ .stroke(Color.white.opacity(0.12), lineWidth: 1)+ )+ .frame(maxWidth: self.maxWidth)+ .onHover { hovering in+ self.onHoverChanged(hovering)+ }+ }+}++private struct BottomOverlayPromptMenuView: View {+ @ObservedObject private var settings = SettingsStore.shared++ let promptMode: SettingsStore.PromptMode+ let maxWidth: CGFloat+ let onHoverChanged: (Bool) -> Void+ let onDismissRequested: () -> Void+ @State private var hoveredRowID: String?++ private func rowBackground(isSelected: Bool, rowID: String) -> some View {+ let isHovered = self.hoveredRowID == rowID+ let fillColor: Color+ if isSelected {+ fillColor = Color.white.opacity(0.28)+ } else if isHovered {+ fillColor = Color.white.opacity(0.20)+ } else {+ fillColor = Color.clear+ }++ let strokeColor: Color+ if isSelected {+ strokeColor = Color.white.opacity(0.38)+ } else if isHovered {+ strokeColor = Color.white.opacity(0.24)+ } else {+ strokeColor = Color.clear+ }++ return RoundedRectangle(cornerRadius: 7)+ .fill(fillColor)+ .overlay(+ RoundedRectangle(cornerRadius: 7)+ .stroke(strokeColor, lineWidth: 1)+ )+ }++ @ViewBuilder+ private func defaultRow(selectedID: String?) -> some View {+ let isSelected = selectedID == nil+ Button(action: {+ self.settings.setSelectedPromptID(nil, for: self.promptMode)+ self.restoreTypingTargetApp()+ self.onDismissRequested()+ }) {+ HStack {+ Text("Default")+ Spacer()+ if isSelected {+ Image(systemName: "checkmark")+ .font(.system(size: 10, weight: .semibold))+ }+ }+ .padding(.horizontal, 8)+ .padding(.vertical, 6)+ .background(self.rowBackground(isSelected: isSelected, rowID: "default"))+ }+ .buttonStyle(.plain)+ .onHover { hovering in+ self.hoveredRowID = hovering ? "default" : nil+ }+ }++ @ViewBuilder+ private func profileRow(_ profile: SettingsStore.DictationPromptProfile, selectedID: String?) -> some View {+ let isSelected = selectedID == profile.id+ Button(action: {+ self.settings.setSelectedPromptID(profile.id, for: self.promptMode)+ self.restoreTypingTargetApp()+ self.onDismissRequested()+ }) {+ HStack {+ Text(profile.name.isEmpty ? "Untitled" : profile.name)+ Spacer()+ if isSelected {+ Image(systemName: "checkmark")+ .font(.system(size: 10, weight: .semibold))+ }+ }+ .padding(.horizontal, 8)+ .padding(.vertical, 6)+ .background(self.rowBackground(isSelected: isSelected, rowID: profile.id))+ }+ .buttonStyle(.plain)+ .onHover { hovering in+ self.hoveredRowID = hovering ? profile.id : nil+ }+ }++ var body: some View {+ let selectedID = self.settings.selectedPromptID(for: self.promptMode)+ let profiles = self.settings.promptProfiles(for: self.promptMode)++ VStack(alignment: .leading, spacing: 0) {+ self.defaultRow(selectedID: selectedID)++ if !profiles.isEmpty {+ Divider()+ .padding(.vertical, 4)++ ForEach(profiles) { profile in+ self.profileRow(profile, selectedID: selectedID)+ }+ }+ }+ .padding(.horizontal, 8)+ .padding(.vertical, 4)+ .background(Color.black)+ .cornerRadius(8)+ .overlay(+ RoundedRectangle(cornerRadius: 8)+ .stroke(Color.white.opacity(0.12), lineWidth: 1)+ )+ .frame(maxWidth: self.maxWidth)+ .onHover { hovering in+ self.onHoverChanged(hovering)+ }+ }++ private func restoreTypingTargetApp() {+ let pid = NotchContentState.shared.recordingTargetPID+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {+ if let pid { _ = TypingService.activateApp(pid: pid) }+ }+ }+}++private struct BottomOverlayActionsMenuView: View {+ @ObservedObject private var contentState = NotchContentState.shared+ @ObservedObject private var historyStore = TranscriptionHistoryStore.shared++ let maxWidth: CGFloat+ let onHoverChanged: (Bool) -> Void+ let onDismissRequested: () -> Void++ @State private var hoveredRowID: String?++ private var canReprocessLast: Bool {+ !self.historyStore.entries.isEmpty && !self.contentState.isProcessing+ }++ private var latestEntry: TranscriptionHistoryEntry? {+ self.historyStore.entries.first+ }++ private var canCopyLast: Bool {+ guard !self.contentState.isProcessing else { return false }+ guard let latest = self.latestEntry else { return false }+ let processed = latest.processedText.trimmingCharacters(in: .whitespacesAndNewlines)+ let raw = latest.rawText.trimmingCharacters(in: .whitespacesAndNewlines)+ return !(processed.isEmpty && raw.isEmpty)+ }++ private var canUndoLastAI: Bool {+ guard !self.contentState.isProcessing else { return false }+ guard let latest = self.latestEntry else { return false }+ let raw = latest.rawText.trimmingCharacters(in: .whitespacesAndNewlines)+ return latest.wasAIProcessed && !raw.isEmpty+ }++ private func rowBackground(isSelected: Bool, rowID: String) -> some View {+ let isHovered = self.hoveredRowID == rowID+ let fillColor: Color+ if isSelected {+ fillColor = Color.white.opacity(0.28)+ } else if isHovered {+ fillColor = Color.white.opacity(0.20)+ } else {+ fillColor = Color.clear+ }++ let strokeColor: Color+ if isSelected {+ strokeColor = Color.white.opacity(0.38)+ } else if isHovered {+ strokeColor = Color.white.opacity(0.24)+ } else {+ strokeColor = Color.clear+ }++ return RoundedRectangle(cornerRadius: 7)+ .fill(fillColor)+ .overlay(+ RoundedRectangle(cornerRadius: 7)+ .stroke(strokeColor, lineWidth: 1)+ )+ }++ @ViewBuilder+ private func actionRow(+ title: String,+ icon: String,+ rowID: String,+ enabled: Bool,+ action: @escaping () -> Void+ ) -> some View {+ Button(action: {+ guard enabled else { return }+ action()+ self.onDismissRequested()+ }) {+ HStack(spacing: 8) {+ Text(title)+ .font(.system(size: 14, weight: .semibold))+ Spacer()+ Image(systemName: icon)+ .font(.system(size: 11, weight: .semibold))+ }+ .padding(.horizontal, 8)+ .padding(.vertical, 6)+ .background(self.rowBackground(isSelected: false, rowID: rowID))+ }+ .buttonStyle(.plain)+ .disabled(!enabled)+ .opacity(enabled ? 1 : 0.45)+ .onHover { hovering in+ guard enabled else {+ self.hoveredRowID = nil+ return+ }+ self.hoveredRowID = hovering ? rowID : nil+ }+ }++ var body: some View {+ VStack(alignment: .leading, spacing: 0) {+ self.actionRow(+ title: "Reprocess Last Dictation",+ icon: "arrow.clockwise",+ rowID: "reprocess_last",+ enabled: self.canReprocessLast+ ) {+ self.contentState.onReprocessLastRequested?()+ }++ self.actionRow(+ title: "Copy Last Transcription",+ icon: "doc.on.doc",+ rowID: "copy_last",+ enabled: self.canCopyLast+ ) {+ self.contentState.onCopyLastRequested?()+ }++ Divider()+ .padding(.vertical, 4)++ self.actionRow(+ title: "Undo AI on Last",+ icon: "arrow.uturn.backward",+ rowID: "undo_ai_last",+ enabled: self.canUndoLastAI+ ) {+ self.contentState.onUndoLastAIRequested?()+ }+ }+ .padding(.horizontal, 8)+ .padding(.vertical, 4)+ .background(Color.black)+ .cornerRadius(8)+ .overlay(+ RoundedRectangle(cornerRadius: 8)+ .stroke(Color.white.opacity(0.12), lineWidth: 1)+ )+ .frame(maxWidth: self.maxWidth)+ .onHover { hovering in+ self.onHoverChanged(hovering)+ }+ }+}++private struct PromptSelectorAnchorReader: NSViewRepresentable {+ let onFrameChange: (CGRect, NSWindow?) -> Void++ func makeNSView(context: Context) -> AnchorReportingView {+ let view = AnchorReportingView()+ view.onFrameChange = self.onFrameChange+ return view+ }++ func updateNSView(_ nsView: AnchorReportingView, context: Context) {+ nsView.onFrameChange = self.onFrameChange+ nsView.reportFrame(force: true)+ }++ final class AnchorReportingView: NSView {+ var onFrameChange: ((CGRect, NSWindow?) -> Void)?+ private var windowObservers: [NSObjectProtocol] = []+ private var lastReportedFrameInScreen: CGRect = .null+ private weak var lastReportedWindow: NSWindow?++ override func viewDidMoveToWindow() {+ super.viewDidMoveToWindow()+ self.installWindowObservers()+ self.reportFrame(force: true)+ }++ override func layout() {+ super.layout()+ self.reportFrame()+ }++ deinit {+ self.cleanup()+ }++ func cleanup() {+ for observer in self.windowObservers {+ NotificationCenter.default.removeObserver(observer)+ }+ self.windowObservers.removeAll()+ }++ private func installWindowObservers() {+ self.cleanup()+ guard let window = self.window else { return }++ let center = NotificationCenter.default+ self.windowObservers.append(+ center.addObserver(forName: NSWindow.didMoveNotification, object: window, queue: .main) { [weak self] _ in+ self?.reportFrame()+ }+ )+ self.windowObservers.append(+ center.addObserver(forName: NSWindow.didResizeNotification, object: window, queue: .main) { [weak self] _ in+ self?.reportFrame()+ }+ )+ self.windowObservers.append(+ center.addObserver(forName: NSWindow.didChangeScreenNotification, object: window, queue: .main) { [weak self] _ in+ self?.reportFrame()+ }+ )+ }++ func reportFrame(force: Bool = false) {+ guard let window = self.window else {+ if force || !self.lastReportedFrameInScreen.isNull {+ self.lastReportedFrameInScreen = .null+ self.lastReportedWindow = nil+ self.onFrameChange?(CGRect.zero, nil)+ }+ return+ }++ let frameInWindow = self.convert(self.bounds, to: nil)+ let frameInScreen = window.convertToScreen(frameInWindow)+ let frameTolerance: CGFloat = 0.5+ let hasLastFrame = !self.lastReportedFrameInScreen.isNull+ let frameChanged = !hasLastFrame ||+ abs(frameInScreen.origin.x - self.lastReportedFrameInScreen.origin.x) > frameTolerance ||+ abs(frameInScreen.origin.y - self.lastReportedFrameInScreen.origin.y) > frameTolerance ||+ abs(frameInScreen.size.width - self.lastReportedFrameInScreen.size.width) > frameTolerance ||+ abs(frameInScreen.size.height - self.lastReportedFrameInScreen.size.height) > frameTolerance+ let windowChanged = self.lastReportedWindow !== window++ guard force || frameChanged || windowChanged else { return }++ self.lastReportedFrameInScreen = frameInScreen+ self.lastReportedWindow = window+ self.onFrameChange?(frameInScreen, window)+ }+ }+}++// MARK: - Bottom Overlay SwiftUI View++struct BottomOverlayView: View {+ @ObservedObject private var contentState = NotchContentState.shared+ @ObservedObject private var appServices = AppServices.shared+ @ObservedObject private var activeAppMonitor = ActiveAppMonitor.shared+ @ObservedObject private var historyStore = TranscriptionHistoryStore.shared+ @ObservedObject private var settings = SettingsStore.shared+ @Environment(\.theme) private var theme+ @State private var isHoveringModeChip = false+ @State private var isHoveringPromptChip = false+ @State private var isHoveringAIToggleChip = false+ @State private var isHoveringActionsChip = false+ @State private var isHoveringSettingsChip = false+ @State private var modeSelectorFrameInScreen: CGRect = .zero+ @State private var modeSelectorWindow: NSWindow?+ @State private var promptSelectorFrameInScreen: CGRect = .zero+ @State private var promptSelectorWindow: NSWindow?+ @State private var actionsSelectorFrameInScreen: CGRect = .zero+ @State private var actionsSelectorWindow: NSWindow?++ struct LayoutConstants {+ let hPadding: CGFloat+ let vPadding: CGFloat+ let waveformWidth: CGFloat+ let waveformHeight: CGFloat+ let iconSize: CGFloat+ let transFontSize: CGFloat+ let modeFontSize: CGFloat+ let cornerRadius: CGFloat+ let barCount: Int+ let barWidth: CGFloat+ let barSpacing: CGFloat+ let minBarHeight: CGFloat+ let maxBarHeight: CGFloat+ let containerWidth: CGFloat+ let overlayWidth: CGFloat+ let overlayHeight: CGFloat+ let previewBoxHeight: CGFloat+ let usesFixedCanvas: Bool+ let showsTopControls: Bool+ let showsPreview: Bool++ static func get(for size: SettingsStore.OverlaySize) -> LayoutConstants {+ switch size {+ case .small:+ return LayoutConstants(+ hPadding: 10,+ vPadding: 6,+ waveformWidth: 90,+ waveformHeight: 20,+ iconSize: 16,+ transFontSize: 11,+ modeFontSize: 10,cornerRadius: 14,barCount: 7,barWidth: 3.0,barSpacing: 3.5,minBarHeight: 5,- maxBarHeight: 16+ maxBarHeight: 16,+ containerWidth: 200,+ overlayWidth: 300,+ overlayHeight: 124,+ previewBoxHeight: 0,+ usesFixedCanvas: false,+ showsTopControls: false,+ showsPreview: true)case .medium:return LayoutConstants(@@ -670,12 +1641,19 @@ struct BottomOverlayView: View {barWidth: 3.5,barSpacing: 4.5,minBarHeight: 6,- maxBarHeight: 28+ maxBarHeight: 28,+ containerWidth: 340,+ overlayWidth: 380,+ overlayHeight: 156,+ previewBoxHeight: 0,+ usesFixedCanvas: false,+ showsTopControls: true,+ showsPreview: true)case .large:return LayoutConstants(- hPadding: 24,- vPadding: 18,+ hPadding: 18,+ vPadding: 12,waveformWidth: 180,waveformHeight: 48,iconSize: 26,@@ -686,7 +1664,14 @@ struct BottomOverlayView: View {barWidth: 5.0,barSpacing: 6.0,minBarHeight: 8,- maxBarHeight: 44+ maxBarHeight: 44,+ containerWidth: 600,+ overlayWidth: 600,+ overlayHeight: 288,+ previewBoxHeight: 92,+ usesFixedCanvas: true,+ showsTopControls: true,+ showsPreview: true)}}@@ -696,6 +1681,10 @@ struct BottomOverlayView: View {LayoutConstants.get(for: self.settings.overlaySize)}+ private var isCompactControls: Bool {+ self.settings.overlaySize == .medium+ }+private var modeColor: Color {self.contentState.mode.notchColor}@@ -703,8 +1692,7 @@ struct BottomOverlayView: View {private var modeLabel: String {switch self.contentState.mode {case .dictation: return "Dictate"- case .rewrite: return "Rewrite"- case .write: return "Write"+ case .edit, .rewrite, .write: return "Edit"case .command: return "Command"}}@@ -712,12 +1700,18 @@ struct BottomOverlayView: View {private var processingLabel: String {switch self.contentState.mode {case .dictation: return "Refining..."- case .rewrite: return "Thinking..."- case .write: return "Thinking..."+ case .edit, .rewrite, .write: return "Thinking..."case .command: return "Working..."}}+ private static let transientOverlayStatusTexts: Set<String> = [+ "Transcribing...",+ "Refining...",+ "Thinking...",+ "Working...",+ ]+// ContentView writes transient status strings into transcriptionText while processing// (e.g. "Transcribing...", "Refining..."). Prefer that when present.private var processingStatusText: String {@@ -726,15 +1720,38 @@ struct BottomOverlayView: View {}private var hasTranscription: Bool {- !self.contentState.transcriptionText.isEmpty+ !self.transcriptionPreviewText.isEmpty+ }++ private var normalizedOverlayMode: OverlayMode {+ switch self.contentState.mode {+ case .dictation:+ return .dictation+ case .edit, .write, .rewrite:+ return .edit+ case .command:+ return .command+ }+ }++ private var activePromptMode: SettingsStore.PromptMode? {+ switch self.normalizedOverlayMode {+ case .dictation:+ return .dictate+ case .edit:+ return .edit+ case .command, .write, .rewrite:+ return nil+ }}- private var isDictationMode: Bool {- self.contentState.mode == .dictation+ private var isPromptSelectableMode: Bool {+ self.activePromptMode != nil}private var selectedPromptLabel: String {- if let profile = self.settings.selectedDictationPromptProfile {+ guard let activePromptMode else { return "N/A" }+ if let profile = self.settings.selectedPromptProfile(for: activePromptMode) {let name = profile.name.trimmingCharacters(in: .whitespacesAndNewlines)return name.isEmpty ? "Untitled" : name}@@ -750,7 +1767,7 @@ struct BottomOverlayView: View {}private var promptMenuGap: CGFloat {- max(4, self.layout.vPadding * 0.35)+ max(0, self.layout.vPadding * 0.05)}private var promptSelectorCornerRadius: CGFloat {@@ -762,7 +1779,7 @@ struct BottomOverlayView: View {}private var previewMaxHeight: CGFloat {- self.layout.transFontSize * 4.2+ self.layout.usesFixedCanvas ? self.layout.previewBoxHeight : self.layout.transFontSize * 4.2}private var previewMaxWidth: CGFloat {@@ -774,7 +1791,55 @@ struct BottomOverlayView: View {}private var transcriptionPreviewText: String {- self.contentState.cachedPreviewText+ let preview = self.contentState.cachedPreviewText.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !self.contentState.isProcessing else { return self.contentState.cachedPreviewText }+ guard Self.transientOverlayStatusTexts.contains(preview) else { return self.contentState.cachedPreviewText }+ return ""+ }++ private var overlayBorderLineWidth: CGFloat {+ self.settings.overlaySize == .large ? 0.8 : 1+ }++ private var overlayBorderTopOpacity: Double {+ self.settings.overlaySize == .large ? 0.10 : 0.15+ }++ private var overlayBorderBottomOpacity: Double {+ self.settings.overlaySize == .large ? 0.05 : 0.08+ }++ private func chipBackground(isHovered: Bool, disabled: Bool) -> some View {+ let fillColor: Color+ if disabled {+ fillColor = Color.black.opacity(0.95)+ } else if isHovered {+ fillColor = Color(red: 0.13, green: 0.13, blue: 0.16)+ } else {+ fillColor = Color.black+ }++ let topStrokeOpacity: Double = disabled ? 0.10 : (isHovered ? 0.36 : 0.14)+ let bottomStrokeOpacity: Double = disabled ? 0.06 : (isHovered ? 0.22 : 0.08)+ let hoverShadowColor: Color = (isHovered && !disabled) ? Color.white.opacity(0.16) : .clear++ return RoundedRectangle(cornerRadius: self.promptSelectorCornerRadius)+ .fill(fillColor)+ .overlay(+ RoundedRectangle(cornerRadius: self.promptSelectorCornerRadius)+ .strokeBorder(+ LinearGradient(+ colors: [+ Color.white.opacity(topStrokeOpacity),+ Color.white.opacity(bottomStrokeOpacity),+ ],+ startPoint: .top,+ endPoint: .bottom+ ),+ lineWidth: 1+ )+ )+ .shadow(color: hoverShadowColor, radius: 6, x: 0, y: 1)}private func closePromptMenu() {@@ -782,15 +1847,13 @@ struct BottomOverlayView: View {}private func handlePromptSelectorHover(_ hovering: Bool) {- guard self.isDictationMode, !self.contentState.isProcessing else {- BottomOverlayPromptMenuController.shared.hide()- return- }- BottomOverlayPromptMenuController.shared.selectorHoverChanged(hovering)+ // Hover-open disabled by design.}private func handlePromptSelectorFrameChange(_ frameInScreen: CGRect, window: NSWindow?) {- guard self.isDictationMode, !self.contentState.isProcessing else {+ self.promptSelectorFrameInScreen = frameInScreen+ self.promptSelectorWindow = window+ guard self.layout.showsTopControls, self.isPromptSelectableMode, !self.contentState.isProcessing else {BottomOverlayPromptMenuController.shared.hide()return}@@ -803,11 +1866,130 @@ struct BottomOverlayView: View {)}+ private func requestModeSwitch(_ mode: OverlayMode) {+ guard !self.contentState.isProcessing else { return }+ self.contentState.onOverlayModeSwitchRequested?(mode)+ BottomOverlayModeMenuController.shared.hide()+ }++ private func closeModeMenu() {+ BottomOverlayModeMenuController.shared.hide()+ }++ private func closeActionsMenu() {+ BottomOverlayActionsMenuController.shared.hide()+ }++ private func handleModeSelectorHover(_ hovering: Bool) {+ guard !self.contentState.isProcessing else {+ self.closeModeMenu()+ return+ }+ BottomOverlayModeMenuController.shared.selectorHoverChanged(hovering)+ }++ private func handleModeSelectorFrameChange(_ frameInScreen: CGRect, window: NSWindow?) {+ self.modeSelectorFrameInScreen = frameInScreen+ self.modeSelectorWindow = window+ guard self.layout.showsTopControls, !self.contentState.isProcessing else {+ BottomOverlayModeMenuController.shared.hide()+ return+ }++ BottomOverlayModeMenuController.shared.updateAnchor(+ selectorFrameInScreen: frameInScreen,+ parentWindow: window,+ maxWidth: self.promptSelectorMaxWidth,+ menuGap: self.promptMenuGap+ )+ }++ private func handleActionsSelectorHover(_ hovering: Bool) {+ let actionsDisabled = self.historyStore.entries.isEmpty || self.contentState.isProcessing+ guard !actionsDisabled else {+ self.closeActionsMenu()+ return+ }+ BottomOverlayActionsMenuController.shared.selectorHoverChanged(hovering)+ }++ private func handleActionsSelectorFrameChange(_ frameInScreen: CGRect, window: NSWindow?) {+ self.actionsSelectorFrameInScreen = frameInScreen+ self.actionsSelectorWindow = window+ let actionsDisabled = self.historyStore.entries.isEmpty || self.contentState.isProcessing+ guard self.layout.showsTopControls, !actionsDisabled else {+ BottomOverlayActionsMenuController.shared.hide()+ return+ }++ BottomOverlayActionsMenuController.shared.updateAnchor(+ selectorFrameInScreen: frameInScreen,+ parentWindow: window,+ maxWidth: self.promptSelectorMaxWidth,+ menuGap: self.promptMenuGap+ )+ }++ private var modeSelectorTrigger: some View {+ HStack(spacing: 5) {+ if !self.isCompactControls {+ Text("Mode:")+ .font(.system(size: self.promptSelectorFontSize, weight: .medium))+ .foregroundStyle(.white.opacity(0.5))+ .lineLimit(1)+ .fixedSize(horizontal: true, vertical: false)+ }+ Text(self.modeLabel)+ .font(.system(size: self.promptSelectorFontSize, weight: .semibold))+ .foregroundStyle(.white.opacity(0.75))+ .lineLimit(1)+ Image(systemName: "chevron.up")+ .font(.system(size: max(self.promptSelectorFontSize - 1, 8), weight: .semibold))+ .foregroundStyle(.white.opacity(0.45))+ }+ .fixedSize(horizontal: true, vertical: false)+ .padding(.horizontal, 8)+ .padding(.vertical, self.promptSelectorVerticalPadding)+ .background(+ self.chipBackground(isHovered: self.isHoveringModeChip, disabled: self.contentState.isProcessing)+ )+ }++ private var modeSelectorView: some View {+ self.modeSelectorTrigger+ .background(+ PromptSelectorAnchorReader { frameInScreen, window in+ self.handleModeSelectorFrameChange(frameInScreen, window: window)+ }+ .allowsHitTesting(false)+ )+ .contentShape(Rectangle())+ .onHover { hovering in+ self.isHoveringModeChip = hovering && !self.contentState.isProcessing+ }+ .onTapGesture {+ guard self.layout.showsTopControls, !self.contentState.isProcessing else { return }+ self.closePromptMenu()+ self.closeActionsMenu()+ BottomOverlayModeMenuController.shared.updateAnchor(+ selectorFrameInScreen: self.modeSelectorFrameInScreen,+ parentWindow: self.modeSelectorWindow,+ maxWidth: self.promptSelectorMaxWidth,+ menuGap: self.promptMenuGap+ )+ BottomOverlayModeMenuController.shared.toggleFromTap()+ }+ }+private var promptSelectorTrigger: some View {HStack(spacing: 5) {- Text("Prompt:")- .font(.system(size: self.promptSelectorFontSize, weight: .medium))- .foregroundStyle(.white.opacity(0.5))+ if !self.isCompactControls {+ Text("Prompt:")+ .font(.system(size: self.promptSelectorFontSize, weight: .medium))+ .foregroundStyle(.white.opacity(0.5))+ .lineLimit(1)+ .fixedSize(horizontal: true, vertical: false)+ }Text(self.selectedPromptLabel).font(.system(size: self.promptSelectorFontSize, weight: .semibold)).foregroundStyle(.white.opacity(0.75))@@ -816,99 +1998,317 @@ struct BottomOverlayView: View {.font(.system(size: max(self.promptSelectorFontSize - 1, 8), weight: .semibold)).foregroundStyle(.white.opacity(0.45))}+ .fixedSize(horizontal: true, vertical: false).padding(.horizontal, 8).padding(.vertical, self.promptSelectorVerticalPadding).background(- RoundedRectangle(cornerRadius: self.promptSelectorCornerRadius)- .fill(Color.black)- .overlay(- RoundedRectangle(cornerRadius: self.promptSelectorCornerRadius)- .strokeBorder(- LinearGradient(- colors: [- Color.white.opacity(0.14),- Color.white.opacity(0.08),- ],- startPoint: .top,- endPoint: .bottom- ),- lineWidth: 1- )- )+ self.chipBackground(+ isHovered: self.isHoveringPromptChip,+ disabled: !self.isPromptSelectableMode || self.contentState.isProcessing+ ))}private var promptSelectorView: some View {- self.promptSelectorTrigger+ Group {+ if self.isPromptSelectableMode {+ self.promptSelectorTrigger+ .background(+ PromptSelectorAnchorReader { frameInScreen, window in+ self.handlePromptSelectorFrameChange(frameInScreen, window: window)+ }+ .allowsHitTesting(false)+ )+ .contentShape(Rectangle())+ .onHover { hovering in+ self.isHoveringPromptChip = hovering && !self.contentState.isProcessing+ }+ .onTapGesture {+ guard self.layout.showsTopControls, self.isPromptSelectableMode, !self.contentState.isProcessing else { return }+ self.closeModeMenu()+ self.closeActionsMenu()+ BottomOverlayPromptMenuController.shared.updateAnchor(+ selectorFrameInScreen: self.promptSelectorFrameInScreen,+ parentWindow: self.promptSelectorWindow,+ maxWidth: self.promptSelectorMaxWidth,+ menuGap: self.promptMenuGap+ )+ BottomOverlayPromptMenuController.shared.toggleFromTap()+ }+ } else {+ self.promptSelectorTrigger+ .opacity(0.6)+ .onHover { _ in+ self.isHoveringPromptChip = false+ }+ }+ }+ }++ private var actionsSelectorTrigger: some View {+ let actionsDisabled = self.historyStore.entries.isEmpty || self.contentState.isProcessing+ return HStack(spacing: 5) {+ Text("Actions")+ .font(.system(size: self.promptSelectorFontSize, weight: .medium))+ .foregroundStyle(.white.opacity(0.75))+ .lineLimit(1)+ Image(systemName: "chevron.up")+ .font(.system(size: max(self.promptSelectorFontSize - 1, 8), weight: .semibold))+ .foregroundStyle(.white.opacity(0.45))+ }+ .fixedSize(horizontal: true, vertical: false)+ .padding(.horizontal, 8)+ .padding(.vertical, self.promptSelectorVerticalPadding)+ .background(+ self.chipBackground(+ isHovered: self.isHoveringActionsChip,+ disabled: actionsDisabled+ )+ )+ }++ private var aiToggleChip: some View {+ let disabled = self.contentState.isProcessing+ let isEnabled = self.settings.enableAIProcessing+ return HStack(spacing: self.isCompactControls ? 0 : 5) {+ if self.isCompactControls {+ Text(isEnabled ? "AI On" : "AI Off")+ .font(.system(size: self.promptSelectorFontSize, weight: .semibold))+ .foregroundStyle(isEnabled ? .white.opacity(0.82) : .white.opacity(0.7))+ .lineLimit(1)+ } else {+ Text("AI:")+ .font(.system(size: self.promptSelectorFontSize, weight: .medium))+ .foregroundStyle(.white.opacity(0.5))+ .lineLimit(1)+ Text(isEnabled ? "On" : "Off")+ .font(.system(size: self.promptSelectorFontSize, weight: .semibold))+ .foregroundStyle(isEnabled ? .white.opacity(0.82) : .white.opacity(0.7))+ .lineLimit(1)+ Image(systemName: isEnabled ? "brain.fill" : "brain")+ .font(.system(size: max(self.promptSelectorFontSize - 1, 8), weight: .semibold))+ .foregroundStyle(isEnabled ? .white.opacity(0.65) : .white.opacity(0.45))+ }+ }+ .fixedSize(horizontal: true, vertical: false)+ .padding(.horizontal, 8)+ .padding(.vertical, self.promptSelectorVerticalPadding)+ .background(+ self.chipBackground(+ isHovered: self.isHoveringAIToggleChip,+ disabled: disabled+ )+ )+ .contentShape(Rectangle())+ .onHover { hovering in+ self.isHoveringAIToggleChip = hovering && !disabled+ }+ .onTapGesture {+ guard !disabled else { return }+ self.closePromptMenu()+ self.closeModeMenu()+ self.closeActionsMenu()+ self.contentState.onToggleAIProcessingRequested?()+ }+ .help("Toggle AI enhancement for dictation")+ .opacity(disabled ? 0.65 : 1)+ }++ private var actionsSelectorView: some View {+ let actionsDisabled = self.historyStore.entries.isEmpty || self.contentState.isProcessing+ return self.actionsSelectorTrigger.background(PromptSelectorAnchorReader { frameInScreen, window in- self.handlePromptSelectorFrameChange(frameInScreen, window: window)+ self.handleActionsSelectorFrameChange(frameInScreen, window: window)}.allowsHitTesting(false))- .frame(maxWidth: self.promptSelectorMaxWidth, alignment: .center).contentShape(Rectangle()).onHover { hovering in- self.handlePromptSelectorHover(hovering)+ self.isHoveringActionsChip = hovering && !actionsDisabled+ self.handleActionsSelectorHover(hovering)+ }+ .onTapGesture {+ guard self.layout.showsTopControls, !actionsDisabled else { return }+ self.closePromptMenu()+ self.closeModeMenu()+ BottomOverlayActionsMenuController.shared.updateAnchor(+ selectorFrameInScreen: self.actionsSelectorFrameInScreen,+ parentWindow: self.actionsSelectorWindow,+ maxWidth: self.promptSelectorMaxWidth,+ menuGap: self.promptMenuGap+ )+ BottomOverlayActionsMenuController.shared.toggleFromTap()}+ .help(+ self.historyStore.entries.isEmpty+ ? "No saved dictation history available"+ : "Reprocess the latest dictation using current AI settings"+ )+ }++ private var settingsChip: some View {+ let disabled = false+ return HStack(spacing: 0) {+ Image(systemName: "gearshape")+ .font(.system(size: max(self.promptSelectorFontSize + 1, 10), weight: .semibold))+ .foregroundStyle(.white.opacity(0.72))+ }+ .padding(.horizontal, 9)+ .padding(.vertical, self.promptSelectorVerticalPadding)+ .background(+ self.chipBackground(+ isHovered: self.isHoveringSettingsChip,+ disabled: disabled+ )+ )+ .contentShape(Rectangle())+ .onHover { hovering in+ self.isHoveringSettingsChip = hovering+ }+ .onTapGesture {+ self.closePromptMenu()+ self.closeModeMenu()+ self.closeActionsMenu()+ self.contentState.onOpenPreferencesRequested?()+ }+ .help("Open Preferences")}var body: some View {VStack(spacing: max(4, self.layout.vPadding / 2)) {- if self.isDictationMode && !self.contentState.isProcessing {- self.promptSelectorView+ if self.layout.showsTopControls {+ HStack(spacing: self.isCompactControls ? 6 : 8) {+ self.modeSelectorView+ self.promptSelectorView+ Spacer(minLength: 4)+ self.aiToggleChip+ self.actionsSelectorView+ if !self.isCompactControls {+ self.settingsChip+ }+ }+ .frame(maxWidth: .infinity, alignment: self.isCompactControls ? .center : .leading)+ .padding(.horizontal, self.layout.hPadding)}VStack(spacing: self.layout.vPadding / 2) {- // Transcription text area (wrapped)- Group {- if self.hasTranscription && !self.contentState.isProcessing {- let previewText = self.transcriptionPreviewText- if !previewText.isEmpty {- ScrollViewReader { proxy in- ScrollView(.vertical, showsIndicators: false) {- Text(previewText)- .font(.system(size: self.layout.transFontSize, weight: .medium))- .foregroundStyle(.white.opacity(0.9))- .multilineTextAlignment(.leading)- .lineLimit(nil)- .fixedSize(horizontal: false, vertical: true)- .frame(maxWidth: .infinity, alignment: .leading)- Color.clear.frame(height: 1).id("bottom")- }- .frame(width: self.previewMaxWidth)- .frame(maxHeight: self.previewMaxHeight)- .clipped()- .onAppear {- DispatchQueue.main.async {- proxy.scrollTo("bottom", anchor: .bottom)+ if self.layout.showsPreview {+ if self.layout.usesFixedCanvas {+ // Transcription text area (fixed-height in large mode)+ Group {+ if self.contentState.isProcessing {+ ShimmerText(+ text: self.processingStatusText,+ color: self.modeColor,+ font: .system(size: self.layout.transFontSize, weight: .medium)+ )+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)+ } else if self.hasTranscription {+ let previewText = self.transcriptionPreviewText+ if !previewText.isEmpty {+ ScrollViewReader { proxy in+ ScrollView(.vertical, showsIndicators: false) {+ Text(previewText)+ .font(.system(size: self.layout.transFontSize, weight: .medium))+ .foregroundStyle(.white.opacity(0.9))+ .multilineTextAlignment(.leading)+ .lineLimit(nil)+ .fixedSize(horizontal: false, vertical: true)+ .frame(maxWidth: .infinity, alignment: .leading)+ Color.clear.frame(height: 1).id("bottom")+ }+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)+ .clipped()+ .onAppear {+ DispatchQueue.main.async {+ proxy.scrollTo("bottom", anchor: .bottom)+ }+ }+ .onChange(of: previewText) { _, _ in+ DispatchQueue.main.async {+ proxy.scrollTo("bottom", anchor: .bottom)+ }+ }}}- .onChange(of: previewText) { _, _ in- DispatchQueue.main.async {- proxy.scrollTo("bottom", anchor: .bottom)+ } else {+ Color.clear+ }+ }+ .padding(.vertical, self.transcriptionVerticalPadding)+ .frame(+ maxWidth: .infinity,+ minHeight: self.previewMaxHeight,+ maxHeight: self.previewMaxHeight,+ alignment: .topLeading+ )+ } else {+ // Original dynamic preview behavior for small/medium+ Group {+ if self.hasTranscription && !self.contentState.isProcessing {+ let previewText = self.transcriptionPreviewText+ if !previewText.isEmpty {+ if self.settings.overlaySize == .small {+ Text(previewText)+ .font(.system(size: self.layout.transFontSize, weight: .medium))+ .foregroundStyle(.white.opacity(0.9))+ .multilineTextAlignment(.leading)+ .lineLimit(1)+ .truncationMode(.head)+ .frame(maxWidth: .infinity, alignment: .leading)+ .padding(.vertical, max(2, self.transcriptionVerticalPadding - 1))+ } else {+ ScrollViewReader { proxy in+ ScrollView(.vertical, showsIndicators: false) {+ Text(previewText)+ .font(.system(size: self.layout.transFontSize, weight: .medium))+ .foregroundStyle(.white.opacity(0.9))+ .multilineTextAlignment(.leading)+ .lineLimit(nil)+ .fixedSize(horizontal: false, vertical: true)+ .frame(maxWidth: .infinity, alignment: .leading)+ Color.clear.frame(height: 1).id("bottom")+ }+ .frame(width: self.previewMaxWidth)+ .frame(maxHeight: self.previewMaxHeight)+ .clipped()+ .onAppear {+ DispatchQueue.main.async {+ proxy.scrollTo("bottom", anchor: .bottom)+ }+ }+ .onChange(of: previewText) { _, _ in+ DispatchQueue.main.async {+ proxy.scrollTo("bottom", anchor: .bottom)+ }+ }+ }+ .padding(.vertical, self.transcriptionVerticalPadding)}}+ } else if self.contentState.isProcessing {+ ShimmerText(+ text: self.processingStatusText,+ color: self.modeColor,+ font: .system(size: self.layout.transFontSize, weight: .medium)+ )}- .padding(.vertical, self.transcriptionVerticalPadding)}- } else if self.contentState.isProcessing {- ShimmerText(- text: self.processingStatusText,- color: self.modeColor,- font: .system(size: self.layout.transFontSize, weight: .medium)+ .frame(+ maxWidth: self.previewMaxWidth,+ minHeight: self.hasTranscription || self.contentState.isProcessing ? self.layout.transFontSize * 1.5 : 0)}}- .frame(- maxWidth: self.previewMaxWidth,- minHeight: self.hasTranscription || self.contentState.isProcessing ? self.layout.transFontSize * 1.5 : 0- )// Waveform + Mode label rowHStack(spacing: self.layout.hPadding / 1.5) {// Target app icon (the app where text will be typed)- if let appIcon = contentState.targetAppIcon {+ let appIcon = self.contentState.targetAppIcon ?? self.activeAppMonitor.activeAppIcon+ if appIcon != nil || !self.appServices.asr.isAsrReady &&+ (self.appServices.asr.isLoadingModel || self.appServices.asr.isDownloadingModel)+ {let showModelLoading = !self.appServices.asr.isAsrReady &&(self.appServices.asr.isLoadingModel || self.appServices.asr.isDownloadingModel)VStack(spacing: 2) {@@ -917,12 +2317,16 @@ struct BottomOverlayView: View {.controlSize(.mini).fixedSize()}- Image(nsImage: appIcon)- .resizable()- .aspectRatio(contentMode: .fit)- .frame(width: self.layout.iconSize, height: self.layout.iconSize)- .clipShape(RoundedRectangle(cornerRadius: self.layout.iconSize / 4))+ if let appIcon = appIcon {+ Image(nsImage: appIcon)+ .resizable()+ .aspectRatio(contentMode: .fit)+ .frame(width: self.layout.iconSize, height: self.layout.iconSize)+ .clipShape(RoundedRectangle(cornerRadius: self.layout.iconSize / 4))+ }}+ .frame(width: self.layout.iconSize, height: self.layout.iconSize)+ .opacity((appIcon != nil || self.appServices.asr.isLoadingModel || self.appServices.asr.isDownloadingModel) ? 1 : 0)}// Waveform visualization@@ -939,6 +2343,7 @@ struct BottomOverlayView: View {if !self.appServices.asr.isAsrReady &&(self.appServices.asr.isLoadingModel || self.appServices.asr.isDownloadingModel)+ && self.settings.overlaySize != .small{Text("Loading model…").font(.system(size: max(self.layout.modeFontSize - 2, 9), weight: .medium))@@ -950,6 +2355,7 @@ struct BottomOverlayView: View {}.padding(.horizontal, self.layout.hPadding).padding(.vertical, self.layout.vPadding)+ .frame(maxWidth: .infinity, alignment: .center).background(ZStack {// Solid pitch black background@@ -961,34 +2367,75 @@ struct BottomOverlayView: View {.strokeBorder(LinearGradient(colors: [- Color.white.opacity(0.15),- Color.white.opacity(0.08),+ Color.white.opacity(self.overlayBorderTopOpacity),+ Color.white.opacity(self.overlayBorderBottomOpacity),],startPoint: .top,endPoint: .bottom),- lineWidth: 1+ lineWidth: self.overlayBorderLineWidth)})+ .frame(maxWidth: .infinity, alignment: .top)}- .onChange(of: self.contentState.cachedPreviewText) { _, _ in+ .frame(+ width: self.layout.usesFixedCanvas ? self.layout.overlayWidth : self.layout.containerWidth,+ height: self.layout.usesFixedCanvas ? self.layout.overlayHeight : nil,+ alignment: .top+ )+ .onChange(of: self.settings.overlaySize) { _, _ inBottomOverlayWindowController.shared.refreshSizeForContent()}+ .onChange(of: self.contentState.cachedPreviewText) { _, _ in+ if !self.layout.usesFixedCanvas {+ BottomOverlayWindowController.shared.refreshSizeForContent()+ }+ }.onChange(of: self.contentState.mode) { _, _ in- if !self.isDictationMode || self.contentState.isProcessing {+ if !self.isPromptSelectableMode || self.contentState.isProcessing {self.closePromptMenu()}- BottomOverlayWindowController.shared.refreshSizeForContent()+ self.closeModeMenu()+ self.closeActionsMenu()+ self.isHoveringModeChip = false+ self.isHoveringPromptChip = false+ self.isHoveringAIToggleChip = false+ self.isHoveringActionsChip = false+ self.isHoveringSettingsChip = false+ switch self.contentState.mode {+ case .dictation: self.contentState.promptPickerMode = .dictate+ case .edit, .write, .rewrite: self.contentState.promptPickerMode = .edit+ case .command: break+ }+ if !self.layout.usesFixedCanvas {+ BottomOverlayWindowController.shared.refreshSizeForContent()+ }}.onChange(of: self.contentState.isProcessing) { _, processing inif processing {self.closePromptMenu()+ self.closeModeMenu()+ self.closeActionsMenu()+ }+ self.isHoveringModeChip = false+ self.isHoveringPromptChip = false+ self.isHoveringAIToggleChip = false+ self.isHoveringActionsChip = false+ self.isHoveringSettingsChip = false+ if !self.layout.usesFixedCanvas {+ BottomOverlayWindowController.shared.refreshSizeForContent()}- BottomOverlayWindowController.shared.refreshSizeForContent()}.onDisappear {self.closePromptMenu()+ self.closeModeMenu()+ self.closeActionsMenu()+ self.isHoveringModeChip = false+ self.isHoveringPromptChip = false+ self.isHoveringAIToggleChip = false+ self.isHoveringActionsChip = false+ self.isHoveringSettingsChip = false}// TODO: Add tap-to-expand for command mode history (future enhancement)// .contentShape(Rectangle())diff --git a/Sources/Fluid/Views/NotchContentViews.swift b/Sources/Fluid/Views/NotchContentViews.swiftindex 44ffa91f..eb174e2d 100644--- a/Sources/Fluid/Views/NotchContentViews.swift+++ b/Sources/Fluid/Views/NotchContentViews.swift@@ -18,6 +18,7 @@ class NotchContentState: ObservableObject {@Published var transcriptionText: String = ""@Published var mode: OverlayMode = .dictation+ @Published var promptPickerMode: SettingsStore.PromptMode = .dictate@Published var isProcessing: Bool = false // AI processing state// Icon of the target app (where text will be typed)@@ -124,6 +125,21 @@ class NotchContentState: ObservableObject {@Published var bottomOverlayAudioLevel: CGFloat = 0 // Audio level for bottom overlay waveform+ /// Called when the user requests a live mode switch from the prompt picker tabs.+ var onPromptModeSwitchRequested: ((SettingsStore.PromptMode) -> Void)?+ /// Called when the user requests a live overlay mode switch from the mode picker.+ var onOverlayModeSwitchRequested: ((OverlayMode) -> Void)?+ /// Called when the user requests reprocessing the latest saved dictation entry.+ var onReprocessLastRequested: (() -> Void)?+ /// Called when the user requests copying the latest saved transcription entry.+ var onCopyLastRequested: (() -> Void)?+ /// Called when the user requests undoing AI processing for the latest entry.+ var onUndoLastAIRequested: (() -> Void)?+ /// Called when the user requests toggling dictation AI enhancement.+ var onToggleAIProcessingRequested: (() -> Void)?+ /// Called when the user requests opening Preferences.+ var onOpenPreferencesRequested: (() -> Void)?+/// Set recording state (for waveform visibility in expanded view)func setRecordingInExpandedMode(_ recording: Bool) {self.isRecordingInExpandedMode = recording@@ -198,6 +214,8 @@ extension OverlayMode {switch self {case .dictation:return Color.white.opacity(0.85)+ case .edit:+ return Color(red: 0.4, green: 0.6, blue: 1.0) // Blue (Edit)case .rewrite:return Color(red: 0.45, green: 0.55, blue: 1.0) // Lighter bluecase .write:@@ -263,8 +281,7 @@ struct NotchExpandedView: View {private var modeLabel: String {switch self.contentState.mode {case .dictation: return "Dictate"- case .rewrite: return "Rewrite"- case .write: return "Write"+ case .edit, .rewrite, .write: return "Edit"case .command: return "Command"}}@@ -272,8 +289,7 @@ struct NotchExpandedView: View {private var processingLabel: String {switch self.contentState.mode {case .dictation: return "Refining..."- case .rewrite: return "Thinking..."- case .write: return "Thinking..."+ case .edit, .rewrite, .write: return "Thinking..."case .command: return "Working..."}}@@ -294,12 +310,35 @@ struct NotchExpandedView: View {self.contentState.mode == .command && !self.contentState.commandConversationHistory.isEmpty}- private var isDictationMode: Bool {- self.contentState.mode == .dictation+ private var normalizedOverlayMode: OverlayMode {+ switch self.contentState.mode {+ case .dictation:+ return .dictation+ case .edit, .write, .rewrite:+ return .edit+ case .command:+ return .command+ }+ }++ private var activePromptMode: SettingsStore.PromptMode? {+ switch self.normalizedOverlayMode {+ case .dictation:+ return .dictate+ case .edit:+ return .edit+ case .command, .write, .rewrite:+ return nil+ }+ }++ private var isPromptSelectableMode: Bool {+ self.activePromptMode != nil}private var selectedPromptLabel: String {- if let profile = self.settings.selectedDictationPromptProfile {+ guard let activePromptMode else { return "N/A" }+ if let profile = self.settings.selectedPromptProfile(for: activePromptMode) {let name = profile.name.trimmingCharacters(in: .whitespacesAndNewlines)return name.isEmpty ? "Untitled" : name}@@ -315,6 +354,10 @@ struct NotchExpandedView: View {}private func handlePromptHover(_ hovering: Bool) {+ guard self.isPromptSelectableMode, !self.contentState.isProcessing else {+ self.showPromptHoverMenu = false+ return+ }self.promptHoverWorkItem?.cancel()let task = DispatchWorkItem {self.showPromptHoverMenu = hovering@@ -324,9 +367,11 @@ struct NotchExpandedView: View {}private func promptMenuContent() -> some View {- VStack(alignment: .leading, spacing: 0) {+ let promptMode = self.activePromptMode ?? .dictate++ return VStack(alignment: .leading, spacing: 0) {Button(action: {- self.settings.selectedDictationPromptID = nil+ self.settings.setSelectedPromptID(nil, for: promptMode)let pid = NotchContentState.shared.recordingTargetPIDDispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {if let pid { _ = TypingService.activateApp(pid: pid) }@@ -336,7 +381,7 @@ struct NotchExpandedView: View {HStack {Text("Default")Spacer()- if self.settings.selectedDictationPromptID == nil {+ if self.settings.selectedPromptID(for: promptMode) == nil {Image(systemName: "checkmark").font(.system(size: 10, weight: .semibold))}@@ -345,13 +390,13 @@ struct NotchExpandedView: View {.buttonStyle(.plain).padding(.vertical, 4)- if !self.settings.dictationPromptProfiles.isEmpty {+ if !self.settings.promptProfiles(for: promptMode).isEmpty {Divider().padding(.vertical, 4)- ForEach(self.settings.dictationPromptProfiles) { profile in+ ForEach(self.settings.promptProfiles(for: promptMode)) { profile inButton(action: {- self.settings.selectedDictationPromptID = profile.id+ self.settings.setSelectedPromptID(profile.id, for: promptMode)let pid = NotchContentState.shared.recordingTargetPIDDispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {if let pid { _ = TypingService.activateApp(pid: pid) }@@ -361,7 +406,7 @@ struct NotchExpandedView: View {HStack {Text(profile.name.isEmpty ? "Untitled" : profile.name)Spacer()- if self.settings.selectedDictationPromptID == profile.id {+ if self.settings.selectedPromptID(for: promptMode) == profile.id {Image(systemName: "checkmark").font(.system(size: 10, weight: .semibold))}@@ -412,11 +457,14 @@ struct NotchExpandedView: View {.font(.system(size: 9, weight: .medium)).foregroundStyle(self.modeColor).opacity(0.9)+ .onHover { hovering in+ self.handlePromptHover(hovering)+ }}}- // Dictation prompt selector (only in dictation mode)- if self.isDictationMode && !self.contentState.isProcessing {+ // Prompt selector+ if !self.contentState.isProcessing {ZStack(alignment: .top) {HStack(spacing: 6) {Text("Prompt:")@@ -434,6 +482,7 @@ struct NotchExpandedView: View {.padding(.vertical, 4).background(Color.white.opacity(0.00)).cornerRadius(6)+ .opacity(self.isPromptSelectableMode ? 1.0 : 0.6).onHover { hovering inself.handlePromptHover(hovering)}@@ -492,6 +541,16 @@ struct NotchExpandedView: View {NotchOverlayManager.shared.onNotchClicked?()}}+ .onChange(of: self.contentState.mode) { _, _ in+ if !self.isPromptSelectableMode {+ self.showPromptHoverMenu = false+ }+ switch self.contentState.mode {+ case .dictation: self.contentState.promptPickerMode = .dictate+ case .edit, .write, .rewrite: self.contentState.promptPickerMode = .edit+ case .command: break+ }+ }.animation(.spring(response: 0.25, dampingFraction: 0.8), value: self.hasTranscription).animation(.easeInOut(duration: 0.2), value: self.contentState.mode).animation(.easeInOut(duration: 0.25), value: self.contentState.isProcessing)diff --git a/Sources/Fluid/Views/RewriteModeView.swift b/Sources/Fluid/Views/RewriteModeView.swiftindex 1a91a7d8..26109422 100644--- a/Sources/Fluid/Views/RewriteModeView.swift+++ b/Sources/Fluid/Views/RewriteModeView.swift@@ -25,7 +25,7 @@ struct RewriteModeView: View {Image(systemName: "pencil.and.outline").font(.title2).foregroundStyle(self.theme.palette.accent)- Text("Write Mode")+ Text("Edit Mode").font(.title2).fontWeight(.bold)@@ -40,6 +40,19 @@ struct RewriteModeView: View {.padding().background(self.theme.palette.windowBackground)+ HStack(spacing: 6) {+ Image(systemName: "info.circle")+ .font(.caption)+ .foregroundStyle(self.theme.palette.secondaryText)+ Text("Edit Mode is powered by Custom Prompts.")+ .font(.caption)+ .foregroundStyle(self.theme.palette.secondaryText)+ Spacer(minLength: 0)+ }+ .padding(.horizontal)+ .padding(.bottom, 8)+ .background(self.theme.palette.windowBackground)+// How To (collapsible)self.howToSection@@ -79,7 +92,7 @@ struct RewriteModeView: View {Image(systemName: "text.bubble").font(.system(size: 48)).foregroundStyle(self.theme.palette.accent)- Text("Write Mode")+ Text("Edit Mode").font(.title2).fontWeight(.bold)Text("Ask the AI to write anything for you - emails, replies, summaries, answers, and more.")@@ -193,8 +206,8 @@ struct RewriteModeView: View {// Input field (flexible)TextField(self.service.originalText.isEmpty- ? "Ask me to write anything..."- : "How should I rewrite this?",+ ? "Ask me to write or edit..."+ : "How should I edit this?",text: self.$inputText).textFieldStyle(.roundedBorder)@@ -334,9 +347,9 @@ struct RewriteModeView: View {if self.showHowTo {VStack(alignment: .leading, spacing: 12) {- // Write fresh+ // Create new textVStack(alignment: .leading, spacing: 4) {- Text("To Write Fresh")+ Text("Create New Text").font(.caption).fontWeight(.semibold).foregroundStyle(.secondary)@@ -360,9 +373,9 @@ struct RewriteModeView: View {self.howToItem("\"Draft a thank you note\"")}- // Rewrite+ // Edit selected textVStack(alignment: .leading, spacing: 4) {- Text("To Rewrite/Edit")+ Text("Edit Selected Text").font(.caption).fontWeight(.semibold).foregroundStyle(.secondary)diff --git a/Tests/FluidDictationIntegrationTests/DictationE2ETests.swift b/Tests/FluidDictationIntegrationTests/DictationE2ETests.swiftindex 68201136..c9e93417 100644--- a/Tests/FluidDictationIntegrationTests/DictationE2ETests.swift+++ b/Tests/FluidDictationIntegrationTests/DictationE2ETests.swift@@ -4,6 +4,42 @@ import XCTest@testable import FluidVoice_Debugfinal class DictationE2ETests: XCTestCase {+ private let enableTranscriptionSoundsKey = "EnableTranscriptionSounds"+ private let transcriptionStartSoundKey = "TranscriptionStartSound"++ func testTranscriptionStartSound_noneOptionHasNoFile() {+ XCTAssertEqual(SettingsStore.TranscriptionStartSound.none.displayName, "None")+ XCTAssertNil(SettingsStore.TranscriptionStartSound.none.soundFileName)+ }++ func testTranscriptionStartSound_legacyDisabledToggleMigratesToNone() {+ self.withRestoredDefaults(keys: [self.enableTranscriptionSoundsKey, self.transcriptionStartSoundKey]) {+ let defaults = UserDefaults.standard+ defaults.set(false, forKey: self.enableTranscriptionSoundsKey)+ defaults.set(SettingsStore.TranscriptionStartSound.fluidSfx1.rawValue, forKey: self.transcriptionStartSoundKey)++ let value = SettingsStore.shared.transcriptionStartSound++ XCTAssertEqual(value, .none)+ XCTAssertNil(defaults.object(forKey: self.enableTranscriptionSoundsKey))+ XCTAssertEqual(defaults.string(forKey: self.transcriptionStartSoundKey), SettingsStore.TranscriptionStartSound.none.rawValue)+ }+ }++ func testTranscriptionStartSound_legacyEnabledToggleKeepsSelectedSound() {+ self.withRestoredDefaults(keys: [self.enableTranscriptionSoundsKey, self.transcriptionStartSoundKey]) {+ let defaults = UserDefaults.standard+ defaults.set(true, forKey: self.enableTranscriptionSoundsKey)+ defaults.set(SettingsStore.TranscriptionStartSound.fluidSfx2.rawValue, forKey: self.transcriptionStartSoundKey)++ let value = SettingsStore.shared.transcriptionStartSound++ XCTAssertEqual(value, .fluidSfx2)+ XCTAssertNil(defaults.object(forKey: self.enableTranscriptionSoundsKey))+ XCTAssertEqual(defaults.string(forKey: self.transcriptionStartSoundKey), SettingsStore.TranscriptionStartSound.fluidSfx2.rawValue)+ }+ }+func testDictationEndToEnd_whisperTiny_transcribesFixture() async throws {// ArrangeSettingsStore.shared.shareAnonymousAnalytics = false@@ -63,4 +99,26 @@ final class DictationE2ETests: XCTestCase {return collapsed}++ private func withRestoredDefaults(keys: [String], run: () -> Void) {+ let defaults = UserDefaults.standard+ var snapshot: [String: Any] = [:]+ for key in keys {+ if let value = defaults.object(forKey: key) {+ snapshot[key] = value+ }+ }++ defer {+ for key in keys {+ if let previous = snapshot[key] {+ defaults.set(previous, forKey: key)+ } else {+ defaults.removeObject(forKey: key)+ }+ }+ }++ run()+ }}diff --git a/build.sh b/build.shnew file mode 100755index 00000000..86d7fef4--- /dev/null+++ b/build.sh@@ -0,0 +1,30 @@+#!/bin/bash++# FluidVoice Build Profile Router+# Routes to existing scripts without changing build_dev.sh behavior.+#+# Usage:+# ./build.sh # dev/full-compatible path (build_dev.sh)+# ./build.sh dev # same as above+# ./build.sh full # same as above+# ./build.sh incremental # fast local loop (build_incremental.sh)+# BUILD_PROFILE=incremental ./build.sh++set -euo pipefail++PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"+PROFILE="${1:-${BUILD_PROFILE:-dev}}"++case "${PROFILE}" in+ dev|full)+ exec "${PROJECT_DIR}/build_dev.sh"+ ;;+ incremental|fast)+ exec "${PROJECT_DIR}/build_incremental.sh"+ ;;+ *)+ echo "Unknown build profile: ${PROFILE}"+ echo "Valid profiles: dev, full, incremental (or fast)"+ exit 1+ ;;+esacdiff --git a/build_incremental.sh b/build_incremental.shnew file mode 100755index 00000000..92f05766--- /dev/null+++ b/build_incremental.sh@@ -0,0 +1,22 @@+#!/bin/bash++# FluidVoice Fast Incremental Build Wrapper+# Keeps build_dev.sh unchanged; only overrides defaults for local fast loops.+#+# Defaults:+# - Release configuration+# - Incremental Swift compilation+# - Install + launch enabled+#+# You can override any value:+# INSTALL_APP=1 LAUNCH_APP=1 ./build_incremental.sh++set -euo pipefail++PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"++CONFIGURATION="${CONFIGURATION:-Release}" \+SWIFT_COMPILATION_MODE="${SWIFT_COMPILATION_MODE:-incremental}" \+INSTALL_APP="${INSTALL_APP:-1}" \+LAUNCH_APP="${LAUNCH_APP:-1}" \+"${PROJECT_DIR}/build_dev.sh"diff --git a/docs/MACOS_UI_AUTOMATION_BRANCH_PLAN.md b/docs/MACOS_UI_AUTOMATION_BRANCH_PLAN.mdnew file mode 100644index 00000000..8efac2d7--- /dev/null+++ b/docs/MACOS_UI_AUTOMATION_BRANCH_PLAN.md@@ -0,0 +1,97 @@+# macOS UI Automation Plan (Separate Branch)++## Goal+Build reliable automated test coverage for FluidVoice native macOS UI behavior (overlay, prompt picker, mode switching, context behavior), without blocking release stabilization work.++## Branch Strategy+- Branch name: `B/macos-ui-automation`+- Keep this work isolated from release branch changes.+- No schema/storage migrations in this branch unless explicitly required for testability.++## Scope+- Add stable accessibility identifiers for key UI controls.+- Add macOS `XCUITest` smoke coverage for Dictate/Edit/Command interaction flows.+- Add deterministic app launch mode for UI tests (`--ui-testing`) to reduce flakiness.+- Add targeted logic tests for migration/state synchronization edge cases.++## Out of Scope+- Per-prompt shortcut assignment.+- Product behavior redesign.+- Replacing rewrite internals in this phase.++## Phase 1: Testability Hooks (Accessibility IDs)+### Files likely to touch+- `/Users/barathwajanandan/Documents/mac_apps/FluidVoice/Sources/Fluid/Views/BottomOverlayView.swift`+- `/Users/barathwajanandan/Documents/mac_apps/FluidVoice/Sources/Fluid/Views/NotchContentViews.swift`+- `/Users/barathwajanandan/Documents/mac_apps/FluidVoice/Sources/Fluid/UI/AISettingsView+AdvancedSettings.swift`++### IDs to add first+- Prompt chip button+- Prompt menu tab: Dictate+- Prompt menu tab: Edit+- Prompt list row (profile)+- Selected checkmark container+- Right-side mode label+- Context toggle (editor)+- Save button (editor)++## Phase 2: UI Smoke Suite (`XCUITest`)+### New target/files+- `/Users/barathwajanandan/Documents/mac_apps/FluidVoice/Tests/FluidVoiceUITests/FluidVoiceUITests.swift`+- `/Users/barathwajanandan/Documents/mac_apps/FluidVoice/Tests/FluidVoiceUITests/PromptPickerSmokeTests.swift`+- `/Users/barathwajanandan/Documents/mac_apps/FluidVoice/Tests/FluidVoiceUITests/ModeSwitchSmokeTests.swift`++### Initial smoke tests+1. Prompt picker tab switch keeps chip/tab/checkmark aligned.+2. Dictate -> Edit live switch updates right-side label to `Edit`.+3. Edit -> Dictate live switch updates right-side label to `Dictate`.+4. Command mode entry/exit does not corrupt picker mode state.+5. Prompt selection persists after close/reopen of overlay.++## Phase 3: Deterministic UI Test Runtime+### Files likely to touch+- `/Users/barathwajanandan/Documents/mac_apps/FluidVoice/Sources/Fluid/FluidApp.swift`+- `/Users/barathwajanandan/Documents/mac_apps/FluidVoice/Sources/Fluid/ContentView.swift`+- `/Users/barathwajanandan/Documents/mac_apps/FluidVoice/Sources/Fluid/Services/NotchOverlayManager.swift`++### Additions+- `--ui-testing` launch argument handling.+- Disable or stub fragile external dependencies in test mode where needed (network/transcription side effects).+- Keep prompt composition logic intact; only remove nondeterminism.++## Phase 4: Logic/Concurrency Guard Tests+### Files likely to touch+- `/Users/barathwajanandan/Documents/mac_apps/FluidVoice/Tests/FluidTests/SettingsStorePromptMigrationTests.swift`+- `/Users/barathwajanandan/Documents/mac_apps/FluidVoice/Tests/FluidTests/PromptPickerStateSyncTests.swift`+- `/Users/barathwajanandan/Documents/mac_apps/FluidVoice/Tests/FluidTests/LiveModeSwitchTests.swift`++### Assertions+- Legacy write/rewrite prompt modes normalize to edit once.+- Normalized state does not re-write storage repeatedly.+- Live switch preserves context when already present.+- Processing guard blocks unsafe mode switch mutations.++## CI / Execution+- Add UI smoke job (macOS runner) gated on target branch or label.+- Keep runtime short (<= 3-5 minutes).+- Fail fast on first critical smoke failure.++## Performance and Low-Resource Principles+- Prefer small deterministic smoke tests over heavy end-to-end scripts.+- Avoid polling loops and long sleeps; use expectations with short timeouts.+- Reuse shared helpers to reduce startup overhead in tests.++## Definition of Done+1. Accessibility IDs exist for all prompt-picker critical controls.+2. Smoke suite passes locally and in CI.+3. No regression to Dictate/Edit/Command user-facing labels.+4. Migration/state sync tests cover known release-risk edges.+5. Test docs include how to run locally.++## Local Run Commands (to finalize when branch starts)+- Unit tests: `xcodebuild test -project Fluid.xcodeproj -scheme Fluid -destination 'platform=macOS,arch=arm64' -only-testing:FluidTests`+- UI tests: `xcodebuild test -project Fluid.xcodeproj -scheme Fluid -destination 'platform=macOS,arch=arm64' -only-testing:FluidVoiceUITests`++## Notes+- Keep internal compatibility symbols (`rewrite*`) unchanged in this automation branch unless needed for explicit test seams.+- Revisit per-prompt shortcut assignment in a later dedicated branch.