Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions packages/ui/src/components/project-switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { useState } from 'react';
import { ChevronsUpDown, Github, Plus, Star, Settings, Loader2, Check } from 'lucide-react';
import { ChevronsUpDown, GitBranch, Plus, Star, Settings, Loader2, Check } from 'lucide-react';
import { Button, cn } from '@/library';
import {
Command,
Expand All @@ -23,7 +23,7 @@ import {
import { Skeleton } from '@/library';
import { useCurrentProject, useProjectMutations, useProjects } from '../hooks/useProjectQuery';
import { CreateProjectDialog } from './projects/create-project-dialog';
import { GitHubImportDialog } from './projects/github-import-dialog';
import { GitImportDialog } from './projects/git-import-dialog';
import { ProjectAvatar } from './shared/project-avatar';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
Expand All @@ -43,7 +43,7 @@ export function ProjectSwitcher({ collapsed }: ProjectSwitcherProps) {

const [open, setOpen] = useState(false);
const [showNewProjectDialog, setShowNewProjectDialog] = useState(false);
const [showGithubImportDialog, setShowGithubImportDialog] = useState(false);
const [showGitImportDialog, setShowGitImportDialog] = useState(false);
const [isSwitching, setIsSwitching] = useState(false);

// Show skeleton during initial load
Expand Down Expand Up @@ -100,9 +100,9 @@ export function ProjectSwitcher({ collapsed }: ProjectSwitcherProps) {
open={showNewProjectDialog}
onOpenChange={setShowNewProjectDialog}
/>
<GitHubImportDialog
open={showGithubImportDialog}
onOpenChange={setShowGithubImportDialog}
<GitImportDialog
open={showGitImportDialog}
onOpenChange={setShowGitImportDialog}
/>
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
Expand Down Expand Up @@ -208,12 +208,12 @@ export function ProjectSwitcher({ collapsed }: ProjectSwitcherProps) {
className="cursor-pointer"
onSelect={() => {
setOpen(false);
setShowGithubImportDialog(true);
setShowGitImportDialog(true);
}}
>
<div className="flex items-center gap-2">
<Github className="h-4 w-4" />
<span>Import from GitHub</span>
<GitBranch className="h-4 w-4" />
<span>Import from Git</span>
</div>
</CommandItem>
<CommandItem
Expand Down
30 changes: 15 additions & 15 deletions packages/ui/src/components/projects/create-project-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import { FolderOpen, Github } from 'lucide-react';
import { FolderOpen, GitBranch } from 'lucide-react';
import {
Button,
Dialog,
Expand All @@ -13,28 +13,28 @@ import {
import { useProjectMutations } from '../../hooks/useProjectQuery';
import { useCapabilities } from '../../hooks/useCapabilities';
import { DirectoryPicker } from './directory-picker';
import { GitHubImportForm } from './github-import-form';
import { GitImportForm } from './git-import-form';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';

interface CreateProjectDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
initialTab?: 'local' | 'github';
initialTab?: 'local' | 'git';
}

export function CreateProjectDialog({ open, onOpenChange, initialTab }: CreateProjectDialogProps) {
const { addProject } = useProjectMutations();
const navigate = useNavigate();
const { hasSource } = useCapabilities();
const showLocal = hasSource('local');
const showGithub = hasSource('github');
const showTabs = showLocal && showGithub;
const defaultTab = initialTab ?? (showLocal ? 'local' : 'github');
const showGit = hasSource('git');
const showTabs = showLocal && showGit;
const defaultTab = initialTab ?? (showLocal ? 'local' : 'git');

const [path, setPath] = useState('');
const [mode, setMode] = useState<'picker' | 'manual'>('picker');
const [tab, setTab] = useState<'local' | 'github'>(defaultTab);
const [tab, setTab] = useState<'local' | 'git'>(defaultTab);
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const { t } = useTranslation('common');
Expand Down Expand Up @@ -90,8 +90,8 @@ export function CreateProjectDialog({ open, onOpenChange, initialTab }: CreatePr
<DialogHeader>
<DialogTitle>{t('createProject.title')}</DialogTitle>
<DialogDescription>
{tab === 'github'
? 'Connect a GitHub repository containing LeanSpec specs.'
{tab === 'git'
? 'Connect a Git repository containing LeanSpec specs.'
: mode === 'picker'
? t('createProject.descriptionPicker')
: t('createProject.descriptionManual')}
Expand All @@ -116,20 +116,20 @@ export function CreateProjectDialog({ open, onOpenChange, initialTab }: CreatePr
<button
type="button"
className={`flex-1 flex items-center justify-center gap-2 px-3 py-1.5 text-sm font-medium rounded-md transition-colors ${
tab === 'github'
tab === 'git'
? 'bg-background text-foreground shadow-sm'
: 'text-muted-foreground hover:text-foreground'
}`}
onClick={() => { setTab('github'); setError(null); }}
onClick={() => { setTab('git'); setError(null); }}
>
<Github className="h-4 w-4" />
GitHub
<GitBranch className="h-4 w-4" />
Git
</button>
</div>
)}

{tab === 'github' && showGithub ? (
<GitHubImportForm
{tab === 'git' && showGit ? (
<GitImportForm
onSuccess={(projectId) => {
onOpenChange(false);
navigate(`/projects/${projectId}/specs`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Github } from 'lucide-react';
import { GitBranch } from 'lucide-react';
import {
Dialog,
DialogContent,
Expand All @@ -7,30 +7,30 @@ import {
DialogTitle,
} from '@/library';
import { useNavigate } from 'react-router-dom';
import { GitHubImportForm } from './github-import-form';
import { GitImportForm } from './git-import-form';

interface GitHubImportDialogProps {
interface GitImportDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
}

export function GitHubImportDialog({ open, onOpenChange }: GitHubImportDialogProps) {
export function GitImportDialog({ open, onOpenChange }: GitImportDialogProps) {
const navigate = useNavigate();

return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[520px]">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<Github className="h-5 w-5" />
Import from GitHub
<GitBranch className="h-5 w-5" />
Import from Git
</DialogTitle>
<DialogDescription>
Connect a GitHub repository containing LeanSpec specs.
Connect a Git repository containing LeanSpec specs.
</DialogDescription>
</DialogHeader>

<GitHubImportForm
<GitImportForm
onSuccess={(projectId) => {
onOpenChange(false);
navigate(`/projects/${projectId}/specs`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ import { Search, AlertCircle, CheckCircle } from 'lucide-react';
import { Button, Input, Label } from '@/library';
import { api } from '../../lib/api';
import { useQueryClient } from '@tanstack/react-query';
import type { GitHubDetectResult } from '../../lib/backend-adapter/core';
import type { GitDetectResult } from '../../lib/backend-adapter/core';

interface GitHubImportFormProps {
interface GitImportFormProps {
onSuccess: (projectId: string) => void;
onCancel: () => void;
}

export function GitHubImportForm({ onSuccess, onCancel }: GitHubImportFormProps) {
export function GitImportForm({ onSuccess, onCancel }: GitImportFormProps) {
const queryClient = useQueryClient();
const [repo, setRepo] = useState('');
const [token, setToken] = useState('');
const [detected, setDetected] = useState<GitHubDetectResult | null>(null);
const [detected, setDetected] = useState<GitDetectResult | null>(null);
const [isDetecting, setIsDetecting] = useState(false);
const [isImporting, setIsImporting] = useState(false);
const [error, setError] = useState<string | null>(null);
Expand All @@ -25,7 +24,7 @@ export function GitHubImportForm({ onSuccess, onCancel }: GitHubImportFormProps)
setError(null);
setDetected(null);
try {
const result = await api.detectGithubSpecs(repo.trim(), undefined, token || undefined);
const result = await api.detectGitSpecs(repo.trim());
if (!result) {
setError('No LeanSpec specs found in this repository. Make sure it has a `specs/` directory with numbered spec folders.');
} else {
Expand All @@ -43,10 +42,9 @@ export function GitHubImportForm({ onSuccess, onCancel }: GitHubImportFormProps)
setIsImporting(true);
setError(null);
try {
const result = await api.importGithubRepo(detected.repo, {
const result = await api.importGitRepo(repo.trim(), {
branch: detected.branch,
specsPath: detected.specsDir,
token: token || undefined,
});
await queryClient.invalidateQueries({ queryKey: ['projects'] });
onSuccess(result.projectId);
Expand All @@ -60,13 +58,13 @@ export function GitHubImportForm({ onSuccess, onCancel }: GitHubImportFormProps)
return (
<div className="space-y-4">
<div className="grid gap-2">
<Label htmlFor="github-repo">Repository</Label>
<Label htmlFor="git-repo">Repository</Label>
<div className="flex gap-2">
<Input
id="github-repo"
id="git-repo"
value={repo}
onChange={(e) => { setRepo(e.target.value); setDetected(null); }}
placeholder="owner/repo or GitHub URL"
placeholder="owner/repo, HTTPS URL, or SSH URL"
disabled={isDetecting || isImporting}
onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); void handleDetect(); } }}
/>
Expand All @@ -84,25 +82,7 @@ export function GitHubImportForm({ onSuccess, onCancel }: GitHubImportFormProps)
</Button>
</div>
<p className="text-xs text-muted-foreground">
e.g. <code>acme/my-project</code> or <code>https://github.com/acme/my-project</code>
</p>
</div>

<div className="grid gap-2">
<Label htmlFor="github-token">
GitHub Token{' '}
<span className="text-muted-foreground font-normal">(optional for public repos)</span>
</Label>
<Input
id="github-token"
type="password"
value={token}
onChange={(e) => setToken(e.target.value)}
placeholder="ghp_..."
disabled={isDetecting || isImporting}
/>
<p className="text-xs text-muted-foreground">
Required for private repos. Set <code>LEANSPEC_GITHUB_TOKEN</code> on the server to avoid entering it here.
Any Git repository — <code>acme/project</code>, <code>https://github.com/acme/project</code>, or <code>git@gitlab.com:team/repo.git</code>
</p>
</div>

Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/hooks/useCapabilities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

export type ProjectSource = 'local' | 'github';
export type ProjectSource = 'local' | 'git';

export interface Capabilities {
projectSources: ProjectSource[];
Expand All @@ -12,7 +12,7 @@ const VITE_FALLBACK: ProjectSource[] = (() => {
if (env) {
return env.split(',').map(s => s.trim().toLowerCase()).filter(Boolean) as ProjectSource[];
}
return ['local', 'github'];
return ['local', 'git'];
})();

async function fetchCapabilities(): Promise<Capabilities> {
Expand Down
13 changes: 6 additions & 7 deletions packages/ui/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ class ProjectAPI {
validateProject = (projectId: string) => this.backend.validateProject(projectId);
listDirectory = (path?: string) => this.backend.listDirectory(path);

// GitHub integration
listGithubRepos = () => this.backend.listGithubRepos();
detectGithubSpecs = (repo: string, branch?: string, token?: string) =>
this.backend.detectGithubSpecs(repo, branch, token);
importGithubRepo = (repo: string, opts?: { branch?: string; specsPath?: string; name?: string; token?: string }) =>
this.backend.importGithubRepo(repo, opts);
syncGithubProject = (projectId: string) => this.backend.syncGithubProject(projectId);
// Git integration
detectGitSpecs = (repo: string, branch?: string) =>
this.backend.detectGitSpecs(repo, branch);
importGitRepo = (repo: string, opts?: { branch?: string; specsPath?: string; name?: string }) =>
this.backend.importGitRepo(repo, opts);
syncGitProject = (projectId: string) => this.backend.syncGitProject(projectId);
getContextFiles = () => this.backend.getContextFiles();
getContextFile = (path: string) => this.backend.getContextFile(path);

Expand Down
19 changes: 8 additions & 11 deletions packages/ui/src/lib/backend-adapter/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ import type {
RunnerScope,
RunnerValidateResponse,
RunnerVersionResponse,
GitHubRepo,
GitHubDetectResult,
GitHubImportResult,
GitDetectResult,
GitImportResult,
} from '../../types/api';
import type { ChatConfig } from '../../types/chat-config';
import type { ModelsRegistryResponse } from '../../types/models-registry';
Expand Down Expand Up @@ -220,11 +219,10 @@ export interface BackendAdapter {
getProjectFile(projectId: string, path: string): Promise<FileContentResponse>;
searchProjectFiles(projectId: string, query: string, limit?: number): Promise<FileSearchResponse>;

// GitHub integration
listGithubRepos(): Promise<GitHubRepo[]>;
detectGithubSpecs(repo: string, branch?: string, token?: string): Promise<GitHubDetectResult | null>;
importGithubRepo(repo: string, opts?: { branch?: string; specsPath?: string; name?: string; token?: string }): Promise<GitHubImportResult>;
syncGithubProject(projectId: string): Promise<{ projectId: string; syncedSpecs: number }>;
// Git integration
detectGitSpecs(repo: string, branch?: string): Promise<GitDetectResult | null>;
importGitRepo(repo: string, opts?: { branch?: string; specsPath?: string; name?: string }): Promise<GitImportResult>;
syncGitProject(projectId: string): Promise<{ projectId: string; syncedSpecs: number }>;
}

export type {
Expand Down Expand Up @@ -263,7 +261,6 @@ export type {
FileSearchResponse,
SpecSearchFilters,
SpecSearchResponse,
GitHubRepo,
GitHubDetectResult,
GitHubImportResult,
GitDetectResult,
GitImportResult,
};
Loading
Loading