9e8079de69
Bundles a string of multi-repo fixes and refactors that came up while testing the feature end-to-end: - workspace_path stored on multi-repo TaskEnvironment was one level too high, so agentctl booted with the wrong WorkDir on cold start; fixed in resolveTaskEnvWorkspacePath + GetWorkspaceInfoForSession. - Stage/Unstage/Discard/Commit/Revert/Reset/Amend now thread `repo` through agentctl client → WS handler → frontend hook → SessionGit fan-out, so the right git repo is targeted (was running at the task root, which isn't a git repo for multi-repo tasks). - agentctl GitLog is multi-repo aware: when no `repo` is specified and per-repo trackers exist, fans out one log per repo and merges sorted newest-first with RepositoryName stamped on each commit. - Per-repo grouping for files (Changes panel) and commits, with collapsible group headers; commits section defaults to collapsed. Algorithm extracted into one generic groupByRepositoryName helper (was copy-pasted three times). - Task creation dialog rewritten around a unified `fs.repositories[]` list — no more "primary vs extras" split. Chip-style row with one pill per repo + branch, "+" to add, x to remove, GitHub URL toggle inline. Discovered (on-machine) repos appear in any chip's dropdown. Removes ~6 fields and 3 helpers from the dialog state. - Branch listing endpoints collapsed to one: GET /workspaces/:id/branches?repository_id=X | path=Y Frontend collapses to a single useBranches hook with a tagged-union source. Drops two HTTP routes, two service methods, two API client funcs, and one whole hook file. Tests added across the chain: workspace_path resolver, sort-commits- by-date, manager poll-mode propagation, RepoSubpaths, chip grouping + collapse + per-repo isLatest, group-by-repo helper, dialog payload builder + chip wiring + discovered-repo flow.
122 lines
3.8 KiB
TypeScript
122 lines
3.8 KiB
TypeScript
"use client";
|
|
|
|
import { useCallback } from "react";
|
|
import type { Repository } from "@/lib/types/http";
|
|
import type { DialogFormState, TaskRepoRow } from "@/components/task-create-dialog-types";
|
|
import { setLocalStorage } from "@/lib/local-storage";
|
|
import { STORAGE_KEYS } from "@/lib/settings/constants";
|
|
|
|
/**
|
|
* Centralizes form-field change handlers for the task-create dialog.
|
|
*
|
|
* The dialog now stores all repos in a single `fs.repositories` list (no
|
|
* "primary vs extras" split), so the per-row handlers are uniform: changing
|
|
* a repo on row N is the same op whether N==0 or N==5.
|
|
*/
|
|
export function useDialogHandlers(fs: DialogFormState, repositories: Repository[]) {
|
|
/**
|
|
* Resolves a picker value into the right shape for a row:
|
|
* - If it matches a workspace repo id → `{ repositoryId, localPath: undefined }`.
|
|
* - Otherwise treat as a discovered on-machine path → `{ localPath, repositoryId: undefined }`.
|
|
* The branch is reset because the previous branch may not exist on the new repo.
|
|
*/
|
|
const handleRowRepositoryChange = useCallback(
|
|
(key: string, value: string) => {
|
|
const isWorkspaceRepo = repositories.some((r: Repository) => r.id === value);
|
|
const patch: Partial<TaskRepoRow> = isWorkspaceRepo
|
|
? { repositoryId: value, localPath: undefined, branch: "" }
|
|
: { repositoryId: undefined, localPath: value, branch: "" };
|
|
fs.updateRepository(key, patch);
|
|
if (isWorkspaceRepo) setLocalStorage(STORAGE_KEYS.LAST_REPOSITORY_ID, value);
|
|
},
|
|
[repositories, fs],
|
|
);
|
|
|
|
const handleRowBranchChange = useCallback(
|
|
(key: string, value: string) => {
|
|
fs.updateRepository(key, { branch: value });
|
|
setLocalStorage(STORAGE_KEYS.LAST_BRANCH, value);
|
|
},
|
|
[fs],
|
|
);
|
|
|
|
const handleAgentProfileChange = useCallback(
|
|
(value: string) => {
|
|
fs.setAgentProfileId(value);
|
|
setLocalStorage(STORAGE_KEYS.LAST_AGENT_PROFILE_ID, value);
|
|
},
|
|
[fs],
|
|
);
|
|
const handleExecutorProfileChange = useCallback(
|
|
(value: string) => {
|
|
fs.setExecutorProfileId(value);
|
|
setLocalStorage(STORAGE_KEYS.LAST_EXECUTOR_PROFILE_ID, value);
|
|
},
|
|
[fs],
|
|
);
|
|
const handleTaskNameChange = useCallback(
|
|
(value: string) => {
|
|
fs.setTaskName(value);
|
|
fs.setHasTitle(value.trim().length > 0);
|
|
},
|
|
[fs],
|
|
);
|
|
const handleGitHubBranchChange = useCallback(
|
|
(value: string) => {
|
|
fs.setGitHubBranch(value);
|
|
setLocalStorage(STORAGE_KEYS.LAST_BRANCH, value);
|
|
},
|
|
[fs],
|
|
);
|
|
const handleWorkflowChange = useCallback(
|
|
(value: string) => {
|
|
fs.setSelectedWorkflowId(value);
|
|
},
|
|
[fs],
|
|
);
|
|
|
|
/**
|
|
* Toggles between "repo chips" mode and "GitHub URL" mode. URL mode
|
|
* replaces the chip row with a single URL input; flipping back restores
|
|
* the chip flow with whatever rows were already there.
|
|
*/
|
|
const handleToggleGitHubUrl = useCallback(() => {
|
|
const next = !fs.useGitHubUrl;
|
|
fs.setUseGitHubUrl(next);
|
|
if (next) {
|
|
// Stash the rows aside while in URL mode; flipping back keeps them.
|
|
// (Nothing to do here — chips re-render off `fs.repositories` once
|
|
// useGitHubUrl flips back to false.)
|
|
} else {
|
|
fs.setGitHubUrl("");
|
|
fs.setGitHubBranches([]);
|
|
fs.setGitHubUrlError(null);
|
|
fs.setGitHubPrHeadBranch(null);
|
|
}
|
|
fs.setGitHubBranch("");
|
|
}, [fs]);
|
|
|
|
const handleGitHubUrlChange = useCallback(
|
|
(value: string) => {
|
|
fs.setGitHubUrl(value);
|
|
fs.setGitHubBranch("");
|
|
fs.setGitHubBranches([]);
|
|
fs.setGitHubUrlError(null);
|
|
fs.setGitHubPrHeadBranch(null);
|
|
},
|
|
[fs],
|
|
);
|
|
|
|
return {
|
|
handleRowRepositoryChange,
|
|
handleRowBranchChange,
|
|
handleAgentProfileChange,
|
|
handleExecutorProfileChange,
|
|
handleTaskNameChange,
|
|
handleGitHubBranchChange,
|
|
handleWorkflowChange,
|
|
handleToggleGitHubUrl,
|
|
handleGitHubUrlChange,
|
|
};
|
|
}
|