Skip to content

Commit 23c638d

Browse files
committed
Add custom command type description
1 parent 12dbf3c commit 23c638d

File tree

5 files changed

+628
-284
lines changed

5 files changed

+628
-284
lines changed

Core/Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ let package = Package(
128128
"CodeiumService",
129129
"SuggestionModel",
130130
"LaunchAgentManager",
131+
.product(name: "MarkdownUI", package: "swift-markdown-ui"),
131132
.product(name: "OpenAIService", package: "Tool"),
132133
.product(name: "Preferences", package: "Tool"),
134+
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
133135
]
134136
),
135137

Core/Sources/HostApp/CustomCommandView.swift renamed to Core/Sources/HostApp/CustomCommandSettings/CustomCommandView.swift

Lines changed: 100 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import ComposableArchitecture
2+
import MarkdownUI
13
import Preferences
24
import SwiftUI
35

@@ -29,8 +31,8 @@ struct CustomCommandView: View {
2931
}
3032

3133
@State var editingCommand: EditingCommand?
32-
3334
@StateObject var settings = Settings()
35+
@Environment(\.toast) var toast
3436

3537
var body: some View {
3638
HStack(spacing: 0) {
@@ -122,16 +124,81 @@ struct CustomCommandView: View {
122124

123125
if let editingCommand {
124126
EditCustomCommandView(
125-
editingCommand: $editingCommand,
126-
settings: settings
127+
store: .init(
128+
initialState: .init(editingCommand),
129+
reducer: EditCustomCommand(
130+
settings: settings,
131+
toast: toast,
132+
editingCommand: $editingCommand
133+
)
134+
)
127135
).id(editingCommand.command.id)
128136
} else {
129-
Color.clear
137+
CustomCommandTypeDescription(text: """
138+
# Send Message
139+
140+
This command sends a message to the active chat tab. You can provide additional context through the "Extra System Prompt" as well.
141+
142+
# Prompt to Code
143+
144+
This command opens the prompt-to-code panel and executes the provided requirements on the selected code. You can provide additional context through the "Extra Context" as well.
145+
146+
# Custom Chat
147+
148+
This command will overwrite the system prompt to let the bot behave differently.
149+
150+
# One-time Dialog
151+
152+
This command allows you to send a message to a temporary chat without opening the chat panel.
153+
154+
It is particularly useful for one-time commands, such as running a terminal command with `/run`.
155+
156+
For example, you can set the prompt to `/run open $FILE_PATH -a "Finder.app"` to reveal the active document in Finder.
157+
""")
130158
}
131159
}
132160
}
133161
}
134162

163+
struct CustomCommandTypeDescription: View {
164+
let text: String
165+
var body: some View {
166+
ScrollView {
167+
Markdown(text)
168+
.lineLimit(nil)
169+
.markdownTheme(
170+
.gitHub
171+
.text {
172+
ForegroundColor(.secondary)
173+
BackgroundColor(.clear)
174+
FontSize(14)
175+
}
176+
.heading1 { conf in
177+
VStack(alignment: .leading, spacing: 0) {
178+
conf.label
179+
.relativePadding(.bottom, length: .em(0.3))
180+
.relativeLineSpacing(.em(0.125))
181+
.markdownMargin(top: 24, bottom: 16)
182+
.markdownTextStyle {
183+
FontWeight(.semibold)
184+
FontSize(.em(1.25))
185+
}
186+
Divider()
187+
}
188+
}
189+
)
190+
.padding()
191+
.background(Color.primary.opacity(0.02), in: RoundedRectangle(cornerRadius: 8))
192+
.overlay {
193+
RoundedRectangle(cornerRadius: 8)
194+
.stroke(style: .init(lineWidth: 1))
195+
.foregroundColor(Color(nsColor: .separatorColor))
196+
}
197+
.padding()
198+
}
199+
}
200+
}
201+
135202
// MARK: - Previews
136203

137204
struct CustomCommandView_Preview: PreviewProvider {
@@ -171,3 +238,32 @@ struct CustomCommandView_Preview: PreviewProvider {
171238
}
172239
}
173240

241+
struct CustomCommandView_NoEditing_Preview: PreviewProvider {
242+
static var previews: some View {
243+
CustomCommandView(
244+
editingCommand: nil,
245+
settings: .init(customCommands: .init(wrappedValue: [
246+
.init(
247+
commandId: "1",
248+
name: "Explain Code",
249+
feature: .chatWithSelection(
250+
extraSystemPrompt: nil,
251+
prompt: "Hello",
252+
useExtraSystemPrompt: false
253+
)
254+
),
255+
.init(
256+
commandId: "2",
257+
name: "Refactor Code",
258+
feature: .promptToCode(
259+
extraSystemPrompt: nil,
260+
prompt: "Refactor",
261+
continuousMode: false,
262+
generateDescription: true
263+
)
264+
),
265+
], "CustomCommandView_Preview"))
266+
)
267+
}
268+
}
269+

0 commit comments

Comments
 (0)