feat: implement default Git identity management and local identity check

This commit is contained in:
Bohdan Triapitsyn
2026-01-14 22:34:17 +02:00
parent e0cc212823
commit e0279e59b0
18 changed files with 310 additions and 25 deletions
@@ -25,6 +25,7 @@ import { getDesktopSettings, isDesktopRuntime, isVSCodeRuntime } from '@/lib/des
import { updateDesktopSettings } from '@/lib/persistence';
import type { DesktopSettings, SkillCatalogConfig } from '@/lib/desktop';
import { useSkillsCatalogStore } from '@/stores/useSkillsCatalogStore';
import { useGitIdentitiesStore } from '@/stores/useGitIdentitiesStore';
const generateCatalogId = () => `custom:${Date.now()}-${Math.random().toString(16).slice(2)}`;
@@ -81,6 +82,8 @@ interface AddCatalogDialogProps {
export const AddCatalogDialog: React.FC<AddCatalogDialogProps> = ({ open, onOpenChange }) => {
const { scanRepo, loadCatalog, isScanning } = useSkillsCatalogStore();
const defaultGitIdentityId = useGitIdentitiesStore((s) => s.defaultGitIdentityId);
const loadDefaultGitIdentityId = useGitIdentitiesStore((s) => s.loadDefaultGitIdentityId);
const [label, setLabel] = React.useState('');
const [source, setSource] = React.useState('');
@@ -104,13 +107,14 @@ export const AddCatalogDialog: React.FC<AddCatalogDialogProps> = ({ open, onOpen
setScanOk(false);
setIdentityOptions([]);
setGitIdentityId(null);
void loadDefaultGitIdentityId();
void (async () => {
const settings = await loadSettings();
const catalogs = Array.isArray(settings?.skillCatalogs) ? settings?.skillCatalogs : [];
setExistingCatalogs(catalogs || []);
})();
}, [open]);
}, [open, loadDefaultGitIdentityId]);
const isDuplicate = React.useMemo(() => {
const normalizedSource = source.trim();
@@ -153,7 +157,13 @@ export const AddCatalogDialog: React.FC<AddCatalogDialogProps> = ({ open, onOpen
const ids = (result.error.identities || []) as IdentityOption[];
setIdentityOptions(ids);
if (!gitIdentityId && ids.length > 0) {
setGitIdentityId(ids[0].id);
const preferred =
defaultGitIdentityId &&
defaultGitIdentityId !== 'global' &&
ids.some((i) => i.id === defaultGitIdentityId)
? defaultGitIdentityId
: ids[0].id;
setGitIdentityId(preferred);
}
toast.error('Authentication required. Select a Git identity and scan again.');
return;
@@ -25,6 +25,7 @@ import { isVSCodeRuntime } from '@/lib/desktop';
import type { SkillsCatalogItem } from '@/lib/api/types';
import { useSkillsCatalogStore } from '@/stores/useSkillsCatalogStore';
import { useSkillsStore } from '@/stores/useSkillsStore';
import { useGitIdentitiesStore } from '@/stores/useGitIdentitiesStore';
import { InstallConflictsDialog, type ConflictDecision, type SkillConflict } from './InstallConflictsDialog';
interface InstallFromRepoDialogProps {
@@ -37,6 +38,8 @@ type IdentityOption = { id: string; name: string };
export const InstallFromRepoDialog: React.FC<InstallFromRepoDialogProps> = ({ open, onOpenChange }) => {
const { scanRepo, installSkills, isScanning, isInstalling } = useSkillsCatalogStore();
const installedSkills = useSkillsStore((s) => s.skills);
const defaultGitIdentityId = useGitIdentitiesStore((s) => s.defaultGitIdentityId);
const loadDefaultGitIdentityId = useGitIdentitiesStore((s) => s.loadDefaultGitIdentityId);
const [source, setSource] = React.useState('');
const [subpath, setSubpath] = React.useState('');
@@ -69,10 +72,13 @@ export const InstallFromRepoDialog: React.FC<InstallFromRepoDialogProps> = ({ op
setSearch('');
setIdentities([]);
setGitIdentityId(null);
void loadDefaultGitIdentityId();
setConflictsOpen(false);
setConflicts([]);
setBaseInstallRequest(null);
}, [open]);
}, [open, loadDefaultGitIdentityId]);
const installedByName = React.useMemo(() => {
const map = new Map<string, { scope: 'user' | 'project' }>();
@@ -127,7 +133,13 @@ export const InstallFromRepoDialog: React.FC<InstallFromRepoDialogProps> = ({ op
const ids = (result.error.identities || []) as IdentityOption[];
setIdentities(ids);
if (!gitIdentityId && ids.length > 0) {
setGitIdentityId(ids[0].id);
const preferred =
defaultGitIdentityId &&
defaultGitIdentityId !== 'global' &&
ids.some((i) => i.id === defaultGitIdentityId)
? defaultGitIdentityId
: ids[0].id;
setGitIdentityId(preferred);
}
toast.error('Authentication required. Select a Git identity and try scanning again.');
return;
@@ -195,7 +207,13 @@ export const InstallFromRepoDialog: React.FC<InstallFromRepoDialogProps> = ({ op
const ids = (result.error.identities || []) as IdentityOption[];
setIdentities(ids);
if (!gitIdentityId && ids.length > 0) {
setGitIdentityId(ids[0].id);
const preferred =
defaultGitIdentityId &&
defaultGitIdentityId !== 'global' &&
ids.some((i) => i.id === defaultGitIdentityId)
? defaultGitIdentityId
: ids[0].id;
setGitIdentityId(preferred);
}
toast.error('Authentication required. Select a Git identity and try installing again.');
return;