Update files

This commit is contained in:
Mohamed Boudra
2026-01-28 13:25:48 +07:00
parent c615d422ca
commit 96b211a2cf
16 changed files with 229 additions and 323 deletions
@@ -1,15 +1,15 @@
export type CheckoutStatusRevalidationParams = {
serverId: string;
agentId: string;
cwd: string;
isOpen: boolean;
explorerTab: string;
};
export function checkoutStatusRevalidationKey(params: CheckoutStatusRevalidationParams): string | null {
if (!params.agentId) return null;
if (!params.cwd) return null;
if (!params.isOpen) return null;
if (params.explorerTab !== "changes") return null;
return `${params.serverId}:${params.agentId}`;
return `${params.serverId}:${params.cwd}`;
}
export function nextCheckoutStatusRefetchDecision(
@@ -9,16 +9,16 @@ const CHECKOUT_DIFF_STALE_TIME = 30_000;
function checkoutDiffQueryKey(
serverId: string,
agentId: string,
cwd: string,
mode: "uncommitted" | "base",
baseRef?: string
) {
return ["checkoutDiff", serverId, agentId, mode, baseRef ?? ""] as const;
return ["checkoutDiff", serverId, cwd, mode, baseRef ?? ""] as const;
}
interface UseCheckoutDiffQueryOptions {
serverId: string;
agentId: string;
cwd: string;
mode: "uncommitted" | "base";
baseRef?: string;
enabled?: boolean;
@@ -31,7 +31,7 @@ export type HighlightToken = NonNullable<DiffLine["tokens"]>[number];
export function useCheckoutDiffQuery({
serverId,
agentId,
cwd,
mode,
baseRef,
enabled = true,
@@ -51,27 +51,27 @@ export function useCheckoutDiffQuery({
const isOpen = isMobile ? mobileView === "file-explorer" : desktopFileExplorerOpen;
const query = useQuery({
queryKey: checkoutDiffQueryKey(serverId, agentId, mode, baseRef),
queryKey: checkoutDiffQueryKey(serverId, cwd, mode, baseRef),
queryFn: async () => {
if (!client) {
throw new Error("Daemon client not available");
}
return await client.getCheckoutDiff(agentId, { mode, baseRef });
return await client.getCheckoutDiff(cwd, { mode, baseRef });
},
enabled: !!client && isConnected && !!agentId && enabled,
enabled: !!client && isConnected && !!cwd && enabled,
staleTime: CHECKOUT_DIFF_STALE_TIME,
refetchInterval: 10_000,
});
// Revalidate when sidebar opens with "changes" tab active
useEffect(() => {
if (!isOpen || explorerTab !== "changes" || !agentId) {
if (!isOpen || explorerTab !== "changes" || !cwd) {
return;
}
queryClient.invalidateQueries({
queryKey: checkoutDiffQueryKey(serverId, agentId, mode, baseRef),
queryKey: checkoutDiffQueryKey(serverId, cwd, mode, baseRef),
});
}, [isOpen, explorerTab, serverId, agentId, mode, baseRef, queryClient]);
}, [isOpen, explorerTab, serverId, cwd, mode, baseRef, queryClient]);
const refresh = useCallback(() => {
return query.refetch();
@@ -4,13 +4,13 @@ import type { CheckoutPrStatusResponse } from "@server/shared/messages";
const CHECKOUT_PR_STATUS_STALE_TIME = 20_000;
function checkoutPrStatusQueryKey(serverId: string, agentId: string) {
return ["checkoutPrStatus", serverId, agentId] as const;
function checkoutPrStatusQueryKey(serverId: string, cwd: string) {
return ["checkoutPrStatus", serverId, cwd] as const;
}
interface UseCheckoutPrStatusQueryOptions {
serverId: string;
agentId: string;
cwd: string;
enabled?: boolean;
}
@@ -18,7 +18,7 @@ export type CheckoutPrStatusPayload = CheckoutPrStatusResponse["payload"];
export function useCheckoutPrStatusQuery({
serverId,
agentId,
cwd,
enabled = true,
}: UseCheckoutPrStatusQueryOptions) {
const client = useSessionStore(
@@ -29,14 +29,14 @@ export function useCheckoutPrStatusQuery({
);
const query = useQuery({
queryKey: checkoutPrStatusQueryKey(serverId, agentId),
queryKey: checkoutPrStatusQueryKey(serverId, cwd),
queryFn: async () => {
if (!client) {
throw new Error("Daemon client not available");
}
return await client.checkoutPrStatus(agentId);
return await client.checkoutPrStatus(cwd);
},
enabled: !!client && isConnected && !!agentId && enabled,
enabled: !!client && isConnected && !!cwd && enabled,
staleTime: CHECKOUT_PR_STATUS_STALE_TIME,
refetchInterval: 15_000,
});
@@ -7,7 +7,7 @@ describe("useCheckoutStatusQuery", () => {
expect(
checkoutStatusRevalidationKey({
serverId: "daemon-1",
agentId: "agent-1",
cwd: "/path/to/project",
isOpen: false,
explorerTab: "changes",
})
@@ -18,7 +18,7 @@ describe("useCheckoutStatusQuery", () => {
expect(
checkoutStatusRevalidationKey({
serverId: "daemon-1",
agentId: "agent-1",
cwd: "/path/to/project",
isOpen: true,
explorerTab: "files",
})
@@ -29,11 +29,11 @@ describe("useCheckoutStatusQuery", () => {
expect(
checkoutStatusRevalidationKey({
serverId: "daemon-1",
agentId: "agent-1",
cwd: "/path/to/project",
isOpen: true,
explorerTab: "changes",
})
).toBe("daemon-1:agent-1");
).toBe("daemon-1:/path/to/project");
});
});
@@ -17,21 +17,19 @@ export function checkoutStatusQueryKey(serverId: string, cwd: string) {
interface UseCheckoutStatusQueryOptions {
serverId: string;
agentId: string;
cwd: string;
}
export type CheckoutStatusPayload = CheckoutStatusResponse["payload"];
function fetchCheckoutStatus(
client: { getCheckoutStatus: (agentId: string, options?: { cwd?: string }) => Promise<CheckoutStatusPayload> },
agentId: string,
client: { getCheckoutStatus: (cwd: string) => Promise<CheckoutStatusPayload> },
cwd: string
): Promise<CheckoutStatusPayload> {
return client.getCheckoutStatus(agentId, { cwd });
return client.getCheckoutStatus(cwd);
}
export function useCheckoutStatusQuery({ serverId, agentId, cwd }: UseCheckoutStatusQueryOptions) {
export function useCheckoutStatusQuery({ serverId, cwd }: UseCheckoutStatusQueryOptions) {
const client = useSessionStore(
(state) => state.sessions[serverId]?.client ?? null
);
@@ -51,9 +49,9 @@ export function useCheckoutStatusQuery({ serverId, agentId, cwd }: UseCheckoutSt
if (!client) {
throw new Error("Daemon client not available");
}
return await fetchCheckoutStatus(client, agentId, cwd);
return await fetchCheckoutStatus(client, cwd);
},
enabled: !!client && isConnected && !!agentId && !!cwd,
enabled: !!client && isConnected && !!cwd,
staleTime: CHECKOUT_STATUS_STALE_TIME,
refetchInterval: 10_000,
refetchIntervalInBackground: true,
@@ -62,8 +60,8 @@ export function useCheckoutStatusQuery({ serverId, agentId, cwd }: UseCheckoutSt
// Revalidate when sidebar is open with "changes" tab active.
const revalidationKey = useMemo(
() => checkoutStatusRevalidationKey({ serverId, agentId, isOpen, explorerTab }),
[serverId, agentId, isOpen, explorerTab]
() => checkoutStatusRevalidationKey({ serverId, cwd, isOpen, explorerTab }),
[serverId, cwd, isOpen, explorerTab]
);
const lastRevalidationKey = useRef<string | null>(null);
useEffect(() => {
@@ -88,7 +86,7 @@ export function useCheckoutStatusQuery({ serverId, agentId, cwd }: UseCheckoutSt
* initiating a fetch. Useful for list rows where a parent component prefetches
* only the visible agents.
*/
export function useCheckoutStatusCacheOnly({ serverId, agentId, cwd }: UseCheckoutStatusQueryOptions) {
export function useCheckoutStatusCacheOnly({ serverId, cwd }: UseCheckoutStatusQueryOptions) {
const client = useSessionStore(
(state) => state.sessions[serverId]?.client ?? null
);
@@ -99,7 +97,7 @@ export function useCheckoutStatusCacheOnly({ serverId, agentId, cwd }: UseChecko
if (!client) {
throw new Error("Daemon client not available");
}
return await fetchCheckoutStatus(client, agentId, cwd);
return await fetchCheckoutStatus(client, cwd);
},
enabled: false,
staleTime: CHECKOUT_STATUS_STALE_TIME,