Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

feat(aipc): web端分支选择器适配实时监控

kdgmpwc9d8db9c7331
diff --git a/jiuwenswarm/channels/web/frontend/src/features/code-mode/CodeBranchSelector.tsx b/jiuwenswarm/channels/web/frontend/src/features/code-mode/CodeBranchSelector.tsx
index 744d3325f0..67e8ad2afe 100644
--- a/jiuwenswarm/channels/web/frontend/src/features/code-mode/CodeBranchSelector.tsx
+++ b/jiuwenswarm/channels/web/frontend/src/features/code-mode/CodeBranchSelector.tsx
@@ -3,7 +3,7 @@ import { AlertCircle, Check, ChevronDown, GitBranch, LoaderCircle, Plus, Search,
import type { ProjectInfo, WebError } from '../../types';
import { useWorkspaceStore } from '../../stores';
import { gitClient } from './gitClient';
-import type { GitRepoStatus } from './types';
+import type { GitDiffRepoInfo, GitRepoStatus } from './types';
import './CodeMode.css';
interface CodeBranchSelectorProps {
@@ -11,6 +11,7 @@ interface CodeBranchSelectorProps {
compact?: boolean;
disabled?: boolean;
variant?: 'default' | 'environment';
+ liveRepo?: GitDiffRepoInfo | null;
}
function getErrorMessage(error: unknown): string {
@@ -31,7 +32,7 @@ function getErrorMessage(error: unknown): string {
}
}
-export function CodeBranchSelector({ project, compact = false, disabled = false, variant = 'default' }: CodeBranchSelectorProps) {
+export function CodeBranchSelector({ project, compact = false, disabled = false, variant = 'default', liveRepo = null }: CodeBranchSelectorProps) {
const [status, setStatus] = useState<GitRepoStatus | null>(null);
const [loading, setLoading] = useState(false);
const [operating, setOperating] = useState(false);
@@ -79,6 +80,29 @@ export function CodeBranchSelector({ project, compact = false, disabled = false,
void loadStatus();
}, [loadStatus]);
+ useEffect(() => {
+ if (!liveRepo || !project || project.work_mode !== 'code' || project.is_default) return;
+ setNotGit(!liveRepo.is_git);
+ setStatus(previous => {
+ if (!previous) return previous;
+ return {
+ ...previous,
+ repo: {
+ ...previous.repo,
+ is_git: liveRepo.is_git,
+ repo_root: liveRepo.repo_root,
+ branch: liveRepo.branch,
+ head: liveRepo.head,
+ transient: liveRepo.transient,
+ },
+ branches: {
+ ...previous.branches,
+ current: liveRepo.branch,
+ },
+ };
+ });
+ }, [liveRepo, project]);
+
useEffect(() => {
if (!open) return;
const close = (event: MouseEvent) => {
@@ -101,10 +125,15 @@ export function CodeBranchSelector({ project, compact = false, disabled = false,
}, [search, status]);
const isNotGit = notGit || status?.repo.is_git === false || Boolean(!loading && !status && project?.git.status === 'not_git');
- const currentBranch = status?.branches.current || project?.git.branch || '';
+ const currentBranch = liveRepo?.branch || status?.branches.current || project?.git.branch || '';
const branchWritesBlocked = Boolean(status?.repo.transient || status?.repo.detached);
const isUnbornHead = Boolean(status?.repo.is_git && currentBranch && !status.repo.head);
+ const openMenu = () => {
+ setOpen(true);
+ void loadStatus();
+ };
+
const initializeGit = async () => {
if (!project) return;
setOperating(true);
@@ -178,7 +207,7 @@ export function CodeBranchSelector({ project, compact = false, disabled = false,
<button
type='button'
className='code-branch__trigger'
- onClick={() => (open ? closeMenu() : setOpen(true))}
+ onClick={() => (open ? closeMenu() : openMenu())}
disabled={disabled || loading || operating || !status}
aria-haspopup='menu'
aria-expanded={open}
diff --git a/jiuwenswarm/channels/web/frontend/src/features/code-mode/CodeEnvironmentPanel.tsx b/jiuwenswarm/channels/web/frontend/src/features/code-mode/CodeEnvironmentPanel.tsx
index 9faf807d2b..b53d37595e 100644
--- a/jiuwenswarm/channels/web/frontend/src/features/code-mode/CodeEnvironmentPanel.tsx
+++ b/jiuwenswarm/channels/web/frontend/src/features/code-mode/CodeEnvironmentPanel.tsx
@@ -40,7 +40,13 @@ export function CodeEnvironmentPanel({ project, isProcessing, diffWatch, onRevie
</small>
</button>
<div className="code-environment__row code-environment__row--branch">
- <CodeBranchSelector project={project} compact variant="environment" disabled={isProcessing} />
+ <CodeBranchSelector
+ project={project}
+ compact
+ variant="environment"
+ disabled={isProcessing}
+ liveRepo={diffWatch.summary?.repo ?? null}
+ />
</div>
</section>
);