Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7fa80a3
Merge tag '0.25.0' into develop
intitni Oct 11, 2023
4dd4f2f
Add SuggestionServiceMiddleware
intitni Oct 15, 2023
e1a6722
Update
intitni Oct 15, 2023
5116c1d
Fix calling middleware creates infinite loop
intitni Oct 16, 2023
daab571
Merge branch 'feature/suggestion-cheatsheet-2' into develop
intitni Oct 16, 2023
b8ae34e
Support chat tab self-closing
intitni Oct 16, 2023
08b0d76
Add TerminalChatTab
intitni Oct 16, 2023
6cfab90
Update TerminalChatTab to support restoration
intitni Oct 16, 2023
c674551
Add icons to chat tab
intitni Oct 16, 2023
9c1a592
Update
intitni Oct 17, 2023
0e8cad3
Merge branch 'feature/terminal-tab' into develop
intitni Oct 17, 2023
f531278
Support ChatGPTService in debug window
intitni Oct 17, 2023
2ad4d33
Adjust system prompt
intitni Oct 18, 2023
6e1e387
Revert SwiftFocusCodeFinder behavior
intitni Oct 19, 2023
ec796af
Update
intitni Oct 19, 2023
4281a6a
Merge branch 'feature/adjust-symbol-detection-from-conversation' into…
intitni Oct 19, 2023
eec4881
Update
intitni Oct 20, 2023
8099410
Update
intitni Oct 20, 2023
0a28d58
Merge branch 'feature/retrieve-from-active-document-pre' into develop
intitni Oct 20, 2023
6f970de
Update getEditorContent to actively get the focused editor content wh…
intitni Oct 20, 2023
2d864ea
Update custom command template to support {{clipboard}}
intitni Oct 20, 2023
7701377
Update custom prompt to code to support templates
intitni Oct 20, 2023
f71eb47
Merge branch 'feature/custom-command-template-clipboard' into develop
intitni Oct 20, 2023
8dbb5eb
Add global hotkey to show/hide widget
intitni Oct 21, 2023
e77fd16
Allow making hotkey non-global
intitni Oct 21, 2023
9982ee3
Fix the timing of KeyboardShortcuts initialization
intitni Oct 21, 2023
88fc06b
Update README.md
intitni Oct 21, 2023
4983750
Fix that command+M is not hiding chat panel
intitni Oct 21, 2023
c2837ee
Update
intitni Oct 22, 2023
0b93f92
Move MessageScopeParser to ChatContextCollector
intitni Oct 22, 2023
27c9cdc
Fix that the host app is observing the global shortcut
intitni Oct 22, 2023
dd398b5
Fix archiving
intitni Oct 22, 2023
b72dcca
Update README.md
intitni Oct 22, 2023
2cbd4b6
Update
intitni Oct 22, 2023
48f92d5
Update
intitni Oct 22, 2023
d64c817
Bump version to 0.26.0
intitni Oct 22, 2023
f9d2241
Update appcast.xml
intitni Oct 22, 2023
cd41739
Merge branch 'release/0.26.0'
intitni Oct 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Core/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ let isProIncluded: Bool = {
return false
}
do {
if let content = String(
data: try Data(contentsOf: confURL),
if let content = try String(
data: Data(contentsOf: confURL),
encoding: .utf8
) {
if content.hasPrefix("YES") {
Expand Down Expand Up @@ -98,6 +98,9 @@ let package = Package(
url: "https://github.com/pointfreeco/swift-composable-architecture",
from: "0.55.0"
),
// quick hack to support custom UserDefaults
// https://github.com/sindresorhus/KeyboardShortcuts
.package(url: "https://github.com/intitni/KeyboardShortcuts", branch: "main"),
].pro,
targets: [
// MARK: - Main
Expand Down Expand Up @@ -134,6 +137,7 @@ let package = Package(
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "Dependencies", package: "swift-dependencies"),
.product(name: "KeyboardShortcuts", package: "KeyboardShortcuts"),
].pro([
"ProService",
])
Expand Down Expand Up @@ -168,6 +172,7 @@ let package = Package(
.product(name: "OpenAIService", package: "Tool"),
.product(name: "Preferences", package: "Tool"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "KeyboardShortcuts", package: "KeyboardShortcuts"),
].pro([
"ProHostApp",
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public final class SystemInfoChatContextCollector: ChatContextCollector {
) -> ChatContext {
return .init(
systemPrompt: """
Current Time: \(
Self.dateFormatter.string(from: Date())
) (You can use it to calculate time in another time zone)
""",
## System Info

Current Time: \(
Self.dateFormatter.string(from: Date())
) (You can use it to calculate time in another time zone)
""",
retrievedContent: [],
functions: []
)
Expand Down
11 changes: 11 additions & 0 deletions Core/Sources/ChatGPTChatTab/ChatGPTChatTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public class ChatGPTChatTab: ChatTab {
ChatTabItemView(chat: chat)
}

public func buildIcon() -> any View {
WithViewStore(chat, observe: \.isReceivingMessage) { viewStore in
if viewStore.state {
Image(systemName: "ellipsis.message")
} else {
Image(systemName: "message")
}
}
}

public func buildMenu() -> any View {
ChatContextMenu(store: chat.scope(state: \.chatMenu, action: Chat.Action.chatMenu))
}
Expand Down Expand Up @@ -125,3 +135,4 @@ public class ChatGPTChatTab: ChatTab {
}.store(in: &cancellable)
}
}

1 change: 1 addition & 0 deletions Core/Sources/ChatGPTChatTab/ChatPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ struct ChatPanelMessages: View {
.foregroundStyle(.secondary)
.padding(4)
}
.keyboardShortcut(.downArrow, modifiers: [.command])
.opacity(pinnedToBottom ? 0 : 1)
.buttonStyle(.plain)
.onChange(of: viewStore.state) { _ in
Expand Down
11 changes: 9 additions & 2 deletions Core/Sources/ChatService/CustomCommandTemplateProcessor.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import AppKit
import Foundation
import SuggestionModel
import XcodeInspector

struct CustomCommandTemplateProcessor {
func process(_ text: String) -> String {
public struct CustomCommandTemplateProcessor {
public init() {}

public func process(_ text: String) -> String {
let info = getEditorInformation()
let editorContent = info.editorContent
let updatedText = text
Expand All @@ -22,6 +25,10 @@ struct CustomCommandTemplateProcessor {
of: "{{active_editor_file_name}}",
with: info.documentURL?.lastPathComponent ?? ""
)
.replacingOccurrences(
of: "{{clipboard}}",
with: NSPasteboard.general.string(forType: .string) ?? ""
)
return updatedText
}

Expand Down
35 changes: 6 additions & 29 deletions Core/Sources/ChatService/DynamicContextController.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ChatContextCollector
import Foundation
import OpenAIService
import Parsing
import Preferences
import XcodeInspector

Expand Down Expand Up @@ -65,17 +64,17 @@ final class DynamicContextController {
}
return contexts
}

let extraSystemPrompt = contexts
.map(\.systemPrompt)
.filter { !$0.isEmpty }
.joined(separator: "\n")
.joined(separator: "\n\n")

let contextPrompts = contexts
.flatMap(\.retrievedContent)
.filter { !$0.content.isEmpty }
.sorted { $0.priority > $1.priority }

let contextualSystemPrompt = """
\(language.isEmpty ? "" : "You must always reply in \(language)")
\(systemPrompt)\(extraSystemPrompt.isEmpty ? "" : "\n\(extraSystemPrompt)")
Expand All @@ -88,30 +87,8 @@ final class DynamicContextController {

extension DynamicContextController {
static func parseScopes(_ prompt: inout String) -> Set<String> {
guard !prompt.isEmpty else { return [] }
do {
let parser = Parse {
"@"
Many {
Prefix { $0.isLetter }
} separator: {
"+"
} terminator: {
" "
}
Skip {
Many {
" "
}
}
Rest()
}
let (scopes, rest) = try parser.parse(prompt)
prompt = String(rest)
return Set(scopes.map(String.init))
} catch {
return []
}
let parser = MessageScopeParser()
return parser(&prompt)
}
}

14 changes: 13 additions & 1 deletion Core/Sources/HostApp/GeneralView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Client
import ComposableArchitecture
import KeyboardShortcuts
import LaunchAgentManager
import Preferences
import SwiftUI
Expand Down Expand Up @@ -224,6 +225,8 @@ struct GeneralSettingsView: View {
var preferWidgetToStayInsideEditorWhenWidthGreaterThan
@AppStorage(\.hideCircularWidget)
var hideCircularWidget
@AppStorage(\.showHideWidgetShortcutGlobally)
var showHideWidgetShortcutGlobally
}

@StateObject var settings = Settings()
Expand Down Expand Up @@ -286,6 +289,15 @@ struct GeneralSettingsView: View {
Text("pt")
}

KeyboardShortcuts.Recorder("Hotkey to Toggle Widgets", name: .showHideWidget) { _ in
// It's not used in this app!
KeyboardShortcuts.disable(.showHideWidget)
}

Toggle(isOn: $settings.showHideWidgetShortcutGlobally) {
Text("Enable the Hotkey Globally")
}

Toggle(isOn: $settings.hideCircularWidget) {
Text("Hide circular widget")
}
Expand Down Expand Up @@ -342,7 +354,7 @@ struct LargeIconPicker<
}
}
}

var body: some View {
if #available(macOS 13.0, *) {
LabeledContent {
Expand Down
25 changes: 18 additions & 7 deletions Core/Sources/HostApp/HostApp.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import Client
import ComposableArchitecture
import Foundation
import KeyboardShortcuts

#if canImport(LicenseManagement)
import LicenseManagement
#endif

extension KeyboardShortcuts.Name {
static let showHideWidget = Self("ShowHideWidget")
}

struct HostApp: ReducerProtocol {
struct State: Equatable {
var general = General.State()
Expand All @@ -22,16 +27,20 @@ struct HostApp: ReducerProtocol {
}

@Dependency(\.toast) var toast

init() {
KeyboardShortcuts.userDefaults = .shared
}

var body: some ReducerProtocol<State, Action> {
Scope(state: \.general, action: /Action.general) {
General()
}

Scope(state: \.chatModelManagement, action: /Action.chatModelManagement) {
ChatModelManagement()
}

Scope(state: \.embeddingModelManagement, action: /Action.embeddingModelManagement) {
EmbeddingModelManagement()
}
Expand All @@ -40,7 +49,7 @@ struct HostApp: ReducerProtocol {
switch action {
case .appear:
return .none

case .informExtensionServiceAboutLicenseKeyChange:
#if canImport(LicenseManagement)
return .run { _ in
Expand All @@ -55,13 +64,13 @@ struct HostApp: ReducerProtocol {
#else
return .none
#endif

case .general:
return .none

case .chatModelManagement:
return .none

case .embeddingModelManagement:
return .none
}
Expand All @@ -70,8 +79,8 @@ struct HostApp: ReducerProtocol {
}

import Dependencies
import Preferences
import Keychain
import Preferences

struct UserDefaultsDependencyKey: DependencyKey {
static var liveValue: UserDefaultsType = UserDefaults.shared
Expand All @@ -80,6 +89,7 @@ struct UserDefaultsDependencyKey: DependencyKey {
it.removePersistentDomain(forName: "HostAppPreview")
return it
}()

static var testValue: UserDefaultsType = {
let it = UserDefaults(suiteName: "HostAppTest")!
it.removePersistentDomain(forName: "HostAppTest")
Expand All @@ -106,3 +116,4 @@ extension DependencyValues {
set { self[APIKeyKeychainDependencyKey.self] = newValue }
}
}

1 change: 1 addition & 0 deletions Core/Sources/Service/GUI/ChatTabFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum ChatTabFactory {
),
title: BrowserChatTab.name
),
folderIfNeeded(TerminalChatTab.chatBuilders(), title: TerminalChatTab.name),
].compactMap { $0 }

return collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,12 @@ extension ChatTabPool {
externalDependency: ChatTabFactory.externalDependenciesForBrowserChatTab()
) else { break }
return await createTab(id: data.id, from: builder)
case TerminalChatTab.name:
guard let builder = try? await TerminalChatTab.restore(
from: data.data,
externalDependency: ()
) else { break }
return await createTab(id: data.id, from: builder)
default:
break
}
Expand All @@ -397,7 +403,7 @@ extension ChatTabPool {
) else {
return nil
}
return await createTab(from: builder)
return await createTab(id: data.id, from: builder)
}
#endif
}
Expand Down
Loading