fix(ui): improve React Query hooks and fix edge cases

- Update query keys to include all relevant parameters (branches, agents)
- Fix use-branches to pass includeRemote parameter to query key
- Fix use-settings to include sources in agents query key
- Update running-agents-view to use correct query key structure
- Update use-spec-loading to properly use spec query hooks
- Add missing queryClient invalidation in auto-mode mutations
- Add missing cache invalidation in spec mutations after creation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Shirone
2026-01-15 19:11:25 +01:00
parent 3170e22383
commit 361cb06bf0
11 changed files with 57 additions and 25 deletions

View File

@@ -99,21 +99,36 @@ export function useResumeFeature(projectPath: string) {
* Stop a running feature
*
* @returns Mutation for stopping a feature
*
* @example
* ```tsx
* const stopFeature = useStopFeature();
* // Simple stop
* stopFeature.mutate('feature-id');
* // Stop with project path for cache invalidation
* stopFeature.mutate({ featureId: 'feature-id', projectPath: '/path/to/project' });
* ```
*/
export function useStopFeature() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (featureId: string) => {
mutationFn: async (input: string | { featureId: string; projectPath?: string }) => {
const featureId = typeof input === 'string' ? input : input.featureId;
const api = getElectronAPI();
const result = await api.autoMode.stopFeature(featureId);
if (!result.success) {
throw new Error(result.error || 'Failed to stop feature');
}
return result;
// Return projectPath for use in onSuccess
return { ...result, projectPath: typeof input === 'string' ? undefined : input.projectPath };
},
onSuccess: () => {
onSuccess: (data) => {
queryClient.invalidateQueries({ queryKey: queryKeys.runningAgents.all() });
// Also invalidate features cache if projectPath is provided
if (data.projectPath) {
queryClient.invalidateQueries({ queryKey: queryKeys.features.all(data.projectPath) });
}
toast.success('Feature stopped');
},
onError: (error: Error) => {

View File

@@ -9,6 +9,7 @@ import { getElectronAPI, GitHubIssue, GitHubComment } from '@/lib/electron';
import { queryKeys } from '@/lib/query-keys';
import { toast } from 'sonner';
import type { LinkedPRInfo, ModelId } from '@automaker/types';
import { resolveModelString } from '@automaker/model-resolver';
/**
* Input for validating a GitHub issue
@@ -64,10 +65,13 @@ export function useValidateIssue(projectPath: string) {
linkedPRs,
};
// Resolve model alias to canonical model identifier
const resolvedModel = model ? resolveModelString(model) : undefined;
const result = await api.github.validateIssue(
projectPath,
validationInput,
model,
resolvedModel,
thinkingLevel,
reasoningEffort
);

View File

@@ -157,6 +157,11 @@ export function useSaveSpec(projectPath: string) {
return useMutation({
mutationFn: async (content: string) => {
// Guard against empty projectPath to prevent writing to invalid locations
if (!projectPath || projectPath.trim() === '') {
throw new Error('Invalid project path: cannot save spec without a valid project');
}
const api = getElectronAPI();
await api.writeFile(`${projectPath}/.automaker/app_spec.txt`, content);

View File

@@ -107,7 +107,8 @@ export function useDiscoveredAgents(
sources?: Array<'user' | 'project'>
) {
return useQuery({
queryKey: queryKeys.settings.agents(projectPath ?? ''),
// Include sources in query key so different source combinations have separate caches
queryKey: queryKeys.settings.agents(projectPath ?? '', sources),
queryFn: async () => {
const api = getElectronAPI();
const result = await api.settings.discoverAgents(projectPath, sources);

View File

@@ -162,7 +162,8 @@ interface BranchesResult {
*/
export function useWorktreeBranches(worktreePath: string | undefined, includeRemote = false) {
return useQuery({
queryKey: queryKeys.worktrees.branches(worktreePath ?? ''),
// Include includeRemote in query key so different configurations have separate caches
queryKey: queryKeys.worktrees.branches(worktreePath ?? '', includeRemote),
queryFn: async (): Promise<BranchesResult> => {
if (!worktreePath) throw new Error('No worktree path');
const api = getElectronAPI();