mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-26 02:31:40 +00:00
feat(ui): inline compose directory picker and streamline AI session history UX (#4356)
* feat(ui): inline compose directory picker and streamline AI session history UX * fix(ai): exclude workspace members and hidden terminals from active-elsewhere jump targets * fix(ai): clear non-AI magnification overlay when jumping to an active chat tab
This commit is contained in:
24 files changed
+287
-45
No files matched your search
@@ -618,8 +618,8 @@ export const enAiMessages: Messages = {
|
||||
'ai.chat.rebindUsage': 'Usage: /rebind <number from /chats>',
|
||||
'ai.chat.rebindDone': 'Chat "{title}" rebound to this panel.',
|
||||
'ai.chat.rebindUnavailable': 'No rebind target in this panel scope.',
|
||||
'ai.chat.managerScopeTab': 'Current',
|
||||
'ai.chat.managerAllChatsTab': 'All',
|
||||
'ai.chat.managerScopeTab': 'Current chats',
|
||||
'ai.chat.managerAllChatsTab': 'All chats',
|
||||
'ai.chat.managerSearchPlaceholder': 'Search chat titles…',
|
||||
'ai.chat.managerFilterAllAgents': 'All agents',
|
||||
'ai.chat.managerMoreActions': 'More actions',
|
||||
|
||||
@@ -618,8 +618,8 @@ export const esAiMessages: Messages = {
|
||||
'ai.chat.rebindUsage': 'Uso: /rebind <número de /chats>',
|
||||
'ai.chat.rebindDone': 'Chat «{title}» reasociado a este panel.',
|
||||
'ai.chat.rebindUnavailable': 'No hay destino de reasociación en el ámbito de este panel.',
|
||||
'ai.chat.managerScopeTab': 'Actual',
|
||||
'ai.chat.managerAllChatsTab': 'Todos',
|
||||
'ai.chat.managerScopeTab': 'Chats actuales',
|
||||
'ai.chat.managerAllChatsTab': 'Todos los chats',
|
||||
'ai.chat.managerSearchPlaceholder': 'Buscar títulos de chats…',
|
||||
'ai.chat.managerFilterAllAgents': 'Todos los agentes',
|
||||
'ai.chat.managerMoreActions': 'Más acciones',
|
||||
|
||||
@@ -557,8 +557,8 @@ export const ruAiMessages: Messages = {
|
||||
'ai.chat.rebindUsage': 'Использование: /rebind <номер из /chats>',
|
||||
'ai.chat.rebindDone': 'Чат «{title}» привязан к этой панели.',
|
||||
'ai.chat.rebindUnavailable': 'В области этой панели нет цели для привязки.',
|
||||
'ai.chat.managerScopeTab': 'Текущие',
|
||||
'ai.chat.managerAllChatsTab': 'Все',
|
||||
'ai.chat.managerScopeTab': 'Текущие чаты',
|
||||
'ai.chat.managerAllChatsTab': 'Все чаты',
|
||||
'ai.chat.managerSearchPlaceholder': 'Поиск по названиям чатов…',
|
||||
'ai.chat.managerFilterAllAgents': 'Все агенты',
|
||||
'ai.chat.managerMoreActions': 'Ещё действия',
|
||||
|
||||
@@ -618,8 +618,8 @@ export const zhCNAiMessages: Messages = {
|
||||
'ai.chat.rebindUsage': '用法:/rebind <序号>',
|
||||
'ai.chat.rebindDone': '聊天“{title}”已重绑到此面板。',
|
||||
'ai.chat.rebindUnavailable': '当前面板范围内没有可用的重绑目标。',
|
||||
'ai.chat.managerScopeTab': '当前',
|
||||
'ai.chat.managerAllChatsTab': '全部',
|
||||
'ai.chat.managerScopeTab': '当前会话',
|
||||
'ai.chat.managerAllChatsTab': '全部会话',
|
||||
'ai.chat.managerSearchPlaceholder': '搜索会话标题…',
|
||||
'ai.chat.managerFilterAllAgents': '全部 Agent',
|
||||
'ai.chat.managerMoreActions': '更多操作',
|
||||
|
||||
@@ -617,8 +617,8 @@ export const zhTWAiMessages: Messages = {
|
||||
'ai.chat.rebindUsage': '用法:/rebind <序號>',
|
||||
'ai.chat.rebindDone': '聊天「{title}」已重新綁定到此面板。',
|
||||
'ai.chat.rebindUnavailable': '目前面板範圍內沒有可用的重新綁定目標。',
|
||||
'ai.chat.managerScopeTab': '目前',
|
||||
'ai.chat.managerAllChatsTab': '全部',
|
||||
'ai.chat.managerScopeTab': '目前會話',
|
||||
'ai.chat.managerAllChatsTab': '全部會話',
|
||||
'ai.chat.managerSearchPlaceholder': '搜尋會話標題…',
|
||||
'ai.chat.managerFilterAllAgents': '全部 Agent',
|
||||
'ai.chat.managerMoreActions': '更多操作',
|
||||
|
||||
@@ -2,8 +2,8 @@ import { useCallback } from 'react';
|
||||
import { STORAGE_KEY_COMPOSE_BAR_HEIGHT } from '../../infrastructure/config/storageKeys';
|
||||
import { useStoredNumber } from './useStoredNumber';
|
||||
|
||||
export const COMPOSE_BAR_HEIGHT_DEFAULT = 144;
|
||||
export const COMPOSE_BAR_HEIGHT_MIN = 104;
|
||||
export const COMPOSE_BAR_HEIGHT_DEFAULT = 120;
|
||||
export const COMPOSE_BAR_HEIGHT_MIN = 72;
|
||||
export const COMPOSE_BAR_HEIGHT_MAX = 360;
|
||||
|
||||
const HEIGHT_CLAMP = { min: COMPOSE_BAR_HEIGHT_MIN, max: COMPOSE_BAR_HEIGHT_MAX };
|
||||
|
||||
@@ -94,9 +94,6 @@ test("history drawer filters, pages, clears and explains the bounded search in e
|
||||
await enterQuery("[](){}");
|
||||
assert.equal(rows().length, 0);
|
||||
assert.match(renderer.container.textContent ?? "", /No matches in titles or recent retained content/);
|
||||
assert.match(renderer.container.textContent ?? "", /prioritizing newer messages and entries/);
|
||||
assert.match(renderer.container.textContent ?? "", /only a limited portion at the beginning is searched/);
|
||||
assert.match(renderer.container.textContent ?? "", /not full-text search/);
|
||||
await click(renderer.container.querySelector("input")?.parentElement?.querySelector("button"));
|
||||
assert.equal(renderer.container.querySelector("input")?.value, "");
|
||||
assert.equal(rows().length, 80);
|
||||
@@ -113,13 +110,12 @@ test("history drawer filters, pages, clears and explains the bounded search in e
|
||||
await enterQuery("no-such-content");
|
||||
const messages = getLoadedLocaleMessages(locale)!;
|
||||
const input = renderer.container.querySelector("input")!;
|
||||
const hint = dom.document.getElementById(input.getAttribute("aria-describedby")!);
|
||||
for (const key of ["ai.chat.searchSessions", "ai.chat.searchSessionsHint", "ai.chat.noMatchingSessions"]) {
|
||||
for (const key of ["ai.chat.searchSessions", "ai.chat.noMatchingSessions"]) {
|
||||
assert.ok(messages[key], `${locale} is missing ${key}`);
|
||||
}
|
||||
assert.equal(input.placeholder, messages["ai.chat.searchSessions"]);
|
||||
assert.equal(input.getAttribute("aria-label"), messages["ai.chat.searchSessions"]);
|
||||
assert.equal(hint?.textContent, messages["ai.chat.searchSessionsHint"]);
|
||||
assert.equal(input.getAttribute("aria-describedby"), null);
|
||||
assert.ok(renderer.container.textContent?.includes(messages["ai.chat.noMatchingSessions"]));
|
||||
await render([], locale);
|
||||
assert.ok(renderer.container.textContent?.includes(messages["ai.chat.noSessions"]));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useId, useRef, useState } from 'react';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { Download, MoreHorizontal, Pencil, Search, Trash2, Upload, X } from 'lucide-react';
|
||||
import type { AISession } from '../infrastructure/ai/types';
|
||||
import { useI18n } from '../application/i18n/I18nProvider';
|
||||
@@ -57,7 +57,6 @@ export const SessionHistoryDrawer: React.FC<SessionHistoryDrawerProps> = ({
|
||||
const [renamingSessionId, setRenamingSessionId] = useState<string | null>(null);
|
||||
const [renameDraft, setRenameDraft] = useState('');
|
||||
const renameInputRef = useRef<HTMLInputElement>(null);
|
||||
const searchHintId = useId();
|
||||
const searchInputRef = useRef<HTMLInputElement>(null);
|
||||
const { filteredSessions, isSearching } = useSessionHistorySearch(
|
||||
sessions,
|
||||
@@ -201,7 +200,6 @@ export const SessionHistoryDrawer: React.FC<SessionHistoryDrawerProps> = ({
|
||||
maxLength={MAX_SEARCH_QUERY_LENGTH}
|
||||
placeholder={t('ai.chat.searchSessions')}
|
||||
aria-label={t('ai.chat.searchSessions')}
|
||||
aria-describedby={searchHintId}
|
||||
onChange={(event) => setSearchQuery(truncateQueryForMatch(event.target.value))}
|
||||
className="h-8 pl-8 pr-7 text-[12px]"
|
||||
/>
|
||||
@@ -219,9 +217,6 @@ export const SessionHistoryDrawer: React.FC<SessionHistoryDrawerProps> = ({
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<p id={searchHintId} className="mt-1.5 text-[11px] text-muted-foreground/60">
|
||||
{t('ai.chat.searchSessionsHint')}
|
||||
</p>
|
||||
</div>
|
||||
<ScrollArea className="flex-1" aria-busy={isSearching}>
|
||||
{isSearching && (
|
||||
|
||||
@@ -329,6 +329,7 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
scopeLabel,
|
||||
focusedSessionId,
|
||||
onSetWorkspaceAnchorChat,
|
||||
onFocusAIScopeTarget,
|
||||
workspaces = [],
|
||||
terminalSessions = [],
|
||||
appTerminalSessions,
|
||||
@@ -2322,6 +2323,17 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
workspaces,
|
||||
]);
|
||||
|
||||
const handleManagerFocusScope = useCallback((target: {
|
||||
type: 'terminal' | 'workspace';
|
||||
targetId: string;
|
||||
}): boolean => {
|
||||
const focused = onFocusAIScopeTarget?.(target) ?? false;
|
||||
if (focused) {
|
||||
setShowHistory(false);
|
||||
}
|
||||
return focused;
|
||||
}, [onFocusAIScopeTarget]);
|
||||
|
||||
const handleManagerRebind = useCallback(async (sessionId: string, target: GlobalManagerScopeTarget) => {
|
||||
if (!rebindSessionScope) return;
|
||||
// A rebinding while a turn streams into the chat corrupts streaming state
|
||||
@@ -2397,6 +2409,7 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
externalAgents={externalAgents}
|
||||
rebindTargets={managerRebindTargets}
|
||||
onSelect={(sessionId) => { void handleManagerActivate(sessionId); }}
|
||||
onFocusScope={onFocusAIScopeTarget ? handleManagerFocusScope : undefined}
|
||||
onRebind={handleManagerRebind}
|
||||
onRename={handleRenameSession}
|
||||
onDelete={(sessionId) => { void handleManagerDelete(sessionId); }}
|
||||
@@ -2414,10 +2427,12 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
externalAgents,
|
||||
managerRebindTargets,
|
||||
handleManagerActivate,
|
||||
handleManagerFocusScope,
|
||||
handleManagerRebind,
|
||||
handleRenameSession,
|
||||
handleManagerDelete,
|
||||
handleManagerExport,
|
||||
onFocusAIScopeTarget,
|
||||
]);
|
||||
|
||||
const handleAgentChange = useCallback((agentId: string) => {
|
||||
@@ -2632,6 +2647,7 @@ export function aiChatSidePanelPropsAreEqual(
|
||||
if (prev.onOpenVaultHost !== next.onOpenVaultHost) return false;
|
||||
if (prev.onOpenVaultSnippet !== next.onOpenVaultSnippet) return false;
|
||||
if (prev.onOpenVaultSection !== next.onOpenVaultSection) return false;
|
||||
if (prev.onFocusAIScopeTarget !== next.onFocusAIScopeTarget) return false;
|
||||
|
||||
const scopeKey = `${prev.scopeType}:${prev.scopeTargetId ?? ''}`;
|
||||
if (
|
||||
|
||||
@@ -112,6 +112,8 @@ export interface AIChatSidePanelProps {
|
||||
focusedSessionId?: string;
|
||||
/** Issue #4098 phase 2: pin the AI chat a workspace scope is anchored to. */
|
||||
onSetWorkspaceAnchorChat?: (workspaceId: string, chatId: string | null) => void;
|
||||
/** Focus an already-open terminal or workspace tab and ensure its AI side panel is visible. */
|
||||
onFocusAIScopeTarget?: (target: { type: 'terminal' | 'workspace'; targetId: string }) => boolean;
|
||||
/** Live workspaces (with their anchor chat and member host IDs), used for scope titles, anchor resolution, and explicit workspace rebinds. */
|
||||
workspaces?: Array<{ id: string; title: string; anchorChatId?: string; hostIds?: string[] }>;
|
||||
/** All currently live terminal (and workspace) scope target ids. */
|
||||
@@ -123,6 +125,8 @@ export interface AIChatSidePanelProps {
|
||||
hostname: string;
|
||||
label: string;
|
||||
connected: boolean;
|
||||
workspaceId?: string;
|
||||
hiddenFromTabs?: boolean;
|
||||
}>;
|
||||
|
||||
// Terminal session context (from parent)
|
||||
|
||||
@@ -2097,6 +2097,40 @@ const TerminalLayerInner: React.FC<TerminalLayerProps> = ({
|
||||
handleSwitchSidePanelTab('ai');
|
||||
}, [handleSwitchSidePanelTab]);
|
||||
|
||||
// Focus an already-open terminal or workspace hosting an active AI chat and
|
||||
// ensure its AI side panel is visible, instead of moving/interrupting it.
|
||||
const handleFocusAIScopeTarget = useCallback((target: {
|
||||
type: 'terminal' | 'workspace';
|
||||
targetId: string;
|
||||
}): boolean => {
|
||||
let tabId: string | null = null;
|
||||
if (target.type === 'workspace') {
|
||||
const workspace = workspacesRef.current.find((candidate) => candidate.id === target.targetId);
|
||||
if (!workspace) return false;
|
||||
tabId = workspace.id;
|
||||
} else {
|
||||
const terminal = sessionsRef.current.find((candidate) => candidate.id === target.targetId);
|
||||
// Reject hidden/popped-out terminals (no main-window tab) and workspace
|
||||
// members (focused via their owning `workspace:<id>` scope so the active
|
||||
// chat shown in the workspace matches the clicked row).
|
||||
if (!terminal || terminal.hiddenFromTabs || terminal.workspaceId) return false;
|
||||
tabId = terminal.id;
|
||||
}
|
||||
setMagnifiedPane((current) => (
|
||||
current?.tabId === tabId
|
||||
&& !(current.target.kind === 'side-panel' && current.target.tool === 'ai')
|
||||
? null
|
||||
: current
|
||||
));
|
||||
activeTabStore.setActiveTabId(tabId);
|
||||
if (prepareSidePanelTool(tabId, 'ai')) {
|
||||
startTransition(() => {
|
||||
selectSidePanelToolForTab(tabId, 'ai');
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}, [prepareSidePanelTool, selectSidePanelToolForTab]);
|
||||
|
||||
const handleOpenSystem = useCallback(() => {
|
||||
handleSwitchSidePanelTab('system');
|
||||
}, [handleSwitchSidePanelTab]);
|
||||
@@ -2715,6 +2749,7 @@ const TerminalLayerInner: React.FC<TerminalLayerProps> = ({
|
||||
handleOpenScripts,
|
||||
handleOpenTheme,
|
||||
handleOpenAI,
|
||||
handleFocusAIScopeTarget,
|
||||
handleOpenSystem,
|
||||
handleOpenNotes,
|
||||
getActiveTerminalSessionId,
|
||||
|
||||
@@ -48,6 +48,7 @@ function baseProps() {
|
||||
{ type: "terminal" as const, targetId: "t-2", label: "core", hostIds: undefined as string[] | undefined },
|
||||
],
|
||||
onSelect: (_sessionId: string) => {},
|
||||
onFocusScope: undefined as ((_target: { type: "terminal" | "workspace"; targetId: string }) => boolean | void) | undefined,
|
||||
onRebind: (_sessionId: string, _target: { type: string; targetId: string; hostIds?: string[] }) => {},
|
||||
onRename: undefined as ((_sessionId: string, _title: string) => void) | undefined,
|
||||
onDelete: (_sessionId: string) => {},
|
||||
@@ -484,3 +485,60 @@ test("history drawer hosts the manager behind a current/all toggle", async () =>
|
||||
dom.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("clicking an active-elsewhere chat jumps to its open panel instead of moving it; past chats still open directly", async () => {
|
||||
const dom = installDomEnvironment();
|
||||
try {
|
||||
const props = baseProps();
|
||||
props.sessions = [
|
||||
makeSession({ id: "elsewhere-term", title: "Active in core", scope: { type: "terminal", targetId: "t-2" }, updatedAt: 300 }),
|
||||
makeSession({ id: "elsewhere-ws", title: "Active in prod", scope: { type: "workspace", targetId: "w-1" }, updatedAt: 200 }),
|
||||
makeSession({ id: "past-chat", title: "Closed host chat", scope: { type: "terminal", targetId: "t-gone", hostIds: ["h-old"] }, updatedAt: 100 }),
|
||||
];
|
||||
props.activeSessionIdMap = {
|
||||
"terminal:t-2": "elsewhere-term",
|
||||
"workspace:w-1": "elsewhere-ws",
|
||||
};
|
||||
const selected: string[] = [];
|
||||
const focused: Array<{ type: "terminal" | "workspace"; targetId: string }> = [];
|
||||
props.onSelect = (id) => selected.push(id);
|
||||
props.onFocusScope = (target) => {
|
||||
focused.push(target);
|
||||
return true;
|
||||
};
|
||||
const renderer = await renderManager(dom, props);
|
||||
|
||||
const byId = (id: string) => rows(renderer).find((row) => row.dataset.sessionId === id)!;
|
||||
await dispatchDomEvent(byId("elsewhere-term"), new dom.window.MouseEvent("click", { bubbles: true }));
|
||||
await dispatchDomEvent(byId("elsewhere-ws"), new dom.window.KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
|
||||
await dispatchDomEvent(byId("past-chat"), new dom.window.MouseEvent("click", { bubbles: true }));
|
||||
|
||||
assert.deepEqual(focused, [
|
||||
{ type: "terminal", targetId: "t-2" },
|
||||
{ type: "workspace", targetId: "w-1" },
|
||||
]);
|
||||
assert.deepEqual(selected, ["past-chat"]);
|
||||
} finally {
|
||||
dom.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("clicking an active-elsewhere chat falls back to opening locally when focusing the target panel fails", async () => {
|
||||
const dom = installDomEnvironment();
|
||||
try {
|
||||
const props = baseProps();
|
||||
props.sessions = [
|
||||
makeSession({ id: "elsewhere-term", title: "Active in core", scope: { type: "terminal", targetId: "t-2" } }),
|
||||
];
|
||||
props.activeSessionIdMap = { "terminal:t-2": "elsewhere-term" };
|
||||
const selected: string[] = [];
|
||||
props.onSelect = (id) => selected.push(id);
|
||||
props.onFocusScope = () => false;
|
||||
const renderer = await renderManager(dom, props);
|
||||
|
||||
await dispatchDomEvent(rows(renderer)[0], new dom.window.MouseEvent("click", { bubbles: true }));
|
||||
assert.deepEqual(selected, ["elsewhere-term"]);
|
||||
} finally {
|
||||
dom.cleanup();
|
||||
}
|
||||
});
|
||||
@@ -51,6 +51,8 @@ interface GlobalAIChatSessionManagerProps {
|
||||
externalAgents: ExternalAgentConfig[];
|
||||
rebindTargets: GlobalManagerScopeTarget[];
|
||||
onSelect: (sessionId: string) => void;
|
||||
/** Focus an already-open terminal or workspace hosting an active chat instead of moving it. */
|
||||
onFocusScope?: (target: { type: 'terminal' | 'workspace'; targetId: string }) => boolean | void;
|
||||
onRebind: (sessionId: string, target: GlobalManagerScopeTarget) => void;
|
||||
onRename?: (sessionId: string, title: string) => void;
|
||||
onDelete: (sessionId: string) => void;
|
||||
@@ -72,6 +74,7 @@ export const GlobalAIChatSessionManager: React.FC<GlobalAIChatSessionManagerProp
|
||||
externalAgents,
|
||||
rebindTargets,
|
||||
onSelect,
|
||||
onFocusScope,
|
||||
onRebind,
|
||||
onRename,
|
||||
onDelete,
|
||||
@@ -176,6 +179,14 @@ export const GlobalAIChatSessionManager: React.FC<GlobalAIChatSessionManagerProp
|
||||
setMoveSession(null);
|
||||
};
|
||||
|
||||
const activateRow = (row: ReturnType<typeof buildGlobalManagerRows>[number]) => {
|
||||
if (row.isActiveElsewhere && row.activeElsewhereTarget && onFocusScope) {
|
||||
const focused = onFocusScope(row.activeElsewhereTarget);
|
||||
if (focused !== false) return;
|
||||
}
|
||||
onSelect(row.session.id);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex-1 flex flex-col min-h-0" data-section="ai-global-session-manager">
|
||||
<div className="px-3 py-2 shrink-0 border-b border-border/30 flex items-center gap-1.5">
|
||||
@@ -264,13 +275,13 @@ export const GlobalAIChatSessionManager: React.FC<GlobalAIChatSessionManagerProp
|
||||
role="button"
|
||||
tabIndex={row.canActivate ? 0 : -1}
|
||||
onClick={() => {
|
||||
if (!isRenaming && row.canActivate) onSelect(row.session.id);
|
||||
if (!isRenaming && row.canActivate) activateRow(row);
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.target !== e.currentTarget) return;
|
||||
if (!isRenaming && row.canActivate && (e.key === 'Enter' || e.key === ' ')) {
|
||||
e.preventDefault();
|
||||
onSelect(row.session.id);
|
||||
activateRow(row);
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
|
||||
@@ -101,20 +101,69 @@ test("active marker distinguishes current panel active chat vs active elsewhere"
|
||||
input.sessions = [
|
||||
baseSession({ id: "s-active-here", scope: { type: "terminal", targetId: "t-1" } }),
|
||||
baseSession({ id: "s-active-elsewhere", scope: { type: "terminal", targetId: "t-2" } }),
|
||||
baseSession({ id: "s-active-workspace", scope: { type: "workspace", targetId: "w-1" } }),
|
||||
baseSession({ id: "s-stale-active", scope: { type: "terminal", targetId: "t-dead" } }),
|
||||
baseSession({ id: "s-idle", scope: { type: "terminal", targetId: "t-1" } }),
|
||||
];
|
||||
input.activeSessionIdMap = { "terminal:t-1": "s-active-here", "terminal:t-2": "s-active-elsewhere" };
|
||||
input.activeSessionIdMap = {
|
||||
"terminal:t-1": "s-active-here",
|
||||
"terminal:t-2": "s-active-elsewhere",
|
||||
"workspace:w-1": "s-active-workspace",
|
||||
"terminal:t-dead": "s-stale-active",
|
||||
};
|
||||
const rows = buildGlobalManagerRows(input);
|
||||
const byId = new Map(rows.map((row) => [row.session.id, row]));
|
||||
assert.equal(byId.get("s-active-here")!.scopeState, "active");
|
||||
assert.equal(byId.get("s-active-here")!.isCurrentActive, true);
|
||||
assert.equal(byId.get("s-active-here")!.isActiveElsewhere, false);
|
||||
assert.equal(byId.get("s-active-here")!.activeElsewhereTarget, null);
|
||||
assert.equal(byId.get("s-active-elsewhere")!.scopeState, "active");
|
||||
assert.equal(byId.get("s-active-elsewhere")!.isCurrentActive, false);
|
||||
assert.equal(byId.get("s-active-elsewhere")!.isActiveElsewhere, true);
|
||||
assert.deepEqual(byId.get("s-active-elsewhere")!.activeElsewhereTarget, { type: "terminal", targetId: "t-2" });
|
||||
assert.equal(byId.get("s-active-workspace")!.scopeState, "active");
|
||||
assert.equal(byId.get("s-active-workspace")!.isActiveElsewhere, true);
|
||||
assert.deepEqual(byId.get("s-active-workspace")!.activeElsewhereTarget, { type: "workspace", targetId: "w-1" });
|
||||
// Stale active map entries for closed scopes must not mark a past chat as active elsewhere.
|
||||
assert.equal(byId.get("s-stale-active")!.scopeState, "dangling");
|
||||
assert.equal(byId.get("s-stale-active")!.isActiveElsewhere, false);
|
||||
assert.equal(byId.get("s-stale-active")!.activeElsewhereTarget, null);
|
||||
assert.equal(byId.get("s-idle")!.scopeState, "idle");
|
||||
assert.equal(byId.get("s-idle")!.isCurrentActive, false);
|
||||
assert.equal(byId.get("s-idle")!.isActiveElsewhere, false);
|
||||
assert.equal(byId.get("s-idle")!.activeElsewhereTarget, null);
|
||||
});
|
||||
|
||||
test("workspace member and hidden terminal active pointers are not treated as jumpable elsewhere panels", () => {
|
||||
const input = baseInput();
|
||||
input.terminalInfos = [
|
||||
...input.terminalInfos,
|
||||
{ sessionId: "t-member", hostId: "h-3", label: "member", hostname: "member.example", connected: true, workspaceId: "w-1" },
|
||||
{ sessionId: "t-hidden", hostId: "h-4", label: "popout", hostname: "popout.example", connected: true, hiddenFromTabs: true },
|
||||
];
|
||||
input.sessions = [
|
||||
baseSession({ id: "s-ws-active", scope: { type: "workspace", targetId: "w-1" } }),
|
||||
baseSession({ id: "s-member-retained", scope: { type: "terminal", targetId: "t-member" } }),
|
||||
baseSession({ id: "s-hidden-active", scope: { type: "terminal", targetId: "t-hidden" } }),
|
||||
];
|
||||
input.activeSessionIdMap = {
|
||||
"workspace:w-1": "s-ws-active",
|
||||
"terminal:t-member": "s-member-retained",
|
||||
"terminal:t-hidden": "s-hidden-active",
|
||||
};
|
||||
const rows = buildGlobalManagerRows(input);
|
||||
const byId = new Map(rows.map((row) => [row.session.id, row]));
|
||||
|
||||
assert.equal(byId.get("s-ws-active")!.isActiveElsewhere, true);
|
||||
assert.deepEqual(byId.get("s-ws-active")!.activeElsewhereTarget, { type: "workspace", targetId: "w-1" });
|
||||
|
||||
assert.equal(byId.get("s-member-retained")!.isActiveElsewhere, false);
|
||||
assert.equal(byId.get("s-member-retained")!.activeElsewhereTarget, null);
|
||||
assert.equal(byId.get("s-member-retained")!.scopeState, "idle");
|
||||
|
||||
assert.equal(byId.get("s-hidden-active")!.isActiveElsewhere, false);
|
||||
assert.equal(byId.get("s-hidden-active")!.activeElsewhereTarget, null);
|
||||
assert.equal(byId.get("s-hidden-active")!.scopeState, "idle");
|
||||
});
|
||||
|
||||
test("rows sort by updatedAt descending and carry agent labels + counts", () => {
|
||||
|
||||
@@ -20,6 +20,8 @@ export interface GlobalManagerTerminalInfo {
|
||||
label: string;
|
||||
hostname: string;
|
||||
connected: boolean;
|
||||
workspaceId?: string;
|
||||
hiddenFromTabs?: boolean;
|
||||
}
|
||||
|
||||
export interface GlobalManagerHostInfo {
|
||||
@@ -50,9 +52,11 @@ export interface GlobalManagerRow {
|
||||
isCurrentActive: boolean;
|
||||
/** True when the chat is currently active in another open panel. */
|
||||
isActiveElsewhere: boolean;
|
||||
/** Live panel currently displaying this chat when `isActiveElsewhere` is true. */
|
||||
activeElsewhereTarget: { type: 'terminal' | 'workspace'; targetId: string } | null;
|
||||
/**
|
||||
* Clicking the row opens the chat in the viewing panel: directly when it is
|
||||
* already in scope, or by attaching it to the viewing panel automatically.
|
||||
* Clicking the row jumps to the owning open panel when active elsewhere, or
|
||||
* opens the chat in the viewing panel directly when in scope or historical.
|
||||
*/
|
||||
canActivate: boolean;
|
||||
messageCount: number;
|
||||
@@ -114,15 +118,39 @@ export function buildGlobalManagerRows(input: BuildGlobalManagerRowsInput): Glob
|
||||
hostNamesById.set(info.hostId, name);
|
||||
}
|
||||
}
|
||||
const activeSessionIds = new Set(
|
||||
Object.values(activeSessionIdMap).filter((id): id is string => Boolean(id)),
|
||||
);
|
||||
const currentScopeKey = currentScopeTargetId
|
||||
? `${currentScopeType}:${currentScopeTargetId}`
|
||||
: null;
|
||||
const currentPanelActiveSessionId = currentScopeKey
|
||||
? activeSessionIdMap[currentScopeKey] ?? null
|
||||
: null;
|
||||
const activeElsewhereTargetBySessionId = new Map<
|
||||
string,
|
||||
{ type: 'terminal' | 'workspace'; targetId: string }
|
||||
>();
|
||||
for (const [scopeKey, activeChatId] of Object.entries(activeSessionIdMap)) {
|
||||
if (!activeChatId || scopeKey === currentScopeKey) continue;
|
||||
if (scopeKey.startsWith('workspace:')) {
|
||||
const targetId = scopeKey.slice('workspace:'.length);
|
||||
if (workspaceTitles.has(targetId) && !activeElsewhereTargetBySessionId.has(activeChatId)) {
|
||||
activeElsewhereTargetBySessionId.set(activeChatId, { type: 'workspace', targetId });
|
||||
}
|
||||
} else if (scopeKey.startsWith('terminal:')) {
|
||||
const targetId = scopeKey.slice('terminal:'.length);
|
||||
const terminal = liveTerminals.get(targetId);
|
||||
// Only standalone, visible main-window terminal tabs own an independent
|
||||
// AI side panel. Workspace members defer to their `workspace:<id>` panel
|
||||
// pointer, and hidden/popped-out terminals have no main-window tab.
|
||||
if (
|
||||
terminal
|
||||
&& !terminal.workspaceId
|
||||
&& !terminal.hiddenFromTabs
|
||||
&& !activeElsewhereTargetBySessionId.has(activeChatId)
|
||||
) {
|
||||
activeElsewhereTargetBySessionId.set(activeChatId, { type: 'terminal', targetId });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sessions
|
||||
.map((session) => {
|
||||
@@ -158,7 +186,10 @@ export function buildGlobalManagerRows(input: BuildGlobalManagerRowsInput): Glob
|
||||
}
|
||||
|
||||
const isCurrentActive = currentPanelActiveSessionId === session.id;
|
||||
const isActiveElsewhere = !isCurrentActive && !isDangling && activeSessionIds.has(session.id);
|
||||
const activeElsewhereTarget = !isCurrentActive
|
||||
? activeElsewhereTargetBySessionId.get(session.id) ?? null
|
||||
: null;
|
||||
const isActiveElsewhere = activeElsewhereTarget !== null;
|
||||
|
||||
return {
|
||||
session,
|
||||
@@ -166,15 +197,16 @@ export function buildGlobalManagerRows(input: BuildGlobalManagerRowsInput): Glob
|
||||
agentId: session.agentId,
|
||||
agentLabel: resolveChatAgentLabel(session.agentId, externalAgents),
|
||||
scopeLabel,
|
||||
scopeState: isDangling
|
||||
scopeState: isDangling && !isActiveElsewhere
|
||||
? 'dangling'
|
||||
: activeSessionIds.has(session.id)
|
||||
: isCurrentActive || isActiveElsewhere
|
||||
? 'active'
|
||||
: 'idle',
|
||||
isCurrentView,
|
||||
isCurrentActive,
|
||||
isActiveElsewhere,
|
||||
canActivate: Boolean(isCurrentView || currentScopeTargetId),
|
||||
activeElsewhereTarget,
|
||||
canActivate: Boolean(isCurrentView || currentScopeTargetId || isActiveElsewhere),
|
||||
messageCount: session.messages.length,
|
||||
} satisfies GlobalManagerRow;
|
||||
})
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { ArrowUp, ChevronDown, Folder, LoaderCircle, RefreshCw } from 'lucide-react';
|
||||
import { useEffect, useId, useRef, useState } from 'react';
|
||||
import { memo, useEffect, useId, useRef, useState } from 'react';
|
||||
import { useI18n } from '../../application/i18n/I18nProvider';
|
||||
import { useComposeDirectoryPicker } from '../../application/state/useComposeDirectoryPicker';
|
||||
import { directoryDisplayName, directoryLabel } from '../../domain/directoryPicker';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
|
||||
import type { ComposeBarTheme } from './TerminalComposeBar';
|
||||
|
||||
export function ComposeDirectoryPicker({ sessionId, theme, onReturnFocus }: {
|
||||
export const ComposeDirectoryPicker = memo(function ComposeDirectoryPicker({ sessionId, theme, onReturnFocus }: {
|
||||
sessionId: string; theme: ComposeBarTheme; onReturnFocus: () => void;
|
||||
}) {
|
||||
const { t } = useI18n();
|
||||
@@ -47,14 +47,20 @@ export function ComposeDirectoryPicker({ sessionId, theme, onReturnFocus }: {
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div className="shrink-0 flex items-center gap-2 px-3 h-7 min-w-0" role="group" aria-label="Context Chips">
|
||||
<div className="shrink-0 flex items-center gap-1 h-6 min-w-0 max-w-[min(220px,45%)]" role="group" aria-label="Context Chips">
|
||||
<Popover open={model.open} onOpenChange={value => { if (value) outside.current = false; model.setOpen(value); }}>
|
||||
<PopoverTrigger asChild>
|
||||
<button type="button" disabled={model.pending}
|
||||
aria-label={t('terminal.directory.open', { path: model.cwd ? directoryLabel(model.cwd, model.home, model.pathFlavor) : t('terminal.directory.unknown') })}
|
||||
title={model.cwd ? directoryDisplayName(model.cwd) : t('terminal.directory.unknown')}
|
||||
className="h-6 min-w-0 max-w-full flex items-center gap-1.5 rounded border px-2 text-[11px] font-mono focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 disabled:opacity-60"
|
||||
className="h-6 min-w-0 max-w-full flex items-center gap-1.5 rounded border px-2 text-[11px] font-mono transition-colors duration-150 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 disabled:opacity-60"
|
||||
style={{ backgroundColor: theme.chipBg, borderColor: theme.borderColor, color: theme.resolvedFg }}
|
||||
onMouseEnter={(event) => {
|
||||
if (!model.pending) event.currentTarget.style.backgroundColor = theme.chipHoverBg;
|
||||
}}
|
||||
onMouseLeave={(event) => {
|
||||
event.currentTarget.style.backgroundColor = theme.chipBg;
|
||||
}}
|
||||
>
|
||||
{model.pending ? <LoaderCircle size={12} className="shrink-0 animate-spin" /> : <Folder size={12} className="shrink-0" />}
|
||||
<span className="truncate">{model.cwd ? directoryDisplayName(directoryLabel(model.cwd, model.home, model.pathFlavor)) : t('terminal.directory.unknown')}</span>
|
||||
@@ -126,4 +132,4 @@ export function ComposeDirectoryPicker({ sessionId, theme, onReturnFocus }: {
|
||||
</Popover>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -44,6 +44,9 @@ test('disabling Context Chips preserves the compose draft and stops extra cwd re
|
||||
let root!: ReactTestRenderer;
|
||||
await act(async () => { root = create(render(true), { createNodeMock: el => el.type === 'textarea' ? textarea : null }); });
|
||||
assert.equal(probes, 1);
|
||||
const topBar = root.root.findByProps({ 'data-compose-top-bar': true });
|
||||
assert.equal(topBar.findAllByProps({ 'aria-label': 'Context Chips' }).length, 1);
|
||||
assert.equal(topBar.findAllByProps({ 'data-compose-snippet-strip': true }).length, 1);
|
||||
textarea.value = 'keep this draft'; textarea.selectionStart = 2; textarea.selectionEnd = 8;
|
||||
await act(async () => { root.update(render(false)); });
|
||||
assert.equal(root.root.findAllByProps({ 'aria-label': 'Context Chips' }).length, 0);
|
||||
|
||||
@@ -740,6 +740,10 @@ export const TerminalComposeBar: React.FC<TerminalComposeBarProps> = ({
|
||||
}
|
||||
}, [handleSend, navigate, onClose, sessionId]);
|
||||
|
||||
const handleReturnFocus = useCallback(() => {
|
||||
textareaRef.current?.focus({ preventScroll: true });
|
||||
}, []);
|
||||
|
||||
const handleResizeStart = useCallback((e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
resizeCleanupRef.current?.();
|
||||
@@ -804,9 +808,28 @@ export const TerminalComposeBar: React.FC<TerminalComposeBarProps> = ({
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="flex-shrink-0 flex items-center gap-1 px-2 min-w-0"
|
||||
data-compose-top-bar
|
||||
className="flex-shrink-0 flex items-center gap-1.5 px-2 min-w-0"
|
||||
style={{ height: SNIPPET_STRIP_HEIGHT }}
|
||||
>
|
||||
{contextChipsEnabled && (
|
||||
<>
|
||||
<ComposeDirectoryPicker
|
||||
key={sessionId}
|
||||
sessionId={sessionId}
|
||||
theme={theme}
|
||||
onReturnFocus={handleReturnFocus}
|
||||
/>
|
||||
{pinnedSnippets.length > 0 && (
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="h-3.5 w-px flex-shrink-0"
|
||||
style={{ backgroundColor: theme.borderColor }}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
<div
|
||||
data-compose-snippet-strip
|
||||
className="flex-1 min-w-0 flex items-center gap-1 overflow-x-auto scrollbar-thin"
|
||||
@@ -849,9 +872,6 @@ export const TerminalComposeBar: React.FC<TerminalComposeBarProps> = ({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{contextChipsEnabled && <ComposeDirectoryPicker key={sessionId} sessionId={sessionId} theme={theme}
|
||||
onReturnFocus={() => textareaRef.current?.focus({ preventScroll: true })} />}
|
||||
|
||||
<div className="flex-1 min-h-0 px-3 pt-1.5 pb-2 flex flex-col">
|
||||
<div className="flex flex-1 min-h-0 items-start gap-1.5">
|
||||
{(onToggleComposeSendTarget || sendToAll) && (
|
||||
|
||||
@@ -305,6 +305,8 @@ interface AIChatPanelsHostProps {
|
||||
onOpenVaultSnippetFromChat?: (snippetId: string) => void;
|
||||
/** Issue #4098 phase 2: pin the AI chat a workspace scope is anchored to. */
|
||||
onSetWorkspaceAnchorChat?: (workspaceId: string, chatId: string | null) => void;
|
||||
/** Focus an already-open terminal or workspace hosting an active AI chat. */
|
||||
onFocusAIScopeTarget?: (target: { type: 'terminal' | 'workspace'; targetId: string }) => boolean;
|
||||
/** Live workspaces, threaded to AI chats for `/chats` scope titles. */
|
||||
workspaces?: Workspace[] | null;
|
||||
}
|
||||
@@ -475,6 +477,7 @@ function aiChatPanelsHostAreEqual(
|
||||
if (prev.onOpenVaultSectionFromChat !== next.onOpenVaultSectionFromChat) return false;
|
||||
if (prev.onOpenVaultSnippetFromChat !== next.onOpenVaultSnippetFromChat) return false;
|
||||
if (prev.onSetWorkspaceAnchorChat !== next.onSetWorkspaceAnchorChat) return false;
|
||||
if (prev.onFocusAIScopeTarget !== next.onFocusAIScopeTarget) return false;
|
||||
if (prev.workspaces !== next.workspaces) return false;
|
||||
if (prev.activeTabId === next.activeTabId) return true;
|
||||
|
||||
@@ -517,6 +520,7 @@ const AIChatPanelsHostInner: React.FC<AIChatPanelsHostProps> = ({
|
||||
onOpenVaultSectionFromChat,
|
||||
onOpenVaultSnippetFromChat,
|
||||
onSetWorkspaceAnchorChat,
|
||||
onFocusAIScopeTarget,
|
||||
workspaces,
|
||||
}) => {
|
||||
const aiConfig = useContext(AIConfigContext);
|
||||
@@ -688,6 +692,7 @@ const AIChatPanelsHostInner: React.FC<AIChatPanelsHostProps> = ({
|
||||
focusedSessionId={context.focusedSessionId}
|
||||
workspaces={aiPanelWorkspaces}
|
||||
onSetWorkspaceAnchorChat={onSetWorkspaceAnchorChat}
|
||||
onFocusAIScopeTarget={onFocusAIScopeTarget}
|
||||
terminalSessions={context.terminalSessions}
|
||||
appTerminalSessions={appTerminalSessions}
|
||||
liveScopeTargetIds={liveScopeTargetIds}
|
||||
|
||||
@@ -495,6 +495,7 @@ export function TerminalLayerTabBridge({ stableRef }: { stableRef: StableRef })
|
||||
handleFontWeightChangeForFocusedSession: themeState.handleFontWeightChangeForFocusedSession,
|
||||
handleFontWeightResetForFocusedSession: themeState.handleFontWeightResetForFocusedSession,
|
||||
handleOpenAI: s.handleOpenAI,
|
||||
handleFocusAIScopeTarget: s.handleFocusAIScopeTarget,
|
||||
handleOpenNotes: s.handleOpenNotes,
|
||||
getActiveTerminalSessionId: s.getActiveTerminalSessionId,
|
||||
handleSwitchSidePanelTab: s.handleSwitchSidePanelTab,
|
||||
|
||||
@@ -606,6 +606,7 @@ function SidePanelAiSlotInner({
|
||||
onOpenVaultSectionFromChat,
|
||||
onOpenVaultSnippetFromChat,
|
||||
onSetWorkspaceAnchorChat,
|
||||
handleFocusAIScopeTarget,
|
||||
validAIScopeTargetIds,
|
||||
} = ctx;
|
||||
const workspaces = ctx.workspaces as Workspace[];
|
||||
@@ -670,6 +671,7 @@ function SidePanelAiSlotInner({
|
||||
onOpenVaultSectionFromChat={onOpenVaultSectionFromChat}
|
||||
onOpenVaultSnippetFromChat={onOpenVaultSnippetFromChat}
|
||||
onSetWorkspaceAnchorChat={onSetWorkspaceAnchorChat as ((workspaceId: string, chatId: string | null) => void) | undefined}
|
||||
onFocusAIScopeTarget={handleFocusAIScopeTarget as ((target: { type: 'terminal' | 'workspace'; targetId: string }) => boolean) | undefined}
|
||||
workspaces={workspaces}
|
||||
/>
|
||||
</AISidePanelStateRoot>
|
||||
|
||||
@@ -316,6 +316,7 @@ const SIDE_PANEL_STABLE_CTX_KEYS = [
|
||||
'handleOpenScripts',
|
||||
'handleOpenTheme',
|
||||
'handleOpenAI',
|
||||
'handleFocusAIScopeTarget',
|
||||
'handleOpenNotes',
|
||||
'getActiveTerminalSessionId',
|
||||
'handleSwitchSidePanelTab',
|
||||
|
||||
@@ -31,6 +31,8 @@ export type AIPanelTerminalSessionLike = {
|
||||
shellType?: string;
|
||||
deviceType?: string;
|
||||
connected: boolean;
|
||||
workspaceId?: string;
|
||||
hiddenFromTabs?: boolean;
|
||||
hostChain?: AIPanelHostChainHop[];
|
||||
activePortForwards?: AIPanelPortForwardLike[];
|
||||
};
|
||||
@@ -97,6 +99,8 @@ function aiTerminalSessionInfoEqual(
|
||||
&& a.shellType === b.shellType
|
||||
&& a.deviceType === b.deviceType
|
||||
&& a.connected === b.connected
|
||||
&& a.workspaceId === b.workspaceId
|
||||
&& Boolean(a.hiddenFromTabs) === Boolean(b.hiddenFromTabs)
|
||||
&& hostChainEqual(a.hostChain, b.hostChain)
|
||||
&& portForwardsEqual(a.activePortForwards, b.activePortForwards);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ export type AITerminalSessionInfo = {
|
||||
shellType?: string;
|
||||
deviceType?: string;
|
||||
connected: boolean;
|
||||
workspaceId?: string;
|
||||
hiddenFromTabs?: boolean;
|
||||
hostChain?: Array<{ hostId: string; label?: string; hostname?: string }>;
|
||||
activePortForwards?: Array<{
|
||||
ruleId: string;
|
||||
@@ -98,6 +100,8 @@ export const buildAITerminalSessionInfo = (
|
||||
shellType: session?.shellType && session.shellType !== 'unknown' ? session.shellType : undefined,
|
||||
deviceType,
|
||||
connected: session?.status === 'connected',
|
||||
...(session?.workspaceId ? { workspaceId: session.workspaceId } : {}),
|
||||
...(session?.hiddenFromTabs ? { hiddenFromTabs: true } : {}),
|
||||
...(hostChain?.length ? { hostChain } : {}),
|
||||
...(activePortForwards?.length ? { activePortForwards } : {}),
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user