feat: carry archive UI label hard cut updates

This commit is contained in:
Mohamed Boudra
2026-03-04 10:39:28 +07:00
parent bf1cded8a1
commit 111b9d95f4
26 changed files with 408 additions and 175 deletions
@@ -86,6 +86,10 @@ import {
resolveWorkspaceHeader,
shouldRenderMissingWorkspaceDescriptor,
} from "@/screens/workspace/workspace-header-source";
import {
canOpenAgentTabFromRoute,
deriveWorkspaceAgentVisibility,
} from "@/screens/workspace/workspace-agent-visibility";
const TERMINALS_QUERY_STALE_TIME = 5_000;
const DROPDOWN_WIDTH = 220;
@@ -191,17 +195,6 @@ function resolveTabAvailability(input: {
return input.terminalIds.has(input.tab.terminalId) ? "available" : "invalid";
}
function sortAgentsByCreatedAtDescending(agents: Agent[]): Agent[] {
return [...agents].sort((left, right) => {
const createdAtDelta =
right.createdAt.getTime() - left.createdAt.getTime();
if (createdAtDelta !== 0) {
return createdAtDelta;
}
return right.lastActivityAt.getTime() - left.lastActivityAt.getTime();
});
}
export function WorkspaceScreen({
serverId,
workspaceId,
@@ -238,24 +231,15 @@ function WorkspaceScreenContent({
const sessionAgents = useSessionStore(
(state) => state.sessions[normalizedServerId]?.agents
);
const workspaceAgents = useMemo(() => {
if (!sessionAgents || !normalizedWorkspaceId) {
return [] as Agent[];
}
const collected: Agent[] = [];
for (const agent of sessionAgents.values()) {
if (agent.archivedAt) {
continue;
}
if ((trimNonEmpty(agent.cwd) ?? "") !== normalizedWorkspaceId) {
continue;
}
collected.push(agent);
}
return sortAgentsByCreatedAtDescending(collected);
}, [normalizedWorkspaceId, sessionAgents]);
const workspaceAgentVisibility = useMemo(
() =>
deriveWorkspaceAgentVisibility({
sessionAgents,
workspaceId: normalizedWorkspaceId,
}),
[normalizedWorkspaceId, sessionAgents]
);
const workspaceAgents = workspaceAgentVisibility.visibleAgents;
const terminalsQueryKey = useMemo(
() => ["terminals", normalizedServerId, normalizedWorkspaceId] as const,
@@ -482,13 +466,7 @@ function WorkspaceScreenContent({
return () => handler.remove();
}, [closeToAgent, isExplorerOpen]);
const agentsById = useMemo(() => {
const map = new Map<string, Agent>();
for (const agent of workspaceAgents) {
map.set(agent.id, agent);
}
return map;
}, [workspaceAgents]);
const agentsById = workspaceAgentVisibility.lookupById;
const terminalIds = useMemo(() => {
const set = new Set<string>();
@@ -575,7 +553,13 @@ function WorkspaceScreenContent({
if (normalized.startsWith("agent_")) {
const agentId = normalized.slice("agent_".length).trim();
if (agentId) {
if (areWorkspaceAgentsHydrated && !agentsById.has(agentId)) {
if (
!canOpenAgentTabFromRoute({
agentId,
agentsHydrated: areWorkspaceAgentsHydrated,
workspaceAgentLookup: agentsById,
})
) {
return;
}
const tabId = openOrFocusTab({