bc218dfbbe
* feat: add workspace sources from files panel * fix: preserve worktree identity during recovery * feat: unify workspace source actions * fix: validate recovered workspace repositories * fix: harden workspace source filesystem boundaries * test: split workspace repository chip coverage * fix: restrict repository rescan recovery paths * fix: stabilize workspace source CI checks * test: canonicalize workspace source paths * test: align workspace source container paths * fix: populate direct workspace repository names * test: preserve git fixture rewrites across restarts * test: isolate backend git fixture config * fix: resume remote workspace executions before creation * fix: preserve ssh agent identity during resume * fix: preserve SSH workspace across backend restart * fix: simplify workspace actions trigger * fix: refine add workspace repositories UX * docs: narrow workspace source UX updates * fix: avoid phantom turn on session resume * test(web): normalize workspace source request headers * feat(web): streamline workspace source picker * docs: remove trailing spaces from workspace source plan * fix: prevent resume status from creating phantom turns * fix(web): stabilize workspace source attachment * refactor(web): extract workspace source store contract * fix: avoid phantom turns on idle agent resume * fix: address backend static analysis findings * fix: preserve agentctl readiness status value * fix: preserve resume messages without active turns * fix: resume agents from promoted workspace root * chore: merge origin/main into feature/add-new-repo-folder-d97 * feat(web): explain workspace source consequences * test(websocket): count session activity subscription
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
"use client";
|
|
|
|
import { useCallback, useState } from "react";
|
|
import {
|
|
addWorkspaceSourceRow,
|
|
getWorkspaceSourceValidation,
|
|
removeWorkspaceSourceRow,
|
|
updateWorkspaceSourceRow,
|
|
type WorkspaceSourceRow,
|
|
} from "@/components/workspace-source-picker/workspace-source-state";
|
|
|
|
export function useWorkspaceSourceRows(executorType?: string | null) {
|
|
const [rows, setRows] = useState<WorkspaceSourceRow[]>([]);
|
|
const [validatedRowKeys, setValidatedRowKeys] = useState<Set<string>>(() => new Set());
|
|
const errors = getWorkspaceSourceValidation(rows);
|
|
const visibleErrors = Object.fromEntries(
|
|
Object.entries(errors).filter(([key]) => validatedRowKeys.has(key)),
|
|
);
|
|
|
|
const add = useCallback(
|
|
(kind: NonNullable<WorkspaceSourceRow["sourceType"]>) =>
|
|
setRows((current) => addWorkspaceSourceRow(current, kind, executorType)),
|
|
[executorType],
|
|
);
|
|
const update = useCallback(
|
|
(key: string, patch: Partial<WorkspaceSourceRow>) =>
|
|
setRows((current) => updateWorkspaceSourceRow(current, key, patch)),
|
|
[],
|
|
);
|
|
const remove = useCallback(
|
|
(key: string) => setRows((current) => removeWorkspaceSourceRow(current, key)),
|
|
[],
|
|
);
|
|
const reset = useCallback(() => {
|
|
setRows([]);
|
|
setValidatedRowKeys(new Set());
|
|
}, []);
|
|
const resetValidation = useCallback(() => setValidatedRowKeys(new Set()), []);
|
|
const validate = useCallback(
|
|
() => setValidatedRowKeys(new Set(rows.map((row) => row.key))),
|
|
[rows],
|
|
);
|
|
|
|
return {
|
|
rows,
|
|
errors,
|
|
visibleErrors,
|
|
add,
|
|
update,
|
|
remove,
|
|
reset,
|
|
resetValidation,
|
|
validate,
|
|
};
|
|
}
|