fix(agent-manager): fetch sessions from worktree directories
This commit is contained in:
@@ -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([]);
|
||||||
|
|||||||
@@ -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[]>();
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user