feat(ios): add new task workspace controls
This commit is contained in:
8 files changed
+564
-13
No files matched your search
@@ -132,6 +132,7 @@ public final class FeatureRootModel {
|
||||
public func startTask(_ request: NewTaskRequest) async -> FeatureThread? {
|
||||
let prompt = request.trimmedPrompt
|
||||
guard !prompt.isEmpty || !request.attachments.isEmpty else { return nil }
|
||||
guard request.workspaceMode != .worktree || request.branch != nil else { return nil }
|
||||
|
||||
let environment = currentEnvironmentIdentity
|
||||
var created: FeatureThread?
|
||||
@@ -142,6 +143,10 @@ public final class FeatureRootModel {
|
||||
selection: request.selection,
|
||||
runtimeMode: request.runtimeMode.mobileNormalized,
|
||||
interactionMode: request.interactionMode.mobileNormalized,
|
||||
workspaceMode: request.workspaceMode,
|
||||
branch: request.branch,
|
||||
worktreePath: request.worktreePath,
|
||||
startFromOrigin: request.startFromOrigin,
|
||||
attachments: request.attachments.map(\.upload)
|
||||
)
|
||||
guard currentEnvironmentIdentity == environment else {
|
||||
@@ -153,6 +158,13 @@ public final class FeatureRootModel {
|
||||
return succeeded ? created : nil
|
||||
}
|
||||
|
||||
public func workspaceBranches(
|
||||
projectID: String,
|
||||
refresh: Bool = false
|
||||
) async throws -> [FeatureWorkspaceBranch] {
|
||||
try await client.listWorkspaceBranches(projectID: projectID, refresh: refresh)
|
||||
}
|
||||
|
||||
public func renameThread(_ id: String, title: String) async {
|
||||
let environment = currentEnvironmentIdentity
|
||||
await perform {
|
||||
|
||||
@@ -22,6 +22,22 @@ public protocol FeatureClient: AnyObject {
|
||||
interactionMode: FeatureInteractionMode,
|
||||
attachments: [FeatureUploadAttachment]
|
||||
) async throws -> FeatureThread
|
||||
func createThreadAndSend(
|
||||
projectID: String,
|
||||
prompt: String,
|
||||
selection: FeatureSelection?,
|
||||
runtimeMode: FeatureRuntimeMode,
|
||||
interactionMode: FeatureInteractionMode,
|
||||
workspaceMode: FeatureWorkspaceMode,
|
||||
branch: String?,
|
||||
worktreePath: String?,
|
||||
startFromOrigin: Bool,
|
||||
attachments: [FeatureUploadAttachment]
|
||||
) async throws -> FeatureThread
|
||||
func listWorkspaceBranches(
|
||||
projectID: String,
|
||||
refresh: Bool
|
||||
) async throws -> [FeatureWorkspaceBranch]
|
||||
func renameThread(id: String, title: String) async throws
|
||||
func setThreadArchived(id: String, archived: Bool) async throws
|
||||
func setThreadSettled(id: String, settled: Bool) async throws
|
||||
@@ -89,6 +105,37 @@ public extension FeatureClient {
|
||||
func setRuntimeMode(id: String, mode: FeatureRuntimeMode) async throws {}
|
||||
func setInteractionMode(id: String, mode: FeatureInteractionMode) async throws {}
|
||||
|
||||
func listWorkspaceBranches(
|
||||
projectID: String,
|
||||
refresh: Bool
|
||||
) async throws -> [FeatureWorkspaceBranch] {
|
||||
[]
|
||||
}
|
||||
|
||||
/// Legacy clients still create in the current checkout. Native clients
|
||||
/// override this overload to prepare worktrees atomically with the first turn.
|
||||
func createThreadAndSend(
|
||||
projectID: String,
|
||||
prompt: String,
|
||||
selection: FeatureSelection?,
|
||||
runtimeMode: FeatureRuntimeMode,
|
||||
interactionMode: FeatureInteractionMode,
|
||||
workspaceMode: FeatureWorkspaceMode,
|
||||
branch: String?,
|
||||
worktreePath: String?,
|
||||
startFromOrigin: Bool,
|
||||
attachments: [FeatureUploadAttachment]
|
||||
) async throws -> FeatureThread {
|
||||
try await createThreadAndSend(
|
||||
projectID: projectID,
|
||||
prompt: prompt,
|
||||
selection: selection,
|
||||
runtimeMode: runtimeMode,
|
||||
interactionMode: interactionMode,
|
||||
attachments: attachments
|
||||
)
|
||||
}
|
||||
|
||||
func createThreadAndSend(
|
||||
projectID: String,
|
||||
prompt: String,
|
||||
|
||||
@@ -32,6 +32,10 @@ public struct NewTaskRequest: Sendable, Equatable {
|
||||
public var selection: FeatureSelection?
|
||||
public var runtimeMode: FeatureRuntimeMode
|
||||
public var interactionMode: FeatureInteractionMode
|
||||
public var workspaceMode: FeatureWorkspaceMode
|
||||
public var branch: String?
|
||||
public var worktreePath: String?
|
||||
public var startFromOrigin: Bool
|
||||
public var attachments: [FeatureDraftAttachment]
|
||||
|
||||
public init(
|
||||
@@ -40,6 +44,10 @@ public struct NewTaskRequest: Sendable, Equatable {
|
||||
selection: FeatureSelection?,
|
||||
runtimeMode: FeatureRuntimeMode,
|
||||
interactionMode: FeatureInteractionMode,
|
||||
workspaceMode: FeatureWorkspaceMode = .local,
|
||||
branch: String? = nil,
|
||||
worktreePath: String? = nil,
|
||||
startFromOrigin: Bool = true,
|
||||
attachments: [FeatureDraftAttachment] = []
|
||||
) {
|
||||
self.projectID = projectID
|
||||
@@ -47,12 +55,24 @@ public struct NewTaskRequest: Sendable, Equatable {
|
||||
self.selection = selection
|
||||
self.runtimeMode = runtimeMode.mobileNormalized
|
||||
self.interactionMode = interactionMode.mobileNormalized
|
||||
self.workspaceMode = workspaceMode
|
||||
self.branch = Self.nonEmpty(branch)
|
||||
self.worktreePath = workspaceMode == .local ? Self.nonEmpty(worktreePath) : nil
|
||||
self.startFromOrigin = workspaceMode == .worktree && startFromOrigin
|
||||
self.attachments = attachments
|
||||
}
|
||||
|
||||
public var trimmedPrompt: String {
|
||||
prompt.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
|
||||
private static func nonEmpty(_ value: String?) -> String? {
|
||||
guard let trimmed = value?.trimmingCharacters(in: .whitespacesAndNewlines),
|
||||
!trimmed.isEmpty else {
|
||||
return nil
|
||||
}
|
||||
return trimmed
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeatureMessageSubmission: Sendable, Equatable {
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import Foundation
|
||||
|
||||
public enum FeatureWorkspaceMode: String, CaseIterable, Sendable, Codable {
|
||||
case local
|
||||
case worktree
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .local: "Current checkout"
|
||||
case .worktree: "New worktree"
|
||||
}
|
||||
}
|
||||
|
||||
var systemImage: String {
|
||||
switch self {
|
||||
case .local: "folder"
|
||||
case .worktree: "arrow.triangle.branch"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeatureWorkspaceBranch: Identifiable, Sendable, Equatable, Hashable {
|
||||
public var name: String
|
||||
public var isRemote: Bool
|
||||
public var isCurrent: Bool
|
||||
public var isDefault: Bool
|
||||
public var worktreePath: String?
|
||||
|
||||
public init(
|
||||
name: String,
|
||||
isRemote: Bool = false,
|
||||
isCurrent: Bool = false,
|
||||
isDefault: Bool = false,
|
||||
worktreePath: String? = nil
|
||||
) {
|
||||
self.name = name
|
||||
self.isRemote = isRemote
|
||||
self.isCurrent = isCurrent
|
||||
self.isDefault = isDefault
|
||||
self.worktreePath = worktreePath
|
||||
}
|
||||
|
||||
public var id: String {
|
||||
"\(isRemote ? "remote" : "local"):\(name)"
|
||||
}
|
||||
|
||||
var badge: String? {
|
||||
if isCurrent { return "Current" }
|
||||
if worktreePath != nil { return "Worktree" }
|
||||
if isDefault { return "Default" }
|
||||
if isRemote { return "Remote" }
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
enum NewTaskWorkspaceDefaults {
|
||||
static func localBranch(in branches: [FeatureWorkspaceBranch]) -> FeatureWorkspaceBranch? {
|
||||
branches.first { $0.isCurrent }
|
||||
?? branches.first { $0.isDefault && !$0.isRemote }
|
||||
?? branches.first { !$0.isRemote }
|
||||
?? branches.first
|
||||
}
|
||||
|
||||
static func worktreeBase(in branches: [FeatureWorkspaceBranch]) -> FeatureWorkspaceBranch? {
|
||||
branches.first { $0.isDefault && !$0.isRemote }
|
||||
?? branches.first { $0.isCurrent }
|
||||
?? branches.first { $0.isDefault }
|
||||
?? branches.first { !$0.isRemote }
|
||||
?? branches.first
|
||||
}
|
||||
|
||||
static func normalizedWorktreePath(
|
||||
for branch: FeatureWorkspaceBranch?,
|
||||
projectPath: String
|
||||
) -> String? {
|
||||
guard let path = branch?.worktreePath?.trimmingCharacters(in: .whitespacesAndNewlines),
|
||||
!path.isEmpty,
|
||||
URL(fileURLWithPath: path).standardizedFileURL.path
|
||||
!= URL(fileURLWithPath: projectPath).standardizedFileURL.path else {
|
||||
return nil
|
||||
}
|
||||
return path
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,13 @@ public struct NewThreadView: View {
|
||||
@State private var prompt = ""
|
||||
@State private var selection: FeatureSelection?
|
||||
@State private var attachments: [FeatureDraftAttachment] = []
|
||||
@State private var workspaceMode: FeatureWorkspaceMode = .local
|
||||
@State private var branches: [FeatureWorkspaceBranch] = []
|
||||
@State private var selectedBranch: FeatureWorkspaceBranch?
|
||||
@State private var startFromOrigin = true
|
||||
@State private var branchesLoading = false
|
||||
@State private var branchLoadFailed = false
|
||||
@State private var showingBranchPicker = false
|
||||
@State private var isSubmitting = false
|
||||
@State private var submissionFailed = false
|
||||
@FocusState private var promptFocused: Bool
|
||||
@@ -36,19 +43,24 @@ public struct NewThreadView: View {
|
||||
}
|
||||
}
|
||||
.safeAreaInset(edge: .bottom, spacing: 0) {
|
||||
FeatureComposerView(
|
||||
text: $prompt,
|
||||
selection: $selection,
|
||||
attachments: $attachments,
|
||||
providers: creationProviders,
|
||||
threadSelection: nil,
|
||||
isSending: isSubmitting,
|
||||
isWorking: false,
|
||||
focused: $promptFocused,
|
||||
onSend: startTask,
|
||||
onStop: {},
|
||||
forceExpanded: true
|
||||
)
|
||||
VStack(spacing: 0) {
|
||||
workspaceControls
|
||||
|
||||
FeatureComposerView(
|
||||
text: $prompt,
|
||||
selection: $selection,
|
||||
attachments: $attachments,
|
||||
providers: creationProviders,
|
||||
threadSelection: nil,
|
||||
isSending: isSubmitting,
|
||||
isWorking: false,
|
||||
focused: $promptFocused,
|
||||
onSend: startTask,
|
||||
onStop: {},
|
||||
forceExpanded: true
|
||||
)
|
||||
}
|
||||
.background(T3Colors.background)
|
||||
}
|
||||
.onAppear {
|
||||
if projectID.isEmpty {
|
||||
@@ -60,6 +72,21 @@ public struct NewThreadView: View {
|
||||
}
|
||||
.onChange(of: projectID) {
|
||||
selection = initialSelection
|
||||
resetWorkspaceSelection()
|
||||
}
|
||||
.task(id: projectID) { await loadBranches() }
|
||||
.sheet(isPresented: $showingBranchPicker) {
|
||||
NewTaskBranchPicker(
|
||||
branches: branches,
|
||||
selection: selectedBranch,
|
||||
isLoading: branchesLoading,
|
||||
loadFailed: branchLoadFailed,
|
||||
onSelect: { branch in
|
||||
selectedBranch = branch
|
||||
showingBranchPicker = false
|
||||
},
|
||||
onRefresh: { Task { await loadBranches(refresh: true) } }
|
||||
)
|
||||
}
|
||||
.alert("Couldn’t start task", isPresented: $submissionFailed) {
|
||||
Button("OK") {}
|
||||
@@ -141,6 +168,101 @@ public struct NewThreadView: View {
|
||||
creationProjects.first { $0.id == projectID }
|
||||
}
|
||||
|
||||
private var workspaceControls: some View {
|
||||
HStack(spacing: 14) {
|
||||
Menu {
|
||||
Button {
|
||||
setWorkspaceMode(.local)
|
||||
} label: {
|
||||
Label(
|
||||
FeatureWorkspaceMode.local.title,
|
||||
systemImage: workspaceMode == .local ? "checkmark" : "folder"
|
||||
)
|
||||
}
|
||||
Button {
|
||||
setWorkspaceMode(.worktree)
|
||||
} label: {
|
||||
Label(
|
||||
FeatureWorkspaceMode.worktree.title,
|
||||
systemImage: workspaceMode == .worktree
|
||||
? "checkmark"
|
||||
: "arrow.triangle.branch"
|
||||
)
|
||||
}
|
||||
} label: {
|
||||
workspaceControlLabel(
|
||||
workspaceMode.title,
|
||||
systemImage: workspaceMode.systemImage,
|
||||
showsChevron: true
|
||||
)
|
||||
}
|
||||
.disabled(isSubmitting)
|
||||
|
||||
if workspaceMode == .worktree {
|
||||
Button {
|
||||
showingBranchPicker = true
|
||||
} label: {
|
||||
workspaceControlLabel(
|
||||
selectedBranch?.name
|
||||
?? (branchesLoading ? "Loading branches" : "Choose branch"),
|
||||
systemImage: "arrow.triangle.branch",
|
||||
showsChevron: true
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(isSubmitting)
|
||||
.accessibilityLabel("Base branch")
|
||||
.accessibilityValue(selectedBranch?.name ?? "Not selected")
|
||||
|
||||
Button {
|
||||
startFromOrigin.toggle()
|
||||
} label: {
|
||||
Label(
|
||||
"Latest origin",
|
||||
systemImage: startFromOrigin ? "checkmark.circle.fill" : "circle"
|
||||
)
|
||||
.lineLimit(1)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.foregroundStyle(
|
||||
startFromOrigin ? T3Colors.textSecondary : T3Colors.textTertiary
|
||||
)
|
||||
.disabled(isSubmitting)
|
||||
.accessibilityValue(startFromOrigin ? "On" : "Off")
|
||||
} else if let selectedBranch {
|
||||
Label(selectedBranch.name, systemImage: "arrow.triangle.branch")
|
||||
.lineLimit(1)
|
||||
.foregroundStyle(T3Colors.textTertiary)
|
||||
.accessibilityLabel("Current branch, \(selectedBranch.name)")
|
||||
}
|
||||
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.font(T3Typography.supporting)
|
||||
.padding(.horizontal, 18)
|
||||
.frame(minHeight: 38)
|
||||
.animation(.snappy(duration: 0.18), value: workspaceMode)
|
||||
}
|
||||
|
||||
private func workspaceControlLabel(
|
||||
_ title: String,
|
||||
systemImage: String,
|
||||
showsChevron: Bool
|
||||
) -> some View {
|
||||
HStack(spacing: 5) {
|
||||
Image(systemName: systemImage)
|
||||
.font(.system(size: 12, weight: .medium))
|
||||
Text(title)
|
||||
.lineLimit(1)
|
||||
if showsChevron {
|
||||
Image(systemName: "chevron.down")
|
||||
.font(.system(size: 8, weight: .bold))
|
||||
}
|
||||
}
|
||||
.foregroundStyle(T3Colors.textSecondary)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
|
||||
private var creationProjects: [FeatureProject] {
|
||||
DailyUXCreationContext.projects(in: model.snapshot)
|
||||
}
|
||||
@@ -171,6 +293,7 @@ public struct NewThreadView: View {
|
||||
&& !projectID.isEmpty
|
||||
&& (!trimmedPrompt.isEmpty || !attachments.isEmpty)
|
||||
&& (attachments.isEmpty || imagesAllowed)
|
||||
&& (workspaceMode != .worktree || selectedBranch != nil)
|
||||
}
|
||||
|
||||
private var trimmedPrompt: String {
|
||||
@@ -194,6 +317,15 @@ public struct NewThreadView: View {
|
||||
selection: selection,
|
||||
runtimeMode: .fullAccess,
|
||||
interactionMode: .standard,
|
||||
workspaceMode: workspaceMode,
|
||||
branch: selectedBranch?.name,
|
||||
worktreePath: workspaceMode == .local
|
||||
? NewTaskWorkspaceDefaults.normalizedWorktreePath(
|
||||
for: selectedBranch,
|
||||
projectPath: selectedProject?.path ?? ""
|
||||
)
|
||||
: nil,
|
||||
startFromOrigin: startFromOrigin,
|
||||
attachments: attachments
|
||||
)
|
||||
|
||||
@@ -207,6 +339,64 @@ public struct NewThreadView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func resetWorkspaceSelection() {
|
||||
branches = []
|
||||
selectedBranch = nil
|
||||
branchLoadFailed = false
|
||||
}
|
||||
|
||||
private func setWorkspaceMode(_ mode: FeatureWorkspaceMode) {
|
||||
workspaceMode = mode
|
||||
selectedBranch = switch mode {
|
||||
case .local: NewTaskWorkspaceDefaults.localBranch(in: branches)
|
||||
case .worktree: NewTaskWorkspaceDefaults.worktreeBase(in: branches)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func loadBranches(refresh: Bool = false) async {
|
||||
let requestedProjectID = projectID
|
||||
guard !requestedProjectID.isEmpty else { return }
|
||||
|
||||
branchesLoading = true
|
||||
branchLoadFailed = false
|
||||
do {
|
||||
let loaded = try await model.workspaceBranches(
|
||||
projectID: requestedProjectID,
|
||||
refresh: refresh
|
||||
)
|
||||
guard !Task.isCancelled, projectID == requestedProjectID else { return }
|
||||
branches = loaded.sorted(by: Self.branchSort)
|
||||
|
||||
if let selectedBranch,
|
||||
let updated = branches.first(where: { $0.id == selectedBranch.id }) {
|
||||
self.selectedBranch = updated
|
||||
} else {
|
||||
self.selectedBranch = switch workspaceMode {
|
||||
case .local: NewTaskWorkspaceDefaults.localBranch(in: branches)
|
||||
case .worktree: NewTaskWorkspaceDefaults.worktreeBase(in: branches)
|
||||
}
|
||||
}
|
||||
} catch is CancellationError {
|
||||
return
|
||||
} catch {
|
||||
guard projectID == requestedProjectID else { return }
|
||||
branchLoadFailed = true
|
||||
}
|
||||
guard projectID == requestedProjectID else { return }
|
||||
branchesLoading = false
|
||||
}
|
||||
|
||||
private static func branchSort(
|
||||
_ lhs: FeatureWorkspaceBranch,
|
||||
_ rhs: FeatureWorkspaceBranch
|
||||
) -> Bool {
|
||||
let lhsRank = lhs.isCurrent ? 0 : lhs.isDefault ? 1 : lhs.isRemote ? 3 : 2
|
||||
let rhsRank = rhs.isCurrent ? 0 : rhs.isDefault ? 1 : rhs.isRemote ? 3 : 2
|
||||
if lhsRank != rhsRank { return lhsRank < rhsRank }
|
||||
return lhs.name.localizedCaseInsensitiveCompare(rhs.name) == .orderedAscending
|
||||
}
|
||||
}
|
||||
|
||||
private struct DottedUnderline: Shape {
|
||||
@@ -217,3 +407,108 @@ private struct DottedUnderline: Shape {
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
private struct NewTaskBranchPicker: View {
|
||||
@SwiftUI.Environment(\.dismiss) private var dismiss
|
||||
|
||||
let branches: [FeatureWorkspaceBranch]
|
||||
let selection: FeatureWorkspaceBranch?
|
||||
let isLoading: Bool
|
||||
let loadFailed: Bool
|
||||
let onSelect: (FeatureWorkspaceBranch) -> Void
|
||||
let onRefresh: () -> Void
|
||||
|
||||
@State private var query = ""
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Group {
|
||||
if isLoading, branches.isEmpty {
|
||||
ProgressView("Loading branches")
|
||||
.foregroundStyle(T3Colors.textSecondary)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
} else if filteredBranches.isEmpty {
|
||||
ContentUnavailableView {
|
||||
Label(
|
||||
loadFailed ? "Branches unavailable" : "No branches found",
|
||||
systemImage: loadFailed
|
||||
? "exclamationmark.triangle"
|
||||
: "arrow.triangle.branch"
|
||||
)
|
||||
} description: {
|
||||
Text(
|
||||
loadFailed
|
||||
? "Check the connection and try again."
|
||||
: "Try a different search."
|
||||
)
|
||||
} actions: {
|
||||
if loadFailed {
|
||||
Button("Try again", action: onRefresh)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List(filteredBranches) { branch in
|
||||
Button {
|
||||
onSelect(branch)
|
||||
} label: {
|
||||
HStack(spacing: 12) {
|
||||
Image(systemName: "arrow.triangle.branch")
|
||||
.foregroundStyle(T3Colors.textTertiary)
|
||||
|
||||
Text(branch.name)
|
||||
.foregroundStyle(T3Colors.textPrimary)
|
||||
.lineLimit(1)
|
||||
|
||||
Spacer(minLength: 10)
|
||||
|
||||
if let badge = branch.badge {
|
||||
Text(badge)
|
||||
.font(T3Typography.supporting)
|
||||
.foregroundStyle(T3Colors.textTertiary)
|
||||
}
|
||||
|
||||
if branch.id == selection?.id {
|
||||
Image(systemName: "checkmark")
|
||||
.font(.system(size: 13, weight: .semibold))
|
||||
.foregroundStyle(T3Colors.accent)
|
||||
}
|
||||
}
|
||||
.frame(minHeight: 34)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.listRowBackground(T3Colors.background)
|
||||
}
|
||||
.listStyle(.plain)
|
||||
.refreshable { onRefresh() }
|
||||
}
|
||||
}
|
||||
.background(T3Colors.background)
|
||||
.navigationTitle("Base branch")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.searchable(text: $query, prompt: "Search branches")
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("Cancel") { dismiss() }
|
||||
}
|
||||
ToolbarItem(placement: .primaryAction) {
|
||||
Button(action: onRefresh) {
|
||||
Image(systemName: "arrow.clockwise")
|
||||
}
|
||||
.disabled(isLoading)
|
||||
.accessibilityLabel("Refresh branches")
|
||||
}
|
||||
}
|
||||
}
|
||||
.presentationDetents([.medium, .large])
|
||||
.presentationBackground(T3Colors.background)
|
||||
.preferredColorScheme(.dark)
|
||||
}
|
||||
|
||||
private var filteredBranches: [FeatureWorkspaceBranch] {
|
||||
let trimmed = query.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else { return branches }
|
||||
return branches.filter {
|
||||
$0.name.localizedCaseInsensitiveContains(trimmed)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,10 @@ public struct WorkspaceView: View {
|
||||
selection: request.selection,
|
||||
runtimeMode: request.runtimeMode,
|
||||
interactionMode: request.interactionMode,
|
||||
workspaceMode: request.workspaceMode,
|
||||
branch: request.branch,
|
||||
worktreePath: request.worktreePath,
|
||||
startFromOrigin: request.startFromOrigin,
|
||||
attachments: request.attachments.map(\.uploadValue)
|
||||
)
|
||||
await model.reload()
|
||||
|
||||
@@ -24,9 +24,66 @@ struct DailyUXNewTaskTests {
|
||||
#expect(request.trimmedPrompt == "Build it")
|
||||
#expect(request.runtimeMode == .automatic)
|
||||
#expect(request.interactionMode == .standard)
|
||||
#expect(request.workspaceMode == .local)
|
||||
#expect(request.branch == nil)
|
||||
#expect(request.worktreePath == nil)
|
||||
#expect(!request.startFromOrigin)
|
||||
#expect(request.attachments.first?.byteCount == 3)
|
||||
}
|
||||
|
||||
@Test
|
||||
func worktreeRequestKeepsBaseBranchAndDropsExistingCheckoutPath() {
|
||||
let request = NewTaskRequest(
|
||||
projectID: "project",
|
||||
prompt: "Build it",
|
||||
selection: nil,
|
||||
runtimeMode: .fullAccess,
|
||||
interactionMode: .standard,
|
||||
workspaceMode: .worktree,
|
||||
branch: " main ",
|
||||
worktreePath: "/existing/worktree",
|
||||
startFromOrigin: true
|
||||
)
|
||||
|
||||
#expect(request.branch == "main")
|
||||
#expect(request.worktreePath == nil)
|
||||
#expect(request.startFromOrigin)
|
||||
}
|
||||
|
||||
@Test
|
||||
func workspaceDefaultsPreferCurrentCheckoutAndLocalDefaultBase() throws {
|
||||
let branches = [
|
||||
FeatureWorkspaceBranch(name: "origin/main", isRemote: true, isDefault: true),
|
||||
FeatureWorkspaceBranch(name: "feature", isCurrent: true),
|
||||
FeatureWorkspaceBranch(name: "main", isDefault: true),
|
||||
]
|
||||
|
||||
#expect(NewTaskWorkspaceDefaults.localBranch(in: branches)?.name == "feature")
|
||||
#expect(NewTaskWorkspaceDefaults.worktreeBase(in: branches)?.name == "main")
|
||||
|
||||
let root = FeatureWorkspaceBranch(
|
||||
name: "feature",
|
||||
worktreePath: "/repo/./"
|
||||
)
|
||||
#expect(
|
||||
NewTaskWorkspaceDefaults.normalizedWorktreePath(
|
||||
for: root,
|
||||
projectPath: "/repo"
|
||||
) == nil
|
||||
)
|
||||
|
||||
let linked = FeatureWorkspaceBranch(
|
||||
name: "linked",
|
||||
worktreePath: "/worktrees/linked"
|
||||
)
|
||||
#expect(
|
||||
NewTaskWorkspaceDefaults.normalizedWorktreePath(
|
||||
for: linked,
|
||||
projectPath: "/repo"
|
||||
) == "/worktrees/linked"
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
func mobileModeChoicesOnlyExposeSupportedValues() {
|
||||
#expect(FeatureRuntimeMode.allCases == [.automatic, .fullAccess])
|
||||
|
||||
@@ -145,6 +145,9 @@ struct FeatureRootModelTests {
|
||||
selection: .init(providerID: "codex", modelID: "gpt-5.6-sol"),
|
||||
runtimeMode: .fullAccess,
|
||||
interactionMode: .standard,
|
||||
workspaceMode: .worktree,
|
||||
branch: "main",
|
||||
startFromOrigin: true,
|
||||
attachments: [attachment]
|
||||
)
|
||||
)
|
||||
@@ -152,6 +155,10 @@ struct FeatureRootModelTests {
|
||||
#expect(result == created)
|
||||
#expect(client.startedPrompt == "Ship the native app")
|
||||
#expect(client.startedAttachments.map(\.name) == ["reference.jpg"])
|
||||
#expect(client.startedWorkspaceMode == .worktree)
|
||||
#expect(client.startedBranch == "main")
|
||||
#expect(client.startedWorktreePath == nil)
|
||||
#expect(client.startedFromOrigin)
|
||||
#expect(client.createThreadCallCount == 0)
|
||||
#expect(client.sendMessageCallCount == 0)
|
||||
#expect(model.snapshot.threads == [created])
|
||||
@@ -521,6 +528,10 @@ private final class FeatureClientStub: FeatureClient {
|
||||
var sentText: String?
|
||||
var startedPrompt: String?
|
||||
var startedAttachments: [FeatureUploadAttachment] = []
|
||||
var startedWorkspaceMode: FeatureWorkspaceMode?
|
||||
var startedBranch: String?
|
||||
var startedWorktreePath: String?
|
||||
var startedFromOrigin = false
|
||||
var createThreadCallCount = 0
|
||||
var sendMessageCallCount = 0
|
||||
var loadThreadError: (any Error)?
|
||||
@@ -579,6 +590,27 @@ private final class FeatureClientStub: FeatureClient {
|
||||
return createdThread
|
||||
}
|
||||
|
||||
func createThreadAndSend(
|
||||
projectID: String,
|
||||
prompt: String,
|
||||
selection: FeatureSelection?,
|
||||
runtimeMode: FeatureRuntimeMode,
|
||||
interactionMode: FeatureInteractionMode,
|
||||
workspaceMode: FeatureWorkspaceMode,
|
||||
branch: String?,
|
||||
worktreePath: String?,
|
||||
startFromOrigin: Bool,
|
||||
attachments: [FeatureUploadAttachment]
|
||||
) async throws -> FeatureThread {
|
||||
startedPrompt = prompt
|
||||
startedAttachments = attachments
|
||||
startedWorkspaceMode = workspaceMode
|
||||
startedBranch = branch
|
||||
startedWorktreePath = worktreePath
|
||||
startedFromOrigin = startFromOrigin
|
||||
return createdThread
|
||||
}
|
||||
|
||||
func renameThread(id: String, title: String) async throws {}
|
||||
func setThreadArchived(id: String, archived: Bool) async throws {}
|
||||
func deleteThread(id: String) async throws {}
|
||||
|
||||
Reference in new issue
Block a user