Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions apps/array/src/main/services/workspace/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const createWorkspaceInput = z.object({
folderPath: z.string().min(2, "Folder path must be a valid directory path"),
mode: workspaceModeSchema,
branch: z.string().optional(),
fetchLatest: z.boolean().optional(),
});

export const deleteWorkspaceInput = z.object({
Expand Down
35 changes: 33 additions & 2 deletions apps/array/src/main/services/workspace/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,15 @@ export class WorkspaceService extends TypedEventEmitter<WorkspaceServiceEvents>
}

async createWorkspace(options: CreateWorkspaceInput): Promise<WorkspaceInfo> {
const { taskId, mainRepoPath, folderId, folderPath, mode, branch } =
options;
const {
taskId,
mainRepoPath,
folderId,
folderPath,
mode,
branch,
fetchLatest,
} = options;
log.info(
`Creating workspace for task ${taskId} in ${mainRepoPath} (mode: ${mode})`,
);
Expand Down Expand Up @@ -276,6 +283,30 @@ export class WorkspaceService extends TypedEventEmitter<WorkspaceServiceEvents>
);
}
}

// Fetch latest from origin if requested - pull from the base branch the user selected
if (fetchLatest) {
const baseBranch = branch ?? worktree.baseBranch;
if (baseBranch) {
try {
log.info(
`Fetching latest from origin/${baseBranch} for task ${taskId}`,
);
await execAsync("git fetch origin", { cwd: worktree.worktreePath });
await execAsync(`git pull origin ${baseBranch}`, {
cwd: worktree.worktreePath,
});
log.info(`Successfully fetched latest for task ${taskId}`);
} catch (error) {
log.warn(`Failed to fetch latest for task ${taskId}:`, error);
// Don't fail workspace creation, just warn
}
} else {
log.info(
`Skipping fetch latest for task ${taskId}: no base branch specified`,
);
}
}
} catch (error) {
log.error(`Failed to create worktree for task ${taskId}:`, error);
throw new Error(`Failed to create worktree: ${String(error)}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ export function SettingsView() {
defaultRunMode,
createPR,
desktopNotifications,
fetchLatestOnNewTask,
setAutoRunTasks,
setDefaultRunMode,
setCreatePR,
setDesktopNotifications,
setFetchLatestOnNewTask,
} = useSettingsStore();
const terminalLayoutMode = useTerminalLayoutStore(
(state) => state.terminalLayoutMode,
Expand Down Expand Up @@ -337,6 +339,23 @@ export function SettingsView() {
size="1"
/>
</Flex>

<Flex align="center" justify="between">
<Flex direction="column" gap="1">
<Text size="1" weight="medium">
Fetch latest on new task
</Text>
<Text size="1" color="gray">
Pull the latest changes from origin after creating a
workspace
</Text>
</Flex>
<Switch
checked={fetchLatestOnNewTask}
onCheckedChange={setFetchLatestOnNewTask}
size="1"
/>
</Flex>
</Flex>
</Card>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface SettingsStore {
defaultModel: string;
defaultFramework: AgentFramework;
desktopNotifications: boolean;
fetchLatestOnNewTask: boolean;

setAutoRunTasks: (autoRun: boolean) => void;
setDefaultRunMode: (mode: DefaultRunMode) => void;
Expand All @@ -30,6 +31,7 @@ interface SettingsStore {
setDefaultModel: (model: string) => void;
setDefaultFramework: (framework: AgentFramework) => void;
setDesktopNotifications: (enabled: boolean) => void;
setFetchLatestOnNewTask: (enabled: boolean) => void;
}

export const useSettingsStore = create<SettingsStore>()(
Expand All @@ -44,6 +46,7 @@ export const useSettingsStore = create<SettingsStore>()(
defaultModel: DEFAULT_MODEL,
defaultFramework: DEFAULT_FRAMEWORK,
desktopNotifications: true,
fetchLatestOnNewTask: true,

setAutoRunTasks: (autoRun) => set({ autoRunTasks: autoRun }),
setDefaultRunMode: (mode) => set({ defaultRunMode: mode }),
Expand All @@ -56,6 +59,8 @@ export const useSettingsStore = create<SettingsStore>()(
setDefaultFramework: (framework) => set({ defaultFramework: framework }),
setDesktopNotifications: (enabled) =>
set({ desktopNotifications: enabled }),
setFetchLatestOnNewTask: (enabled) =>
set({ fetchLatestOnNewTask: enabled }),
}),
{
name: "settings-storage",
Expand Down
3 changes: 3 additions & 0 deletions apps/array/src/renderer/sagas/task/task-creation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { PostHogAPIClient } from "@api/posthogClient";
import { buildPromptBlocks } from "@features/editor/utils/prompt-builder";
import { getSessionActions } from "@features/sessions/stores/sessionStore";
import { useSettingsStore } from "@features/settings/stores/settingsStore";
import { useWorkspaceStore } from "@features/workspace/stores/workspaceStore";
import { logger } from "@renderer/lib/logger";
import { useTaskDirectoryStore } from "@renderer/stores/taskDirectoryStore";
Expand Down Expand Up @@ -108,6 +109,7 @@ export class TaskCreationSaga extends Saga<
});
}

const fetchLatest = useSettingsStore.getState().fetchLatestOnNewTask;
const workspaceInfo = await this.step({
name: "workspace_creation",
execute: async () => {
Expand All @@ -118,6 +120,7 @@ export class TaskCreationSaga extends Saga<
folderPath: repoPath,
mode: workspaceMode,
branch: branch ?? undefined,
fetchLatest,
});
},
rollback: async () => {
Expand Down