fix(agent-manager): fetch sessions from worktree directories

This commit is contained in:
Bohdan Triapitsyn
2026-01-04 00:11:42 +02:00
parent 98fee8a8c0
commit 8965d7841e
3 changed files with 34 additions and 12 deletions
@@ -34,7 +34,7 @@ interface AttachedFile {
interface AgentManagerEmptyStateProps { interface AgentManagerEmptyStateProps {
className?: string; className?: string;
/** Called when the user submits to create a new agent group */ /** Called when the user submits to create a new agent group */
onCreateGroup?: (params: CreateMultiRunParams) => void; onCreateGroup?: (params: CreateMultiRunParams) => Promise<void> | void;
/** Indicates if a group creation is in progress */ /** Indicates if a group creation is in progress */
isCreating?: boolean; isCreating?: boolean;
} }
@@ -150,7 +150,7 @@ export const AgentManagerEmptyState: React.FC<AgentManagerEmptyStateProps> = ({
})) }))
: undefined; : undefined;
onCreateGroup?.({ await onCreateGroup?.({
name: groupName.trim(), name: groupName.trim(),
prompt: prompt.trim(), prompt: prompt.trim(),
models, models,
@@ -158,7 +158,7 @@ export const AgentManagerEmptyState: React.FC<AgentManagerEmptyStateProps> = ({
files, files,
}); });
// Reset form on success // Reset form on success - only after onCreateGroup completes
setGroupName(''); setGroupName('');
setPrompt(''); setPrompt('');
setSelectedModels([]); setSelectedModels([]);
+30 -9
View File
@@ -175,17 +175,11 @@ export const useAgentGroupsStore = create<AgentGroupsStore>()(
try { try {
const apiClient = opencodeClient.getApiClient(); const apiClient = opencodeClient.getApiClient();
// Fetch all sessions from the main project directory // Get git worktree info first - we need to query each worktree separately
// All worktree sessions are visible from here
const response = await apiClient.session.list({
directory: normalizedCurrent,
});
const allSessions: Session[] = Array.isArray(response.data) ? response.data : [];
// Get git worktree info for metadata
let worktreeInfoMap = new Map<string, Awaited<ReturnType<typeof listWorktrees>>[number]>(); let worktreeInfoMap = new Map<string, Awaited<ReturnType<typeof listWorktrees>>[number]>();
let worktreeInfoList: Awaited<ReturnType<typeof listWorktrees>> = [];
try { try {
const worktreeInfoList = await listWorktrees(normalizedCurrent); worktreeInfoList = await listWorktrees(normalizedCurrent);
worktreeInfoMap = new Map( worktreeInfoMap = new Map(
worktreeInfoList.map((info) => [normalize(info.worktree), info]) worktreeInfoList.map((info) => [normalize(info.worktree), info])
); );
@@ -193,6 +187,33 @@ export const useAgentGroupsStore = create<AgentGroupsStore>()(
console.debug('Failed to list git worktrees'); console.debug('Failed to list git worktrees');
} }
// Fetch sessions from each worktree directory (sessions are stored per-directory in OpenCode)
// Filter to only .openchamber worktrees (agent group worktrees)
const openchamberWorktrees = worktreeInfoList.filter(
(info) => normalize(info.worktree).includes(`/${OPENCHAMBER_DIR}/`)
);
const sessionsMap = new Map<string, Session>();
// Fetch sessions from each openchamber worktree
await Promise.all(
openchamberWorktrees.map(async (worktree) => {
try {
const response = await apiClient.session.list({
directory: normalize(worktree.worktree),
});
const sessions: Session[] = Array.isArray(response.data) ? response.data : [];
for (const session of sessions) {
sessionsMap.set(session.id, session);
}
} catch (err) {
console.debug('Failed to fetch sessions from worktree:', worktree.worktree, err);
}
})
);
const allSessions = Array.from(sessionsMap.values());
// Parse sessions and group by groupSlug // Parse sessions and group by groupSlug
const groupsMap = new Map<string, AgentGroupSession[]>(); const groupsMap = new Map<string, AgentGroupSession[]>();
+1
View File
@@ -107,6 +107,7 @@ export const createVSCodeGitAPI = (): GitAPI => ({
path: payload.path, path: payload.path,
branch: payload.branch, branch: payload.branch,
createBranch: payload.createBranch, createBranch: payload.createBranch,
startPoint: payload.startPoint,
}); });
}, },