mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-10-30 18:32:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a138ba0b1 |
No files matched your search
@@ -699,89 +699,6 @@ test('connection log host snapshot includes custom host icon fields', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('toggleOpacity hotkey invokes toggleWindowOpacity', () => {
|
||||
let called = false;
|
||||
const noop = () => {};
|
||||
|
||||
executeHotkeyActionImpl(
|
||||
() => ({
|
||||
IS_DEV: false,
|
||||
MOVE_FOCUS_DEBOUNCE_MS: 0,
|
||||
activeTabStore: { getActiveTabId: () => 'vault' },
|
||||
addConnectionLogRef: { current: noop },
|
||||
closeSession: noop,
|
||||
closeTabInFlightRef: { current: false },
|
||||
closeWorkspace: noop,
|
||||
collectSessionIds: () => [],
|
||||
confirmIfBusyLocalTerminal: async () => true,
|
||||
createLocalTerminalWithCurrentShell: noop,
|
||||
editorTabs: [],
|
||||
fromEditorTabId: () => null,
|
||||
handleOpenSettingsRef: { current: noop },
|
||||
handleRequestCloseEditorTabRef: { current: noop },
|
||||
isEditorTabId: () => false,
|
||||
isQuickSwitcherOpen: false,
|
||||
lastMoveFocusTimeRef: { current: 0 },
|
||||
moveFocusInWorkspace: noop,
|
||||
orderedTabs: [],
|
||||
resolveCloseIntent: () => ({ kind: 'noop' }),
|
||||
resolveSnippetsShortcutIntent: () => ({ kind: 'noop' }),
|
||||
sessions: [],
|
||||
setActiveTabId: noop,
|
||||
setAddToWorkspaceDialog: noop,
|
||||
setIsQuickSwitcherOpen: noop,
|
||||
setNavigateToSection: noop,
|
||||
settings: { showSftpTab: true, shellOnlyTabNumberShortcuts: false },
|
||||
splitSessionWithCurrentShell: noop,
|
||||
systemInfoRef: { current: { username: 'user', hostname: 'host' } },
|
||||
toEditorTabId: (id: string) => `editor:${id}`,
|
||||
toggleBroadcast: noop,
|
||||
toggleScriptsSidePanelRef: { current: noop },
|
||||
toggleSidePanelRef: { current: noop },
|
||||
toggleWindowOpacity: () => { called = true; },
|
||||
toggleWorkspaceViewMode: noop,
|
||||
workspaces: [],
|
||||
}),
|
||||
'toggleOpacity',
|
||||
{ key: 'u', code: 'KeyU', ctrlKey: true, shiftKey: true } as KeyboardEvent,
|
||||
);
|
||||
|
||||
assert.equal(called, true);
|
||||
});
|
||||
|
||||
for (const scenario of [
|
||||
{ name: 'IME process key with its original physical code', key: 'Process', keyCode: 229, isComposing: false, expected: false },
|
||||
{ name: 'key during composition', key: 'U', keyCode: 85, isComposing: true, expected: false },
|
||||
{ name: 'ordinary shortcut', key: 'U', keyCode: 85, isComposing: false, expected: true },
|
||||
]) {
|
||||
test(`transparency shortcut respects ${scenario.name}`, () => {
|
||||
const target = new FakeHTMLElement();
|
||||
const actions: string[] = [];
|
||||
let prevented = false;
|
||||
const event = {
|
||||
...scenario,
|
||||
code: 'KeyU',
|
||||
ctrlKey: true,
|
||||
shiftKey: true,
|
||||
altKey: false,
|
||||
metaKey: false,
|
||||
target,
|
||||
composedPath: () => [target],
|
||||
preventDefault: () => { prevented = true; },
|
||||
stopPropagation: () => {},
|
||||
} as unknown as KeyboardEvent;
|
||||
handleGlobalHotkeyKeyDownImpl(() => ({
|
||||
HOTKEY_DEBUG: false,
|
||||
closeTabKeyStr: 'Ctrl + W',
|
||||
executeHotkeyAction: (action: string) => actions.push(action),
|
||||
hotkeyScheme: 'pc',
|
||||
keyBindings: DEFAULT_KEY_BINDINGS,
|
||||
matchesKeyBinding,
|
||||
}), event);
|
||||
assert.deepEqual(actions, scenario.expected ? ['toggleOpacity'] : []);
|
||||
assert.equal(prevented, scenario.expected);
|
||||
});
|
||||
}
|
||||
for (const scenario of [
|
||||
{ name: 'single orphan', active: 'one', sessions: [{ id: 'one' }], available: false, expected: null },
|
||||
{ name: 'two orphans', active: 'one', sessions: [{ id: 'one' }, { id: 'two' }], available: true, expected: 'global' },
|
||||
|
||||
@@ -306,11 +306,6 @@ export function handleGlobalHotkeyKeyDownImpl(getCtx: AppContextGetter, e: Keybo
|
||||
for (const binding of keyBindings) {
|
||||
const keyStr = isMac ? binding.mac : binding.pc;
|
||||
if (!matchesKeyBinding(e, keyStr, isMac)) continue;
|
||||
// IME-filtered keys retain their physical code (e.g. Linux Unicode entry).
|
||||
// Let composition handle them instead of treating them as opacity toggles.
|
||||
if (binding.action === 'toggleOpacity' && (e.isComposing || e.keyCode === 229 || e.key === 'Process')) {
|
||||
return;
|
||||
}
|
||||
if (HOTKEY_DEBUG) console.log('[Hotkeys] Matched binding:', binding.action, keyStr);
|
||||
if (binding.category === 'sftp') {
|
||||
continue;
|
||||
@@ -786,7 +781,7 @@ export async function closeTabsBatchImpl(getCtx: AppContextGetter, targetIds: st
|
||||
}
|
||||
|
||||
export function executeHotkeyActionImpl(getCtx: AppContextGetter, action: string, e: KeyboardEvent) {
|
||||
const { IS_DEV, MOVE_FOCUS_DEBOUNCE_MS, activeTabStore, addConnectionLogRef, canUseGlobalBroadcast, closePluginViewTab, closeSession, closeTabInFlightRef, closeWorkspace, collectSessionIds, confirmIfBusyLocalTerminal, createLocalTerminalWithCurrentShell, editorTabs, fromEditorTabId, handleOpenSettingsRef, handleRequestCloseEditorTabRef, isEditorTabId, isPluginViewTabId, isQuickSwitcherOpen, lastMoveFocusTimeRef, moveFocusInWorkspace, orderedTabs, resolveCloseIntent, resolveSnippetsShortcutIntent, sessions, setActiveTabId, setAddToWorkspaceDialog, setIsQuickSwitcherOpen, setNavigateToSection, settings, sftpPaneMagnificationRef, splitSessionWithCurrentShell, systemInfoRef, terminalPaneMagnificationRef, toEditorTabId, toggleBroadcast, toggleGlobalBroadcast, toggleScriptsSidePanelRef, toggleSidePanelRef, toggleWindowOpacity, workspaces } = getCtx();
|
||||
const { IS_DEV, MOVE_FOCUS_DEBOUNCE_MS, activeTabStore, addConnectionLogRef, canUseGlobalBroadcast, closePluginViewTab, closeSession, closeTabInFlightRef, closeWorkspace, collectSessionIds, confirmIfBusyLocalTerminal, createLocalTerminalWithCurrentShell, editorTabs, fromEditorTabId, handleOpenSettingsRef, handleRequestCloseEditorTabRef, isEditorTabId, isPluginViewTabId, isQuickSwitcherOpen, lastMoveFocusTimeRef, moveFocusInWorkspace, orderedTabs, resolveCloseIntent, resolveSnippetsShortcutIntent, sessions, setActiveTabId, setAddToWorkspaceDialog, setIsQuickSwitcherOpen, setNavigateToSection, settings, sftpPaneMagnificationRef, splitSessionWithCurrentShell, systemInfoRef, terminalPaneMagnificationRef, toEditorTabId, toggleBroadcast, toggleGlobalBroadcast, toggleScriptsSidePanelRef, toggleSidePanelRef, workspaces } = getCtx();
|
||||
{
|
||||
const shortcutTabs = buildNumberShortcutTabTargets({
|
||||
showSftpTab: settings.showSftpTab ?? true,
|
||||
@@ -976,9 +971,6 @@ export function executeHotkeyActionImpl(getCtx: AppContextGetter, action: string
|
||||
setNavigateToSection('snippets');
|
||||
}
|
||||
break;
|
||||
case 'toggleOpacity':
|
||||
toggleWindowOpacity();
|
||||
break;
|
||||
case 'toggleSidePanel':
|
||||
toggleSidePanelRef.current?.();
|
||||
break;
|
||||
|
||||
@@ -42,7 +42,6 @@ import { resolveHostDefaultLocalShell } from '../../domain/localShellHost';
|
||||
import { resolveGroupDefaults, applyGroupDefaults } from '../../domain/groupConfig';
|
||||
import { upsertKnownHost } from '../../domain/knownHosts';
|
||||
import { materializeHostProxyProfile } from '../../domain/proxyProfiles';
|
||||
import { useVaultHostDeletion } from '../state/useVaultHostDeletion';
|
||||
import { buildSshDeepLinkConnectionHost, buildSshDeepLinkEphemeralHost, buildSshDeepLinkEphemeralHostFromSaved, buildSshDeepLinkHostDraft, findSshDeepLinkHost, parseSshDeepLink } from '../../domain/sshDeepLink';
|
||||
import { buildTelnetDeepLinkConnectionHost, buildTelnetDeepLinkEphemeralHostFromSaved, buildTelnetDeepLinkOpenHost, findTelnetDeepLinkHost, materializeTelnetDeepLinkMatchHost, parseTelnetDeepLink } from '../../domain/telnetDeepLink';
|
||||
import { buildJmsDeepLinkEphemeralHost, isSupportedJmsProtocol, parseJmsDeepLink } from '../../domain/jmsDeepLink';
|
||||
@@ -152,7 +151,6 @@ export function AppSideEffects() {
|
||||
showSftpTab,
|
||||
shellOnlyTabNumberShortcuts,
|
||||
workspaceFocusStyle,
|
||||
toggleWindowOpacity,
|
||||
} = settings;
|
||||
|
||||
// Always publish terminal keyboard focus to the main process. When font zoom
|
||||
@@ -1081,7 +1079,6 @@ export function AppSideEffects() {
|
||||
canUseGlobalBroadcast: canUseGlobalBroadcastRef.current,
|
||||
toggleScriptsSidePanelRef,
|
||||
toggleSidePanelRef,
|
||||
toggleWindowOpacity,
|
||||
toggleWorkspaceViewMode,
|
||||
workspaces: workspacesRefForHotkeys.current,
|
||||
}), action, e);
|
||||
@@ -1094,7 +1091,6 @@ export function AppSideEffects() {
|
||||
splitSessionWithCurrentShell,
|
||||
moveFocusInWorkspace,
|
||||
toggleBroadcast,
|
||||
toggleWindowOpacity,
|
||||
toggleGlobalBroadcast,
|
||||
toggleWorkspaceViewMode,
|
||||
confirmIfBusyLocalTerminal,
|
||||
@@ -1200,16 +1196,11 @@ export function AppSideEffects() {
|
||||
setDeleteHostConfirm({ hostId, name: target?.label || hostId });
|
||||
}, [hosts]);
|
||||
|
||||
const deleteVaultHosts = useVaultHostDeletion(commitVaultGroupMutation);
|
||||
const handleConfirmDeleteHost = useCallback(async () => {
|
||||
const handleConfirmDeleteHost = useCallback(() => {
|
||||
if (!deleteHostConfirm) return;
|
||||
try {
|
||||
await deleteVaultHosts([deleteHostConfirm.hostId]);
|
||||
setDeleteHostConfirm(null);
|
||||
} catch {
|
||||
toast.error(t('common.error'));
|
||||
}
|
||||
}, [deleteHostConfirm, deleteVaultHosts, t]);
|
||||
updateHosts(hosts.filter(h => h.id !== deleteHostConfirm.hostId));
|
||||
setDeleteHostConfirm(null);
|
||||
}, [deleteHostConfirm, hosts, updateHosts]);
|
||||
|
||||
const handleCancelDeleteHost = useCallback(() => {
|
||||
setDeleteHostConfirm(null);
|
||||
|
||||
@@ -261,7 +261,7 @@ function AppViewInner({ domains }: AppViewProps) {
|
||||
useMainWindowInputFocusRecovery({ onPageHidden: dismissTransientOverlays });
|
||||
|
||||
const {
|
||||
addShellHistoryEntry, clearAllCommandHistory, removeShellHistoryEntry, addSessionToWorkspace, addToWorkspaceDialog, appendHostToWorkspace, appendLocalTerminalToWorkspace,
|
||||
addShellHistoryEntry, removeShellHistoryEntry, addSessionToWorkspace, addToWorkspaceDialog, appendHostToWorkspace, appendLocalTerminalToWorkspace,
|
||||
clearAndRemoveSource, clearAndRemoveSources, closeLogView, closeSession, closeTabsBatch, closeWorkspace, commitPluginImporterData, commitVaultImportTransaction, commitVaultGroupMutation, copySessionToNewWindowWithCurrentShell, copySessionWithCurrentShell, duplicateSessionWithCurrentShell, copyWorkspaceWithCurrentShell,
|
||||
convertKnownHostToHost, createWorkspaceFromSessions, createWorkspaceFromTargets, createWorkspaceWithHosts,
|
||||
customGroups, currentTerminalTheme, deepLinkHostDraft, draggingSessionId, effectiveKnownHosts, editorTabs, editorWordWrap, emptyVaultConflict,
|
||||
@@ -749,7 +749,6 @@ function AppViewInner({ domains }: AppViewProps) {
|
||||
onAddKnownHost={handleAddKnownHost}
|
||||
onCommandExecuted={handleTerminalCommandExecuted}
|
||||
onDeleteShellHistoryEntry={removeShellHistoryEntry}
|
||||
onClearCommandHistory={clearAllCommandHistory}
|
||||
onTerminalDataCapture={handleTerminalDataCapture}
|
||||
onCreateWorkspaceFromSessions={createWorkspaceFromSessions}
|
||||
onAddSessionToWorkspace={addSessionToWorkspace}
|
||||
|
||||
@@ -36,7 +36,6 @@ export function VaultHost() {
|
||||
return {
|
||||
addShellHistoryEntry: actions?.addShellHistoryEntry,
|
||||
removeShellHistoryEntry: actions?.removeShellHistoryEntry,
|
||||
clearAllCommandHistory: actions?.clearAllCommandHistory,
|
||||
commitPluginImporterData: actions?.commitPluginImporterData,
|
||||
commitVaultImportTransaction: actions?.commitVaultImportTransaction,
|
||||
commitVaultGroupMutation: actions?.commitVaultGroupMutation,
|
||||
|
||||
@@ -72,7 +72,6 @@ export function VaultPublisher({ children }: VaultPublisherProps) {
|
||||
updateHostLastConnected,
|
||||
addShellHistoryEntry,
|
||||
removeShellHistoryEntry,
|
||||
clearAllCommandHistory,
|
||||
} = vault;
|
||||
|
||||
useLayoutEffect(() => {
|
||||
@@ -145,14 +144,12 @@ export function VaultPublisher({ children }: VaultPublisherProps) {
|
||||
updateHostLastConnected,
|
||||
addShellHistoryEntry,
|
||||
removeShellHistoryEntry,
|
||||
clearAllCommandHistory,
|
||||
});
|
||||
return () => {
|
||||
registerVaultSnapshotActions(null);
|
||||
};
|
||||
}, [
|
||||
addShellHistoryEntry,
|
||||
clearAllCommandHistory,
|
||||
commitPluginImporterData,
|
||||
commitVaultImportTransaction,
|
||||
commitVaultGroupMutation,
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
type ConvergentMigrationProviderInput,
|
||||
} from '../domain/convergentSync';
|
||||
import { isProviderReadyForSync } from '../domain/sync';
|
||||
import { isPreserveDeletionsStrategy } from '../domain/syncStrategy';
|
||||
import { getCloudSyncManager, type CloudSyncManager } from '../infrastructure/services/CloudSyncManager';
|
||||
import { markConvergentSyncInitialized } from '../infrastructure/services/convergentSyncConfig';
|
||||
import { applyProtectedSyncPayload } from './localVaultBackups';
|
||||
@@ -114,7 +113,6 @@ export async function prepareConvergentSyncMigration(
|
||||
providers: inputs,
|
||||
deviceId: manager.getState().deviceId,
|
||||
now,
|
||||
preserveDeletions: isPreserveDeletionsStrategy(manager.getState().syncStrategy),
|
||||
});
|
||||
if (plan.state) {
|
||||
for (const seed of legacyBaselineSeeds) {
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import en from '../locales/en.ts';
|
||||
import ru from '../locales/ru.ts';
|
||||
import es from '../locales/es.ts';
|
||||
import zhCN from '../locales/zh-CN.ts';
|
||||
import zhTW from '../locales/zh-TW.ts';
|
||||
|
||||
const keys = [
|
||||
'cloudSync.provider.disconnect',
|
||||
'cloudSync.provider.disconnect.confirmTitle',
|
||||
'cloudSync.provider.disconnect.confirmMessage',
|
||||
'cloudSync.provider.disconnect.confirmAction',
|
||||
'cloudSync.provider.disconnect.toastTitle',
|
||||
'cloudSync.provider.disconnect.cloudRemains',
|
||||
'cloudSync.provider.disconnect.failed',
|
||||
] as const;
|
||||
|
||||
test('disconnect copy exists in every bundled locale', () => {
|
||||
for (const [locale, messages] of Object.entries({ en, ru, es, zhCN, zhTW })) {
|
||||
for (const key of keys) {
|
||||
assert.equal(typeof messages[key], 'string', `${locale} is missing ${key}`);
|
||||
assert.notEqual(messages[key], '', `${locale} has empty ${key}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('disconnect confirm copy states that saved provider credentials are removed', () => {
|
||||
// The confirm dialog must explain the data consequence of disconnecting:
|
||||
// locally saved endpoint + credentials removal, not just "stops syncing".
|
||||
const expected = [
|
||||
[en, 'will be removed'],
|
||||
[es, 'eliminarán'],
|
||||
[ru, 'будут удалены'],
|
||||
[zhCN, '删除'],
|
||||
[zhTW, '刪除'],
|
||||
] as const;
|
||||
for (const [messages, fragment] of expected) {
|
||||
assert.ok(
|
||||
(messages['cloudSync.provider.disconnect.confirmMessage'] as string).includes(fragment),
|
||||
`confirmMessage should mention credential removal: ${fragment}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('disconnect toast copy explains the cloud copy is retained', () => {
|
||||
for (const [locale, messages] of Object.entries({ en, ru, es, zhCN, zhTW })) {
|
||||
assert.ok(
|
||||
(messages['cloudSync.provider.disconnect.cloudRemains'] as string).includes(
|
||||
'{name}',
|
||||
),
|
||||
`${locale} cloudRemains hint should reference the provider name`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('disconnect copy distinguishes login cleanup from retained local data', () => {
|
||||
assert.match(en['cloudSync.provider.disconnect.confirmMessage'], /backup history and sync encryption password stay here/);
|
||||
assert.doesNotMatch(en['cloudSync.provider.disconnect.cloudRemains'], /change.*password/);
|
||||
for (const messages of [en, ru, es, zhCN, zhTW]) {
|
||||
assert.ok(messages['cloudSync.provider.disconnect.failed'].includes('{name}'));
|
||||
}
|
||||
});
|
||||
@@ -11,16 +11,10 @@ const strategyKeys = [
|
||||
"cloudSync.strategy.desc",
|
||||
"cloudSync.strategy.smartMerge",
|
||||
"cloudSync.strategy.smartMergeDesc",
|
||||
"cloudSync.strategy.smartMergePreserve",
|
||||
"cloudSync.strategy.smartMergePreserveDesc",
|
||||
"cloudSync.strategy.preferCloud",
|
||||
"cloudSync.strategy.preferCloudDesc",
|
||||
"cloudSync.strategy.preferLocal",
|
||||
"cloudSync.strategy.preferLocalDesc",
|
||||
"cloudSync.aiSessions.title",
|
||||
"cloudSync.aiSessions.desc",
|
||||
"cloudSync.aiSessions.compatibility",
|
||||
"cloudSync.aiSessions.enableFailed",
|
||||
] as const;
|
||||
|
||||
test("cloud sync strategy copy exists in every bundled locale", () => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Messages } from '../types';
|
||||
|
||||
export const enAiMessages: Messages = {
|
||||
'ai.chat.attachmentContentUnavailable': 'Content not available on this device',
|
||||
// AI Settings
|
||||
'ai.agentSettings': 'Agent Settings',
|
||||
'ai.chat.preparing': 'Preparing…',
|
||||
@@ -514,10 +513,6 @@ export const enAiMessages: Messages = {
|
||||
'ai.chat.pinModel': 'Pin model',
|
||||
'ai.chat.unpinModel': 'Unpin model',
|
||||
'ai.chat.loadingModels': 'Loading models...',
|
||||
'ai.chat.modelCatalogSourceLive': 'Live catalog',
|
||||
'ai.chat.modelCatalogSourceCached': 'Cached · last success {time}',
|
||||
'ai.chat.modelCatalogSourceCachedNoTime': 'Cached',
|
||||
'ai.chat.modelCatalogSourcePresets': 'Built-in default list',
|
||||
'ai.chat.noMatchingModels': 'No matching models',
|
||||
'ai.chat.recent': 'Recent',
|
||||
'ai.chat.viewAll': 'View All',
|
||||
|
||||
@@ -1149,9 +1149,6 @@ Highlight the focused split pane:
|
||||
'vault.hosts.deleteMultiple.success': 'Deleted {count} hosts',
|
||||
'vault.hosts.connectSelected': 'Connect ({count})',
|
||||
'vault.hosts.connectMultiple.success': 'Connecting {count} hosts',
|
||||
'vault.hosts.moveSelected': 'Move to group ({count})',
|
||||
'vault.hosts.moveSelected.description': 'Move the selected hosts to an existing group, or leave them ungrouped. Selected groups are not moved.',
|
||||
'vault.hosts.moveMultiple.success': 'Moved {count} hosts to {group}',
|
||||
'vault.hosts.moveToGroup.success': 'Moved {host} to {group}',
|
||||
'vault.hosts.errors.nameRequired': 'Host name is required.',
|
||||
'vault.hosts.empty.title': 'Set up your hosts',
|
||||
|
||||
@@ -44,10 +44,6 @@ export const enTerminalMessages: Messages = {
|
||||
'history.action.run': 'Run in terminal',
|
||||
'history.action.saveAsSnippet': 'Save as snippet',
|
||||
'history.action.delete': 'Delete from history',
|
||||
'history.action.clearAll': 'Clear all history',
|
||||
'history.clearAll.dialog.title': 'Clear all command history?',
|
||||
'history.clearAll.dialog.desc': 'This permanently deletes all locally recorded command history and autocomplete suggestions. This cannot be undone.',
|
||||
'history.clearAll.dialog.confirm': 'Clear all',
|
||||
'terminal.toolbar.library': 'Library',
|
||||
'terminal.toolbar.noSnippets': 'No snippets available',
|
||||
'terminal.toolbar.terminalSettings': 'Terminal settings',
|
||||
@@ -314,11 +310,8 @@ export const enTerminalMessages: Messages = {
|
||||
'cloudSync.provider.connecting': 'Connecting...',
|
||||
'cloudSync.provider.disconnect': 'Disconnect',
|
||||
'cloudSync.provider.disconnect.confirmTitle': 'Disconnect "{name}"?',
|
||||
'cloudSync.provider.disconnect.confirmMessage': 'This device will stop syncing with {name}. Its saved address and login credentials will be removed. Your local vault, backup history and sync encryption password stay here. If system credential storage is unavailable, plugin credentials may need manual removal.',
|
||||
'cloudSync.provider.disconnect.confirmMessage': 'This device will stop syncing with {name}. Your local vault stays on this computer.',
|
||||
'cloudSync.provider.disconnect.confirmAction': 'Disconnect',
|
||||
'cloudSync.provider.disconnect.toastTitle': 'Disconnected',
|
||||
'cloudSync.provider.disconnect.cloudRemains': 'Encrypted sync copies may still exist in your {name} storage. To remove them, delete the sync files there. Disconnecting does not clear this device for handover.',
|
||||
'cloudSync.provider.disconnect.failed': 'Could not finish disconnecting from {name}. Saved connection details may remain. Please try again.',
|
||||
'cloudSync.provider.webdav': 'WebDAV',
|
||||
'cloudSync.provider.webdav.desc': 'Connect to a self-hosted WebDAV endpoint',
|
||||
'cloudSync.provider.s3': 'S3 Compatible',
|
||||
@@ -388,12 +381,6 @@ export const enTerminalMessages: Messages = {
|
||||
'cloudSync.strategy.title': 'Sync strategy',
|
||||
'cloudSync.strategy.desc': 'Choose what happens when local and cloud data both changed.',
|
||||
'cloudSync.strategy.smartMerge': 'Smart merge (recommended)',
|
||||
'cloudSync.aiSessions.title': 'Sync AI chat history',
|
||||
'cloudSync.aiSessions.desc': 'Include AI chat sessions in cloud sync. Messages merge append-only across devices; attachment contents stay on this device.',
|
||||
'cloudSync.aiSessions.compatibility': 'Older versions may overwrite chat history. Use an updated Netcatty on every synced device.',
|
||||
'cloudSync.aiSessions.enableFailed': 'Could not update chat sync. Check the cloud connection and available local storage, then try again.',
|
||||
'cloudSync.strategy.smartMergePreserve': 'Smart merge (never delete)',
|
||||
'cloudSync.strategy.smartMergePreserveDesc': 'Combine changes from both sides and never propagate a one-sided deletion — an entry survives until it is removed on every device. Recommended when you restore backups or keep several machines in sync.',
|
||||
'cloudSync.strategy.smartMergeDesc': 'Combine changes from both sides when possible; if Netcatty cannot decide safely, ask you to choose.',
|
||||
'cloudSync.strategy.preferCloud': 'Cloud wins',
|
||||
'cloudSync.strategy.preferCloudDesc': 'When both sides changed, download the cloud version and replace local changes.',
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Messages } from '../types';
|
||||
|
||||
export const esAiMessages: Messages = {
|
||||
'ai.chat.attachmentContentUnavailable': 'Contenido no disponible en este dispositivo',
|
||||
// AI Settings
|
||||
'ai.agentSettings': 'Configuración del agente',
|
||||
'ai.chat.preparing': 'Preparando…',
|
||||
@@ -505,10 +504,6 @@ export const esAiMessages: Messages = {
|
||||
'ai.chat.pinModel': 'Fijar modelo',
|
||||
'ai.chat.unpinModel': 'Quitar modelo fijado',
|
||||
'ai.chat.loadingModels': 'Cargando modelos...',
|
||||
'ai.chat.modelCatalogSourceLive': 'Catálogo en vivo',
|
||||
'ai.chat.modelCatalogSourceCached': 'En caché · último éxito {time}',
|
||||
'ai.chat.modelCatalogSourceCachedNoTime': 'En caché',
|
||||
'ai.chat.modelCatalogSourcePresets': 'Lista predeterminada integrada',
|
||||
'ai.chat.noMatchingModels': 'No hay modelos coincidentes',
|
||||
'ai.chat.recent': 'Recientes',
|
||||
'ai.chat.viewAll': 'Ver todo',
|
||||
|
||||
@@ -883,7 +883,6 @@ Resalta el panel dividido enfocado:
|
||||
'settings.shortcuts.binding.new-workspace': 'Nuevo espacio de trabajo',
|
||||
'settings.shortcuts.binding.snippets': 'Abrir fragmentos',
|
||||
'settings.shortcuts.binding.broadcast': 'Alternar modo de transmisión',
|
||||
'settings.shortcuts.binding.toggle-opacity': 'Alternar la transparencia de la ventana',
|
||||
'settings.shortcuts.binding.toggle-side-panel': 'Alternar panel lateral',
|
||||
'settings.shortcuts.binding.sftp-copy': 'Copiar archivos',
|
||||
'settings.shortcuts.binding.sftp-cut': 'Cortar archivos',
|
||||
@@ -1108,9 +1107,6 @@ Resalta el panel dividido enfocado:
|
||||
'vault.hosts.deleteMultiple.success': 'Se eliminaron {count} hosts',
|
||||
'vault.hosts.connectSelected': 'Conectar ({count})',
|
||||
'vault.hosts.connectMultiple.success': 'Conectando {count} hosts',
|
||||
'vault.hosts.moveSelected': 'Mover al grupo ({count})',
|
||||
'vault.hosts.moveSelected.description': 'Mueve los hosts seleccionados a un grupo existente o los deja sin grupo. Los grupos seleccionados no se mueven.',
|
||||
'vault.hosts.moveMultiple.success': 'Se movieron {count} hosts a {group}',
|
||||
'vault.hosts.moveToGroup.success': 'Se movió {host} a {group}',
|
||||
'vault.hosts.errors.nameRequired': 'Se requiere el nombre del host.',
|
||||
'vault.hosts.empty.title': 'Configura tus hosts',
|
||||
|
||||
@@ -44,10 +44,6 @@ export const esTerminalMessages: Messages = {
|
||||
'history.action.run': 'Ejecutar en la terminal',
|
||||
'history.action.saveAsSnippet': 'Guardar como snippet',
|
||||
'history.action.delete': 'Eliminar del historial',
|
||||
'history.action.clearAll': 'Borrar todo el historial',
|
||||
'history.clearAll.dialog.title': '¿Borrar todo el historial de comandos?',
|
||||
'history.clearAll.dialog.desc': 'Esto elimina de forma permanente todo el historial de comandos local y las sugerencias de autocompletado. Esta acción no se puede deshacer.',
|
||||
'history.clearAll.dialog.confirm': 'Borrar todo',
|
||||
'terminal.toolbar.library': 'Biblioteca',
|
||||
'terminal.toolbar.noSnippets': 'No hay snippets disponibles',
|
||||
'terminal.toolbar.terminalSettings': 'Configuración de la terminal',
|
||||
@@ -313,11 +309,8 @@ export const esTerminalMessages: Messages = {
|
||||
'cloudSync.provider.connecting': 'Conectando...',
|
||||
'cloudSync.provider.disconnect': 'Desconectar',
|
||||
'cloudSync.provider.disconnect.confirmTitle': '¿Desconectar "{name}"?',
|
||||
'cloudSync.provider.disconnect.confirmMessage': 'Este dispositivo dejará de sincronizar con {name}. Se eliminarán su dirección y credenciales de acceso guardadas. La bóveda local, las copias de seguridad y la contraseña de cifrado de sincronización permanecerán aquí. Si el almacén de credenciales del sistema no está disponible, puede ser necesario eliminar manualmente las credenciales de los complementos.',
|
||||
'cloudSync.provider.disconnect.confirmMessage': 'Este dispositivo dejará de sincronizar con {name}. La bóveda local permanecerá en este equipo.',
|
||||
'cloudSync.provider.disconnect.confirmAction': 'Desconectar',
|
||||
'cloudSync.provider.disconnect.toastTitle': 'Desconectado',
|
||||
'cloudSync.provider.disconnect.cloudRemains': 'Las copias de sincronización cifradas pueden seguir en tu almacenamiento de {name}. Para eliminarlas, borra los archivos de sincronización allí. Desconectar no prepara este dispositivo para entregarlo a otra persona.',
|
||||
'cloudSync.provider.disconnect.failed': 'No se pudo completar la desconexión de {name}. Los datos de conexión guardados podrían permanecer. Inténtalo de nuevo.',
|
||||
'cloudSync.provider.webdav': 'WebDAV',
|
||||
'cloudSync.provider.webdav.desc': 'Conectar a un endpoint WebDAV autoalojado',
|
||||
'cloudSync.provider.s3': 'Compatible con S3',
|
||||
@@ -387,12 +380,6 @@ export const esTerminalMessages: Messages = {
|
||||
'cloudSync.strategy.title': 'Estrategia de sincronización',
|
||||
'cloudSync.strategy.desc': 'Elige qué sucede cuando cambian tanto los datos locales como los de la nube.',
|
||||
'cloudSync.strategy.smartMerge': 'Fusión inteligente (recomendada)',
|
||||
'cloudSync.aiSessions.title': 'Sincronizar el historial de chats de IA',
|
||||
'cloudSync.aiSessions.desc': 'Incluye las sesiones de chat de IA en la sincronización en la nube. Los mensajes se combinan de forma incremental entre dispositivos; el contenido de los adjuntos permanece en este dispositivo.',
|
||||
'cloudSync.aiSessions.compatibility': 'Las versiones antiguas pueden sobrescribir el historial. Actualiza Netcatty en todos los dispositivos sincronizados.',
|
||||
'cloudSync.aiSessions.enableFailed': 'No se pudo actualizar la sincronización del chat. Comprueba la conexión con la nube y el espacio local disponible e inténtalo de nuevo.',
|
||||
'cloudSync.strategy.smartMergePreserve': 'Fusión inteligente (sin borrar)',
|
||||
'cloudSync.strategy.smartMergePreserveDesc': 'Combina los cambios de ambos lados y nunca propaga un borrado de un solo lado: una entrada se conserva hasta que se elimina en todos los dispositivos. Recomendado al restaurar copias de seguridad o al usar varios equipos.',
|
||||
'cloudSync.strategy.smartMergeDesc': 'Combina los cambios de ambos lados cuando sea posible; si Netcatty no puede decidir con seguridad, te pedirá que elijas.',
|
||||
'cloudSync.strategy.preferCloud': 'Gana la nube',
|
||||
'cloudSync.strategy.preferCloudDesc': 'Cuando ambos lados cambiaron, descarga la versión de la nube y reemplaza los cambios locales.',
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Messages } from '../types';
|
||||
|
||||
export const ruAiMessages: Messages = {
|
||||
'ai.chat.attachmentContentUnavailable': 'Содержимое недоступно на этом устройстве',
|
||||
'ai.chat.contextUsage': 'Контекст: {used} / {max} токенов',
|
||||
// AI Settings
|
||||
'ai.agentSettings': 'Настройки агента',
|
||||
@@ -461,10 +460,6 @@ export const ruAiMessages: Messages = {
|
||||
'ai.chat.pinModel': 'Закрепить модель',
|
||||
'ai.chat.unpinModel': 'Открепить модель',
|
||||
'ai.chat.loadingModels': 'Загрузка моделей...',
|
||||
'ai.chat.modelCatalogSourceLive': 'Актуальный список моделей',
|
||||
'ai.chat.modelCatalogSourceCached': 'Кэш · обновлён {time}',
|
||||
'ai.chat.modelCatalogSourceCachedNoTime': 'Кэш',
|
||||
'ai.chat.modelCatalogSourcePresets': 'Встроенный список моделей',
|
||||
'ai.chat.noMatchingModels': 'Нет подходящих моделей',
|
||||
'ai.chat.recent': 'Недавние',
|
||||
'ai.chat.viewAll': 'Показать всё',
|
||||
|
||||
@@ -908,7 +908,6 @@ export const ruCoreMessages: Messages = {
|
||||
'settings.shortcuts.binding.new-workspace': 'Новая рабочая область',
|
||||
'settings.shortcuts.binding.snippets': 'Открыть сниппеты',
|
||||
'settings.shortcuts.binding.broadcast': 'Переключить режим трансляции',
|
||||
'settings.shortcuts.binding.toggle-opacity': 'Переключить прозрачность окна',
|
||||
'settings.shortcuts.binding.toggle-side-panel': 'Переключить боковую панель',
|
||||
'settings.shortcuts.binding.sftp-copy': 'Копировать файл',
|
||||
'settings.shortcuts.binding.sftp-cut': 'Вырезать файл',
|
||||
|
||||
@@ -65,10 +65,6 @@ export const ruTerminalMessages: Messages = {
|
||||
'history.action.run': 'Выполнить в терминале',
|
||||
'history.action.saveAsSnippet': 'Сохранить как сниппет',
|
||||
'history.action.delete': 'Удалить из истории',
|
||||
'history.action.clearAll': 'Очистить всю историю',
|
||||
'history.clearAll.dialog.title': 'Очистить всю историю команд?',
|
||||
'history.clearAll.dialog.desc': 'Будет безвозвратно удалена вся локальная история команд и подсказки автодополнения. Это действие нельзя отменить.',
|
||||
'history.clearAll.dialog.confirm': 'Очистить всё',
|
||||
'terminal.toolbar.library': 'Библиотека',
|
||||
'terminal.toolbar.noSnippets': 'Нет доступных сниппетов',
|
||||
'terminal.toolbar.terminalSettings': 'Настройки терминала',
|
||||
@@ -332,11 +328,8 @@ export const ruTerminalMessages: Messages = {
|
||||
'cloudSync.provider.connecting': 'Подключение...',
|
||||
'cloudSync.provider.disconnect': 'Отключить',
|
||||
'cloudSync.provider.disconnect.confirmTitle': 'Отключить "{name}"?',
|
||||
'cloudSync.provider.disconnect.confirmMessage': 'Это устройство перестанет синхронизироваться с {name}. Сохранённый адрес и данные для входа будут удалены. Локальное хранилище, резервные копии и пароль шифрования синхронизации останутся здесь. Если системное хранилище учётных данных недоступно, данные для входа плагинов может потребоваться удалить вручную.',
|
||||
'cloudSync.provider.disconnect.confirmMessage': 'Это устройство перестанет синхронизироваться с {name}. Локальное хранилище останется на этом компьютере.',
|
||||
'cloudSync.provider.disconnect.confirmAction': 'Отключить',
|
||||
'cloudSync.provider.disconnect.toastTitle': 'Отключено',
|
||||
'cloudSync.provider.disconnect.cloudRemains': 'Зашифрованные копии синхронизации могут остаться в хранилище {name}. Чтобы удалить их, удалите там файлы синхронизации. Отключение не очищает устройство для передачи другому человеку.',
|
||||
'cloudSync.provider.disconnect.failed': 'Не удалось завершить отключение от {name}. Сохранённые данные подключения могут остаться. Повторите попытку.',
|
||||
'cloudSync.provider.webdav': 'WebDAV',
|
||||
'cloudSync.provider.webdav.desc': 'Подключение к самостоятельно размещённому WebDAV endpoint',
|
||||
'cloudSync.provider.s3': 'Совместимое с S3',
|
||||
@@ -406,12 +399,6 @@ export const ruTerminalMessages: Messages = {
|
||||
'cloudSync.strategy.title': 'Стратегия синхронизации',
|
||||
'cloudSync.strategy.desc': 'Выберите, что делать, когда изменились и локальные, и облачные данные.',
|
||||
'cloudSync.strategy.smartMerge': 'Умное объединение (рекомендуется)',
|
||||
'cloudSync.aiSessions.title': 'Синхронизировать историю ИИ-чатов',
|
||||
'cloudSync.aiSessions.desc': 'Включать сессии ИИ-чатов в облачную синхронизацию. Сообщения объединяются дополнением между устройствами; содержимое вложений остаётся на этом устройстве.',
|
||||
'cloudSync.aiSessions.compatibility': 'Старые версии могут перезаписать историю. Обновите Netcatty на всех синхронизируемых устройствах.',
|
||||
'cloudSync.aiSessions.enableFailed': 'Не удалось изменить синхронизацию чатов. Проверьте подключение к облаку и свободное место на устройстве, затем повторите попытку.',
|
||||
'cloudSync.strategy.smartMergePreserve': 'Умное слияние (без удалений)',
|
||||
'cloudSync.strategy.smartMergePreserveDesc': 'Объединяет изменения с обеих сторон и никогда не передаёт удаление с одной стороны: запись сохраняется, пока её не убрали на всех устройствах. Рекомендуется при восстановлении из резервных копий или при работе с несколькими машинами.',
|
||||
'cloudSync.strategy.smartMergeDesc': 'По возможности объединять изменения с обеих сторон; если Netcatty не сможет безопасно выбрать, он попросит вас решить вручную.',
|
||||
'cloudSync.strategy.preferCloud': 'Приоритет облака',
|
||||
'cloudSync.strategy.preferCloudDesc': 'Когда изменились обе стороны, скачать облачную версию и заменить локальные изменения.',
|
||||
|
||||
@@ -128,9 +128,6 @@ export const ruVaultMessages: Messages = {
|
||||
'vault.hosts.deleteMultiple.success': 'Удалено хостов: {count}',
|
||||
'vault.hosts.connectSelected': 'Подключить ({count})',
|
||||
'vault.hosts.connectMultiple.success': 'Подключение хостов: {count}',
|
||||
'vault.hosts.moveSelected': 'Переместить в группу ({count})',
|
||||
'vault.hosts.moveSelected.description': 'Переместить выбранные хосты в существующую группу или оставить без группы. Выбранные группы не перемещаются.',
|
||||
'vault.hosts.moveMultiple.success': 'Перемещено {count} хостов в {group}',
|
||||
'vault.hosts.moveToGroup.success': 'Хост {host} перемещён в {group}',
|
||||
'vault.hosts.empty.title': 'Настройте свои хосты',
|
||||
'vault.hosts.empty.desc': 'Сохраняйте хосты, чтобы быстро подключаться к серверам, виртуальным машинам и контейнерам.',
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Messages } from '../types';
|
||||
|
||||
export const zhCNAiMessages: Messages = {
|
||||
'ai.chat.attachmentContentUnavailable': '附件内容未保留在此设备',
|
||||
// AI Settings
|
||||
'ai.agentSettings': 'Agent 设置',
|
||||
'ai.chat.preparing': '准备中…',
|
||||
@@ -514,10 +513,6 @@ export const zhCNAiMessages: Messages = {
|
||||
'ai.chat.pinModel': '固定模型',
|
||||
'ai.chat.unpinModel': '取消固定',
|
||||
'ai.chat.loadingModels': '正在加载模型...',
|
||||
'ai.chat.modelCatalogSourceLive': '实时目录',
|
||||
'ai.chat.modelCatalogSourceCached': '缓存 · 上次成功 {time}',
|
||||
'ai.chat.modelCatalogSourceCachedNoTime': '缓存',
|
||||
'ai.chat.modelCatalogSourcePresets': '内置默认列表',
|
||||
'ai.chat.noMatchingModels': '没有匹配的模型',
|
||||
'ai.chat.recent': '最近',
|
||||
'ai.chat.viewAll': '查看全部',
|
||||
|
||||
@@ -766,9 +766,6 @@ export const zhCNCoreMessages: Messages = {
|
||||
'vault.hosts.deleteMultiple.success': '已删除 {count} 个主机',
|
||||
'vault.hosts.connectSelected': '连接 ({count})',
|
||||
'vault.hosts.connectMultiple.success': '正在连接 {count} 个主机',
|
||||
'vault.hosts.moveSelected': '移动到分组 ({count})',
|
||||
'vault.hosts.moveSelected.description': '将选中的主机移动到现有分组,也可移出分组。选中的分组本身不会移动。',
|
||||
'vault.hosts.moveMultiple.success': '已将 {count} 个主机移动到 {group}',
|
||||
'vault.hosts.moveToGroup.success': '已将 {host} 移动到 {group}',
|
||||
'vault.hosts.errors.nameRequired': '主机名称不能为空。',
|
||||
'vault.hosts.empty.title': '设置你的主机',
|
||||
|
||||
@@ -63,10 +63,6 @@ export const zhCNTerminalMessages: Messages = {
|
||||
'history.action.run': '在终端执行',
|
||||
'history.action.saveAsSnippet': '保存为代码片段',
|
||||
'history.action.delete': '从历史记录中删除',
|
||||
'history.action.clearAll': '清空全部历史',
|
||||
'history.clearAll.dialog.title': '清空全部命令历史?',
|
||||
'history.clearAll.dialog.desc': '这将永久删除所有本地记录的命令历史及自动补全建议,且无法撤销。',
|
||||
'history.clearAll.dialog.confirm': '全部清空',
|
||||
// SFTP File Opener
|
||||
'sftp.context.copyPath': '复制文件路径',
|
||||
'sftp.context.openWith': '打开方式...',
|
||||
@@ -598,7 +594,6 @@ export const zhCNTerminalMessages: Messages = {
|
||||
'settings.shortcuts.binding.new-workspace': '新建工作区',
|
||||
'settings.shortcuts.binding.snippets': '打开代码片段',
|
||||
'settings.shortcuts.binding.broadcast': '切换广播模式',
|
||||
'settings.shortcuts.binding.toggle-opacity': '切换窗口透明度',
|
||||
'settings.shortcuts.binding.toggle-side-panel': '切换侧边栏',
|
||||
'settings.shortcuts.binding.sftp-copy': '复制文件',
|
||||
'settings.shortcuts.binding.sftp-cut': '剪切文件',
|
||||
|
||||
@@ -717,11 +717,8 @@ export const zhCNVaultMessages: Messages = {
|
||||
'cloudSync.provider.connecting': '连接中...',
|
||||
'cloudSync.provider.disconnect': '断开连接',
|
||||
'cloudSync.provider.disconnect.confirmTitle': '断开 “{name}”?',
|
||||
'cloudSync.provider.disconnect.confirmMessage': '此设备将停止与 {name} 同步,并删除本机保存的该服务商地址与登录凭据。本地主机库、备份历史和同步加密密码仍会保留。若系统凭据存储不可用,插件凭据可能需要手动删除。',
|
||||
'cloudSync.provider.disconnect.confirmMessage': '此设备将停止与 {name} 同步。本地保险库仍保留在这台电脑上。',
|
||||
'cloudSync.provider.disconnect.confirmAction': '断开连接',
|
||||
'cloudSync.provider.disconnect.toastTitle': '已断开连接',
|
||||
'cloudSync.provider.disconnect.cloudRemains': '云端的加密同步副本可能仍保存在 {name} 存储中。如需清除,请到该服务商删除同步文件。断开连接不代表设备已完成交接清理。',
|
||||
'cloudSync.provider.disconnect.failed': '未能完成与 {name} 的断开连接,保存的连接资料可能仍在,请重试。',
|
||||
'cloudSync.provider.webdav': 'WebDAV',
|
||||
'cloudSync.provider.webdav.desc': '连接到自建 WebDAV 端点',
|
||||
'cloudSync.provider.s3': 'S3 兼容存储',
|
||||
@@ -791,12 +788,6 @@ export const zhCNVaultMessages: Messages = {
|
||||
'cloudSync.strategy.title': '同步策略',
|
||||
'cloudSync.strategy.desc': '当本地和云端都发生变化时,选择如何处理。',
|
||||
'cloudSync.strategy.smartMerge': '智能合并(推荐)',
|
||||
'cloudSync.aiSessions.title': '同步 AI 对话记录',
|
||||
'cloudSync.aiSessions.desc': '把 AI 对话记录纳入云同步。多设备的对话会按追加方式合并,附件内容仍保留在本机。',
|
||||
'cloudSync.aiSessions.compatibility': '旧版本可能覆盖对话记录,请先更新所有参与同步的设备。',
|
||||
'cloudSync.aiSessions.enableFailed': '无法更改聊天同步设置,请检查云端连接和本地可用空间,然后重试。',
|
||||
'cloudSync.strategy.smartMergePreserve': '智能合并(不传播删除)',
|
||||
'cloudSync.strategy.smartMergePreserveDesc': '合并两边的变化,且单侧删除不会同步到其它设备——只有所有设备都删掉才会真正消失。恢复备份或多台机器同步时推荐使用。',
|
||||
'cloudSync.strategy.smartMergeDesc': '尽量保留两边的变化;如果无法安全判断,会再让你手动选择。',
|
||||
'cloudSync.strategy.preferCloud': '云端优先',
|
||||
'cloudSync.strategy.preferCloudDesc': '两边都有变化时,下载云端版本,并替换本地变化。',
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Messages } from '../types';
|
||||
|
||||
export const zhTWAiMessages: Messages = {
|
||||
'ai.chat.attachmentContentUnavailable': '附件內容未保留在此裝置',
|
||||
// AI Settings
|
||||
'ai.agentSettings': 'Agent 設定',
|
||||
'ai.chat.preparing': '準備中…',
|
||||
@@ -504,10 +503,6 @@ export const zhTWAiMessages: Messages = {
|
||||
'ai.chat.pinModel': '釘選模型',
|
||||
'ai.chat.unpinModel': '取消釘選',
|
||||
'ai.chat.loadingModels': '正在載入模型...',
|
||||
'ai.chat.modelCatalogSourceLive': '即時目錄',
|
||||
'ai.chat.modelCatalogSourceCached': '快取 · 上次成功 {time}',
|
||||
'ai.chat.modelCatalogSourceCachedNoTime': '快取',
|
||||
'ai.chat.modelCatalogSourcePresets': '內建預設清單',
|
||||
'ai.chat.noMatchingModels': '沒有符合的模型',
|
||||
'ai.chat.recent': '最近',
|
||||
'ai.chat.viewAll': '檢視全部',
|
||||
|
||||
@@ -768,9 +768,6 @@ export const zhTWCoreMessages: Messages = {
|
||||
'vault.hosts.deleteMultiple.success': '已刪除 {count} 個主機',
|
||||
'vault.hosts.connectSelected': '連線 ({count})',
|
||||
'vault.hosts.connectMultiple.success': '正在連線 {count} 個主機',
|
||||
'vault.hosts.moveSelected': '移動到群組 ({count})',
|
||||
'vault.hosts.moveSelected.description': '將選取的主機移動到現有群組,也可移出群組。選取的群組本身不會移動。',
|
||||
'vault.hosts.moveMultiple.success': '已將 {count} 個主機移動到 {group}',
|
||||
'vault.hosts.moveToGroup.success': '已將 {host} 移動到 {group}',
|
||||
'vault.hosts.errors.nameRequired': '主機名稱不能為空。',
|
||||
'vault.hosts.empty.title': '設定你的主機',
|
||||
|
||||
@@ -63,10 +63,6 @@ export const zhTWTerminalMessages: Messages = {
|
||||
'history.action.run': '在終端執行',
|
||||
'history.action.saveAsSnippet': '儲存為程式碼片段',
|
||||
'history.action.delete': '從歷史記錄中刪除',
|
||||
'history.action.clearAll': '清空全部歷史',
|
||||
'history.clearAll.dialog.title': '清空全部指令歷史?',
|
||||
'history.clearAll.dialog.desc': '這將永久刪除所有本機記錄的指令歷史及自動補全建議,且無法復原。',
|
||||
'history.clearAll.dialog.confirm': '全部清空',
|
||||
// SFTP File Opener
|
||||
'sftp.context.copyPath': '複製檔案路徑',
|
||||
'sftp.context.openWith': '開啟方式...',
|
||||
@@ -598,7 +594,6 @@ export const zhTWTerminalMessages: Messages = {
|
||||
'settings.shortcuts.binding.new-workspace': '新增工作區',
|
||||
'settings.shortcuts.binding.snippets': '開啟程式碼片段',
|
||||
'settings.shortcuts.binding.broadcast': '切換廣播模式',
|
||||
'settings.shortcuts.binding.toggle-opacity': '切換視窗透明度',
|
||||
'settings.shortcuts.binding.toggle-side-panel': '切換側邊欄',
|
||||
'settings.shortcuts.binding.sftp-copy': '複製檔案',
|
||||
'settings.shortcuts.binding.sftp-cut': '剪下檔案',
|
||||
|
||||
@@ -717,11 +717,8 @@ export const zhTWVaultMessages: Messages = {
|
||||
'cloudSync.provider.connecting': '連線中...',
|
||||
'cloudSync.provider.disconnect': '中斷連線',
|
||||
'cloudSync.provider.disconnect.confirmTitle': '中斷「{name}」?',
|
||||
'cloudSync.provider.disconnect.confirmMessage': '此裝置將停止與 {name} 同步,並刪除本機保存的該服務商位址與登入憑證。本機主機庫、備份歷史和同步加密密碼仍會保留。若系統憑證儲存無法使用,外掛憑證可能需要手動刪除。',
|
||||
'cloudSync.provider.disconnect.confirmMessage': '此裝置將停止與 {name} 同步。本機保險庫仍保留在這台電腦上。',
|
||||
'cloudSync.provider.disconnect.confirmAction': '中斷連線',
|
||||
'cloudSync.provider.disconnect.toastTitle': '已中斷連線',
|
||||
'cloudSync.provider.disconnect.cloudRemains': '雲端的加密同步副本可能仍保存在 {name} 儲存空間中。如需清除,請到該服務商刪除同步檔案。中斷連線不代表裝置已完成交接清理。',
|
||||
'cloudSync.provider.disconnect.failed': '未能完成與 {name} 的中斷連線,保存的連線資料可能仍在,請重試。',
|
||||
'cloudSync.provider.webdav': 'WebDAV',
|
||||
'cloudSync.provider.webdav.desc': '連線到自建 WebDAV 端點',
|
||||
'cloudSync.provider.s3': 'S3 相容儲存',
|
||||
@@ -791,12 +788,6 @@ export const zhTWVaultMessages: Messages = {
|
||||
'cloudSync.strategy.title': '同步策略',
|
||||
'cloudSync.strategy.desc': '當本機和雲端都發生變化時,選擇如何處理。',
|
||||
'cloudSync.strategy.smartMerge': '智慧合併(推薦)',
|
||||
'cloudSync.aiSessions.title': '同步 AI 對話記錄',
|
||||
'cloudSync.aiSessions.desc': '把 AI 對話記錄納入雲同步。多裝置的對話會按追加方式合併,附件內容仍保留在本機。',
|
||||
'cloudSync.aiSessions.compatibility': '舊版本可能覆寫對話記錄,請先更新所有參與同步的裝置。',
|
||||
'cloudSync.aiSessions.enableFailed': '無法變更聊天同步設定,請檢查雲端連線與本機可用空間,然後重試。',
|
||||
'cloudSync.strategy.smartMergePreserve': '智慧合併(不傳播刪除)',
|
||||
'cloudSync.strategy.smartMergePreserveDesc': '合併兩邊的變化,且單側刪除不會同步到其它裝置——只有所有裝置都刪掉才會真正消失。還原備份或多台機器同步時建議使用。',
|
||||
'cloudSync.strategy.smartMergeDesc': '儘量保留兩邊的變化;如果無法安全判斷,會再讓你手動選擇。',
|
||||
'cloudSync.strategy.preferCloud': '雲端優先',
|
||||
'cloudSync.strategy.preferCloudDesc': '兩邊都有變化時,下載雲端版本,並替換本機變化。',
|
||||
|
||||
@@ -2,7 +2,6 @@ import { localStorageAdapter } from '../../infrastructure/persistence/localStora
|
||||
import {
|
||||
STORAGE_KEY_AI_ACTIVE_SESSION_MAP,
|
||||
STORAGE_KEY_AI_SESSIONS,
|
||||
STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS,
|
||||
} from '../../infrastructure/config/storageKeys';
|
||||
import type {
|
||||
AIDraft,
|
||||
@@ -48,10 +47,12 @@ export const AI_STATE_CHANGED_PANEL_VIEW_BY_SCOPE = 'netcatty:ai-panel-view-by-s
|
||||
export type DraftsByScope = Partial<Record<string, AIDraft>>;
|
||||
export type PanelViewByScope = Partial<Record<string, AIPanelView>>;
|
||||
|
||||
export async function cleanupSdkAgentSessions(sessionIds: string[]): Promise<void> {
|
||||
export function cleanupSdkAgentSessions(sessionIds: string[]) {
|
||||
const bridge = getAIBridge();
|
||||
if (sessionIds.length === 0) return;
|
||||
await Promise.all(sessionIds.map((sessionId) => bridge?.aiSdkAgentCleanup?.(sessionId).catch(() => {})));
|
||||
for (const sessionId of sessionIds) {
|
||||
void bridge?.aiSdkAgentCleanup?.(sessionId).catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
export function cleanupDeletedAIChatSessions(sessionIds: string[]) {
|
||||
@@ -470,11 +471,6 @@ export function serializeSessionsForStorage(
|
||||
* could not be persisted even after escalation (it stays memory-only).
|
||||
*/
|
||||
export function writeSessionsForStorage(sessions: AISession[]): boolean {
|
||||
// Synced records are authoritative after restart: silently evicting a
|
||||
// session or turn here would turn local retention into cloud deletion.
|
||||
if (localStorageAdapter.read<{ enabled?: boolean }>(STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS)?.enabled) {
|
||||
return localStorageAdapter.write(STORAGE_KEY_AI_SESSIONS, sessions);
|
||||
}
|
||||
let previousLength = Number.POSITIVE_INFINITY;
|
||||
for (const configuredBudget of [MAX_SESSIONS_JSON_BYTES, ...RETRY_SESSIONS_JSON_BYTES]) {
|
||||
// A real quota failure means the next attempt must be smaller even when
|
||||
|
||||
@@ -1,328 +0,0 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
STORAGE_KEY_COMMAND_HISTORY,
|
||||
STORAGE_KEY_COMMAND_HISTORY_CLEARED,
|
||||
} from "../../infrastructure/config/storageKeys";
|
||||
|
||||
type StorageEventLike = { key: string | null; newValue: string | null; oldValue: string | null };
|
||||
type StorageListener = (event: StorageEventLike) => void;
|
||||
|
||||
type DeferredRead = { resolve: (value: string) => void };
|
||||
|
||||
const COMMAND_HISTORY_STORAGE_KEY = STORAGE_KEY_COMMAND_HISTORY;
|
||||
|
||||
function installLocalStorage(): Map<string, string> {
|
||||
const store = new Map<string, string>();
|
||||
Object.defineProperty(globalThis, "localStorage", {
|
||||
value: {
|
||||
getItem: (key: string) => (store.has(key) ? store.get(key)! : null),
|
||||
setItem: (key: string, value: string) => {
|
||||
store.set(key, String(value));
|
||||
},
|
||||
removeItem: (key: string) => {
|
||||
store.delete(key);
|
||||
},
|
||||
clear: () => {
|
||||
store.clear();
|
||||
},
|
||||
},
|
||||
configurable: true,
|
||||
});
|
||||
return store;
|
||||
}
|
||||
|
||||
/**
|
||||
* The store registers its cross-window `storage` listener at module load, so
|
||||
* the DOM globals must exist before the dynamic imports below.
|
||||
*/
|
||||
function installWindow(): (key: string, newValue: string | null, oldValue?: string | null) => void {
|
||||
const listeners = new Set<StorageListener>();
|
||||
Object.defineProperty(globalThis, "window", {
|
||||
value: {
|
||||
addEventListener: (type: string, listener: StorageListener) => {
|
||||
if (type === "storage") listeners.add(listener);
|
||||
},
|
||||
removeEventListener: (type: string, listener: StorageListener) => {
|
||||
if (type === "storage") listeners.delete(listener);
|
||||
},
|
||||
netcatty: undefined as unknown,
|
||||
},
|
||||
configurable: true,
|
||||
});
|
||||
return (key: string, newValue: string | null, oldValue: string | null = null) => {
|
||||
for (const listener of listeners) listener({ key, newValue, oldValue });
|
||||
};
|
||||
}
|
||||
|
||||
async function waitFor(condition: () => boolean, timeoutMs = 2000): Promise<void> {
|
||||
const start = Date.now();
|
||||
while (!condition()) {
|
||||
if (Date.now() - start > timeoutMs) throw new Error("waitFor timed out");
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
}
|
||||
}
|
||||
|
||||
const storage = installLocalStorage();
|
||||
const dispatchStorageEvent = installWindow();
|
||||
|
||||
const {
|
||||
clearHistory,
|
||||
flushCommandHistoryStore,
|
||||
getCommandHistoryClearGeneration,
|
||||
hasCommandHistoryBeenCleared,
|
||||
markCommandHistoryCleared,
|
||||
queryHistory,
|
||||
recordCommand,
|
||||
subscribeCommandHistoryCleared,
|
||||
} = await import("./commandHistoryStore.ts");
|
||||
const { seedLocalShellHistoryFromHistfiles } = await import(
|
||||
"../../components/terminal/autocomplete/localShellHistorySeed.ts"
|
||||
);
|
||||
|
||||
function readPersistedCommands(): string[] {
|
||||
const raw = storage.get(COMMAND_HISTORY_STORAGE_KEY);
|
||||
if (!raw) return [];
|
||||
const parsed = JSON.parse(raw) as { entries: Array<{ command: string }> };
|
||||
return parsed.entries.map((entry) => entry.command);
|
||||
}
|
||||
|
||||
function readPersistedGeneration(): number {
|
||||
const raw = storage.get(COMMAND_HISTORY_STORAGE_KEY);
|
||||
if (!raw) return 0;
|
||||
const parsed = JSON.parse(raw) as { clearGeneration?: number };
|
||||
return typeof parsed.clearGeneration === "number" ? parsed.clearGeneration : 0;
|
||||
}
|
||||
|
||||
test("a fresh popup keeps compose recall on an ordinary peer write after an earlier clear", async () => {
|
||||
const baseline = JSON.stringify({ entries: [], version: 1, clearGeneration: 3 });
|
||||
storage.set(COMMAND_HISTORY_STORAGE_KEY, baseline);
|
||||
const composeBar = await import("./composeBarHistoryStore.ts");
|
||||
composeBar.recordComposeBarHistory("fresh-popup", "echo popup-current-command");
|
||||
|
||||
// No autocomplete query has loaded this renderer's command-history store.
|
||||
const recorded = JSON.stringify({
|
||||
entries: [{ command: "peer-command", hostId: "host-2", os: "linux", frequency: 1, createdAt: 1, lastUsedAt: 1 }],
|
||||
version: 1, clearGeneration: 3,
|
||||
});
|
||||
dispatchStorageEvent(COMMAND_HISTORY_STORAGE_KEY, recorded, baseline);
|
||||
assert.deepEqual(composeBar.getComposeBarHistory("fresh-popup"), ["echo popup-current-command"]);
|
||||
|
||||
const cleared = JSON.stringify({ entries: [], version: 1, clearGeneration: 4 });
|
||||
storage.set(COMMAND_HISTORY_STORAGE_KEY, cleared);
|
||||
dispatchStorageEvent(COMMAND_HISTORY_STORAGE_KEY, cleared, recorded);
|
||||
assert.deepEqual(composeBar.getComposeBarHistory("fresh-popup"), []);
|
||||
});
|
||||
|
||||
test("a stale pending write cannot overwrite a peer clear before its storage event arrives", () => {
|
||||
clearHistory();
|
||||
recordCommand("old-command", "host-1");
|
||||
flushCommandHistoryStore();
|
||||
recordCommand("pending-before-clear", "host-1");
|
||||
|
||||
// localStorage is already updated in the peer, but this renderer has not yet
|
||||
// processed its queued storage event when the pending save runs.
|
||||
const generation = readPersistedGeneration() + 1;
|
||||
storage.set(COMMAND_HISTORY_STORAGE_KEY, JSON.stringify({
|
||||
entries: [], version: 1, clearGeneration: generation,
|
||||
}));
|
||||
flushCommandHistoryStore();
|
||||
assert.deepEqual(readPersistedCommands(), []);
|
||||
assert.equal(readPersistedGeneration(), generation);
|
||||
assert.deepEqual(queryHistory("old", { hostId: "host-1" }), []);
|
||||
|
||||
recordCommand("new-after-clear", "host-1");
|
||||
flushCommandHistoryStore();
|
||||
assert.deepEqual(readPersistedCommands(), ["new-after-clear"]);
|
||||
});
|
||||
|
||||
test("an ordinary peer write does not cancel a locally pending command", async () => {
|
||||
clearHistory();
|
||||
recordCommand("local-pending-command", "host-1");
|
||||
const before = storage.get(COMMAND_HISTORY_STORAGE_KEY)!;
|
||||
const ordinary = JSON.stringify({
|
||||
entries: [{ command: "peer-command", hostId: "host-2", os: "linux", frequency: 1, createdAt: 1, lastUsedAt: 1 }],
|
||||
version: 1, clearGeneration: getCommandHistoryClearGeneration(),
|
||||
});
|
||||
storage.set(COMMAND_HISTORY_STORAGE_KEY, ordinary);
|
||||
dispatchStorageEvent(COMMAND_HISTORY_STORAGE_KEY, ordinary, before);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 600));
|
||||
assert.ok(readPersistedCommands().includes("local-pending-command"));
|
||||
});
|
||||
|
||||
test("an external clear invalidates the cached history and cannot be resurrected", () => {
|
||||
storage.clear();
|
||||
clearHistory();
|
||||
|
||||
recordCommand("stale-command --flag", "host-1");
|
||||
flushCommandHistoryStore();
|
||||
assert.ok(queryHistory("stale", { hostId: "host-1" }).length > 0);
|
||||
|
||||
// Simulate another renderer (main window or a detached terminal popup)
|
||||
// clearing the shared localStorage entry.
|
||||
const cleared = JSON.stringify({ entries: [], version: 1, clearGeneration: 1 });
|
||||
storage.set(COMMAND_HISTORY_STORAGE_KEY, cleared);
|
||||
dispatchStorageEvent(COMMAND_HISTORY_STORAGE_KEY, cleared);
|
||||
|
||||
// The stale module-local cache must be dropped immediately.
|
||||
assert.equal(queryHistory("stale", { hostId: "host-1" }).length, 0);
|
||||
|
||||
// A later recordCommand must persist only the new command, never the stale
|
||||
// snapshot it still held in memory.
|
||||
recordCommand("fresh-command", "host-1");
|
||||
flushCommandHistoryStore();
|
||||
assert.deepEqual(readPersistedCommands(), ["fresh-command"]);
|
||||
});
|
||||
|
||||
test("clearHistory persists synchronously and cancels a pending debounced write", async () => {
|
||||
storage.clear();
|
||||
clearHistory();
|
||||
|
||||
recordCommand("pending-command", "host-1");
|
||||
// No flush: the debounced write is still scheduled.
|
||||
clearHistory();
|
||||
assert.deepEqual(readPersistedCommands(), []);
|
||||
|
||||
// Wait past the debounce window to prove the cancelled write cannot restore
|
||||
// the entries.
|
||||
await new Promise((resolve) => setTimeout(resolve, 600));
|
||||
assert.deepEqual(readPersistedCommands(), []);
|
||||
});
|
||||
|
||||
test("a local clear bumps the generation and notifies subscribers", () => {
|
||||
storage.clear();
|
||||
clearHistory();
|
||||
|
||||
const before = getCommandHistoryClearGeneration();
|
||||
let notified = 0;
|
||||
const unsubscribe = subscribeCommandHistoryCleared(() => {
|
||||
notified += 1;
|
||||
});
|
||||
|
||||
recordCommand("notify-local", "host-1");
|
||||
clearHistory();
|
||||
|
||||
assert.equal(getCommandHistoryClearGeneration(), before + 1);
|
||||
assert.equal(readPersistedGeneration(), before + 1);
|
||||
assert.equal(notified, 1);
|
||||
|
||||
unsubscribe();
|
||||
clearHistory();
|
||||
assert.equal(notified, 1);
|
||||
});
|
||||
|
||||
test("an external clear notifies subscribers, while an external record does not", () => {
|
||||
storage.clear();
|
||||
clearHistory();
|
||||
|
||||
const baseline = getCommandHistoryClearGeneration();
|
||||
let notified = 0;
|
||||
const unsubscribe = subscribeCommandHistoryCleared(() => {
|
||||
notified += 1;
|
||||
});
|
||||
|
||||
// A normal record from another renderer keeps the generation: no clear event.
|
||||
const recorded = JSON.stringify({ entries: [], version: 1, clearGeneration: baseline });
|
||||
storage.set(COMMAND_HISTORY_STORAGE_KEY, recorded);
|
||||
dispatchStorageEvent(COMMAND_HISTORY_STORAGE_KEY, recorded);
|
||||
assert.equal(notified, 0);
|
||||
|
||||
// A clear from another renderer bumps the generation: subscribers fire.
|
||||
const cleared = JSON.stringify({ entries: [], version: 1, clearGeneration: baseline + 1 });
|
||||
storage.set(COMMAND_HISTORY_STORAGE_KEY, cleared);
|
||||
dispatchStorageEvent(COMMAND_HISTORY_STORAGE_KEY, cleared);
|
||||
assert.equal(notified, 1);
|
||||
assert.equal(getCommandHistoryClearGeneration(), baseline + 1);
|
||||
|
||||
unsubscribe();
|
||||
});
|
||||
|
||||
test("a histfile import that started before a clear is discarded", async () => {
|
||||
storage.clear();
|
||||
clearHistory();
|
||||
|
||||
const hostId = `local-seed-clear-${Date.now()}`;
|
||||
const deferredReads: DeferredRead[] = [];
|
||||
(window as unknown as { netcatty?: unknown }).netcatty = {
|
||||
getHomeDir: async () => "/home/demo",
|
||||
readLocalFile: () =>
|
||||
new Promise<string>((resolve) => {
|
||||
deferredReads.push({ resolve });
|
||||
}),
|
||||
};
|
||||
|
||||
const seedPromise = seedLocalShellHistoryFromHistfiles(hostId, "macos");
|
||||
// Let the seeder resolve getHomeDir and reach the histfile reads.
|
||||
await waitFor(() => deferredReads.length === 4);
|
||||
|
||||
// The user clears history while the bridge reads are still pending.
|
||||
clearHistory();
|
||||
|
||||
for (const deferred of deferredReads) {
|
||||
deferred.resolve(": 1700000000:0;echo seeded\n");
|
||||
}
|
||||
|
||||
assert.equal(await seedPromise, 0);
|
||||
assert.equal(queryHistory("echo", { hostId, limit: 5 }).length, 0);
|
||||
|
||||
// The host is marked seeded so a later open cannot re-import the deleted
|
||||
// commands.
|
||||
assert.equal(await seedLocalShellHistoryFromHistfiles(hostId, "macos"), 0);
|
||||
assert.equal(queryHistory("echo", { hostId, limit: 5 }).length, 0);
|
||||
});
|
||||
|
||||
test("markCommandHistoryCleared persists a tombstone for histfile seeding", () => {
|
||||
storage.clear();
|
||||
assert.equal(hasCommandHistoryBeenCleared(), false);
|
||||
|
||||
markCommandHistoryCleared();
|
||||
|
||||
assert.equal(hasCommandHistoryBeenCleared(), true);
|
||||
assert.equal(storage.get(STORAGE_KEY_COMMAND_HISTORY_CLEARED), "true");
|
||||
});
|
||||
|
||||
test("a first-time histfile import is skipped once history has been cleared", async () => {
|
||||
storage.clear();
|
||||
clearHistory();
|
||||
markCommandHistoryCleared();
|
||||
|
||||
const hostId = `local-seed-tombstone-${Date.now()}`;
|
||||
(window as unknown as { netcatty?: unknown }).netcatty = {
|
||||
getHomeDir: async () => "/home/demo",
|
||||
readLocalFile: async () => ": 1700000000:0;echo resurrected\n",
|
||||
};
|
||||
|
||||
assert.equal(await seedLocalShellHistoryFromHistfiles(hostId, "macos"), 0);
|
||||
assert.equal(queryHistory("echo", { hostId, limit: 5 }).length, 0);
|
||||
});
|
||||
|
||||
test("an external clear also drops in-memory compose-bar recall", async () => {
|
||||
const composeBar = await import("./composeBarHistoryStore.ts");
|
||||
storage.clear();
|
||||
clearHistory();
|
||||
composeBar.pruneComposeBarHistory([]);
|
||||
composeBar.recordComposeBarHistory("session-1", "echo compose");
|
||||
assert.deepEqual(composeBar.getComposeBarHistory("session-1"), ["echo compose"]);
|
||||
|
||||
let notified = 0;
|
||||
const unsubscribe = composeBar.subscribeComposeBarHistoryCleared(() => {
|
||||
notified += 1;
|
||||
});
|
||||
|
||||
// Simulate another renderer clearing command history. The compose-bar store
|
||||
// follows the same clear event, so a detached popup drops its recall too.
|
||||
const cleared = JSON.stringify({
|
||||
entries: [],
|
||||
version: 1,
|
||||
clearGeneration: getCommandHistoryClearGeneration() + 1,
|
||||
});
|
||||
storage.set(COMMAND_HISTORY_STORAGE_KEY, cleared);
|
||||
dispatchStorageEvent(COMMAND_HISTORY_STORAGE_KEY, cleared);
|
||||
|
||||
assert.deepEqual(composeBar.getComposeBarHistory("session-1"), []);
|
||||
assert.equal(notified, 1);
|
||||
|
||||
unsubscribe();
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { getComposeBarHistory, pruneComposeBarHistory, recordComposeBarHistory, clearComposeBarHistory, subscribeComposeBarHistoryCleared } from './composeBarHistoryStore';
|
||||
import { getComposeBarHistory, pruneComposeBarHistory, recordComposeBarHistory } from './composeBarHistoryStore';
|
||||
|
||||
test('compose history is isolated per terminal and removed when its session closes', () => {
|
||||
pruneComposeBarHistory([]);
|
||||
@@ -40,24 +40,3 @@ test('failed submissions unblock later successes in submission order', async ()
|
||||
assert.deepEqual(getComposeBarHistory('a'), ['accepted']);
|
||||
pruneComposeBarHistory([]);
|
||||
});
|
||||
|
||||
test('clearComposeBarHistory drops every session and notifies live compose bars', () => {
|
||||
pruneComposeBarHistory([]);
|
||||
recordComposeBarHistory('a', 'echo a');
|
||||
recordComposeBarHistory('b', 'echo b');
|
||||
|
||||
let notified = 0;
|
||||
const unsubscribe = subscribeComposeBarHistoryCleared(() => {
|
||||
notified += 1;
|
||||
});
|
||||
|
||||
clearComposeBarHistory();
|
||||
|
||||
assert.deepEqual(getComposeBarHistory('a'), []);
|
||||
assert.deepEqual(getComposeBarHistory('b'), []);
|
||||
assert.equal(notified, 1);
|
||||
|
||||
unsubscribe();
|
||||
clearComposeBarHistory();
|
||||
assert.equal(notified, 1);
|
||||
});
|
||||
@@ -1,14 +1,10 @@
|
||||
import { appendComposeBarHistory } from '../../domain/composeBarHistory';
|
||||
import { subscribeCommandHistoryCleared } from './commandHistoryStore';
|
||||
|
||||
// Session-only memory: survives closing the bar and moving a terminal into a
|
||||
// workspace, but is discarded when that terminal session is removed.
|
||||
type PendingSend = { settled: boolean; command?: string };
|
||||
const histories = new Map<string, { entries: readonly string[]; pending: PendingSend[] }>();
|
||||
|
||||
type Listener = () => void;
|
||||
const clearedListeners = new Set<Listener>();
|
||||
|
||||
export function getComposeBarHistory(sessionId: string): readonly string[] {
|
||||
return histories.get(sessionId)?.entries ?? [];
|
||||
}
|
||||
@@ -48,36 +44,3 @@ export function pruneComposeBarHistory(sessionIds: readonly string[]): void {
|
||||
if (!active.has(id)) histories.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to full compose-bar history clears. A live compose bar uses this to
|
||||
* drop the history walk it cached, so ArrowUp cannot recall deleted commands.
|
||||
*/
|
||||
export function subscribeComposeBarHistoryCleared(listener: Listener): () => void {
|
||||
clearedListeners.add(listener);
|
||||
return () => {
|
||||
clearedListeners.delete(listener);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the in-memory compose-bar history for every session.
|
||||
*
|
||||
* This store is session-only (never persisted), so the "clear all command
|
||||
* history" action must clear it explicitly. Otherwise a command sent through
|
||||
* the compose bar stays recallable, and resending it would re-record it into
|
||||
* shell history and autocomplete after the user deleted it.
|
||||
*/
|
||||
export function clearComposeBarHistory(): void {
|
||||
histories.clear();
|
||||
// Always notify: a live compose bar can still hold a cached walk even when
|
||||
// the map is already empty (for example after its session was pruned).
|
||||
for (const listener of [...clearedListeners]) listener();
|
||||
}
|
||||
|
||||
// The compose bar holds the most recent commands sent through it, so clearing
|
||||
// command history must drop it too. Subscribing to the command-history clear
|
||||
// event covers every renderer: a detached terminal popup renders its own
|
||||
// TerminalComposeBar and learns about a main-window clear through the shared
|
||||
// clear generation, while the main window is notified synchronously.
|
||||
subscribeCommandHistoryCleared(clearComposeBarHistory);
|
||||
@@ -4,7 +4,7 @@ import test from "node:test";
|
||||
import type { Host } from "../../domain/models";
|
||||
import { prepareSerialConfigForSavedHost } from "../../domain/serialBackspace";
|
||||
import { buildTelnetDeepLinkConnectionHost } from "../../domain/telnetDeepLink";
|
||||
import { resolveEffectiveTerminalHost, resolveTerminalSessionHost } from "../../domain/terminalHostResolution";
|
||||
import { resolveEffectiveTerminalHost } from "../../domain/terminalHostResolution";
|
||||
import {
|
||||
createHostTerminalSession,
|
||||
createSerialTerminalSession,
|
||||
@@ -171,16 +171,3 @@ test("host session factories snapshot plugin connection configuration", () => {
|
||||
assert.deepEqual(workspace.pluginConnection, pluginConnection);
|
||||
assert.notEqual(workspace.pluginConnection, pluginConnection);
|
||||
});
|
||||
|
||||
test("local sessions preserve intentionally absent display metadata when the saved shell changes", () => {
|
||||
const original = host({ protocol: "local", hostname: "localhost", localShell: "/bin/bash" });
|
||||
const source = createHostTerminalSession("original-bash", original);
|
||||
const edited = { ...original, localShell: "/bin/zsh", localShellName: "Zsh", localShellIcon: "zsh" };
|
||||
const copied = resolveTerminalSessionHost({ session: source, hosts: [edited], groupConfigs: [], proxyProfiles: [], localOs: "macos" });
|
||||
assert.equal(copied.localShell, "/bin/bash");
|
||||
assert.equal(copied.localShellName, "");
|
||||
assert.equal(copied.localShellIcon, "");
|
||||
const named = createHostTerminalSession("named-zsh", edited);
|
||||
assert.equal(named.localShellName, "Zsh");
|
||||
assert.equal(named.localShellIcon, "zsh");
|
||||
});
|
||||
@@ -153,8 +153,8 @@ export const createHostTerminalSession = (
|
||||
// Preserve field presence: an edited host must not contribute its args
|
||||
// to a session that was launched with an explicit shell and no args.
|
||||
localShellArgs: host.localShellArgs ?? EMPTY_LOCAL_SHELL_ARGS,
|
||||
localShellName: host.localShellName ?? "",
|
||||
localShellIcon: host.localShellIcon ?? "",
|
||||
localShellName: host.localShellName,
|
||||
localShellIcon: host.localShellIcon,
|
||||
// Effective directory from resolveHostDefaultLocalShell, including a
|
||||
// Settings directory the saved host inherits. Copy Tab overlays this
|
||||
// snapshot, so a later settings or vault edit cannot move the relaunch.
|
||||
|
||||
@@ -148,8 +148,7 @@ test("session peer windows do not run main-window startup effects", () => {
|
||||
assert.match(settingsStateSource, /const enableSettingsSync = options\.enableSettingsSync !== false/);
|
||||
assert.match(settingsStateSource, /useSettingsIpcSync\(\{[^}]*enabled: enableSettingsSync/s);
|
||||
assert.match(settingsStateSource, /useSettingsStorageSync\(\{[^}]*enabled: enableSettingsSync/s);
|
||||
// Detached windows share opacity, while general settings broadcasts stay off.
|
||||
assert.match(settingsStateSource, /if \(!enableSettingsSync && key !== STORAGE_KEY_WINDOW_OPACITY\) return;\s*try \{\s*netcattyBridge\.get\(\)\?\.notifySettingsChanged/s);
|
||||
assert.match(settingsStateSource, /if \(!enableSettingsSync\) return;\s*try \{\s*netcattyBridge\.get\(\)\?\.notifySettingsChanged/s);
|
||||
assert.match(settingsStateSource, /useSystemSettingsEffects\(\{[^}]*enabled: enableSystemEffects/s);
|
||||
assert.match(settingsIpcSyncSource, /enabled\?: boolean/);
|
||||
assert.match(settingsIpcSyncSource, /if \(!enabled\) return;/);
|
||||
|
||||
@@ -133,11 +133,6 @@ export type OpenTransferSftpSessionOptions = {
|
||||
* credentials. When false, try sourceSessionId first (shared transport).
|
||||
*/
|
||||
dedicated?: boolean;
|
||||
/**
|
||||
* Connect-time jump-host snapshots. When set, this session dials through the
|
||||
* pinned chain the pane connected with, not the live (possibly edited) chain.
|
||||
*/
|
||||
jumpHosts?: Host[];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -164,7 +159,6 @@ export async function openTransferSftpSession(
|
||||
identities: [...deps.identities],
|
||||
knownHosts: deps.knownHosts ? [...deps.knownHosts] : undefined,
|
||||
terminalSettings: deps.terminalSettings,
|
||||
jumpHostsOverride: options?.jumpHosts,
|
||||
});
|
||||
// Shared transport path: open an SFTP channel on the already-authenticated
|
||||
// terminal connection. The transport registry lease keeps the conn alive
|
||||
|
||||
@@ -137,26 +137,11 @@ async function tryStatTransferTarget(
|
||||
return tryStatTransferPath(targetPath, targetIsLocal, targetSftpId, targetEncoding);
|
||||
}
|
||||
|
||||
export interface TransferConnectHosts {
|
||||
source?: Host;
|
||||
target?: Host;
|
||||
/**
|
||||
* Connect-time jump-host chain snapshots. Pinned together with the top-level
|
||||
* host so leases opened after a bastion edit still dial through the chain the
|
||||
* pane's session connected with (private hostnames can resolve differently
|
||||
* per bastion). Present only when the matching endpoint is pinned.
|
||||
*/
|
||||
sourceChain?: Host[];
|
||||
targetChain?: Host[];
|
||||
}
|
||||
|
||||
export type AcquireTransferSessionFn = (
|
||||
hostId: string,
|
||||
transferId: string,
|
||||
/** Connect-time host (session hostname/port/user overrides). Prefer over vault. */
|
||||
connectHost?: Host,
|
||||
/** Connect-time jump-host snapshots; undefined re-resolves the live chain. */
|
||||
jumpHosts?: Host[],
|
||||
) => Promise<TransferConnectionLease>;
|
||||
|
||||
interface UseSftpDirectoryTransferOpsParams {
|
||||
@@ -283,7 +268,6 @@ export function useSftpDirectoryTransferOps({
|
||||
targetEncoding: SftpFilenameEncoding,
|
||||
rootTaskId: string, // The original top-level task ID for cancellation checking
|
||||
sameHost?: boolean,
|
||||
connectHosts?: TransferConnectHosts,
|
||||
): Promise<void> => {
|
||||
// Check if task or root task was cancelled before starting
|
||||
if (cancelledTasksRef.current.has(task.id) || cancelledTasksRef.current.has(rootTaskId)) {
|
||||
@@ -331,14 +315,10 @@ export function useSftpDirectoryTransferOps({
|
||||
// Dedicated pool only for remote ends — panel/browse sessions die when
|
||||
// the SFTP tab is closed, which freezes global transfer center rows.
|
||||
if (acquireTransferSession && !sourceIsLocal && task.sourceHostId) {
|
||||
sourceLease = await acquireTransferSession(
|
||||
task.sourceHostId, task.id, connectHosts?.source, connectHosts?.sourceChain,
|
||||
);
|
||||
sourceLease = await acquireTransferSession(task.sourceHostId, task.id);
|
||||
}
|
||||
if (acquireTransferSession && !targetIsLocal && task.targetHostId) {
|
||||
targetLease = await acquireTransferSession(
|
||||
task.targetHostId, task.id, connectHosts?.target, connectHosts?.targetChain,
|
||||
);
|
||||
targetLease = await acquireTransferSession(task.targetHostId, task.id);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -561,7 +541,6 @@ export function useSftpDirectoryTransferOps({
|
||||
followSymlinks = false, // Only true for downloadToLocal — uploads/copies treat symlinks as files
|
||||
discoveryProgress?: DirectoryDiscoveryProgress,
|
||||
traversalBudget?: SftpDirectoryTraversalBudget,
|
||||
connectHosts?: TransferConnectHosts,
|
||||
) => {
|
||||
// Check if task or root task was cancelled before starting
|
||||
if (cancelledTasksRef.current.has(task.id) || cancelledTasksRef.current.has(rootTaskId)) {
|
||||
@@ -719,7 +698,6 @@ export function useSftpDirectoryTransferOps({
|
||||
followSymlinks,
|
||||
progress,
|
||||
traversal,
|
||||
connectHosts,
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
@@ -947,7 +925,6 @@ export function useSftpDirectoryTransferOps({
|
||||
targetEncoding,
|
||||
rootTaskId,
|
||||
sameHost,
|
||||
connectHosts,
|
||||
);
|
||||
|
||||
activeChildIdsRef.current.get(rootTaskId)?.delete(fileId);
|
||||
|
||||
@@ -42,12 +42,6 @@ interface UseSftpConnectionsParams {
|
||||
lastConnectedHostRef: MutableRefObject<{ left: Host | "local" | null; right: Host | "local" | null }>;
|
||||
connectionCacheKeyMapRef: MutableRefObject<Map<string, string>>;
|
||||
connectedHostByTabIdRef: MutableRefObject<Map<string, Host | "local">>;
|
||||
/**
|
||||
* Jump-host chain snapshots captured when each tab connected, keyed by tab
|
||||
* id. Same lifecycle as connectedHostByTabIdRef; used to keep transfer
|
||||
* session opens on the pane's connect-time bastion chain after chain edits.
|
||||
*/
|
||||
connectedHostChainByTabIdRef?: MutableRefObject<Map<string, Host[]>>;
|
||||
connectInFlightRef: MutableRefObject<Map<string, Promise<void>>>;
|
||||
connectRequestByTabIdRef: MutableRefObject<Map<string, symbol>>;
|
||||
makeCacheKey: (connectionId: string, path: string, encoding?: SftpFilenameEncoding) => string;
|
||||
@@ -421,15 +415,12 @@ export async function closeSftpTabLifecycle(params: {
|
||||
connectRequests: Map<string, symbol>;
|
||||
connectInFlight: Map<string, Promise<void>>;
|
||||
connectedHosts: { delete: (tabId: string) => boolean };
|
||||
/** Connect-time jump-host chain snapshots, same tab-id lifecycle. */
|
||||
connectedHostChains?: { delete: (tabId: string) => boolean };
|
||||
closeTab: (side: "left" | "right") => void;
|
||||
releaseConnection: () => Promise<void>;
|
||||
}): Promise<void> {
|
||||
invalidateSftpTabConnectRequest(params.connectRequests, params.tabId);
|
||||
clearSftpConnectInFlightForTab(params.connectInFlight, params.tabId);
|
||||
params.connectedHosts.delete(params.tabId);
|
||||
params.connectedHostChains?.delete(params.tabId);
|
||||
applyToLiveSftpTabSide({
|
||||
requestedSide: params.requestedSide,
|
||||
tabId: params.tabId,
|
||||
@@ -590,7 +581,6 @@ export const useSftpConnections = ({
|
||||
lastConnectedHostRef,
|
||||
connectionCacheKeyMapRef,
|
||||
connectedHostByTabIdRef,
|
||||
connectedHostChainByTabIdRef,
|
||||
connectInFlightRef,
|
||||
connectRequestByTabIdRef,
|
||||
makeCacheKey,
|
||||
@@ -873,24 +863,6 @@ export const useSftpConnections = ({
|
||||
// Always remember the full connect-time Host for this tab so background
|
||||
// upload reconnects can restore session-time overrides (not just vault hostId).
|
||||
connectedHostByTabIdRef.current.set(activeTabId, host);
|
||||
// Snapshot the resolved jump-host chain so retained transfer leases keep
|
||||
// dialing the chain this tab connected through, even after one of the
|
||||
// bastion hosts is edited (private hostnames can resolve differently
|
||||
// per bastion — the live chain must not silently replace this one).
|
||||
if (connectedHostChainByTabIdRef) {
|
||||
if (host !== "local" && host.hostChain?.hostIds?.length) {
|
||||
const chain = host.hostChain.hostIds
|
||||
.map((chainId) => hosts.find((candidate) => candidate.id === chainId))
|
||||
.filter((candidate): candidate is Host => !!candidate);
|
||||
if (chain.length === host.hostChain.hostIds.length) {
|
||||
connectedHostChainByTabIdRef.current.set(activeTabId, chain);
|
||||
} else {
|
||||
connectedHostChainByTabIdRef.current.delete(activeTabId);
|
||||
}
|
||||
} else {
|
||||
connectedHostChainByTabIdRef.current.delete(activeTabId);
|
||||
}
|
||||
}
|
||||
// Store the cache key for this connection so pane actions can look it up
|
||||
// by connectionId instead of relying on the per-side lastConnectedHostRef.
|
||||
if (host !== "local") {
|
||||
@@ -1454,7 +1426,6 @@ export const useSftpConnections = ({
|
||||
|
||||
lastConnectedHostRef.current[side] = null;
|
||||
connectedHostByTabIdRef.current.delete(activeTabId);
|
||||
connectedHostChainByTabIdRef?.current.delete(activeTabId);
|
||||
|
||||
if (pane.connection && !pane.connection.isLocal && sftpId) {
|
||||
try {
|
||||
|
||||
@@ -148,7 +148,6 @@ export const useSftpExternalOperations = (
|
||||
connectionCacheKeyMapRef,
|
||||
ensureRemoteSftpId,
|
||||
resolveConnectedHost,
|
||||
resolveConnectedChain,
|
||||
acquireTransferSession,
|
||||
clearDirCacheEntry,
|
||||
useCompressedUpload = false,
|
||||
@@ -166,15 +165,6 @@ export const useSftpExternalOperations = (
|
||||
[resolveConnectedHost],
|
||||
);
|
||||
|
||||
/** Jump-host chain the tab dialed at connect time, when still meaningful. */
|
||||
const resolveUploadConnectChain = useCallback(
|
||||
(tabId: string, isLocal: boolean): Host[] | undefined => {
|
||||
if (isLocal || !resolveConnectedChain) return undefined;
|
||||
return resolveConnectedChain(tabId) ?? undefined;
|
||||
},
|
||||
[resolveConnectedChain],
|
||||
);
|
||||
|
||||
/**
|
||||
* Resolve an SFTP id for upload prep (mkdir/stat/conflict checks).
|
||||
* File bytes use dedicated pool connections inside startStreamTransfer
|
||||
@@ -853,7 +843,6 @@ export const useSftpExternalOperations = (
|
||||
// (session hostname/port/user overrides), not the vault entry by hostId alone.
|
||||
const createUploadBridge = useCallback((
|
||||
connectHost?: Host,
|
||||
connectChain?: Host[],
|
||||
readTransferConcurrency = () => localStorageAdapter.readNumber(STORAGE_KEY_SFTP_TRANSFER_CONCURRENCY),
|
||||
): UploadBridge => {
|
||||
const bridge = netcattyBridge.get();
|
||||
@@ -931,7 +920,6 @@ export const useSftpExternalOperations = (
|
||||
options.targetHostId,
|
||||
options.transferId,
|
||||
connectHost,
|
||||
connectChain,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1054,10 +1042,8 @@ export const useSftpExternalOperations = (
|
||||
const uploadPaneId = livePane.id;
|
||||
const liveTargetPath = targetPath || livePane.connection.currentPath;
|
||||
const connectHost = resolveUploadConnectHost(uploadPaneId, livePane.connection.isLocal);
|
||||
const connectChain = resolveUploadConnectChain(uploadPaneId, livePane.connection.isLocal);
|
||||
const uploadBridge = createUploadBridge(
|
||||
connectHost,
|
||||
connectChain,
|
||||
readSftpFileTransferConcurrency,
|
||||
);
|
||||
const liveCallbacks = livePane.connection.id === pane.connection.id
|
||||
@@ -1223,8 +1209,7 @@ export const useSftpExternalOperations = (
|
||||
const uploadPaneId = livePane.id;
|
||||
const liveTargetPath = targetPath || livePane.connection.currentPath;
|
||||
const connectHost = resolveUploadConnectHost(uploadPaneId, livePane.connection.isLocal);
|
||||
const connectChain = resolveUploadConnectChain(uploadPaneId, livePane.connection.isLocal);
|
||||
const uploadBridge = createUploadBridge(connectHost, connectChain);
|
||||
const uploadBridge = createUploadBridge(connectHost);
|
||||
|
||||
// Retarget callbacks if the pane path/id changed after reconnect.
|
||||
const liveCallbacks = livePane.connection.id === pane.connection.id
|
||||
@@ -1267,7 +1252,7 @@ export const useSftpExternalOperations = (
|
||||
jobId: `compressed-upload-${crypto.randomUUID()}`,
|
||||
prepSftpId: sftpId,
|
||||
acquire: acquireTransferSession
|
||||
? (hostId, jobId) => acquireTransferSession(hostId, jobId, connectHost, connectChain)
|
||||
? (hostId, jobId) => acquireTransferSession(hostId, jobId, connectHost)
|
||||
: undefined,
|
||||
shouldDiscard: isSessionError,
|
||||
run: async (uploadSftpId) => uploadEntriesDirect(
|
||||
@@ -1346,7 +1331,6 @@ export const useSftpExternalOperations = (
|
||||
refresh,
|
||||
resolveRemoteSftpId,
|
||||
resolveUploadConnectHost,
|
||||
resolveUploadConnectChain,
|
||||
useCompressedUpload,
|
||||
],
|
||||
);
|
||||
@@ -1383,8 +1367,7 @@ export const useSftpExternalOperations = (
|
||||
),
|
||||
);
|
||||
const connectHost = resolveUploadConnectHost(uploadPaneId, livePane.connection.isLocal);
|
||||
const connectChain = resolveUploadConnectChain(uploadPaneId, livePane.connection.isLocal);
|
||||
const uploadBridge = createUploadBridge(connectHost, connectChain);
|
||||
const uploadBridge = createUploadBridge(connectHost);
|
||||
|
||||
try {
|
||||
const files = Array.from(fileList);
|
||||
@@ -1399,7 +1382,7 @@ export const useSftpExternalOperations = (
|
||||
jobId: `compressed-upload-${crypto.randomUUID()}`,
|
||||
prepSftpId: sftpId,
|
||||
acquire: acquireTransferSession
|
||||
? (hostId, jobId) => acquireTransferSession(hostId, jobId, connectHost, connectChain)
|
||||
? (hostId, jobId) => acquireTransferSession(hostId, jobId, connectHost)
|
||||
: undefined,
|
||||
shouldDiscard: isSessionError,
|
||||
run: async (uploadSftpId) => uploadFromFileList(
|
||||
@@ -1458,7 +1441,6 @@ export const useSftpExternalOperations = (
|
||||
refresh,
|
||||
resolveRemoteSftpId,
|
||||
resolveUploadConnectHost,
|
||||
resolveUploadConnectChain,
|
||||
useCompressedUpload,
|
||||
],
|
||||
);
|
||||
@@ -1575,11 +1557,7 @@ export const useSftpExternalOperations = (
|
||||
uploadPaneId,
|
||||
livePane.connection.isLocal,
|
||||
);
|
||||
const uploadConnectChain = resolveUploadConnectChain(
|
||||
uploadPaneId,
|
||||
livePane.connection.isLocal,
|
||||
);
|
||||
const uploadBridge = createUploadBridge(uploadConnectHost, uploadConnectChain);
|
||||
const uploadBridge = createUploadBridge(uploadConnectHost);
|
||||
const liveCallbacks = bindUploadControllerCallbacks(
|
||||
controller,
|
||||
createUploadCallbacks(
|
||||
@@ -1625,7 +1603,7 @@ export const useSftpExternalOperations = (
|
||||
jobId: `compressed-upload-${crypto.randomUUID()}`,
|
||||
prepSftpId: sftpId,
|
||||
acquire: acquireTransferSession
|
||||
? (hostId, jobId) => acquireTransferSession(hostId, jobId, uploadConnectHost, uploadConnectChain)
|
||||
? (hostId, jobId) => acquireTransferSession(hostId, jobId, uploadConnectHost)
|
||||
: undefined,
|
||||
shouldDiscard: isSessionError,
|
||||
run: async (uploadSftpId) => uploadEntriesDirect(
|
||||
@@ -1709,7 +1687,6 @@ export const useSftpExternalOperations = (
|
||||
refresh,
|
||||
resolveRemoteSftpId,
|
||||
resolveUploadConnectHost,
|
||||
resolveUploadConnectChain,
|
||||
useCompressedUpload,
|
||||
],
|
||||
);
|
||||
@@ -1798,8 +1775,7 @@ export const useSftpExternalOperations = (
|
||||
),
|
||||
);
|
||||
const connectHost = resolveUploadConnectHost(uploadPaneId, livePane.connection.isLocal);
|
||||
const connectChain = resolveUploadConnectChain(uploadPaneId, livePane.connection.isLocal);
|
||||
const directUploadBridge = createUploadBridge(connectHost, connectChain);
|
||||
const directUploadBridge = createUploadBridge(connectHost);
|
||||
|
||||
try {
|
||||
const hasDirectory = entries.some((entry) => (
|
||||
@@ -1813,7 +1789,7 @@ export const useSftpExternalOperations = (
|
||||
jobId: `compressed-upload-${crypto.randomUUID()}`,
|
||||
prepSftpId: sftpId,
|
||||
acquire: acquireTransferSession
|
||||
? (hostId, jobId) => acquireTransferSession(hostId, jobId, connectHost, connectChain)
|
||||
? (hostId, jobId) => acquireTransferSession(hostId, jobId, connectHost)
|
||||
: undefined,
|
||||
shouldDiscard: isSessionError,
|
||||
run: async (uploadSftpId) => uploadEntriesDirect(
|
||||
@@ -1880,7 +1856,6 @@ export const useSftpExternalOperations = (
|
||||
refresh,
|
||||
resolveRemoteSftpId,
|
||||
resolveUploadConnectHost,
|
||||
resolveUploadConnectChain,
|
||||
useCompressedUpload,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -32,12 +32,6 @@ export interface UseSftpExternalOperationsParams {
|
||||
* Used so pooled stream uploads open the pinned browse endpoint.
|
||||
*/
|
||||
resolveConnectedHost?: (tabId: string) => Host | "local" | null | undefined;
|
||||
/**
|
||||
* Jump-host chain snapshots captured when the tab connected, keyed by tab id.
|
||||
* Lets pooled uploads keep dialing the pane's connect-time bastion chain
|
||||
* after a chain host is edited.
|
||||
*/
|
||||
resolveConnectedChain?: (tabId: string) => Host[] | null | undefined;
|
||||
/**
|
||||
* FileZilla-style dedicated transfer sessions for bulk uploads.
|
||||
* When set, remote stream uploads prefer pool connections (1–2/host)
|
||||
@@ -47,7 +41,6 @@ export interface UseSftpExternalOperationsParams {
|
||||
hostId: string,
|
||||
transferId: string,
|
||||
connectHost?: Host,
|
||||
connectChain?: Host[],
|
||||
) => Promise<{ sftpId: string; release: () => void; discard: () => void }>;
|
||||
clearDirCacheEntry?: (connectionId: string, path: string) => void;
|
||||
useCompressedUpload?: boolean;
|
||||
|
||||
@@ -707,30 +707,3 @@ test("imported IdentityFile paths remain usable when agent login is disabled", (
|
||||
assert.equal(credentials.useSshAgent, false);
|
||||
assert.deepEqual(credentials.identityFilePaths, ["~/.ssh/id_work"]);
|
||||
});
|
||||
|
||||
test("buildSftpHostCredentials pins the captured jump chain over edited vault hosts", () => {
|
||||
const oldBastion = host({ id: "jump-1", hostname: "bastion-internal.old" });
|
||||
const editedBastion = host({ id: "jump-1", hostname: "bastion-internal.edited" });
|
||||
const credentials = buildSftpHostCredentials({
|
||||
host: host({ hostChain: { hostIds: ["jump-1"] } }),
|
||||
hosts: [editedBastion],
|
||||
keys: [],
|
||||
identities: [],
|
||||
jumpHostsOverride: [oldBastion],
|
||||
});
|
||||
|
||||
assert.equal(credentials.jumpHosts?.[0]?.hostname, "bastion-internal.old");
|
||||
assert.equal(credentials.jumpHosts?.[0]?.hostId, "jump-1");
|
||||
});
|
||||
|
||||
test("buildSftpHostCredentials re-resolves the live chain without a pinned snapshot", () => {
|
||||
const editedBastion = host({ id: "jump-1", hostname: "bastion-internal.edited" });
|
||||
const credentials = buildSftpHostCredentials({
|
||||
host: host({ hostChain: { hostIds: ["jump-1"] } }),
|
||||
hosts: [editedBastion],
|
||||
keys: [],
|
||||
identities: [],
|
||||
});
|
||||
|
||||
assert.equal(credentials.jumpHosts?.[0]?.hostname, "bastion-internal.edited");
|
||||
});
|
||||
@@ -38,17 +38,7 @@ export const buildSftpHostCredentials = ({
|
||||
identities,
|
||||
knownHosts,
|
||||
terminalSettings,
|
||||
jumpHostsOverride,
|
||||
}: UseSftpHostCredentialsParams & {
|
||||
host: Host;
|
||||
/**
|
||||
* Connect-time jump-host snapshots. When set, the chain resolves from these
|
||||
* pinned Host objects instead of the live `hosts` array, so leases opened
|
||||
* after a bastion edit keep connecting through the chain the pane's session
|
||||
* dialed — private hostnames can resolve differently per bastion.
|
||||
*/
|
||||
jumpHostsOverride?: Host[];
|
||||
}): NetcattySSHOptions => {
|
||||
}: UseSftpHostCredentialsParams & { host: Host }): NetcattySSHOptions => {
|
||||
const globalTerminalSettings = { ...FALLBACK_TERMINAL_SETTINGS, ...(terminalSettings ?? {}) };
|
||||
if (host.proxyProfileId && !host.proxyConfig) {
|
||||
throw new Error(`Saved proxy for host "${host.label || host.hostname}" is missing. Open host settings and select a valid proxy.`);
|
||||
@@ -67,21 +57,12 @@ export const buildSftpHostCredentials = ({
|
||||
? resolveProxyConfigAuth(host.proxyConfig, identities)
|
||||
: undefined;
|
||||
let jumpHosts: NetcattyJumpHost[] | undefined;
|
||||
const resolveChainHost = (hostId: string): Host => {
|
||||
const jumpHost = hosts.find((candidate) => candidate.id === hostId);
|
||||
if (!jumpHost) {
|
||||
throw new Error(`Jump host "${hostId}" is missing. Open host settings and repair the jump host chain.`);
|
||||
}
|
||||
return jumpHost;
|
||||
};
|
||||
// A non-empty pinned chain snapshot wins over live hostChain resolution.
|
||||
const chainHosts: Host[] | null = jumpHostsOverride && jumpHostsOverride.length > 0
|
||||
? jumpHostsOverride
|
||||
: host.hostChain?.hostIds && host.hostChain.hostIds.length > 0
|
||||
? host.hostChain.hostIds.map(resolveChainHost)
|
||||
: null;
|
||||
if (chainHosts) {
|
||||
jumpHosts = chainHosts.map((jumpHost, index) => {
|
||||
if (host.hostChain?.hostIds && host.hostChain.hostIds.length > 0) {
|
||||
jumpHosts = host.hostChain.hostIds.map((hostId) => {
|
||||
const jumpHost = hosts.find((candidate) => candidate.id === hostId);
|
||||
if (!jumpHost) {
|
||||
throw new Error(`Jump host "${hostId}" is missing. Open host settings and repair the jump host chain.`);
|
||||
}
|
||||
if (jumpHost.proxyProfileId && !jumpHost.proxyConfig) {
|
||||
throw new Error(`Saved proxy for jump host "${jumpHost.label || jumpHost.hostname}" is missing. Open host settings and select a valid proxy.`);
|
||||
}
|
||||
@@ -91,6 +72,8 @@ export const buildSftpHostCredentials = ({
|
||||
if (findIncompleteProxyIdentityId(jumpHost.proxyConfig, identities)) {
|
||||
throw new Error(formatIncompleteProxyIdentityMessage(jumpHost.label || jumpHost.hostname));
|
||||
}
|
||||
return jumpHost;
|
||||
}).map((jumpHost, index) => {
|
||||
const jumpAuth = resolveHostAuth({
|
||||
host: jumpHost,
|
||||
keys,
|
||||
|
||||
@@ -5,7 +5,6 @@ import React from "react";
|
||||
import { act, create, type ReactTestRenderer } from "react-test-renderer";
|
||||
import { PREFLIGHT_STAT_CONCURRENCY, PREFLIGHT_STAT_MAX_FILES, useSftpTransfers } from "./useSftpTransfers";
|
||||
import { sftpTransferCenterStore } from "../sftpTransferCenterStore";
|
||||
import type { Host } from "../../../domain/models";
|
||||
import type { SftpPane } from "./types";
|
||||
|
||||
type StartOptions = {
|
||||
@@ -84,160 +83,6 @@ function installGlobals(netty: Record<string, unknown>) {
|
||||
};
|
||||
}
|
||||
|
||||
for (const pinned of [false, true]) {
|
||||
for (const direction of ["download", "upload"] as const) {
|
||||
test(`${pinned ? "existing" : "new"} dual-pane ${direction} preserves its endpoint after host edits`, async () => {
|
||||
const acquired: string[] = [];
|
||||
const started: StartOptions[] = [];
|
||||
const restore = installGlobals({
|
||||
statSftp: async () => direction === "download"
|
||||
? { name: "aops_dns_view_demo.sh", type: "file", size: 4, sizeKnown: true, lastModified: 1 }
|
||||
: null,
|
||||
statLocal: async () => direction === "upload"
|
||||
? { name: "aops_dns_view_demo.sh", type: "file", size: 4, sizeKnown: true, lastModified: 1 }
|
||||
: null,
|
||||
startStreamTransfer: async (options: StartOptions) => {
|
||||
started.push(options);
|
||||
sftpTransferCenterStore.ingestBackgroundEvent({
|
||||
type: "completed", transferId: options.transferId,
|
||||
transferred: options.totalBytes ?? 0, totalBytes: options.totalBytes ?? 0, lifecycleEpoch: 0,
|
||||
});
|
||||
return {};
|
||||
},
|
||||
});
|
||||
// These pane callbacks stay stable in the app while the saved hosts change.
|
||||
const getActivePane = (side: "left" | "right") => makePane(side);
|
||||
const getPaneByConnectionId = () => null;
|
||||
const getTabByConnectionId = () => null;
|
||||
const updateTab = () => undefined;
|
||||
const sftpSessionsRef = { current: new Map([["remote-conn", "browse-session"]]) };
|
||||
const pinnedHost = { id: "host-1", hostname: "old-endpoint" } as Host;
|
||||
const pinnedChain = [{ id: "jump-1", hostname: "old-bastion" } as Host];
|
||||
const acquiredChains: string[] = [];
|
||||
const acquire = (savedEndpoint: string) => async (
|
||||
_hostId: string, _jobId: string, connectHost?: Host, connectChain?: Host[],
|
||||
) => {
|
||||
const endpoint = connectHost?.hostname ?? savedEndpoint;
|
||||
acquired.push(endpoint);
|
||||
acquiredChains.push(connectChain?.map((hop) => hop.hostname).join(" -> ") ?? "unpinned");
|
||||
return { sftpId: endpoint, poolKey: endpoint, release: () => undefined, discard: () => undefined };
|
||||
};
|
||||
const original = acquire("old-endpoint");
|
||||
const refreshed = acquire("new-endpoint");
|
||||
let ops: ReturnType<typeof useSftpTransfers> | undefined;
|
||||
let renderer: ReactTestRenderer | undefined;
|
||||
function Probe({ acquireSession }: { acquireSession: typeof original }) {
|
||||
ops = useSftpTransfers({
|
||||
ownerId: `refresh-host-${direction}`,
|
||||
getActivePane, getPaneByConnectionId, getTabByConnectionId, updateTab,
|
||||
refresh: async () => undefined, clearCacheForConnection: () => undefined,
|
||||
handleSessionError: () => undefined, sftpSessionsRef,
|
||||
connectionCacheKeyMapRef: { current: new Map() },
|
||||
listLocalFiles: async () => [], listRemoteFiles: async () => [],
|
||||
acquireTransferSession: acquireSession,
|
||||
resolveConnectedHost: () => pinned ? pinnedHost : null,
|
||||
resolveConnectedChain: pinned ? () => pinnedChain : undefined,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
await act(async () => { renderer = create(React.createElement(Probe, { acquireSession: original })); });
|
||||
await act(async () => { renderer!.update(React.createElement(Probe, { acquireSession: refreshed })); });
|
||||
await act(async () => {
|
||||
await ops!.startTransfer([{ name: "aops_dns_view_demo.sh", isDirectory: false }],
|
||||
direction === "download" ? "left" : "right", direction === "download" ? "right" : "left");
|
||||
});
|
||||
assert.equal(acquired.length, 2, "both the work lease and file lease must use the pane endpoint");
|
||||
assert.ok(acquired.every((endpoint) => endpoint === (pinned ? "old-endpoint" : "new-endpoint")), JSON.stringify(acquired));
|
||||
if (pinned) {
|
||||
assert.ok(
|
||||
acquiredChains.every((chain) => chain === "old-bastion"),
|
||||
`the pinned jump chain must ride along with the pinned endpoint: ${JSON.stringify(acquiredChains)}`,
|
||||
);
|
||||
} else {
|
||||
assert.ok(
|
||||
acquiredChains.every((chain) => chain === "unpinned"),
|
||||
`no chain may attach when the connect host is unresolved: ${JSON.stringify(acquiredChains)}`,
|
||||
);
|
||||
}
|
||||
assert.equal(started.length, 1);
|
||||
} finally {
|
||||
await act(async () => { renderer?.unmount(); });
|
||||
restore();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (const direction of ["download", "upload"] as const) {
|
||||
test(`dual-pane ${direction} started during a reconnect falls back to the pane endpoint, not the incoming tab host`, async () => {
|
||||
const acquired: string[] = [];
|
||||
const started: StartOptions[] = [];
|
||||
const restore = installGlobals({
|
||||
statSftp: async () => direction === "download"
|
||||
? { name: "aops_dns_view_demo.sh", type: "file", size: 4, sizeKnown: true, lastModified: 1 }
|
||||
: null,
|
||||
statLocal: async () => direction === "upload"
|
||||
? { name: "aops_dns_view_demo.sh", type: "file", size: 4, sizeKnown: true, lastModified: 1 }
|
||||
: null,
|
||||
startStreamTransfer: async (options: StartOptions) => {
|
||||
started.push(options);
|
||||
sftpTransferCenterStore.ingestBackgroundEvent({
|
||||
type: "completed", transferId: options.transferId,
|
||||
transferred: options.totalBytes ?? 0, totalBytes: options.totalBytes ?? 0, lifecycleEpoch: 0,
|
||||
});
|
||||
return {};
|
||||
},
|
||||
});
|
||||
const getActivePane = (side: "left" | "right") => makePane(side);
|
||||
const getPaneByConnectionId = () => null;
|
||||
const getTabByConnectionId = () => null;
|
||||
const updateTab = () => undefined;
|
||||
const sftpSessionsRef = { current: new Map([["remote-conn", "browse-session"]]) };
|
||||
// connect() has already recorded the incoming endpoint for this tab id
|
||||
// while the pane still shows the old connection (reconnect in flight).
|
||||
const incomingHost = { id: "host-2", hostname: "reconnect-endpoint" } as Host;
|
||||
const acquire = (savedEndpoint: string) => async (_hostId: string, _jobId: string, connectHost?: Host) => {
|
||||
const endpoint = connectHost?.hostname ?? savedEndpoint;
|
||||
acquired.push(endpoint);
|
||||
return { sftpId: endpoint, poolKey: endpoint, release: () => undefined, discard: () => undefined };
|
||||
};
|
||||
const acquireSession = acquire("saved-endpoint");
|
||||
let ops: ReturnType<typeof useSftpTransfers> | undefined;
|
||||
let renderer: ReactTestRenderer | undefined;
|
||||
function Probe() {
|
||||
ops = useSftpTransfers({
|
||||
ownerId: `reconnect-host-${direction}`,
|
||||
getActivePane, getPaneByConnectionId, getTabByConnectionId, updateTab,
|
||||
refresh: async () => undefined, clearCacheForConnection: () => undefined,
|
||||
handleSessionError: () => undefined, sftpSessionsRef,
|
||||
connectionCacheKeyMapRef: { current: new Map() },
|
||||
listLocalFiles: async () => [], listRemoteFiles: async () => [],
|
||||
acquireTransferSession: acquireSession,
|
||||
resolveConnectedHost: () => incomingHost,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
await act(async () => { renderer = create(React.createElement(Probe)); });
|
||||
await act(async () => {
|
||||
await ops!.startTransfer([{ name: "aops_dns_view_demo.sh", isDirectory: false }],
|
||||
direction === "download" ? "left" : "right", direction === "download" ? "right" : "left");
|
||||
});
|
||||
assert.equal(acquired.length, 2, "both the work lease and file lease must be acquired");
|
||||
assert.ok(
|
||||
acquired.every((endpoint) => endpoint === "saved-endpoint"),
|
||||
`the incoming endpoint must not capture the transfer: ${JSON.stringify(acquired)}`,
|
||||
);
|
||||
assert.equal(started.length, 1);
|
||||
} finally {
|
||||
await act(async () => { renderer?.unmount(); });
|
||||
restore();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (const liveStatAvailable of [true, false]) {
|
||||
test(
|
||||
liveStatAvailable
|
||||
|
||||
@@ -2,7 +2,6 @@ import { useCallback, useEffect, useMemo, useRef, useState, type SetStateAction
|
||||
import {
|
||||
FileConflict,
|
||||
FileConflictAction,
|
||||
Host,
|
||||
SftpFilenameEncoding,
|
||||
TransferDirection,
|
||||
TransferStatus,
|
||||
@@ -26,10 +25,7 @@ import { logger } from "../../../lib/logger";
|
||||
import { sftpTransferCenterStore } from "../sftpTransferCenterStore";
|
||||
import { SftpPane } from "./types";
|
||||
import { isMissingStatError } from "./errors";
|
||||
import {
|
||||
useSftpDirectoryTransferOps,
|
||||
type TransferConnectHosts,
|
||||
} from "./transferDirectoryOps";
|
||||
import { useSftpDirectoryTransferOps } from "./transferDirectoryOps";
|
||||
import { useSftpTransferConflictOps } from "./transferConflictOps";
|
||||
import { useSftpTransferTaskOps } from "./transferTaskOps";
|
||||
import { globalSftpTransferScheduler } from "./globalTransferScheduler";
|
||||
@@ -82,78 +78,6 @@ const STAT_SFTP_TIMEOUT_MS = 10_000;
|
||||
export const PREFLIGHT_STAT_CONCURRENCY = 8;
|
||||
export const PREFLIGHT_STAT_MAX_FILES = 128;
|
||||
|
||||
// A "local" or missing resolved host means the dedicated pool should fall
|
||||
// back to the saved vault host; only a concrete Host pins the endpoint.
|
||||
const toConnectHost = (host: Host | "local" | null | undefined): Host | undefined =>
|
||||
host && host !== "local" ? host : undefined;
|
||||
|
||||
// Stable identity of a pinned proxy transport. Two endpoints sharing
|
||||
// id/hostname/port/username can still dial through different proxies after an
|
||||
// edit; remote DNS behind each proxy may resolve the same hostname to a
|
||||
// different server, so a same-host `cp` pinned to the source route could write
|
||||
// on the wrong one.
|
||||
const proxyIdentity = (p: Host["proxyConfig"]): string =>
|
||||
p
|
||||
? JSON.stringify([p.type, p.host, p.port, p.command ?? "", p.identityId ?? "", p.username ?? "", p.password ?? ""])
|
||||
: "";
|
||||
|
||||
// Stable identity of a pinned jump chain. buildCacheKey omits the chain, so
|
||||
// two panes on the same saved host can share a cache key while pinning
|
||||
// different bastion routes (e.g. one connected before a jump-host edit, one
|
||||
// after) — those routes may reach different servers. Compare identities, not
|
||||
// just cache keys, before allowing any same-host optimization. proxyConfig
|
||||
// must be part of the identity: buildSftpHostCredentials forwards it as the
|
||||
// hop's proxy transport, so two hops sharing id/hostname/port/username can
|
||||
// still dial through different proxies after an edit.
|
||||
const chainIdentity = (chain: Host[] | undefined): string =>
|
||||
(chain ?? []).map(h => `${h.id}@${h.hostname}:${h.port ?? ""}:${h.username}:${proxyIdentity(h.proxyConfig)}`).join("→");
|
||||
|
||||
// Only pin a concrete endpoint while the pane's live connection still belongs
|
||||
// to it. connect() records the incoming tab host before it awaits closure of
|
||||
// the old session and replaces the pane's connection, so during that window a
|
||||
// transfer must not capture endpoint B while its pane snapshot, task paths,
|
||||
// and plan still belong to endpoint A; the pool then falls back to the saved
|
||||
// vault host for the pane's own hostId (mirrors resolveSftpReconnectHost's
|
||||
// tab-host-vs-connection guard).
|
||||
const toConnectHostForPane = (
|
||||
pane: SftpPane,
|
||||
host: Host | "local" | null | undefined,
|
||||
): Host | undefined => {
|
||||
const connection = pane.connection;
|
||||
if (!connection || connection.isLocal) return undefined;
|
||||
return host && host !== "local" && host.id === connection.hostId ? host : undefined;
|
||||
};
|
||||
|
||||
// Snapshot the panes' connect-time endpoints. Called before any preflight
|
||||
// await: tab ids survive reconnect, so resolving this map later can return a
|
||||
// different endpoint than the one the pane snapshot, task paths, and transfer
|
||||
// plan belong to.
|
||||
const captureConnectHosts = (
|
||||
resolveConnectedHost: UseSftpTransfersParams["resolveConnectedHost"],
|
||||
resolveConnectedChain: UseSftpTransfersParams["resolveConnectedChain"],
|
||||
...panes: SftpPane[]
|
||||
): TransferConnectHosts => {
|
||||
const captureEndpoint = (
|
||||
pane: SftpPane | undefined,
|
||||
): { host?: Host; chain?: Host[] } => {
|
||||
if (!pane) return {};
|
||||
const host = toConnectHostForPane(pane, resolveConnectedHost?.(pane.id));
|
||||
if (!host) return {};
|
||||
// Pin only the chain captured with this tab's connection; a later edit of
|
||||
// its bastion hosts must not redirect retained transfers (private
|
||||
// hostnames can resolve differently behind each bastion).
|
||||
return { host, chain: resolveConnectedChain?.(pane.id) ?? undefined };
|
||||
};
|
||||
const source = captureEndpoint(panes[0]);
|
||||
const target = captureEndpoint(panes[1]);
|
||||
return {
|
||||
source: source.host,
|
||||
sourceChain: source.chain,
|
||||
target: target.host,
|
||||
targetChain: target.chain,
|
||||
};
|
||||
};
|
||||
|
||||
/** Keep the MutableRefObject mirror in sync with the process-global latch set. */
|
||||
function syncPausedTasksRef(ref: { current: Set<string> }, taskId: string, latched: boolean) {
|
||||
if (latched) ref.current.add(taskId);
|
||||
@@ -263,8 +187,6 @@ export const useSftpTransfers = ({
|
||||
listRemoteFiles,
|
||||
handleSessionError,
|
||||
acquireTransferSession,
|
||||
resolveConnectedHost,
|
||||
resolveConnectedChain,
|
||||
}: UseSftpTransfersParams): UseSftpTransfersResult => {
|
||||
const { t } = useI18n();
|
||||
const tRef = useRef(t);
|
||||
@@ -554,8 +476,6 @@ export const useSftpTransfers = ({
|
||||
sourcePane: SftpPane,
|
||||
targetPane: SftpPane,
|
||||
targetSide: "left" | "right",
|
||||
/** Connect-time endpoint snapshot captured before any preflight await. */
|
||||
connectHostsOverride?: TransferConnectHosts,
|
||||
): Promise<TransferStatus> => {
|
||||
if (cancelledTasksRef.current.has(task.id)) {
|
||||
return "cancelled";
|
||||
@@ -614,7 +534,7 @@ export const useSftpTransfers = ({
|
||||
|
||||
let walkStatus: TransferStatus = "transferring";
|
||||
await transferRuntime.runWalk(task.id, async () => {
|
||||
walkStatus = await processTransferBody(task, sourcePane, targetPane, targetSide, updateTask, connectHostsOverride);
|
||||
walkStatus = await processTransferBody(task, sourcePane, targetPane, targetSide, updateTask);
|
||||
});
|
||||
return walkStatus;
|
||||
});
|
||||
@@ -626,8 +546,6 @@ export const useSftpTransfers = ({
|
||||
targetPane: SftpPane,
|
||||
targetSide: "left" | "right",
|
||||
updateTask: (updates: Partial<TransferTask>) => void,
|
||||
/** Connect-time endpoint snapshot. Undefined re-resolves the live map. */
|
||||
connectHostsOverride?: TransferConnectHosts,
|
||||
): Promise<TransferStatus> => {
|
||||
|
||||
// Initialize encoding early to avoid temporal dead zone issues
|
||||
@@ -679,29 +597,13 @@ export const useSftpTransfers = ({
|
||||
&& sourceCacheKey === targetCacheKey
|
||||
);
|
||||
|
||||
// Keep the pane's connect-time endpoint even when its saved host is edited.
|
||||
// startTransfer snapshots both hosts before its preflight await so a
|
||||
// reconnect (same tab id, same host id, different endpoint) pending when
|
||||
// processing starts cannot redirect the transfer away from the endpoint
|
||||
// its panes, paths, and plan were captured against.
|
||||
const resolvedConnectHosts = connectHostsOverride
|
||||
?? captureConnectHosts(resolveConnectedHost, resolveConnectedChain, sourcePane, targetPane);
|
||||
const connectHosts: TransferConnectHosts = {
|
||||
source: toConnectHost(resolvedConnectHosts.source),
|
||||
sourceChain: resolvedConnectHosts.sourceChain,
|
||||
target: toConnectHost(resolvedConnectHosts.target),
|
||||
targetChain: resolvedConnectHosts.targetChain,
|
||||
};
|
||||
|
||||
try {
|
||||
// Prefer dedicated work leases for remote ends so folder walks/listings
|
||||
// survive browse park and tab hide (pool holders, not panel map ids).
|
||||
if (!sourcePane.connection?.isLocal) {
|
||||
const sourceHostId = task.sourceHostId || sourcePane.connection?.hostId;
|
||||
if (acquireTransferSession && sourceHostId) {
|
||||
sourceWorkLease = await acquireTransferSession(
|
||||
sourceHostId, `${task.id}:work-source`, connectHosts.source, connectHosts.sourceChain,
|
||||
);
|
||||
sourceWorkLease = await acquireTransferSession(sourceHostId, `${task.id}:work-source`);
|
||||
sourceSftpId = sourceWorkLease.sftpId;
|
||||
}
|
||||
if (!sourceSftpId) {
|
||||
@@ -714,9 +616,7 @@ export const useSftpTransfers = ({
|
||||
if (!targetPane.connection?.isLocal) {
|
||||
const targetHostId = task.targetHostId || targetPane.connection?.hostId;
|
||||
if (acquireTransferSession && targetHostId) {
|
||||
targetWorkLease = await acquireTransferSession(
|
||||
targetHostId, `${task.id}:work-target`, connectHosts.target, connectHosts.targetChain,
|
||||
);
|
||||
targetWorkLease = await acquireTransferSession(targetHostId, `${task.id}:work-target`);
|
||||
targetSftpId = targetWorkLease.sftpId;
|
||||
}
|
||||
if (!targetSftpId) {
|
||||
@@ -725,20 +625,7 @@ export const useSftpTransfers = ({
|
||||
}
|
||||
}
|
||||
|
||||
// The cache-key equality above omits the jump chain. When the two pinned
|
||||
// chains differ (a bastion edit between the panes' connect times), the
|
||||
// "same" saved host may resolve to different servers behind each bastion;
|
||||
// a same-host `cp` would then write on the source-side server. Treat the
|
||||
// transfer as cross-host unless the pinned routes match (both undefined =
|
||||
// both direct, which is equal).
|
||||
const sameHostPinnedChains = chainIdentity(connectHosts.sourceChain) === chainIdentity(connectHosts.targetChain);
|
||||
// buildCacheKey also omits the endpoint's own top-level proxyConfig, and a
|
||||
// proxy edit between the panes' connect times changes the transport (and
|
||||
// possibly the resolved server) without moving the cache key. Compare the
|
||||
// pinned top-level proxy identities too; undefined on both sides means
|
||||
// both dial directly, which is equal.
|
||||
const sameHostPinnedProxies = proxyIdentity(connectHosts.source?.proxyConfig) === proxyIdentity(connectHosts.target?.proxyConfig);
|
||||
const sameHost = sameHostEndpoints && sameHostPinnedChains && sameHostPinnedProxies && !!sourceSftpId && !!targetSftpId;
|
||||
const sameHost = sameHostEndpoints && !!sourceSftpId && !!targetSftpId;
|
||||
|
||||
// Returns the discovered stat so callers that need the size (e.g. the
|
||||
// overwrite conflict dialog) can await this instead of reading stale
|
||||
@@ -1009,7 +896,7 @@ export const useSftpTransfers = ({
|
||||
: t,
|
||||
),
|
||||
);
|
||||
return processTransfer(updatedTask, sourcePane, targetPane, targetSide, connectHostsOverride);
|
||||
return processTransfer(updatedTask, sourcePane, targetPane, targetSide);
|
||||
}
|
||||
|
||||
if (cancelledTasksRef.current.has(task.id)) return "cancelled";
|
||||
@@ -1091,7 +978,6 @@ export const useSftpTransfers = ({
|
||||
targetEncoding,
|
||||
task.id, // rootTaskId - this is the top-level task
|
||||
sameHost,
|
||||
0, false, undefined, undefined, connectHosts,
|
||||
);
|
||||
|
||||
if (dirErrors > 0) {
|
||||
@@ -1139,7 +1025,6 @@ export const useSftpTransfers = ({
|
||||
targetEncoding,
|
||||
task.id, // rootTaskId - this is the top-level task
|
||||
sameHost,
|
||||
connectHosts,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1281,12 +1166,6 @@ export const useSftpTransfers = ({
|
||||
|
||||
if (!sourcePane?.connection || !targetPane?.connection) return [];
|
||||
|
||||
// Capture the connect-time endpoints before the preflight stat await
|
||||
// below: reconnecting either pane to a different endpoint under the same
|
||||
// host id while stats are pending must not redirect the transfer — the
|
||||
// pane snapshot, task paths, and plan all belong to this endpoint.
|
||||
const connectHosts = captureConnectHosts(resolveConnectedHost, resolveConnectedChain, sourcePane, targetPane);
|
||||
|
||||
const sourcePath = options?.sourcePath ?? sourcePane.connection.currentPath;
|
||||
const targetPath = options?.targetPath ?? targetPane.connection.currentPath;
|
||||
const sourceConnectionId = options?.sourceConnectionId ?? sourcePane.connection.id;
|
||||
@@ -1514,7 +1393,7 @@ export const useSftpTransfers = ({
|
||||
}
|
||||
|
||||
const results = await Promise.all(runnableTasks.map(async (task): Promise<TransferResult> => {
|
||||
const status = await processTransfer(task, sourcePane, targetPane, targetSide, connectHosts);
|
||||
const status = await processTransfer(task, sourcePane, targetPane, targetSide);
|
||||
return {
|
||||
id: task.id,
|
||||
fileName: task.fileName,
|
||||
@@ -1525,10 +1404,8 @@ export const useSftpTransfers = ({
|
||||
|
||||
return [...skippedResults, ...results];
|
||||
},
|
||||
// Saved host edits replace acquisition; new transfers must not retain the old endpoint.
|
||||
// Already-running attempts keep the leases they acquired.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[getActivePane, getPaneByConnectionId, getTabByConnectionId, sftpSessionsRef, updateTab, acquireTransferSession, resolveConnectedHost],
|
||||
[getActivePane, getPaneByConnectionId, getTabByConnectionId, sftpSessionsRef, updateTab],
|
||||
);
|
||||
|
||||
const cancelTransfer = useCallback(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { MutableRefObject } from "react";
|
||||
import type { Host, FileConflict, FileConflictAction, SftpFileEntry, SftpFilenameEncoding, TransferStatus, TransferTask } from "../../../domain/models";
|
||||
import type { FileConflict, FileConflictAction, SftpFileEntry, SftpFilenameEncoding, TransferStatus, TransferTask } from "../../../domain/models";
|
||||
import type { SftpPane } from "./types";
|
||||
import type { AcquireTransferSessionFn } from "./transferDirectoryOps";
|
||||
|
||||
@@ -21,14 +21,6 @@ export interface UseSftpTransfersParams {
|
||||
handleSessionError: (side: "left" | "right", error: Error) => void;
|
||||
/** FileZilla-style dedicated transfer sessions (1–2 per host). */
|
||||
acquireTransferSession?: AcquireTransferSessionFn;
|
||||
resolveConnectedHost?: (tabId: string) => Host | "local" | null;
|
||||
/**
|
||||
* Jump-host chain snapshots captured when the tab connected. Lets retained
|
||||
* transfers keep dialing the connect-time bastion chain after a chain host
|
||||
* is edited (private hostnames can resolve differently per bastion);
|
||||
* undefined = chain must be re-resolved from the live vault.
|
||||
*/
|
||||
resolveConnectedChain?: (tabId: string) => Host[] | null;
|
||||
}
|
||||
|
||||
export interface UseSftpTransfersResult {
|
||||
|
||||
@@ -266,9 +266,9 @@ export function useSystemSettingsEffects({
|
||||
notifySettingsChanged(STORAGE_KEY_HTTP_NETWORK_PROXY, normalized);
|
||||
}, [enabled, httpNetworkProxy, notifySettingsChanged, persistMountedRef]);
|
||||
|
||||
// Window chrome also applies in detached sessions, independently of the
|
||||
// OS-level effects disabled there (tray, global shortcuts, autolaunch, ...).
|
||||
// Persist and sync window opacity
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
const bridge = netcattyBridge.get();
|
||||
bridge?.setWindowOpacity?.(windowOpacityRecord.opacity).catch((err) => {
|
||||
console.warn('[WindowOpacity] Failed to apply window opacity:', err);
|
||||
@@ -294,6 +294,7 @@ export function useSystemSettingsEffects({
|
||||
if (!decision.shouldBroadcast) return;
|
||||
notifySettingsChanged(STORAGE_KEY_WINDOW_OPACITY, windowOpacityRecord);
|
||||
}, [
|
||||
enabled,
|
||||
windowOpacityRecord,
|
||||
windowOpacityMutationSourceRef,
|
||||
notifySettingsChanged,
|
||||
|
||||
@@ -18,7 +18,6 @@ import type {
|
||||
} from '../../infrastructure/ai/types';
|
||||
import type { ExecutorContext } from '../../infrastructure/ai/cattyAgent/executor';
|
||||
import { getAgentRuntime } from '../../infrastructure/ai/harness/globalAgentRuntime';
|
||||
import { stopAgentTurn } from '../../infrastructure/ai/harness/agentStop';
|
||||
import type {
|
||||
TurnSteerInput,
|
||||
TurnSteerResult,
|
||||
@@ -47,16 +46,6 @@ export function isAIChatSessionStreaming(sessionId: string | null | undefined):
|
||||
return !!sessionId && sharedStreamingSessionIds.has(sessionId);
|
||||
}
|
||||
|
||||
/** Use the same stop entry and controllers as the UI before replacing history. */
|
||||
export async function stopAIChatSessionBeforeReplacement(sessionId: string): Promise<void> {
|
||||
const controller = sharedAbortControllers.get(sessionId);
|
||||
if (controller || sharedStreamingSessionIds.has(sessionId)) {
|
||||
await stopAgentTurn({ chatSessionId: sessionId, abortController: controller, bridge: getNetcattyBridge() });
|
||||
}
|
||||
await getAgentRuntime().waitForActiveTurn(sessionId);
|
||||
if (controller && sharedAbortControllers.get(sessionId) === controller) sharedAbortControllers.delete(sessionId);
|
||||
}
|
||||
|
||||
function emitStreamingStoreChange(): void {
|
||||
streamingSubscribers.forEach(listener => {
|
||||
try {
|
||||
|
||||
@@ -757,10 +757,7 @@ export function useAIState() {
|
||||
// Non-destructive "undo last turn": branch the session at the boundary
|
||||
// before the latest user message and keep the original in history intact.
|
||||
// Returns the new branch id plus the undone user message for the composer.
|
||||
const undoLastTurnInSession = useCallback(async (
|
||||
sessionId: string,
|
||||
viewingScope?: Pick<AISessionScope, 'type' | 'targetId'>,
|
||||
): Promise<{
|
||||
const undoLastTurnInSession = useCallback(async (sessionId: string): Promise<{
|
||||
sessionId: string;
|
||||
restored: UndoLastTurnRestoredDraft;
|
||||
} | null> => {
|
||||
@@ -771,11 +768,6 @@ export function useAIState() {
|
||||
if (!result) return null;
|
||||
|
||||
const branched = result.session;
|
||||
// Like Fork, Undo belongs to the panel viewing the source, which may have
|
||||
// resumed a chat from a closed terminal or inherited it after a merge.
|
||||
if (viewingScope) {
|
||||
branched.scope = { ...branched.scope, ...viewingScope };
|
||||
}
|
||||
setSessionsRaw(prev => {
|
||||
// Keep both recently used chats within the existing history limit.
|
||||
const next = [branched, { ...source, updatedAt: branched.updatedAt }, ...prev.filter(session => session.id !== source.id)];
|
||||
|
||||
@@ -8,7 +8,6 @@ import type { AISession, UploadedFile } from '../../infrastructure/ai/types.ts';
|
||||
import { getAgentRuntime } from '../../infrastructure/ai/harness/globalAgentRuntime.ts';
|
||||
import { useAIState } from './useAIState.ts';
|
||||
import { useAISessionsStore } from './aiSessionsStore.ts';
|
||||
import { getSessionScopeMatchRank } from '../../components/ai/sessionScopeMatch.ts';
|
||||
import { setLatestAISessionsSnapshot } from './aiStateSnapshots.ts';
|
||||
|
||||
const SCOPE_KEY = 'terminal:terminal-a';
|
||||
@@ -193,39 +192,3 @@ for (const newerCount of [49, 50]) {
|
||||
reloaded.container.remove(); reloaded.dom.window.close();
|
||||
});
|
||||
}
|
||||
|
||||
for (const viewingScope of [
|
||||
{ type: 'terminal' as const, targetId: 'terminal-b' },
|
||||
{ type: 'workspace' as const, targetId: 'workspace-b' },
|
||||
]) {
|
||||
test(`undo stays visible when a ${viewingScope.type} views a chat from a closed terminal`, async () => {
|
||||
const source = {
|
||||
...structuredClone(SOURCE_SESSION),
|
||||
scope: { type: 'terminal' as const, targetId: 'terminal-closed', hostIds: ['host-a'] },
|
||||
};
|
||||
const { dom, container, root, capture } = await setupAiState([source]);
|
||||
const sourceBefore = structuredClone(source);
|
||||
let branchId: string | undefined;
|
||||
await act(async () => {
|
||||
capture.ai!.setActiveSessionId('terminal:terminal-b', source.id);
|
||||
branchId = (await capture.ai!.undoLastTurnInSession(source.id, viewingScope))?.sessionId;
|
||||
});
|
||||
assert.ok(branchId);
|
||||
const branch = capture.sessions.find(item => item.id === branchId)!;
|
||||
assert.deepEqual(branch.messages, source.messages.slice(0, 2));
|
||||
assert.deepEqual(branch.scope, { ...source.scope, ...viewingScope });
|
||||
assert.equal(capture.activeSessionIdMap[`${viewingScope.type}:${viewingScope.targetId}`], branch.id);
|
||||
// The real history predicate must still include the selected branch after
|
||||
// the source terminal no longer belongs to the current workspace.
|
||||
assert.equal(getSessionScopeMatchRank(
|
||||
branch, viewingScope.type, viewingScope.targetId, ['host-a'],
|
||||
new Set([branch.id]), new Set(['terminal-b']), new Set([source.id]),
|
||||
), 3);
|
||||
const original = capture.sessions.find(item => item.id === source.id)!;
|
||||
assert.deepEqual({ ...original, updatedAt: sourceBefore.updatedAt }, sourceBefore);
|
||||
const saved = JSON.parse(dom.window.localStorage.getItem('netcatty_ai_sessions_v1')!) as AISession[];
|
||||
assert.deepEqual(saved.find(item => item.id === branchId)?.scope, branch.scope);
|
||||
await act(async () => root.unmount());
|
||||
container.remove(); dom.window.close();
|
||||
});
|
||||
}
|
||||
@@ -21,14 +21,12 @@ import { isProviderReadyForSync, SYNC_STORAGE_KEYS, type CloudProvider, type Syn
|
||||
import { mergeSyncPayloads } from '../../domain/syncMerge';
|
||||
import { materializeSyncPayloadFromConvergentState } from '../../domain/convergentSync';
|
||||
import {
|
||||
isPreserveDeletionsStrategy,
|
||||
resolveCloudSyncConflictAction,
|
||||
type CloudSyncConflictAction,
|
||||
} from '../../domain/syncStrategy';
|
||||
import {
|
||||
SYNCABLE_SETTING_STORAGE_KEYS,
|
||||
collectCloudSyncableSettings,
|
||||
collectAiSessionsForSync,
|
||||
getEffectivePortForwardingRulesForSync,
|
||||
hasCloudSyncEntityData,
|
||||
hasMeaningfulCloudSyncData,
|
||||
@@ -40,8 +38,6 @@ import { commitPluginSidecarsAfterSuccessfulSync } from '../pluginSyncSidecarBri
|
||||
import { readInterruptedVaultApply } from '../localVaultBackups';
|
||||
import {
|
||||
STORAGE_KEY_VAULT_RESTORE_IN_PROGRESS_UNTIL,
|
||||
STORAGE_KEY_AI_SESSIONS,
|
||||
STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS,
|
||||
} from '../../infrastructure/config/storageKeys';
|
||||
import {
|
||||
LOCAL_STORAGE_ADAPTER_CHANGED_EVENT,
|
||||
@@ -163,7 +159,6 @@ const getSyncPayloadDataHash = (payload: SyncPayload): string => {
|
||||
groupConfigs: payload.groupConfigs,
|
||||
settings: payload.settings,
|
||||
pluginSidecars: payload.pluginSidecars,
|
||||
aiSessions: payload.aiSessions,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -248,11 +243,7 @@ export const useAutoSync = (config: AutoSyncConfig) => {
|
||||
const [syncableSettingsStorageVersion, setSyncableSettingsStorageVersion] = useState(0);
|
||||
useEffect(() => {
|
||||
const bumpIfSyncableSetting = (key: string | null | undefined) => {
|
||||
if (!key) return;
|
||||
const chatChanged = key === STORAGE_KEY_AI_SESSIONS
|
||||
&& localStorageAdapter.read<{ enabled?: boolean }>(STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS)?.enabled === true;
|
||||
if (!SYNCABLE_SETTING_STORAGE_KEY_SET.has(key)
|
||||
&& key !== STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS && !chatChanged) return;
|
||||
if (!key || !SYNCABLE_SETTING_STORAGE_KEY_SET.has(key)) return;
|
||||
setSyncableSettingsStorageVersion((v) => v + 1);
|
||||
};
|
||||
|
||||
@@ -308,10 +299,8 @@ export const useAutoSync = (config: AutoSyncConfig) => {
|
||||
const buildPayload = useCallback(async (): Promise<SyncPayload> => {
|
||||
const { withPluginSyncSidecars } = await import('../syncPayload');
|
||||
const { collectPluginSyncSidecarsFromHost } = await import('../pluginSyncSidecarBridge');
|
||||
const aiSessions = collectAiSessionsForSync();
|
||||
const base: SyncPayload = {
|
||||
...getSyncSnapshot(),
|
||||
...(aiSessions !== undefined ? { aiSessions } : {}),
|
||||
settings: await collectCloudSyncableSettings(),
|
||||
syncedAt: Date.now(),
|
||||
};
|
||||
@@ -792,7 +781,7 @@ export const useAutoSync = (config: AutoSyncConfig) => {
|
||||
}
|
||||
|
||||
const conflictAction = resolveCloudSyncConflictAction(state.syncStrategy, {
|
||||
hasConflict: inspection.remoteChanged || isPreserveDeletionsStrategy(state.syncStrategy),
|
||||
hasConflict: inspection.remoteChanged,
|
||||
hasRemoteFile: Boolean(inspection.remoteFile),
|
||||
});
|
||||
|
||||
@@ -861,9 +850,7 @@ export const useAutoSync = (config: AutoSyncConfig) => {
|
||||
// upload and wipe usable cloud passwords. Same for remote-side poison.
|
||||
const localHealed = healPoisonedSecretsForMerge(localPayload, remoteRaw, base);
|
||||
const remoteHealed = healPoisonedSecretsForMerge(remoteRaw, localPayload, base);
|
||||
const mergeResult = mergeSyncPayloads(base, localHealed, remoteHealed, {
|
||||
preserveDeletions: isPreserveDeletionsStrategy(state.syncStrategy),
|
||||
});
|
||||
const mergeResult = mergeSyncPayloads(base, localHealed, remoteHealed);
|
||||
|
||||
// Apply merged payload to local state BEFORE committing. If the apply
|
||||
// throws, the next startup will re-run the merge with fresh data.
|
||||
|
||||
@@ -28,8 +28,6 @@ import {
|
||||
isProviderReadyForSync,
|
||||
} from '../../domain/sync';
|
||||
import type { CloudSyncStrategy } from '../../domain/syncStrategy';
|
||||
import { LOCAL_STORAGE_ADAPTER_CHANGED_EVENT, localStorageAdapter } from '../../infrastructure/persistence/localStorageAdapter';
|
||||
import { STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS } from '../../infrastructure/config/storageKeys';
|
||||
import type { CloudSyncConflictAction } from '../../domain/syncStrategy';
|
||||
import {
|
||||
getCloudSyncManager,
|
||||
@@ -175,9 +173,6 @@ export interface CloudSyncHook {
|
||||
setAutoSync: (enabled: boolean, intervalMinutes?: number) => void;
|
||||
setDeviceName: (name: string) => void;
|
||||
setSyncStrategy: (strategy: CloudSyncStrategy) => void;
|
||||
/** Whether AI chat sessions are included in cloud sync payloads (opt-in). */
|
||||
aiSessionsSyncEnabled: boolean;
|
||||
setAiSessionsSyncEnabled: (enabled: boolean) => Promise<void>;
|
||||
setConvergentSyncEnabled: (enabled: boolean) => ConvergentSyncLocalConfig;
|
||||
refreshConvergentSyncConfig: () => ConvergentSyncLocalConfig;
|
||||
|
||||
@@ -254,25 +249,6 @@ const getSnapshot = (): SyncManagerState => {
|
||||
return manager.getState();
|
||||
};
|
||||
|
||||
function readAiSessionsSyncEnabled(): boolean {
|
||||
return localStorageAdapter.read<{ enabled?: boolean }>(STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS)?.enabled === true;
|
||||
}
|
||||
|
||||
function subscribeAiSessionsSyncEnabled(listener: () => void): () => void {
|
||||
const storage = (event: StorageEvent) => {
|
||||
if (event.key === STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS || event.key === null) listener();
|
||||
};
|
||||
const local = (event: Event) => {
|
||||
if ((event as CustomEvent<{ key?: string }>).detail?.key === STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS) listener();
|
||||
};
|
||||
window.addEventListener('storage', storage);
|
||||
window.addEventListener(LOCAL_STORAGE_ADAPTER_CHANGED_EVENT, local);
|
||||
return () => {
|
||||
window.removeEventListener('storage', storage);
|
||||
window.removeEventListener(LOCAL_STORAGE_ADAPTER_CHANGED_EVENT, local);
|
||||
};
|
||||
}
|
||||
|
||||
export const useCloudSync = (): CloudSyncHook => {
|
||||
// Use useSyncExternalStore for real-time state sync across all components
|
||||
const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
||||
@@ -748,19 +724,6 @@ export const useCloudSync = (): CloudSyncHook => {
|
||||
manager.setDeviceName(name);
|
||||
}, []);
|
||||
|
||||
const aiSessionsSyncEnabled = useSyncExternalStore(
|
||||
subscribeAiSessionsSyncEnabled, readAiSessionsSyncEnabled, readAiSessionsSyncEnabled,
|
||||
);
|
||||
const setAiSessionsSyncEnabled = useCallback(async (enabled: boolean) => {
|
||||
const { setAiSessionsSyncPreference } = await import('../syncPayload');
|
||||
await setAiSessionsSyncPreference(enabled, async () => {
|
||||
const providers = Object.entries(manager.getAllProviders())
|
||||
.filter(([, connection]) => isProviderReadyForSync(connection));
|
||||
const remotes = await Promise.all(providers.map(([provider]) => manager.downloadFromProvider(provider as CloudProvider)));
|
||||
return remotes.filter((remote) => remote !== null).map((remote) => remote.payload);
|
||||
}, manager.getState().syncStrategy === 'smartMergePreserve');
|
||||
}, []);
|
||||
|
||||
const setSyncStrategy = useCallback((strategy: CloudSyncStrategy) => {
|
||||
manager.setSyncStrategy(strategy);
|
||||
}, []);
|
||||
@@ -901,7 +864,6 @@ export const useCloudSync = (): CloudSyncHook => {
|
||||
}
|
||||
return manager.resolveConvergentConflict(addressKey, candidateDot, applyPayload, {
|
||||
pluginSidecars,
|
||||
aiSessions: (await import('../syncPayload')).collectAiSessionsForSync(),
|
||||
});
|
||||
}, [ensureUnlocked]);
|
||||
|
||||
@@ -994,8 +956,6 @@ export const useCloudSync = (): CloudSyncHook => {
|
||||
setAutoSync,
|
||||
setDeviceName,
|
||||
setSyncStrategy,
|
||||
aiSessionsSyncEnabled,
|
||||
setAiSessionsSyncEnabled,
|
||||
setConvergentSyncEnabled,
|
||||
refreshConvergentSyncConfig,
|
||||
|
||||
|
||||
@@ -3,11 +3,7 @@ import test from 'node:test';
|
||||
import React from 'react';
|
||||
import { act, create, type ReactTestRenderer } from 'react-test-renderer';
|
||||
import { useComposeBarHistory } from './useComposeBarHistory';
|
||||
import {
|
||||
clearComposeBarHistory,
|
||||
pruneComposeBarHistory,
|
||||
recordComposeBarHistory,
|
||||
} from './composeBarHistoryStore';
|
||||
import { pruneComposeBarHistory, recordComposeBarHistory } from './composeBarHistoryStore';
|
||||
|
||||
test('changing workspace focus resets navigation without replacing the draft', async () => {
|
||||
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
||||
@@ -51,31 +47,3 @@ test('an in-progress history walk stays stable when a late send evicts the oldes
|
||||
await act(async () => { root.unmount(); });
|
||||
pruneComposeBarHistory([]);
|
||||
});
|
||||
|
||||
test('clearing history restores the pre-walk draft instead of leaving the recalled command', async () => {
|
||||
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
||||
pruneComposeBarHistory([]);
|
||||
recordComposeBarHistory('a', 'deleted-command');
|
||||
const restoredDrafts: string[] = [];
|
||||
let history!: ReturnType<typeof useComposeBarHistory>;
|
||||
function Harness() {
|
||||
history = useComposeBarHistory('a', (draft) => { restoredDrafts.push(draft); });
|
||||
return null;
|
||||
}
|
||||
let root!: ReactTestRenderer;
|
||||
await act(async () => { root = create(React.createElement(Harness)); });
|
||||
|
||||
// Enter a history walk: the textarea now shows the recalled command while the
|
||||
// hook holds the pre-walk draft.
|
||||
assert.equal(history.navigate('my unsent draft', 'up'), 'deleted-command');
|
||||
|
||||
clearComposeBarHistory();
|
||||
|
||||
// The pre-walk draft is put back, so the deleted command is no longer in the
|
||||
// textarea ready for Enter.
|
||||
assert.deepEqual(restoredDrafts, ['my unsent draft']);
|
||||
assert.equal(history.navigate('my unsent draft', 'up'), undefined);
|
||||
|
||||
await act(async () => { root.unmount(); });
|
||||
pruneComposeBarHistory([]);
|
||||
});
|
||||
@@ -1,10 +1,6 @@
|
||||
import { useCallback, useEffect, useLayoutEffect, useRef } from 'react';
|
||||
import { useCallback, useLayoutEffect, useRef } from 'react';
|
||||
import { navigateComposeBarHistory, type ComposeBarHistoryDirection } from '../../domain/composeBarHistory';
|
||||
import {
|
||||
getComposeBarHistory,
|
||||
createComposeBarHistoryRecorder,
|
||||
subscribeComposeBarHistoryCleared,
|
||||
} from './composeBarHistoryStore';
|
||||
import { getComposeBarHistory, createComposeBarHistoryRecorder } from './composeBarHistoryStore';
|
||||
|
||||
export function useComposeBarHistory(sessionId: string, restoreDraft?: (draft: string) => void) {
|
||||
const cursor = useRef<{ index: number; draft: string; entries?: readonly string[] }>({ index: Infinity, draft: '' });
|
||||
@@ -20,24 +16,6 @@ export function useComposeBarHistory(sessionId: string, restoreDraft?: (draft: s
|
||||
reset();
|
||||
}, [reset, restoreDraft, sessionId]);
|
||||
|
||||
/**
|
||||
* Restore the pre-walk draft and drop the cached history walk.
|
||||
*
|
||||
* While the user is in an ArrowUp walk the textarea shows the recalled
|
||||
* command, so resetting the cursor alone would leave a deleted command ready
|
||||
* for Enter. Put the saved draft back first, exactly like the session-change
|
||||
* path above.
|
||||
*/
|
||||
const handleHistoryCleared = useCallback(() => {
|
||||
if (cursor.current.entries) restoreDraft?.(cursor.current.draft);
|
||||
reset();
|
||||
}, [reset, restoreDraft]);
|
||||
|
||||
useEffect(
|
||||
() => subscribeComposeBarHistoryCleared(handleHistoryCleared),
|
||||
[handleHistoryCleared],
|
||||
);
|
||||
|
||||
const prepareRecord = useCallback(() => createComposeBarHistoryRecorder(sessionId), [sessionId]);
|
||||
|
||||
const navigate = useCallback((currentValue: string, direction: ComposeBarHistoryDirection) => {
|
||||
|
||||
@@ -39,7 +39,6 @@ export const getAppLevelActions = (): Set<string> => {
|
||||
'togglePaneZoom',
|
||||
'openLocal',
|
||||
'openSettings',
|
||||
'toggleOpacity',
|
||||
]);
|
||||
};
|
||||
|
||||
|
||||
@@ -141,6 +141,7 @@ import {
|
||||
DEFAULT_TERMINAL_THEME,
|
||||
DEFAULT_THEME,
|
||||
DEFAULT_WINDOW_OPACITY,
|
||||
clampWindowOpacity,
|
||||
applyThemeTokens,
|
||||
areTerminalSettingsEqual,
|
||||
createCustomKeyBindingsSyncOrigin,
|
||||
@@ -179,8 +180,6 @@ import {
|
||||
import {
|
||||
parseWindowOpacityRecord,
|
||||
shouldApplyWindowOpacityRecord,
|
||||
updateWindowOpacityRecord,
|
||||
toggleWindowOpacityRecord,
|
||||
type WindowOpacityMutationSource,
|
||||
type WindowOpacityRecord,
|
||||
} from './windowOpacitySync';
|
||||
@@ -609,7 +608,9 @@ export const useSettingsState = (options: { enableSettingsSync?: boolean; enable
|
||||
const candidate = typeof nextValue === 'function'
|
||||
? (nextValue as (prevState: number) => number)(prev.opacity)
|
||||
: nextValue;
|
||||
return updateWindowOpacityRecord(prev, candidate);
|
||||
const nextOpacity = clampWindowOpacity(candidate);
|
||||
if (nextOpacity === prev.opacity) return prev;
|
||||
return { opacity: nextOpacity, version: prev.version + 1 };
|
||||
});
|
||||
}, []);
|
||||
const applyIncomingWindowOpacity = useCallback((raw: unknown) => {
|
||||
@@ -624,10 +625,6 @@ export const useSettingsState = (options: { enableSettingsSync?: boolean; enable
|
||||
return incoming;
|
||||
});
|
||||
}, []);
|
||||
const toggleWindowOpacity = useCallback(() => {
|
||||
windowOpacityMutationSourceRef.current = 'local';
|
||||
setWindowOpacityRecord(toggleWindowOpacityRecord);
|
||||
}, []);
|
||||
const [appIconVariant, setAppIconVariantState] = useState<AppIconVariant>(() => {
|
||||
const stored = readStoredString(STORAGE_KEY_APP_ICON_VARIANT);
|
||||
return resolveAppIconVariant(stored ?? DEFAULT_APP_ICON_VARIANT);
|
||||
@@ -788,7 +785,7 @@ export const useSettingsState = (options: { enableSettingsSync?: boolean; enable
|
||||
|
||||
// Helper to notify other windows about settings changes via IPC
|
||||
const notifySettingsChanged = useCallback((key: string, value: unknown) => {
|
||||
if (!enableSettingsSync && key !== STORAGE_KEY_WINDOW_OPACITY) return;
|
||||
if (!enableSettingsSync) return;
|
||||
try {
|
||||
netcattyBridge.get()?.notifySettingsChanged?.({ key, value });
|
||||
} catch {
|
||||
@@ -1244,38 +1241,6 @@ export const useSettingsState = (options: { enableSettingsSync?: boolean; enable
|
||||
setSshTransportIdleTtlMsState,
|
||||
});
|
||||
|
||||
// Detached sessions share opacity and the shortcut configuration needed to
|
||||
// operate it. Keep general settings listeners and OS effects disabled there.
|
||||
useEffect(() => {
|
||||
if (enableSettingsSync) return;
|
||||
const applySharedWindowSetting = (key: string, value: unknown) => {
|
||||
if (key === STORAGE_KEY_WINDOW_OPACITY) applyIncomingWindowOpacity(value);
|
||||
if (key === STORAGE_KEY_HOTKEY_SCHEME && (value === 'disabled' || value === 'mac' || value === 'pc')) {
|
||||
setHotkeyScheme(value);
|
||||
}
|
||||
if (key === STORAGE_KEY_CUSTOM_KEY_BINDINGS) {
|
||||
const incoming = parseCustomKeyBindingsStorageRecord(value);
|
||||
if (incoming) applyIncomingCustomKeyBindings(incoming);
|
||||
}
|
||||
if (key === STORAGE_KEY_HOTKEY_RECORDING && typeof value === 'boolean') {
|
||||
setIsHotkeyRecordingState(value);
|
||||
}
|
||||
};
|
||||
const unsubscribe = netcattyBridge.get()?.onSettingsChanged?.(({ key, value }) => {
|
||||
applySharedWindowSetting(key, value);
|
||||
});
|
||||
const onStorage = (event: StorageEvent) => {
|
||||
if (event.key !== null && event.newValue !== null) {
|
||||
applySharedWindowSetting(event.key, event.newValue);
|
||||
}
|
||||
};
|
||||
window.addEventListener('storage', onStorage);
|
||||
return () => {
|
||||
unsubscribe?.();
|
||||
window.removeEventListener('storage', onStorage);
|
||||
};
|
||||
}, [enableSettingsSync, applyIncomingWindowOpacity, applyIncomingCustomKeyBindings]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!enableSettingsSync) return;
|
||||
const bridge = netcattyBridge.get();
|
||||
@@ -2218,7 +2183,6 @@ export const useSettingsState = (options: { enableSettingsSync?: boolean; enable
|
||||
setGlobalHotkeyEnabled,
|
||||
windowOpacity,
|
||||
setWindowOpacity,
|
||||
toggleWindowOpacity,
|
||||
appIconVariant,
|
||||
setAppIconVariant,
|
||||
rehydrateAllFromStorage,
|
||||
|
||||
@@ -191,10 +191,6 @@ export const useSftpState = (
|
||||
// Full Host used when each tab connected (includes session-time overrides).
|
||||
// Tab ids are stable across reconnect; connection ids are not.
|
||||
const connectedHostByTabIdRef = useRef<Map<string, Host | "local">>(new Map());
|
||||
// Resolved jump-host chain captured at connect time, keyed by tab id.
|
||||
// Retained transfers dial through this pinned chain even when one of the
|
||||
// chain's bastion hosts is edited later.
|
||||
const connectedHostChainByTabIdRef = useRef<Map<string, Host[]>>(new Map());
|
||||
const connectInFlightRef = useRef<Map<string, Promise<void>>>(new Map());
|
||||
const connectRequestByTabIdRef = useRef<Map<string, symbol>>(new Map());
|
||||
|
||||
@@ -231,7 +227,6 @@ export const useSftpState = (
|
||||
connectedHostByTabIdRef.current.set(resolvedTabId, host);
|
||||
} else {
|
||||
connectedHostByTabIdRef.current.delete(resolvedTabId);
|
||||
connectedHostChainByTabIdRef.current.delete(resolvedTabId);
|
||||
}
|
||||
}, [leftTabsRef, rightTabsRef]);
|
||||
|
||||
@@ -245,7 +240,6 @@ export const useSftpState = (
|
||||
connectRequests: connectRequestByTabIdRef.current,
|
||||
connectInFlight: connectInFlightRef.current,
|
||||
connectedHosts: connectedHostByTabIdRef.current,
|
||||
connectedHostChains: connectedHostChainByTabIdRef.current,
|
||||
closeTab: (liveSide) => closeTab(liveSide, tabId),
|
||||
releaseConnection: async () => {
|
||||
if (!pane?.connection) return;
|
||||
@@ -324,7 +318,7 @@ export const useSftpState = (
|
||||
const resolveBrowseSourceSessionId = options?.resolveBrowseSourceSessionId;
|
||||
|
||||
const openPoolSftpSession = useCallback(
|
||||
async (host: Host, jumpHosts?: Host[]) => {
|
||||
async (host: Host) => {
|
||||
// Prefer borrowing the live (or parked) terminal SSH transport so MFA is
|
||||
// not repeated. Transport leases keep the shared conn alive after the
|
||||
// terminal tab closes until the transfer SFTP lease is returned.
|
||||
@@ -343,7 +337,7 @@ export const useSftpState = (
|
||||
knownHosts: transferKnownHosts,
|
||||
terminalSettings: transferTerminalSettings,
|
||||
},
|
||||
{ dedicated: false, sourceSessionId, jumpHosts },
|
||||
{ dedicated: false, sourceSessionId },
|
||||
);
|
||||
} catch (err) {
|
||||
logger.debug(
|
||||
@@ -367,14 +361,14 @@ export const useSftpState = (
|
||||
knownHosts: transferKnownHosts,
|
||||
terminalSettings: transferTerminalSettings,
|
||||
},
|
||||
{ dedicated: false, jumpHosts },
|
||||
{ dedicated: false },
|
||||
);
|
||||
},
|
||||
[hosts, identities, keys, resolveTransferSourceSessionId, transferKnownHosts, transferTerminalSettings],
|
||||
);
|
||||
|
||||
const acquireTransferSession = useCallback(
|
||||
async (hostId: string, transferId: string, connectHost?: Host, jumpHosts?: Host[]) => {
|
||||
async (hostId: string, transferId: string, connectHost?: Host) => {
|
||||
// Prefer the connect-time Host (terminal session overrides) so pooled
|
||||
// uploads open the same endpoint as the browse tab, not the vault entry.
|
||||
const host = connectHost && connectHost.id === hostId
|
||||
@@ -388,11 +382,7 @@ export const useSftpState = (
|
||||
`Transfer connect host id mismatch: expected ${hostId}, got ${connectHost.id}`,
|
||||
);
|
||||
}
|
||||
// Chain-pinned acquisitions key the pool-key cache by the chain snapshot
|
||||
// (stable array captured at connect) so they cannot collide with the
|
||||
// vault-resolved entry for the same host object in the WeakMap.
|
||||
const cacheKey = jumpHosts?.length ? jumpHosts : host;
|
||||
const poolKey = await transferPoolKeyCache.get(cacheKey, () => ({
|
||||
const poolKey = await transferPoolKeyCache.get(host, () => ({
|
||||
hostId: host.id,
|
||||
hostname: host.hostname,
|
||||
port: host.port,
|
||||
@@ -406,10 +396,9 @@ export const useSftpState = (
|
||||
identities,
|
||||
knownHosts: transferKnownHosts,
|
||||
terminalSettings: transferTerminalSettings,
|
||||
jumpHostsOverride: jumpHosts,
|
||||
}),
|
||||
}));
|
||||
return transferPoolRef.current.acquire(poolKey, transferId, () => openPoolSftpSession(host, jumpHosts));
|
||||
return transferPoolRef.current.acquire(poolKey, transferId, () => openPoolSftpSession(host));
|
||||
},
|
||||
[hosts, identities, keys, openPoolSftpSession, transferKnownHosts, transferPoolKeyCache, transferTerminalSettings],
|
||||
);
|
||||
@@ -454,7 +443,6 @@ export const useSftpState = (
|
||||
lastConnectedHostRef,
|
||||
connectionCacheKeyMapRef,
|
||||
connectedHostByTabIdRef,
|
||||
connectedHostChainByTabIdRef,
|
||||
connectInFlightRef,
|
||||
connectRequestByTabIdRef,
|
||||
makeCacheKey,
|
||||
@@ -569,8 +557,6 @@ export const useSftpState = (
|
||||
listRemoteFiles,
|
||||
handleSessionError,
|
||||
acquireTransferSession,
|
||||
resolveConnectedHost: (tabId) => connectedHostByTabIdRef.current.get(tabId) ?? null,
|
||||
resolveConnectedChain: (tabId) => connectedHostChainByTabIdRef.current.get(tabId) ?? null,
|
||||
});
|
||||
|
||||
const {
|
||||
@@ -635,7 +621,6 @@ export const useSftpState = (
|
||||
});
|
||||
},
|
||||
resolveConnectedHost: (tabId) => connectedHostByTabIdRef.current.get(tabId) ?? null,
|
||||
resolveConnectedChain: (tabId) => connectedHostChainByTabIdRef.current.get(tabId) ?? null,
|
||||
acquireTransferSession,
|
||||
clearDirCacheEntry,
|
||||
useCompressedUpload: options?.useCompressedUpload,
|
||||
|
||||
@@ -483,73 +483,3 @@ for (const phase of ["snapshot", "commit"] as const) {
|
||||
assert.equal(commits, phase === "snapshot" ? 0 : 1);
|
||||
});
|
||||
}
|
||||
|
||||
for (const mixedSelection of [false, true]) {
|
||||
test(`group deletion prunes host and inherited chains, mixed selection: ${mixedSelection}`, async () => {
|
||||
const actEnvironment = globalThis as typeof globalThis & {
|
||||
IS_REACT_ACT_ENVIRONMENT?: boolean;
|
||||
};
|
||||
const previousActEnvironment = actEnvironment.IS_REACT_ACT_ENVIRONMENT;
|
||||
actEnvironment.IS_REACT_ACT_ENVIRONMENT = true;
|
||||
|
||||
const storedHosts = [
|
||||
{ id: "jump", group: "A", label: "jump", hostname: "j.example.com", port: 22, username: "root", protocol: "ssh" as const, tags: [], os: "linux" as const },
|
||||
{ id: "survivor", group: "B", label: "survivor", hostname: "s.example.com", port: 22, username: "root", protocol: "ssh" as const, tags: [], os: "linux" as const, hostChain: { hostIds: ["jump"] } },
|
||||
{ id: "extra", group: "B", label: "extra", hostname: "e.example.com", username: "root", tags: [], os: "linux" as const },
|
||||
{ id: "kept", group: "B", label: "kept", hostname: "k.example.com", username: "root", tags: [], os: "linux" as const },
|
||||
];
|
||||
const configs: GroupConfig[] = [{ path: "B", hostChain: { hostIds: ["jump", "extra", "kept"] } }];
|
||||
let deleteGroups: ReturnType<typeof useVaultGroupDeletion> | undefined;
|
||||
let renderer: ReactTestRenderer | null = null;
|
||||
let committedHosts: Array<{ id: string; hostChain?: { hostIds: string[] } }> = [];
|
||||
let committedConfigs: GroupConfig[] = [];
|
||||
|
||||
const Probe = () => {
|
||||
deleteGroups = useVaultGroupDeletion({
|
||||
customGroups: ["A", "B"],
|
||||
hosts: storedHosts,
|
||||
groupConfigs: configs,
|
||||
managedSources: [],
|
||||
onReadPersistedHosts: async () => storedHosts,
|
||||
onReadPersistedManagedSources: () => [],
|
||||
onCommitVaultGroupMutation: async (mutate) => {
|
||||
const result = mutate({
|
||||
groups: ["A", "B"],
|
||||
configs,
|
||||
hosts: storedHosts,
|
||||
managedSources: [],
|
||||
snippets: [],
|
||||
});
|
||||
if (result.ok) {
|
||||
committedHosts = result.state.hosts;
|
||||
committedConfigs = result.state.configs;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
});
|
||||
return null;
|
||||
};
|
||||
|
||||
try {
|
||||
await act(async () => {
|
||||
renderer = create(React.createElement(Probe));
|
||||
});
|
||||
await act(async () => {
|
||||
await deleteGroups?.(["A"], true, new Set(mixedSelection ? ["extra"] : []));
|
||||
});
|
||||
} finally {
|
||||
await act(async () => {
|
||||
renderer?.unmount();
|
||||
});
|
||||
actEnvironment.IS_REACT_ACT_ENVIRONMENT = previousActEnvironment;
|
||||
}
|
||||
|
||||
assert.deepEqual(committedHosts.map(({ id, hostChain }) => ({ id, hostChain })), [
|
||||
{ id: "survivor", hostChain: { hostIds: [] } },
|
||||
...(!mixedSelection ? [{ id: "extra", hostChain: undefined }] : []),
|
||||
{ id: "kept", hostChain: undefined },
|
||||
]);
|
||||
assert.deepEqual(committedConfigs[0].hostChain,
|
||||
{ hostIds: mixedSelection ? ["kept"] : ["extra", "kept"] });
|
||||
});
|
||||
}
|
||||
@@ -3,7 +3,6 @@ import { useCallback, useRef } from "react";
|
||||
import type { GroupConfig, Host, ManagedSource } from "../../domain/models";
|
||||
import { removeSnippetTargetGroupPaths } from "../../domain/hostGroupPathMutations";
|
||||
import { buildVaultGroupDeletion } from "../../domain/vaultGroupDeletion";
|
||||
import { pruneVaultJumpHostReferences } from "../../domain/vaultJumpGraph";
|
||||
import type {
|
||||
VaultGroupMutationResult,
|
||||
VaultGroupMutationState,
|
||||
@@ -156,30 +155,14 @@ export function useVaultGroupDeletion({
|
||||
)) {
|
||||
throw RETRY_VAULT_GROUP_DELETION;
|
||||
}
|
||||
const nextTransactionHosts = currentDeletion.hosts.filter(
|
||||
(host) => !additionallyDeletedHostIds.has(host.id),
|
||||
);
|
||||
// Hosts removed by this transaction must stop being referenced
|
||||
// from other hosts' jump chains (and group config chains), or
|
||||
// those targets keep failing with "A configured jump host is
|
||||
// missing".
|
||||
const retainedHostIds = new Set(
|
||||
nextTransactionHosts.map((host) => host.id),
|
||||
);
|
||||
const removedHostIds = current.hosts
|
||||
.filter((host) => !retainedHostIds.has(host.id))
|
||||
.map((host) => host.id);
|
||||
const prunedReferences = pruneVaultJumpHostReferences({
|
||||
hosts: nextTransactionHosts,
|
||||
groupConfigs: currentDeletion.groupConfigs,
|
||||
removedHostIds,
|
||||
});
|
||||
return {
|
||||
ok: true,
|
||||
state: {
|
||||
groups: currentDeletion.customGroups,
|
||||
hosts: prunedReferences.hosts,
|
||||
configs: prunedReferences.groupConfigs,
|
||||
hosts: currentDeletion.hosts.filter(
|
||||
(host) => !additionallyDeletedHostIds.has(host.id),
|
||||
),
|
||||
configs: currentDeletion.groupConfigs,
|
||||
managedSources: current.managedSources.filter(
|
||||
(source) => !currentDeletion.sourcesToRemove.some(
|
||||
(removed) => removed.id === source.id,
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
import { act, create, type ReactTestRenderer } from 'react-test-renderer';
|
||||
|
||||
import type { Host } from '../../domain/models';
|
||||
import type { VaultGroupMutationState } from '../../domain/vaultGroupMutation';
|
||||
import { useVaultHostDeletion } from './useVaultHostDeletion';
|
||||
import { commitVaultGroupMutationPersistence } from './vaultGroupMutationPersistence';
|
||||
import {
|
||||
STORAGE_KEY_GROUP_CONFIGS,
|
||||
STORAGE_KEY_HOSTS,
|
||||
} from '../../infrastructure/config/storageKeys';
|
||||
|
||||
const host = (id: string, hostIds?: string[]): Host => ({
|
||||
id, label: id, hostname: `${id}.test`, username: 'root', tags: [], os: 'linux',
|
||||
...(hostIds ? { hostChain: { hostIds } } : {}),
|
||||
});
|
||||
|
||||
async function withDeletion(
|
||||
commit: Parameters<typeof useVaultHostDeletion>[0],
|
||||
run: (remove: ReturnType<typeof useVaultHostDeletion>) => Promise<void>,
|
||||
) {
|
||||
const environment = globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean };
|
||||
const previous = environment.IS_REACT_ACT_ENVIRONMENT;
|
||||
environment.IS_REACT_ACT_ENVIRONMENT = true;
|
||||
let remove!: ReturnType<typeof useVaultHostDeletion>;
|
||||
let renderer: ReactTestRenderer | undefined;
|
||||
function Probe() {
|
||||
remove = useVaultHostDeletion(commit);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
await act(async () => { renderer = create(React.createElement(Probe)); });
|
||||
await run(remove);
|
||||
} finally {
|
||||
await act(async () => { renderer?.unmount(); });
|
||||
environment.IS_REACT_ACT_ENVIRONMENT = previous;
|
||||
}
|
||||
}
|
||||
|
||||
for (const removed of [['jump'], ['jump', 'extra']]) {
|
||||
test(`host deletion cleans latest host and group references together: ${removed.join(',')}`, async () => {
|
||||
const latest: VaultGroupMutationState = {
|
||||
hosts: [host('jump'), host('extra'), host('kept'), host('target', ['jump', 'kept'])],
|
||||
configs: [{ path: 'prod', username: 'latest-user', hostChain: { hostIds: ['jump'] } }],
|
||||
groups: ['prod'], managedSources: [], snippets: [],
|
||||
};
|
||||
let committed: VaultGroupMutationState | undefined;
|
||||
await withDeletion(async (mutate) => {
|
||||
const result = mutate(latest);
|
||||
if (result.ok) committed = result.state;
|
||||
return result;
|
||||
}, async (remove) => { await act(async () => { await remove(removed); }); });
|
||||
assert.ok(committed);
|
||||
assert.deepEqual(committed.hosts.map((item) => item.id),
|
||||
removed.length === 1 ? ['extra', 'kept', 'target'] : ['kept', 'target']);
|
||||
assert.deepEqual(committed.hosts.at(-1)?.hostChain, { hostIds: ['kept'] });
|
||||
assert.deepEqual(committed.configs[0], {
|
||||
path: 'prod', username: 'latest-user', hostChain: { hostIds: [] },
|
||||
});
|
||||
assert.equal(committed.snippets, latest.snippets);
|
||||
assert.deepEqual(latest.hosts.at(-1)?.hostChain, { hostIds: ['jump', 'kept'] });
|
||||
});
|
||||
}
|
||||
|
||||
test('a failed group-config write rolls host deletion back and reports failure', async () => {
|
||||
const original = {
|
||||
[STORAGE_KEY_HOSTS]: [host('jump'), host('target', ['jump'])],
|
||||
[STORAGE_KEY_GROUP_CONFIGS]: [{ path: 'prod', hostChain: { hostIds: ['jump'] } }],
|
||||
};
|
||||
const values = new Map(Object.entries(original).map(([key, value]) => [key, JSON.stringify(value)]));
|
||||
const storage = {
|
||||
read: <T,>(key: string): T | null => JSON.parse(values.get(key) ?? 'null'),
|
||||
readString: (key: string) => values.get(key) ?? null,
|
||||
write: <T,>(key: string, value: T) => {
|
||||
if (key === STORAGE_KEY_GROUP_CONFIGS) return false;
|
||||
values.set(key, JSON.stringify(value));
|
||||
return true;
|
||||
},
|
||||
writeString: (key: string, value: string) => { values.set(key, value); return true; },
|
||||
remove: (key: string) => { values.delete(key); },
|
||||
};
|
||||
const identity = async <T,>(value: T) => value;
|
||||
await withDeletion((mutate) => commitVaultGroupMutationPersistence({
|
||||
storage, mutate, prepareState: (value) => value,
|
||||
decryptHosts: identity, decryptConfigs: identity,
|
||||
encryptHosts: identity, encryptConfigs: identity, isCurrent: () => true,
|
||||
}), async (remove) => {
|
||||
await assert.rejects(remove(['jump']), /rejected importer transaction/);
|
||||
});
|
||||
for (const [key, value] of Object.entries(original)) {
|
||||
assert.deepEqual(storage.read(key), value);
|
||||
}
|
||||
});
|
||||
|
||||
test('host deletion reports a rejected or superseded transaction', async () => {
|
||||
for (const failure of [{ ok: false, error: 'unavailable' }, { ok: false, superseded: true }] as const) {
|
||||
await withDeletion(async () => failure, async (remove) => {
|
||||
await assert.rejects(remove(['jump']), /unavailable|superseded/);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1,29 +0,0 @@
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import type { VaultGroupMutationResult, VaultGroupMutationState } from '../../domain/vaultGroupMutation';
|
||||
import { pruneVaultJumpHostReferences } from '../../domain/vaultJumpGraph';
|
||||
|
||||
export function useVaultHostDeletion(
|
||||
commit: (
|
||||
mutate: (current: VaultGroupMutationState) => VaultGroupMutationResult,
|
||||
) => Promise<VaultGroupMutationResult | { ok: false; superseded: true }>,
|
||||
) {
|
||||
return useCallback(async (hostIds: Iterable<string>) => {
|
||||
const removedHostIds = new Set(hostIds);
|
||||
if (removedHostIds.size === 0) return;
|
||||
const result = await commit((current) => {
|
||||
const pruned = pruneVaultJumpHostReferences({
|
||||
hosts: current.hosts.filter((host) => !removedHostIds.has(host.id)),
|
||||
groupConfigs: current.configs,
|
||||
removedHostIds,
|
||||
});
|
||||
return {
|
||||
ok: true,
|
||||
state: { ...current, hosts: pruned.hosts, configs: pruned.groupConfigs },
|
||||
};
|
||||
});
|
||||
if (!result.ok) {
|
||||
throw new Error('error' in result ? result.error : 'Host deletion was superseded. Try again.');
|
||||
}
|
||||
}, [commit]);
|
||||
}
|
||||
@@ -82,10 +82,6 @@ import {
|
||||
import { commitVaultNotesWrite } from "./vaultNotesPersistence";
|
||||
import { rebasePendingVaultNotes } from "../../domain/vaultNotesReconciliation";
|
||||
import { publishShellHistorySnapshot } from "./shellHistoryStore";
|
||||
import {
|
||||
clearHistory as clearAutocompleteHistory,
|
||||
markCommandHistoryCleared,
|
||||
} from "./commandHistoryStore";
|
||||
import { setVaultInitialized } from "./vaultInitStore";
|
||||
import { notify } from "../notification";
|
||||
import {
|
||||
@@ -1254,23 +1250,6 @@ export const useVaultState = () => {
|
||||
publishShellHistorySnapshot([]);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Clear every locally recorded command history: the global shell history, the
|
||||
* terminal autocomplete history, and the in-memory compose-bar recall.
|
||||
*
|
||||
* The autocomplete store persists the clear synchronously and fans it out to
|
||||
* other renderers through its own `storage` listener. The compose-bar store
|
||||
* subscribes to that same clear event, so detached terminal popups drop their
|
||||
* recall too without a separate broadcast.
|
||||
*/
|
||||
const clearAllCommandHistory = useCallback(() => {
|
||||
clearShellHistory();
|
||||
clearAutocompleteHistory();
|
||||
// Tombstone so a later first-time histfile import cannot restore the
|
||||
// commands the user just deleted.
|
||||
markCommandHistoryCleared();
|
||||
}, [clearShellHistory]);
|
||||
|
||||
const removeShellHistoryEntry = useCallback((entryId: string) => {
|
||||
setShellHistory((prev) => {
|
||||
const updated = removeGlobalHistoryEntry(prev, entryId);
|
||||
@@ -2222,7 +2201,6 @@ export const useVaultState = () => {
|
||||
updateGroupConfigs,
|
||||
addShellHistoryEntry,
|
||||
clearShellHistory,
|
||||
clearAllCommandHistory,
|
||||
removeShellHistoryEntry,
|
||||
addConnectionLog,
|
||||
updateConnectionLog,
|
||||
|
||||
@@ -86,7 +86,6 @@ test('vault actions register and unregister', () => {
|
||||
updateHostLastConnected: noop,
|
||||
addShellHistoryEntry: noop,
|
||||
removeShellHistoryEntry: noop,
|
||||
clearAllCommandHistory: noop,
|
||||
});
|
||||
getVaultSnapshotActions()?.updateHosts([]);
|
||||
assert.deepEqual(calls, ['hosts']);
|
||||
|
||||
@@ -63,7 +63,6 @@ export type VaultSnapshotActions = Pick<
|
||||
| 'updateHostLastConnected'
|
||||
| 'addShellHistoryEntry'
|
||||
| 'removeShellHistoryEntry'
|
||||
| 'clearAllCommandHistory'
|
||||
>;
|
||||
|
||||
const EMPTY_HOSTS: readonly Host[] = Object.freeze([]);
|
||||
|
||||
@@ -6,8 +6,6 @@ import {
|
||||
serializeWindowOpacityRecord,
|
||||
shouldApplyWindowOpacityRecord,
|
||||
shouldBroadcastWindowOpacityChange,
|
||||
updateWindowOpacityRecord,
|
||||
toggleWindowOpacityRecord,
|
||||
type WindowOpacityMutationSource,
|
||||
type WindowOpacityRecord,
|
||||
} from './windowOpacitySync.ts';
|
||||
@@ -199,23 +197,3 @@ test('serializeWindowOpacityRecord round-trips through parse', () => {
|
||||
const raw = serializeWindowOpacityRecord({ opacity: 0.55, version: 9 });
|
||||
assert.deepEqual(parseWindowOpacityRecord(JSON.parse(raw)), { opacity: 0.55, version: 9 });
|
||||
});
|
||||
|
||||
test('toggling off and restarting preserves a legacy selected opacity', () => {
|
||||
const selected = parseWindowOpacityRecord('0.6');
|
||||
const opaque = toggleWindowOpacityRecord(selected);
|
||||
assert.equal(opaque.opacity, 1);
|
||||
const restarted = parseWindowOpacityRecord(serializeWindowOpacityRecord(opaque));
|
||||
assert.equal(toggleWindowOpacityRecord(restarted).opacity, 0.6);
|
||||
assert.equal(toggleWindowOpacityRecord(restarted).version, selected.version + 2);
|
||||
});
|
||||
|
||||
test('slider changes replace the preferred opacity and toggles use the latest record', () => {
|
||||
const opaque = toggleWindowOpacityRecord({ opacity: 0.6, version: 2 });
|
||||
const slider = updateWindowOpacityRecord(opaque, 0.7);
|
||||
const next = toggleWindowOpacityRecord(toggleWindowOpacityRecord(slider));
|
||||
assert.equal(next.opacity, 0.7);
|
||||
assert.equal(next.preferredOpacity, 0.7);
|
||||
assert.equal(next.version, 6);
|
||||
assert.equal(updateWindowOpacityRecord(next, 0.7), next);
|
||||
assert.equal(toggleWindowOpacityRecord({ opacity: 1, version: 0 }).opacity, 0.85);
|
||||
});
|
||||
@@ -10,7 +10,6 @@ export type WindowOpacityMutationSource = 'local' | 'incoming';
|
||||
export type WindowOpacityRecord = {
|
||||
opacity: number;
|
||||
version: number;
|
||||
preferredOpacity?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -35,16 +34,12 @@ export function parseWindowOpacityRecord(raw: unknown): WindowOpacityRecord {
|
||||
}
|
||||
|
||||
if (raw && typeof raw === 'object') {
|
||||
const record = raw as { opacity?: unknown; version?: unknown; preferredOpacity?: unknown };
|
||||
const record = raw as { opacity?: unknown; version?: unknown };
|
||||
const opacity = clampWindowOpacity(record.opacity);
|
||||
const version = Number(record.version);
|
||||
const preferred = Number(record.preferredOpacity);
|
||||
return {
|
||||
opacity,
|
||||
version: Number.isFinite(version) && version > 0 ? Math.floor(version) : 0,
|
||||
...(Number.isFinite(preferred) && preferred < 1
|
||||
? { preferredOpacity: clampWindowOpacity(preferred) }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -55,30 +50,9 @@ export function serializeWindowOpacityRecord(record: WindowOpacityRecord): strin
|
||||
return JSON.stringify({
|
||||
opacity: clampWindowOpacity(record.opacity),
|
||||
version: Math.max(0, Math.floor(record.version) || 0),
|
||||
...(record.preferredOpacity !== undefined ? { preferredOpacity: record.preferredOpacity } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Slider changes and temporary toggles share the existing versioned setting. */
|
||||
export function updateWindowOpacityRecord(
|
||||
current: WindowOpacityRecord,
|
||||
nextValue: number,
|
||||
): WindowOpacityRecord {
|
||||
const opacity = clampWindowOpacity(nextValue);
|
||||
if (opacity === current.opacity) return current;
|
||||
const preferredOpacity = opacity < 1 ? opacity
|
||||
: current.opacity < 1 ? current.opacity : current.preferredOpacity;
|
||||
return {
|
||||
opacity,
|
||||
version: current.version + 1,
|
||||
...(preferredOpacity !== undefined ? { preferredOpacity } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export function toggleWindowOpacityRecord(current: WindowOpacityRecord): WindowOpacityRecord {
|
||||
return updateWindowOpacityRecord(current, current.opacity < 1 ? 1 : (current.preferredOpacity ?? 0.85));
|
||||
}
|
||||
|
||||
/**
|
||||
* Incoming peer updates must not clobber a newer local/drag revision.
|
||||
* Equal versions are treated as already-applied (no state thrash).
|
||||
|
||||
@@ -1,337 +0,0 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import type { AISession } from '../infrastructure/ai/types';
|
||||
import type { SyncPayload } from '../domain/sync';
|
||||
import { withSyncReliabilityMeta } from '../domain/syncReliability';
|
||||
import React from 'react';
|
||||
import { act, create, type ReactTestRenderer } from 'react-test-renderer';
|
||||
import { getAgentRuntime } from '../infrastructure/ai/harness/globalAgentRuntime';
|
||||
import { useAIChatStreaming, type UseAIChatStreamingReturn } from './state/useAIChatStreaming';
|
||||
|
||||
const storage = new Map<string, string>();
|
||||
const events = new EventTarget();
|
||||
Object.defineProperty(globalThis, 'localStorage', { configurable: true, value: {
|
||||
getItem: (key: string) => storage.get(key) ?? null,
|
||||
setItem: (key: string, value: string) => storage.set(key, value),
|
||||
removeItem: (key: string) => storage.delete(key),
|
||||
} });
|
||||
Object.defineProperty(globalThis, 'window', { configurable: true, value: events });
|
||||
const keys = await import('../infrastructure/config/storageKeys');
|
||||
const snapshots = await import('./state/aiStateSnapshots');
|
||||
const { getAISessionsSnapshot } = await import('./state/aiSessionsStore');
|
||||
const {
|
||||
buildCloudSyncPayload, buildLocalVaultPayload, collectAiSessionsForSync,
|
||||
applySyncPayload, applyLocalVaultPayload, hasMeaningfulSyncData,
|
||||
setAiSessionsSyncPreference,
|
||||
hasCloudSyncEntityData, hasMeaningfulCloudSyncData, shouldPromptCloudVaultRecovery,
|
||||
} = await import('./syncPayload');
|
||||
|
||||
const vault = { hosts: [], keys: [], identities: [], snippets: [], customGroups: [], knownHosts: [] };
|
||||
const remotePayload = (aiSessions: AISession[]): SyncPayload => ({ ...vault, aiSessions, syncedAt: 1 });
|
||||
const session = (): AISession => ({
|
||||
id: 'chat', title: 'Chat', agentId: 'catty', scope: { type: 'global' }, createdAt: 1, updatedAt: 2,
|
||||
messages: [{ id: 'message', role: 'user', content: 'Inspect', timestamp: 1, attachments: [{
|
||||
filename: 'terminal.log', mediaType: 'text/plain', terminalSelection: true,
|
||||
base64Data: 'cHJpdmF0ZQ==', previewText: 'private', filePath: '/private/device/file', lineCount: 1,
|
||||
}] }],
|
||||
});
|
||||
function save(sessions: AISession[], enabled = true) {
|
||||
snapshots.setLatestAISessionsSnapshot(sessions);
|
||||
storage.set(keys.STORAGE_KEY_AI_SESSIONS, JSON.stringify(sessions));
|
||||
storage.set(keys.STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS, JSON.stringify({ enabled }));
|
||||
}
|
||||
test.beforeEach(() => { storage.clear(); save([], false); });
|
||||
|
||||
test('actual manual upload and auto collector honor consent and explicit empty', async () => {
|
||||
save([session()], false);
|
||||
const options = { collectPluginSidecars: () => undefined };
|
||||
assert.equal((await buildCloudSyncPayload(vault, [], options)).aiSessions, undefined);
|
||||
assert.equal(collectAiSessionsForSync(), undefined);
|
||||
save([], true);
|
||||
assert.deepEqual((await buildCloudSyncPayload(vault, [], options)).aiSessions, []);
|
||||
assert.deepEqual(collectAiSessionsForSync(), []);
|
||||
save([session()], true);
|
||||
const cloud = await buildCloudSyncPayload(vault, [], options);
|
||||
assert.equal(cloud.aiSessions?.length, 1);
|
||||
assert.deepEqual(cloud.aiSessions, collectAiSessionsForSync());
|
||||
assert.equal(JSON.stringify(cloud).includes('cHJpdmF0ZQ=='), false);
|
||||
assert.equal(JSON.stringify(cloud).includes('/private/device/file'), false);
|
||||
assert.equal(JSON.stringify(cloud.aiSessions?.[0].messages[0].attachments).includes('private'), false);
|
||||
});
|
||||
|
||||
test('sync persistence survives restart beyond the local-only history limits', () => {
|
||||
const many = Array.from({ length: 51 }, (_, index) => ({ ...session(), id: `chat-${index}`, updatedAt: index,
|
||||
messages: Array.from({ length: 201 }, (_, turn) => ({ id: `m-${turn}`, role: 'user' as const, content: 'History', timestamp: turn })) }));
|
||||
save(many);
|
||||
assert.equal(snapshots.writeSessionsForStorage(many), true);
|
||||
assert.equal(collectAiSessionsForSync()?.length, 51);
|
||||
snapshots.setLatestAISessionsSnapshot(null as unknown as AISession[]);
|
||||
const afterRestart = collectAiSessionsForSync()!;
|
||||
assert.equal(afterRestart.length, 51);
|
||||
assert.equal(afterRestart[0].messages.length, 201);
|
||||
save(many, false);
|
||||
assert.equal(snapshots.writeSessionsForStorage(many), true);
|
||||
const localOnly = JSON.parse(storage.get(keys.STORAGE_KEY_AI_SESSIONS)!);
|
||||
assert.equal(localOnly.length, 50);
|
||||
assert.equal(localOnly[0].messages.length, 200);
|
||||
});
|
||||
|
||||
test('failed history persistence refuses upload without pruning the cloud representation', async () => {
|
||||
save([session()]);
|
||||
const original = globalThis.localStorage.setItem;
|
||||
globalThis.localStorage.setItem = (key, value) => {
|
||||
if (key === keys.STORAGE_KEY_AI_SESSIONS) throw new DOMException('Full', 'QuotaExceededError');
|
||||
original(key, value);
|
||||
};
|
||||
snapshots.setLatestAISessionsSnapshot([{ ...session(), title: 'Unsaved change' }]);
|
||||
try {
|
||||
await assert.rejects(buildCloudSyncPayload(vault, [], { collectPluginSidecars: () => undefined }), /persist|save/i);
|
||||
assert.equal(JSON.parse(storage.get(keys.STORAGE_KEY_AI_SESSIONS)!)[0].title, 'Chat');
|
||||
const backup = buildLocalVaultPayload(vault);
|
||||
assert.equal(backup.aiSessions?.[0].title, 'Unsaved change');
|
||||
assert.equal(backup.aiSessions?.[0].messages[0].attachments?.[0].base64Data, 'cHJpdmF0ZQ==');
|
||||
} finally { globalThis.localStorage.setItem = original; }
|
||||
});
|
||||
|
||||
test('failed opt-in preference commit leaves local chats and native threads untouched', async () => {
|
||||
const local = { ...session(), externalSessionId: 'native-thread' };
|
||||
save([local], false);
|
||||
const original = globalThis.localStorage.setItem;
|
||||
const cleanups: string[] = [];
|
||||
Object.assign(window, { netcatty: { aiSdkAgentCleanup: async (id: string) => { cleanups.push(id); return { ok: true }; } } });
|
||||
globalThis.localStorage.setItem = (key, value) => {
|
||||
if (key === keys.STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS) throw new DOMException('Full', 'QuotaExceededError');
|
||||
original(key, value);
|
||||
};
|
||||
const incoming = { ...session(), updatedAt: 3, messages: [...session().messages,
|
||||
{ id: 'remote', role: 'assistant' as const, content: 'Remote turn', timestamp: 3 }] };
|
||||
try {
|
||||
await assert.rejects(setAiSessionsSyncPreference(true, async () => [remotePayload([incoming])]), /preference|enable/i);
|
||||
assert.deepEqual(snapshots.latestAISessionsSnapshot, [local]);
|
||||
assert.deepEqual(JSON.parse(storage.get(keys.STORAGE_KEY_AI_SESSIONS)!), [local]);
|
||||
assert.deepEqual(cleanups, []);
|
||||
assert.equal(JSON.parse(storage.get(keys.STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS)!).enabled, false);
|
||||
} finally { globalThis.localStorage.setItem = original; delete (window as unknown as { netcatty?: unknown }).netcatty; }
|
||||
});
|
||||
|
||||
test('local backup retains chat and attachment bytes with cloud consent off', async () => {
|
||||
const local = session();
|
||||
save([local], false);
|
||||
const backup = buildLocalVaultPayload(vault);
|
||||
assert.deepEqual(backup.aiSessions, [local]);
|
||||
assert.equal(hasMeaningfulSyncData({ ...vault, aiSessions: [local], syncedAt: 1 }), true);
|
||||
save([], false);
|
||||
await applyLocalVaultPayload(backup, { importVaultData: () => undefined }, {
|
||||
prepareConvergentRestore: async () => async () => {},
|
||||
});
|
||||
assert.equal(getAISessionsSnapshot().sessions[0].messages[0].attachments?.[0].base64Data, 'cHJpdmF0ZQ==');
|
||||
});
|
||||
|
||||
test('chat-only data is syncable but does not suppress empty-vault recovery', () => {
|
||||
const local = { ...vault, aiSessions: [session()], syncedAt: 1 };
|
||||
assert.equal(hasMeaningfulCloudSyncData(local), true);
|
||||
assert.equal(hasCloudSyncEntityData(local), false);
|
||||
const host = { id: 'remote', label: 'Remote', hostname: 'remote.example', username: 'test', port: 22, protocol: 'ssh' as const, tags: [], os: 'linux' as const };
|
||||
for (const hosts of [[host], [host, { ...host, id: 'second' }]]) {
|
||||
assert.equal(shouldPromptCloudVaultRecovery(local, { ...vault, hosts, syncedAt: 2 }), true);
|
||||
}
|
||||
assert.equal(shouldPromptCloudVaultRecovery({ ...vault, syncedAt: 1 }, local), false);
|
||||
});
|
||||
|
||||
test('download publishes immediately and keeps local attachment bytes on a newer message', async () => {
|
||||
save([session()]);
|
||||
const incoming = session();
|
||||
incoming.updatedAt = 3;
|
||||
incoming.messages[0].content = 'Updated';
|
||||
incoming.messages[0].attachments = [{ base64Data: '', mediaType: 'text/plain', filename: 'terminal.log', terminalSelection: true, contentUnavailable: true }];
|
||||
const payload: SyncPayload = { ...vault, aiSessions: [incoming], syncedAt: 2 };
|
||||
await applySyncPayload(payload, { importVaultData: () => undefined });
|
||||
const current = getAISessionsSnapshot().sessions[0];
|
||||
assert.equal(current.messages[0].content, 'Updated');
|
||||
assert.equal(current.messages[0].attachments?.[0].base64Data, 'cHJpdmF0ZQ==');
|
||||
assert.equal(snapshots.latestAISessionsSnapshot?.[0], current);
|
||||
assert.equal(JSON.parse(storage.get(keys.STORAGE_KEY_AI_SESSIONS)!)[0].messages[0].content, 'Updated');
|
||||
});
|
||||
|
||||
test('restoring an old backup without chat leaves current chats alone', async () => {
|
||||
const local = session();
|
||||
save([local], false);
|
||||
await applyLocalVaultPayload({ ...vault, syncedAt: 1 }, { importVaultData: () => undefined }, {
|
||||
prepareConvergentRestore: async () => async () => {},
|
||||
});
|
||||
assert.deepEqual(snapshots.latestAISessionsSnapshot, [local]);
|
||||
assert.deepEqual(JSON.parse(storage.get(keys.STORAGE_KEY_AI_SESSIONS)!), [local]);
|
||||
});
|
||||
|
||||
test('authoritative cloud session removal stays removed in the next upload', async () => {
|
||||
save([session()]);
|
||||
await applySyncPayload({ ...vault, aiSessions: [], syncedAt: 3 }, { importVaultData: () => undefined });
|
||||
assert.deepEqual(getAISessionsSnapshot().sessions, []);
|
||||
assert.deepEqual(collectAiSessionsForSync(), []);
|
||||
assert.deepEqual((await buildCloudSyncPayload(vault, [], { collectPluginSidecars: () => undefined })).aiSessions, []);
|
||||
});
|
||||
|
||||
test('replacement stops active turns and waits for finalizers before persisting history', async (context) => {
|
||||
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
||||
let hook: UseAIChatStreamingReturn;
|
||||
function Harness() {
|
||||
hook = useAIChatStreaming({ maxIterations: 1, addMessageToSession: () => {}, updateLastMessage: () => {}, updateMessageById: () => {} });
|
||||
return null;
|
||||
}
|
||||
let renderer: ReactTestRenderer;
|
||||
await act(async () => { renderer = create(React.createElement(Harness)); });
|
||||
const original = globalThis.localStorage.setItem;
|
||||
try {
|
||||
for (const remove of [false, true]) {
|
||||
const order: string[] = [];
|
||||
const controller = new AbortController();
|
||||
const local = { ...session(), messages: [...session().messages,
|
||||
{ id: 'reply', role: 'assistant' as const, content: 'Partial', timestamp: 2, executionStatus: 'running' as const }] };
|
||||
save([local]);
|
||||
hook!.abortControllersRef.current.set('chat', controller);
|
||||
await act(async () => { hook!.setStreamingForScope('chat', true); });
|
||||
Object.assign(window, { netcatty: {
|
||||
aiCattyCancelExec: async () => { order.push('cancel'); },
|
||||
aiSdkAgentCancel: async () => ({ ok: true }),
|
||||
aiSdkAgentCleanup: async () => { order.push('cleanup'); return { ok: true }; },
|
||||
} });
|
||||
const wait = context.mock.method(getAgentRuntime(), 'waitForActiveTurn', async () => {
|
||||
assert.equal(controller.signal.aborted, true);
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
snapshots.setLatestAISessionsSnapshot([{ ...local, messages: [local.messages[0],
|
||||
{ ...local.messages[1], content: 'Settled', executionStatus: 'cancelled' }] }]);
|
||||
order.push('settled');
|
||||
});
|
||||
globalThis.localStorage.setItem = (key, value) => { if (key === keys.STORAGE_KEY_AI_SESSIONS) order.push('persist'); original(key, value); };
|
||||
const incoming = { ...session(), updatedAt: 3, messages: [...session().messages,
|
||||
{ id: 'remote', role: 'user' as const, content: 'Remote', timestamp: 3 }] };
|
||||
await applySyncPayload(remotePayload(remove ? [] : [incoming]), { importVaultData: () => undefined });
|
||||
assert.ok(order.indexOf('cancel') < order.indexOf('settled'));
|
||||
assert.ok(order.indexOf('settled') < order.indexOf('persist'));
|
||||
assert.ok(order.indexOf('persist') < order.indexOf('cleanup'));
|
||||
assert.equal(hook!.abortControllersRef.current.has('chat'), false);
|
||||
if (remove) assert.deepEqual(getAISessionsSnapshot().sessions, []);
|
||||
else assert.ok(getAISessionsSnapshot().sessions[0].messages.some(message => message.content === 'Settled'));
|
||||
wait.mock.restore();
|
||||
globalThis.localStorage.setItem = original;
|
||||
await act(async () => { hook!.setStreamingForScope('chat', false); });
|
||||
}
|
||||
} finally {
|
||||
context.mock.restoreAll(); globalThis.localStorage.setItem = original;
|
||||
delete (window as unknown as { netcatty?: unknown }).netcatty;
|
||||
await act(async () => { renderer!.unmount(); });
|
||||
}
|
||||
});
|
||||
|
||||
test('local restore replaces later sessions and later turns with the backup snapshot', async () => {
|
||||
const backedUp = session();
|
||||
const later = { ...session(), updatedAt: 3, messages: [...session().messages,
|
||||
{ id: 'later', role: 'assistant' as const, content: 'After backup', timestamp: 3 }] };
|
||||
save([later, { ...session(), id: 'created-after-backup' }]);
|
||||
await applyLocalVaultPayload({ ...vault, aiSessions: [backedUp], syncedAt: 1 }, { importVaultData: () => undefined }, {
|
||||
prepareConvergentRestore: async () => async () => {},
|
||||
});
|
||||
assert.deepEqual(getAISessionsSnapshot().sessions, [backedUp]);
|
||||
await applyLocalVaultPayload({ ...vault, aiSessions: [], syncedAt: 1 }, { importVaultData: () => undefined }, {
|
||||
prepareConvergentRestore: async () => async () => {},
|
||||
});
|
||||
assert.deepEqual(getAISessionsSnapshot().sessions, []);
|
||||
});
|
||||
|
||||
test('cloud downloads respect local chat opt-in while still applying vault data', async () => {
|
||||
save([], false);
|
||||
let vaultImports = 0;
|
||||
const downloaded = { ...vault, aiSessions: [session()], syncedAt: 2 };
|
||||
await applySyncPayload(downloaded, { importVaultData: () => { vaultImports++; } });
|
||||
assert.equal(vaultImports, 1);
|
||||
assert.deepEqual(snapshots.latestAISessionsSnapshot, []);
|
||||
assert.deepEqual(JSON.parse(storage.get(keys.STORAGE_KEY_AI_SESSIONS)!), []);
|
||||
save([], true);
|
||||
await applySyncPayload(downloaded, { importVaultData: () => { vaultImports++; } });
|
||||
assert.equal(vaultImports, 2);
|
||||
assert.equal(snapshots.latestAISessionsSnapshot?.[0].id, 'chat');
|
||||
});
|
||||
|
||||
test('enabling sync imports existing cloud chats before an empty local list can be uploaded', async () => {
|
||||
save([], false);
|
||||
let loads = 0;
|
||||
await setAiSessionsSyncPreference(true, async () => {
|
||||
loads++;
|
||||
assert.equal(collectAiSessionsForSync(), undefined);
|
||||
return [remotePayload([session()])];
|
||||
});
|
||||
assert.equal(loads, 1);
|
||||
assert.equal(collectAiSessionsForSync()?.[0].id, 'chat');
|
||||
assert.equal(getAISessionsSnapshot().sessions[0].id, 'chat');
|
||||
await setAiSessionsSyncPreference(false, async () => { throw new Error('Disable must not load'); });
|
||||
assert.equal(collectAiSessionsForSync(), undefined);
|
||||
});
|
||||
|
||||
test('an unsuccessful initial cloud read leaves chat sync disabled and local history unchanged', async () => {
|
||||
save([], false);
|
||||
await assert.rejects(setAiSessionsSyncPreference(true, async () => { throw new Error('offline'); }), /offline/);
|
||||
assert.equal(collectAiSessionsForSync(), undefined);
|
||||
assert.deepEqual(snapshots.latestAISessionsSnapshot, []);
|
||||
});
|
||||
|
||||
test('enabling from multiple mirrored providers retains the newer turns from either copy', async () => {
|
||||
save([], false);
|
||||
const newer = session();
|
||||
newer.updatedAt = 3;
|
||||
newer.messages.push({ id: 'new-turn', role: 'assistant', content: 'Newer provider turn', timestamp: 3 });
|
||||
await setAiSessionsSyncPreference(true, async () => [remotePayload([newer]), remotePayload([session()])]);
|
||||
assert.deepEqual(collectAiSessionsForSync()?.[0].messages.map((message) => message.id), ['message', 'new-turn']);
|
||||
});
|
||||
|
||||
test('initial enable retains local-only chats but respects remote deletions and preservation', async () => {
|
||||
const localOnly = { ...session(), id: 'local-only' };
|
||||
save([localOnly], false);
|
||||
await setAiSessionsSyncPreference(true, async () => [remotePayload([session()])]);
|
||||
assert.deepEqual(collectAiSessionsForSync()?.map(item => item.id).sort(), ['chat', 'local-only']);
|
||||
const removed = withSyncReliabilityMeta(remotePayload([]), remotePayload([session()]), { now: 3 });
|
||||
for (const preserve of [false, true]) {
|
||||
save([session(), localOnly], false);
|
||||
await setAiSessionsSyncPreference(true, async () => [removed, remotePayload([session()])], preserve);
|
||||
assert.deepEqual(collectAiSessionsForSync()?.map(item => item.id).sort(), preserve ? ['chat', 'local-only'] : ['local-only']);
|
||||
}
|
||||
});
|
||||
|
||||
test('backup rollback resets the native thread that still contains later turns', async () => {
|
||||
const cleanups: string[] = [];
|
||||
Object.assign(window, { netcatty: { aiSdkAgentCleanup: async (id: string) => { cleanups.push(id); return { ok: true }; } } });
|
||||
const backedUp = { ...session(), agentId: 'codex', externalSessionId: 'native-thread' };
|
||||
save([{ ...backedUp, updatedAt: 4, messages: [...backedUp.messages,
|
||||
{ id: 'later', role: 'assistant', content: 'After backup', timestamp: 4 }] }]);
|
||||
await applyLocalVaultPayload(remotePayload([backedUp]), { importVaultData: () => undefined }, {
|
||||
prepareConvergentRestore: async () => async () => {},
|
||||
});
|
||||
const restored = getAISessionsSnapshot().sessions[0];
|
||||
assert.equal(restored.externalSessionId, undefined);
|
||||
assert.deepEqual(restored.messages, backedUp.messages);
|
||||
assert.deepEqual(cleanups, ['chat']);
|
||||
delete (window as unknown as { netcatty?: unknown }).netcatty;
|
||||
});
|
||||
|
||||
test('cloud restore never resumes a source device SDK thread, and preserves matching local threads', async () => {
|
||||
const local = { ...session(), externalSessionId: 'local-native-thread' };
|
||||
save([local]);
|
||||
const incoming = { ...session(), updatedAt: 3, externalSessionId: 'remote-native-thread' };
|
||||
const fresh = { ...incoming, id: 'new-chat' };
|
||||
await applySyncPayload({ ...vault, aiSessions: [incoming, fresh], syncedAt: 2 }, { importVaultData: () => undefined });
|
||||
const current = getAISessionsSnapshot().sessions;
|
||||
assert.equal(current.find((s) => s.id === 'chat')?.externalSessionId, 'local-native-thread');
|
||||
assert.equal(current.find((s) => s.id === 'new-chat')?.externalSessionId, undefined);
|
||||
});
|
||||
|
||||
test('changed remote transcript resets the local native SDK thread before continuing', async () => {
|
||||
const cleanups: string[] = [];
|
||||
Object.assign(window, { netcatty: { aiSdkAgentCleanup: async (id: string) => { cleanups.push(id); return { ok: true }; } } });
|
||||
save([{ ...session(), agentId: 'codex', externalSessionId: 'local-native-thread' }]);
|
||||
const incoming = { ...session(), agentId: 'codex', updatedAt: 3, externalSessionId: 'remote-native-thread' };
|
||||
incoming.messages.push({ id: 'remote-turn', role: 'user', content: 'Added on another device', timestamp: 3 });
|
||||
await applySyncPayload({ ...vault, aiSessions: [incoming], syncedAt: 2 }, { importVaultData: () => undefined });
|
||||
assert.deepEqual(cleanups, ['chat']);
|
||||
assert.equal(getAISessionsSnapshot().sessions[0].externalSessionId, undefined);
|
||||
assert.equal(getAISessionsSnapshot().sessions[0].messages.at(-1)?.content, 'Added on another device');
|
||||
delete (window as unknown as { netcatty?: unknown }).netcatty;
|
||||
});
|
||||
+15
-149
@@ -46,14 +46,6 @@ import { localStorageAdapter } from '../infrastructure/persistence/localStorageA
|
||||
import { decryptField, encryptField } from '../infrastructure/persistence/secureFieldAdapter';
|
||||
import { sanitizeQuickMessages } from '../infrastructure/ai/quickMessages';
|
||||
import { emitAIStateChanged } from './state/aiStateEvents';
|
||||
import {
|
||||
latestAISessionsSnapshot,
|
||||
setLatestAISessionsSnapshot,
|
||||
writeSessionsForStorage,
|
||||
cleanupSdkAgentSessions,
|
||||
cleanupDeletedAIChatSessions,
|
||||
} from './state/aiStateSnapshots';
|
||||
import { getAISessionsSnapshot, publishAISessionsSnapshot } from './state/aiSessionsStore';
|
||||
import {
|
||||
persistCommandBlocklistSetting,
|
||||
readCommandBlocklistSetting,
|
||||
@@ -72,7 +64,6 @@ import {
|
||||
import { isValidHslToken } from './state/settingsStateDefaults';
|
||||
import {
|
||||
STORAGE_KEY_TERM_AUTO_CLOSE_EXIT_MIGRATED,
|
||||
STORAGE_KEY_VAULT_RESTORE_IN_PROGRESS_UNTIL,
|
||||
STORAGE_KEY_THEME,
|
||||
STORAGE_KEY_UI_THEME_LIGHT,
|
||||
STORAGE_KEY_UI_THEME_DARK,
|
||||
@@ -134,10 +125,7 @@ import {
|
||||
STORAGE_KEY_VAULT_NOTES_FONT_FAMILY,
|
||||
STORAGE_KEY_VAULT_NOTES_FONT_SIZE,
|
||||
STORAGE_KEY_VAULT_NOTES_CODE_FONT_SIZE,
|
||||
STORAGE_KEY_AI_SESSIONS,
|
||||
STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS,
|
||||
} from '../infrastructure/config/storageKeys';
|
||||
import { mergeAiSessionLists, mergeSyncPayloads, stripAiSessionDeviceState, stripAiSessionPayloadForSync } from '../domain/syncMerge';
|
||||
import { isTerminalSidePanelAutoOpenTab } from '../domain/terminalSidePanelAutoOpen';
|
||||
import { prepareRestoredPayloadConvergentWrites } from './convergentSyncReplica';
|
||||
|
||||
@@ -183,7 +171,6 @@ function hasMeaningfulPluginSidecars(payload: SyncPayload): boolean {
|
||||
*/
|
||||
export function hasMeaningfulSyncData(payload: SyncPayload): boolean {
|
||||
if (hasSyncPayloadEntityData(payload, SYNC_PAYLOAD_ENTITY_KEYS)) return true;
|
||||
if (Array.isArray(payload.aiSessions) && payload.aiSessions.length > 0) return true;
|
||||
|
||||
if (
|
||||
payload.settings && Object.values(payload.settings).some((value) => value !== undefined)
|
||||
@@ -213,11 +200,11 @@ export function hasMeaningfulCloudSyncData(payload: SyncPayload): boolean {
|
||||
|
||||
/**
|
||||
* Returns true only when the payload contains synced vault entities.
|
||||
* Settings and chat history are ignored: neither proves that the vault's
|
||||
* hosts and keys survived local data loss.
|
||||
* Settings are intentionally ignored so default settings written on first
|
||||
* launch do not make a new device look non-empty during cloud restore checks.
|
||||
*/
|
||||
export function hasCloudSyncEntityData(payload: SyncPayload): boolean {
|
||||
return hasSyncPayloadEntityData(payload, CLOUD_SYNC_PAYLOAD_ENTITY_KEYS.filter((key) => key !== 'aiSessions'));
|
||||
return hasSyncPayloadEntityData(payload, CLOUD_SYNC_PAYLOAD_ENTITY_KEYS);
|
||||
}
|
||||
|
||||
export function shouldPromptCloudVaultRecovery(
|
||||
@@ -1042,40 +1029,15 @@ function pruneOrphanPerAgentBindings(): void {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* AI chat sessions only leave the device when the user opted in.
|
||||
* Attachments are stripped — see {@link stripAiSessionPayloadForSync}.
|
||||
* Build a complete `SyncPayload` from local data.
|
||||
*
|
||||
* Port-forwarding rules are optional because they are managed by a separate
|
||||
* state hook (`usePortForwardingState`). Callers should strip transient
|
||||
* runtime fields (status, error, lastUsedAt) before passing them in.
|
||||
*/
|
||||
export function collectAiSessionsForSync(): SyncPayload['aiSessions'] {
|
||||
const enabled = localStorageAdapter.read<{ enabled?: boolean }>(STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS);
|
||||
if (enabled?.enabled !== true) return undefined;
|
||||
const sessions = collectLocalAiSessions();
|
||||
if (!writeSessionsForStorage(sessions)) {
|
||||
throw new Error('Unable to persist chat history for cloud sync');
|
||||
}
|
||||
return stripAiSessionPayloadForSync(sessions);
|
||||
}
|
||||
|
||||
function collectLocalAiSessions(): NonNullable<SyncPayload['aiSessions']> {
|
||||
return latestAISessionsSnapshot
|
||||
?? localStorageAdapter.read<SyncPayload['aiSessions']>(STORAGE_KEY_AI_SESSIONS)
|
||||
?? [];
|
||||
}
|
||||
|
||||
/** Build the portable payload; device-local data is added by the backup builder. */
|
||||
export function buildSyncPayload(
|
||||
vault: SyncableVaultData,
|
||||
portForwardingRules?: PortForwardingRule[],
|
||||
): SyncPayload {
|
||||
const aiSessions = collectAiSessionsForSync();
|
||||
return {
|
||||
...buildVaultSyncPayload(vault, portForwardingRules),
|
||||
...(aiSessions !== undefined ? { aiSessions } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function buildVaultSyncPayload(
|
||||
vault: SyncableVaultData,
|
||||
portForwardingRules?: PortForwardingRule[],
|
||||
): SyncPayload {
|
||||
return {
|
||||
hosts: sanitizeHostsForSync(vault.hosts),
|
||||
@@ -1162,7 +1124,6 @@ export async function buildCloudSyncPayload(
|
||||
collectPluginSidecars?: PluginSyncSidecarCollector;
|
||||
},
|
||||
): Promise<SyncPayload> {
|
||||
const aiSessions = collectAiSessionsForSync();
|
||||
const base: SyncPayload = {
|
||||
hosts: sanitizeHostsForSync(vault.hosts),
|
||||
keys: vault.keys,
|
||||
@@ -1175,7 +1136,6 @@ export async function buildCloudSyncPayload(
|
||||
noteGroups: vault.noteGroups,
|
||||
groupConfigs: vault.groupConfigs,
|
||||
portForwardingRules: sanitizePortForwardingRulesForSync(portForwardingRules),
|
||||
...(aiSessions !== undefined ? { aiSessions } : {}),
|
||||
settings: await collectCloudSyncableSettings(),
|
||||
syncedAt: Date.now(),
|
||||
};
|
||||
@@ -1190,13 +1150,11 @@ export function buildLocalVaultPayload(
|
||||
portForwardingRules?: PortForwardingRule[],
|
||||
): SyncPayload {
|
||||
const base: SyncPayload = {
|
||||
...buildVaultSyncPayload(vault, portForwardingRules),
|
||||
...buildSyncPayload(vault, portForwardingRules),
|
||||
// Keep device-local recent-connection timestamps in protective backups.
|
||||
hosts: vault.hosts,
|
||||
settings: collectLocalBackupSettings(),
|
||||
knownHosts: vault.knownHosts,
|
||||
// Cloud consent and cloud attachment stripping do not apply to local backups.
|
||||
aiSessions: collectLocalAiSessions(),
|
||||
};
|
||||
// Protective backups must capture plugin sidecars so restore can recover
|
||||
// plugin settings/baselines. Prefer the last successful host collect cache
|
||||
@@ -1249,96 +1207,12 @@ export async function buildLocalVaultPayloadAsync(
|
||||
return base;
|
||||
}
|
||||
|
||||
/** Merge downloaded chat data through the existing state and persistence boundary. */
|
||||
async function applyAiSessionData(sessions: NonNullable<SyncPayload['aiSessions']>, includeLocalOnlyData: boolean): Promise<void> {
|
||||
const incoming = includeLocalOnlyData
|
||||
? sessions
|
||||
: sessions.map(stripAiSessionDeviceState);
|
||||
const incomingIds = new Set(incoming.map((session) => session.id));
|
||||
const incomingById = new Map(incoming.map((session) => [session.id, session]));
|
||||
const portableMessages = (value: typeof incoming[number]) => stripAiSessionPayloadForSync([value])[0].messages;
|
||||
const affectedIds = collectLocalAiSessions().filter((local) => {
|
||||
const next = incomingById.get(local.id);
|
||||
if (!next) return true;
|
||||
const candidate = includeLocalOnlyData ? next : mergeAiSessionLists([local], [next])[0];
|
||||
return JSON.stringify(portableMessages(local)) !== JSON.stringify(portableMessages(candidate));
|
||||
}).map((session) => session.id);
|
||||
if (affectedIds.length > 0) {
|
||||
const { stopAIChatSessionBeforeReplacement } = await import('./state/useAIChatStreaming');
|
||||
await Promise.all(affectedIds.map(stopAIChatSessionBeforeReplacement));
|
||||
}
|
||||
// Stop finalizers can finish the last local message. Read it again before
|
||||
// merging so the stopped turn cannot write into a replaced/deleted session.
|
||||
const localSessions = collectLocalAiSessions();
|
||||
const localById = new Map(localSessions.map((session) => [session.id, session]));
|
||||
const removedIds = localSessions.filter((session) => !incomingIds.has(session.id)).map((session) => session.id);
|
||||
const resetSdkSessions: string[] = [];
|
||||
// The sync merge has already decided which session IDs survive. Backups
|
||||
// restore their exact transcript; cloud survivors still retain local turns.
|
||||
const candidates = includeLocalOnlyData ? incoming
|
||||
: mergeAiSessionLists(localSessions.filter((session) => incomingIds.has(session.id)), incoming);
|
||||
const mergedSessions = candidates.map((session) => {
|
||||
// Native SDK threads belong to this device. Reuse the local thread
|
||||
// only while it already contains the entire merged transcript.
|
||||
const local = localById.get(session.id);
|
||||
const transcriptChanged = local
|
||||
&& JSON.stringify(portableMessages(local)) !== JSON.stringify(portableMessages(session));
|
||||
if (transcriptChanged) resetSdkSessions.push(session.id);
|
||||
const { externalSessionId: _remoteThread, ...portable } = session;
|
||||
return local?.externalSessionId && !transcriptChanged
|
||||
? { ...portable, externalSessionId: local.externalSessionId }
|
||||
: portable;
|
||||
});
|
||||
if (!writeSessionsForStorage(mergedSessions)) {
|
||||
throw new Error('Unable to save downloaded AI chat history');
|
||||
}
|
||||
cleanupDeletedAIChatSessions(removedIds);
|
||||
await cleanupSdkAgentSessions(resetSdkSessions);
|
||||
setLatestAISessionsSnapshot(mergedSessions);
|
||||
publishAISessionsSnapshot({ ...getAISessionsSnapshot(), sessions: mergedSessions });
|
||||
emitAIStateChanged(STORAGE_KEY_AI_SESSIONS);
|
||||
}
|
||||
|
||||
/** Read existing cloud chats before an enabled empty local list can overwrite them. */
|
||||
export async function setAiSessionsSyncPreference(
|
||||
enabled: boolean,
|
||||
loadRemotePayloads: () => Promise<SyncPayload[]>,
|
||||
preserveDeletions = false,
|
||||
): Promise<void> {
|
||||
const wasEnabled = localStorageAdapter.read<{ enabled?: boolean }>(STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS)?.enabled === true;
|
||||
if (enabled && !wasEnabled) {
|
||||
const remotes = await loadRemotePayloads();
|
||||
// Reuse the ordinary no-base deletion rules, including cloud tombstones,
|
||||
// while retaining local-only chats when this is a first-time opt-in.
|
||||
const local: SyncPayload = { hosts: [], keys: [], identities: [], snippets: [], customGroups: [],
|
||||
aiSessions: collectLocalAiSessions(), syncedAt: 0 };
|
||||
const merged = remotes.reduce((current, remote) =>
|
||||
mergeSyncPayloads(null, current, remote, { preserveDeletions }).payload, local);
|
||||
const previous = localStorageAdapter.readString(STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS);
|
||||
const { withRestoreBarrier } = await import('./localVaultBackups');
|
||||
await withRestoreBarrier(async () => {
|
||||
if ((localStorageAdapter.readNumber(STORAGE_KEY_VAULT_RESTORE_IN_PROGRESS_UNTIL) ?? 0) <= Date.now()) {
|
||||
throw new Error('Unable to pause sync while enabling chat history');
|
||||
}
|
||||
if (!localStorageAdapter.write(STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS, { enabled })) {
|
||||
throw new Error('Unable to save the chat sync preference');
|
||||
}
|
||||
try {
|
||||
await applyAiSessionData(merged.aiSessions ?? [], false);
|
||||
} catch (error) {
|
||||
if (previous === null) localStorageAdapter.remove(STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS);
|
||||
else localStorageAdapter.writeString(STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS, previous);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!localStorageAdapter.write(STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS, { enabled })) {
|
||||
throw new Error('Unable to save the chat sync preference');
|
||||
}
|
||||
}
|
||||
|
||||
/** Apply downloaded vault data and supported settings through their state boundaries. */
|
||||
/**
|
||||
* Apply a downloaded `SyncPayload` to local state via the provided importers.
|
||||
*
|
||||
* This ensures both vault data and port-forwarding rules are imported
|
||||
* consistently across windows.
|
||||
*/
|
||||
async function preparePayloadApply(
|
||||
payload: SyncPayload,
|
||||
importers: SyncPayloadImporters,
|
||||
@@ -1401,14 +1275,6 @@ async function preparePayloadApply(
|
||||
importers.importPortForwardingRules(sanitizedPayload.portForwardingRules);
|
||||
}
|
||||
|
||||
// AI chat sessions merge append-only: a cloud snapshot may be missing
|
||||
// turns that only exist on this device, so union instead of replace.
|
||||
const applyAiSessions = options.includeLocalOnlyData
|
||||
|| localStorageAdapter.read<{ enabled?: boolean }>(STORAGE_KEY_CLOUD_SYNC_AI_SESSIONS)?.enabled === true;
|
||||
if (applyAiSessions && Array.isArray(sanitizedPayload.aiSessions)) {
|
||||
await applyAiSessionData(sanitizedPayload.aiSessions, options.includeLocalOnlyData);
|
||||
}
|
||||
|
||||
// Apply synced settings
|
||||
if (sanitizedPayload.settings) {
|
||||
await applySyncableSettings(sanitizedPayload.settings, preparedProviders);
|
||||
|
||||
@@ -73,10 +73,6 @@ interface AIChatPanelContentProps {
|
||||
modelCatalogWarning?: string;
|
||||
/** Live SDK model catalog is loading (no built-in presets to show yet). */
|
||||
modelCatalogLoading?: boolean;
|
||||
/** Provenance of the active model list, rendered as the picker status chip. */
|
||||
modelCatalogSource?: 'live' | 'last-known-good' | 'presets';
|
||||
/** ISO timestamp of the successful fetch backing `modelCatalogSource`. */
|
||||
modelCatalogFetchedAt?: string;
|
||||
/** Retry a failed SDK model catalog load from the warning banner. */
|
||||
handleModelCatalogRetry?: () => void;
|
||||
agentModelPresets: AgentModelPreset[];
|
||||
@@ -157,8 +153,6 @@ export const AIChatPanelContent: React.FC<AIChatPanelContentProps> = ({
|
||||
modelDisplayName,
|
||||
modelCatalogWarning,
|
||||
modelCatalogLoading = false,
|
||||
modelCatalogSource,
|
||||
modelCatalogFetchedAt,
|
||||
agentModelPresets,
|
||||
allowCustomModelEntry = true,
|
||||
selectedAgentModel,
|
||||
@@ -409,8 +403,6 @@ export const AIChatPanelContent: React.FC<AIChatPanelContentProps> = ({
|
||||
agentName={currentAgentId === 'catty' ? 'Catty Agent' : externalAgents.find(a => a.id === currentAgentId)?.name}
|
||||
modelPresets={agentModelPresets}
|
||||
modelCatalogLoading={modelCatalogLoading}
|
||||
modelCatalogSource={modelCatalogSource}
|
||||
modelCatalogFetchedAt={modelCatalogFetchedAt}
|
||||
allowCustomModelEntry={allowCustomModelEntry}
|
||||
selectedModelId={selectedAgentModel}
|
||||
onModelSelect={handleAgentModelSelect}
|
||||
|
||||
@@ -165,18 +165,6 @@ test('hidden empty AI side panel can release its subtree', () => {
|
||||
assert.equal(shouldKeepAIChatSidePanelMounted(props), false);
|
||||
});
|
||||
|
||||
test('Catty without an SDK catalog request does not claim models are loading', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
React.createElement(I18nProvider, {
|
||||
locale: 'en',
|
||||
children: React.createElement(TooltipProvider, {
|
||||
children: React.createElement(AIChatSidePanel, baseProps({ isVisible: true })),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
assert.doesNotMatch(html, /Loading models|ai\.chat\.loadingModels/);
|
||||
});
|
||||
|
||||
test('hidden AI side panel is retained when it has draft text', () => {
|
||||
const props = baseProps({
|
||||
draftsByScope: {
|
||||
|
||||
+68
-151
@@ -80,21 +80,15 @@ import {
|
||||
buildCursorListModelsAgentEnv,
|
||||
buildSdkRuntimeModelCacheKey,
|
||||
sdkRuntimeModelCache,
|
||||
reconcileRuntimeModelWarning,
|
||||
retainStoredModelPresetForCatalog,
|
||||
toSdkRuntimeModelCatalog,
|
||||
generateId,
|
||||
agentModelPresetsShallowEqual,
|
||||
mergeFallbackThinkingLevels,
|
||||
normalizeStoredAgentModelSelection,
|
||||
normalizeSdkRuntimeModelPresets,
|
||||
resolveSdkRuntimeCatalogDefaultModelId,
|
||||
shouldAdoptSdkCurrentModel,
|
||||
appendRetainedStoredModelPreset,
|
||||
shouldLoadSdkRuntimeModels,
|
||||
shouldUseStoredAgentModel,
|
||||
type SdkRuntimeModelCatalog,
|
||||
type SdkRuntimeModelCatalogSource,
|
||||
} from './AIChatSidePanelHelpers';
|
||||
import { AIChatPanelContent } from './AIChatPanelContent';
|
||||
import { TERMINAL_SIDE_PANEL_INNER_HEADER_CLASS } from './terminalLayer/terminalSidePanelChrome';
|
||||
@@ -333,20 +327,12 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
// is tracked separately to block sends until the branch settles: a turn
|
||||
// submitted meanwhile would run against the (soon hidden) source session.
|
||||
const [isUndoingLastTurn, setIsUndoingLastTurn] = useState(false);
|
||||
const [runtimeAgentModelPresets, setRuntimeAgentModelPresets] = useState<Record<string, { cacheKey: string; models: AgentModelPreset[]; catalogUnavailable: boolean }>>({});
|
||||
const [runtimeAgentModelPresets, setRuntimeAgentModelPresets] = useState<Record<string, { cacheKey: string; models: AgentModelPreset[] }>>({});
|
||||
const [runtimeModelWarnings, setRuntimeModelWarnings] = useState<Record<string, { cacheKey: string; message: string }>>({});
|
||||
// Tracks SDK runtime model catalogs currently loading (per agent scope);
|
||||
// the composer shows the loading row alongside the build-time presets and
|
||||
// the live catalog replaces them when it arrives.
|
||||
// Tracks SDK runtime model catalogs currently loading (per agent scope):
|
||||
// while an OpenCode catalog is pending we must not flash the built-in
|
||||
// OPENCODE_MODEL_PRESETS for providers the user never configured (#3584).
|
||||
const [runtimeModelLoading, setRuntimeModelLoading] = useState<Record<string, { cacheKey: string }>>({});
|
||||
// Provenance of the last applied SDK runtime catalog, per agent scope. The
|
||||
// picker renders a uniform status chip from it; when no runtime catalog is
|
||||
// active the composer falls back to build-time presets ('presets').
|
||||
const [runtimeModelCatalogMeta, setRuntimeModelCatalogMeta] = useState<Record<string, {
|
||||
cacheKey: string;
|
||||
source: SdkRuntimeModelCatalogSource;
|
||||
fetchedAt?: string;
|
||||
}>>({});
|
||||
const [steerWarnings, setSteerWarnings] = useState<Record<string, SteerWarning>>({});
|
||||
const [steeringSessionId, setSteeringSessionId] = useState<string | null>(null);
|
||||
const [userSkillOptions, setUserSkillOptions] = useState<UserSkillOption[]>([]);
|
||||
@@ -866,10 +852,7 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
undoInFlightRef.current = true;
|
||||
setIsUndoingLastTurn(true);
|
||||
try {
|
||||
const result = await undoLastTurnInSession(sessionId, {
|
||||
type: scopeType,
|
||||
targetId: scopeTargetId,
|
||||
});
|
||||
const result = await undoLastTurnInSession(sessionId);
|
||||
if (!result) return;
|
||||
|
||||
ensureScopeDraft(currentAgentId);
|
||||
@@ -916,8 +899,6 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
undoLastTurnInSession,
|
||||
updateScopeDraft,
|
||||
currentAgentId,
|
||||
scopeType,
|
||||
scopeTargetId,
|
||||
]);
|
||||
|
||||
const providersRef = useRef(providers);
|
||||
@@ -1013,37 +994,29 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
const agent = externalAgentsRef.current.find((item) => item.id === target.agentId);
|
||||
if (buildExternalAgentRuntimeModelTarget(agent)?.cacheKey !== target.cacheKey) return;
|
||||
const agentId = target.agentId;
|
||||
// Record the catalog provenance for the picker's status chip. An absent
|
||||
// source (older main without the marker) displays as a live catalog.
|
||||
setRuntimeModelCatalogMeta((prev) => ({
|
||||
...prev,
|
||||
[agentId]: {
|
||||
cacheKey: target.cacheKey,
|
||||
source: catalog.source ?? 'live',
|
||||
...(catalog.fetchedAt ? { fetchedAt: catalog.fetchedAt } : {}),
|
||||
},
|
||||
}));
|
||||
const catalogPresets = mergeFallbackThinkingLevels(
|
||||
normalizeSdkRuntimeModelPresets(catalog.models, catalog.currentModelId),
|
||||
getAgentModelPresets(agent?.command, getExternalAgentSdkBackend(agent)),
|
||||
);
|
||||
const runtimePresets = retainStoredModelPresetForCatalog(
|
||||
const runtimePresets = appendComposerCustomModelPresets(
|
||||
catalogPresets,
|
||||
appendComposerCustomModelPresets(
|
||||
catalogPresets,
|
||||
collectCustomModelIds(agentId, catalogPresets),
|
||||
),
|
||||
agentModelMapRef.current[agentId],
|
||||
agent,
|
||||
Boolean(catalog.warning),
|
||||
collectCustomModelIds(agentId, catalogPresets),
|
||||
);
|
||||
setRuntimeAgentModelPresets((prev) => (
|
||||
prev[agentId]?.cacheKey === target.cacheKey
|
||||
&& prev[agentId].catalogUnavailable === Boolean(catalog.warning)
|
||||
&& agentModelPresetsShallowEqual(prev[agentId].models, catalogPresets)
|
||||
? prev
|
||||
: { ...prev, [agentId]: { cacheKey: target.cacheKey, models: catalogPresets, catalogUnavailable: Boolean(catalog.warning) } }
|
||||
));
|
||||
const storedModelId = agentModelMapRef.current[agentId];
|
||||
if (runtimePresets.length === 0) {
|
||||
setRuntimeAgentModelPresets((prev) => {
|
||||
if (!(agentId in prev)) return prev;
|
||||
const { [agentId]: _removed, ...rest } = prev;
|
||||
return rest;
|
||||
});
|
||||
} else {
|
||||
setRuntimeAgentModelPresets((prev) => (
|
||||
prev[agentId]?.cacheKey === target.cacheKey
|
||||
&& agentModelPresetsShallowEqual(prev[agentId].models, runtimePresets)
|
||||
? prev
|
||||
: { ...prev, [agentId]: { cacheKey: target.cacheKey, models: runtimePresets } }
|
||||
));
|
||||
}
|
||||
// Another path (e.g. send preflight) applied the catalog before the
|
||||
// deferred idle callback scheduled in the visibility effect: clear its
|
||||
// stale pending flag so the composer stops claiming models are loading.
|
||||
@@ -1054,21 +1027,20 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
});
|
||||
|
||||
const normalizedStoredModelId = normalizeStoredAgentModelSelection(
|
||||
agentModelMapRef.current[agentId],
|
||||
storedModelId,
|
||||
runtimePresets,
|
||||
);
|
||||
if (normalizedStoredModelId && normalizedStoredModelId !== agentModelMapRef.current[agentId]) {
|
||||
if (normalizedStoredModelId && normalizedStoredModelId !== storedModelId) {
|
||||
setAgentModel(agentId, normalizedStoredModelId);
|
||||
return;
|
||||
}
|
||||
|
||||
const defaultModelId = resolveSdkRuntimeCatalogDefaultModelId(catalog, agent);
|
||||
if (
|
||||
options.adoptCurrentModel
|
||||
&& defaultModelId
|
||||
&& shouldAdoptSdkCurrentModel(defaultModelId, agentModelMapRef.current[agentId], runtimePresets, agent)
|
||||
&& catalog.currentModelId
|
||||
&& shouldAdoptSdkCurrentModel(catalog.currentModelId, storedModelId, runtimePresets)
|
||||
) {
|
||||
setAgentModel(agentId, defaultModelId);
|
||||
setAgentModel(agentId, catalog.currentModelId);
|
||||
}
|
||||
}, [setAgentModel, setRuntimeModelLoading, buildExternalAgentRuntimeModelTarget, collectCustomModelIds]);
|
||||
|
||||
@@ -1109,25 +1081,13 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
}
|
||||
return next;
|
||||
});
|
||||
return toSdkRuntimeModelCatalog(result);
|
||||
return {
|
||||
currentModelId: result.currentModelId ?? null,
|
||||
models: result.models,
|
||||
};
|
||||
},
|
||||
{ force: options.force },
|
||||
).then((catalog) => {
|
||||
// A refresh that joined another panel's in-flight load never ran the
|
||||
// loader above, so sync this panel's banner from the shared result.
|
||||
setRuntimeModelWarnings((current) => {
|
||||
const agent = externalAgentsRef.current.find((item) => item.id === target.agentId);
|
||||
if (buildExternalAgentRuntimeModelTarget(agent)?.cacheKey !== target.cacheKey) return current;
|
||||
return reconcileRuntimeModelWarning(
|
||||
current,
|
||||
target.agentId,
|
||||
target.cacheKey,
|
||||
Boolean(catalog.warning),
|
||||
t('ai.chat.modelCatalogWarning'),
|
||||
);
|
||||
});
|
||||
return catalog;
|
||||
}).catch((err) => {
|
||||
).catch((err) => {
|
||||
setRuntimeModelWarnings((current) => {
|
||||
const agent = externalAgentsRef.current.find((item) => item.id === target.agentId);
|
||||
if (buildExternalAgentRuntimeModelTarget(agent)?.cacheKey !== target.cacheKey) return current;
|
||||
@@ -1154,16 +1114,6 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
const cached = sdkRuntimeModelCache.read(target.cacheKey);
|
||||
if (cached) {
|
||||
applySdkRuntimeModelCatalog(target, cached);
|
||||
// The cache stores warned (last-known-good) responses too: sync the
|
||||
// banner so another panel or a remount within the TTL does not present
|
||||
// degraded models as live.
|
||||
setRuntimeModelWarnings((current) => reconcileRuntimeModelWarning(
|
||||
current,
|
||||
target.agentId,
|
||||
target.cacheKey,
|
||||
Boolean(cached.warning),
|
||||
t('ai.chat.modelCatalogWarning'),
|
||||
));
|
||||
}
|
||||
|
||||
// Respect renderer TTL / in-flight coalescing for all SDK agents including
|
||||
@@ -1180,10 +1130,10 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
};
|
||||
let cancelled = false;
|
||||
let idleFired = false;
|
||||
// Mark the catalog pending as soon as the refresh is scheduled so the
|
||||
// composer can show its loading affordance for the whole idle delay (and
|
||||
// longer while the composer stays focused) instead of silently keeping
|
||||
// only the build-time presets (#3584). Only do this on a cache miss:
|
||||
// Mark the catalog pending as soon as the refresh is scheduled: otherwise
|
||||
// `runtimeModelLoading` stays false for the whole idle delay (and longer
|
||||
// while the composer stays focused), so the built-in OPENCODE_MODEL_PRESETS
|
||||
// remain selectable the entire time (#3584). Only do this on a cache miss:
|
||||
// when a cached catalog was already applied above, the runtime presets are
|
||||
// available, so a pending flag would keep the composer banner/picker in the
|
||||
// "loading" state indefinitely while the idle callback is deferred.
|
||||
@@ -1219,34 +1169,8 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
buildExternalAgentRuntimeModelTarget,
|
||||
loadSdkRuntimeModelCatalog,
|
||||
applySdkRuntimeModelCatalog,
|
||||
t,
|
||||
]);
|
||||
|
||||
// Uniform status chip inputs: when a runtime catalog is active for the
|
||||
// current agent its recorded provenance wins; otherwise the composer is
|
||||
// showing build-time presets (the renderer-side preset fallback derives
|
||||
// 'presets' here). While a load is pending the picker replaces the chip
|
||||
// with the spinner row.
|
||||
const modelCatalogSource = useMemo((): SdkRuntimeModelCatalogSource | undefined => {
|
||||
// A config-locked Codex picker shows only that configured model, not the
|
||||
// discovered catalog whose provenance is tracked below.
|
||||
if (isCodexManagedAgent && codexConfigModel) return undefined;
|
||||
const target = buildExternalAgentRuntimeModelTarget(currentAgentConfig);
|
||||
const meta = runtimeModelCatalogMeta[currentAgentId];
|
||||
const runtimeEntry = runtimeAgentModelPresets[currentAgentId];
|
||||
if (meta && target && meta.cacheKey === target.cacheKey
|
||||
&& runtimeEntry?.cacheKey === target.cacheKey && runtimeEntry.models.length > 0) {
|
||||
return meta.source;
|
||||
}
|
||||
return 'presets';
|
||||
}, [currentAgentConfig, currentAgentId, runtimeModelCatalogMeta, runtimeAgentModelPresets, buildExternalAgentRuntimeModelTarget, isCodexManagedAgent, codexConfigModel]);
|
||||
const modelCatalogFetchedAt = useMemo((): string | undefined => {
|
||||
const target = buildExternalAgentRuntimeModelTarget(currentAgentConfig);
|
||||
const meta = runtimeModelCatalogMeta[currentAgentId];
|
||||
if (meta && target && meta.cacheKey === target.cacheKey) return meta.fetchedAt;
|
||||
return undefined;
|
||||
}, [currentAgentConfig, currentAgentId, runtimeModelCatalogMeta, buildExternalAgentRuntimeModelTarget]);
|
||||
|
||||
const isCodexAppServer = isCodexManagedAgent && currentAgentConfig?.codexRuntime === 'app-server';
|
||||
const canSteerCurrentTurn = Boolean(activeSessionId && isStreaming && isCodexAppServer);
|
||||
const hasCodexCustomConfig = Boolean(codexConfigModel) && isCodexManagedAgent;
|
||||
@@ -1266,15 +1190,26 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
if (hasCodexCustomConfig && codexConfigModel) {
|
||||
return [{ id: codexConfigModel, name: codexConfigModel }];
|
||||
}
|
||||
if (runtimePresets?.length) {
|
||||
return appendRetainedStoredModelPreset(
|
||||
appendComposerCustomModelPresets(
|
||||
runtimePresets,
|
||||
collectCustomModelIds(currentAgentId, runtimePresets),
|
||||
),
|
||||
agentModelMap[currentAgentId],
|
||||
currentAgentConfig,
|
||||
Boolean(runtimeEntry?.catalogUnavailable),
|
||||
if (runtimePresets) {
|
||||
return appendComposerCustomModelPresets(
|
||||
runtimePresets,
|
||||
collectCustomModelIds(currentAgentId, runtimePresets),
|
||||
);
|
||||
}
|
||||
// While an OpenCode catalog load is pending, do not flash the built-in
|
||||
// OPENCODE_MODEL_PRESETS: they enumerate well-known gateway providers the
|
||||
// user may never have configured, so for a few seconds every switch looks
|
||||
// like a broken default model (#3584). Show only the user's own custom
|
||||
// model ids until the live catalog resolves (or a retryable warning
|
||||
// appears in the composer banner).
|
||||
if (
|
||||
target
|
||||
&& getExternalAgentSdkBackend(currentAgentConfig) === 'opencode'
|
||||
&& runtimeModelLoading[currentAgentId]?.cacheKey === target.cacheKey
|
||||
) {
|
||||
return appendComposerCustomModelPresets(
|
||||
[],
|
||||
collectCustomModelIds(currentAgentId, []),
|
||||
);
|
||||
}
|
||||
const presets = getAgentModelPresets(
|
||||
@@ -1286,22 +1221,15 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
const filteredPresets = filterAgentModelPresetsForCliVersion(presets, cliVersion);
|
||||
// Manual model ids typed in the composer (#3534) stay selectable even when
|
||||
// the CLI catalog does not list them yet.
|
||||
return appendRetainedStoredModelPreset(
|
||||
appendComposerCustomModelPresets(
|
||||
filteredPresets,
|
||||
collectCustomModelIds(currentAgentId, filteredPresets),
|
||||
),
|
||||
agentModelMap[currentAgentId],
|
||||
currentAgentConfig,
|
||||
// Until the initial catalog settles, show the choice a failed
|
||||
// preflight would actually send instead of flashing Auto.
|
||||
!runtimeEntry || !target || runtimeEntry.cacheKey !== target.cacheKey || runtimeEntry.catalogUnavailable,
|
||||
return appendComposerCustomModelPresets(
|
||||
filteredPresets,
|
||||
collectCustomModelIds(currentAgentId, filteredPresets),
|
||||
);
|
||||
}, [
|
||||
currentAgentConfig,
|
||||
currentAgentId,
|
||||
runtimeAgentModelPresets,
|
||||
agentModelMap,
|
||||
runtimeModelLoading,
|
||||
buildExternalAgentRuntimeModelTarget,
|
||||
hasCodexCustomConfig,
|
||||
codexConfigModel,
|
||||
@@ -1526,24 +1454,17 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
getExternalAgentSdkBackend(currentAgentConfig),
|
||||
),
|
||||
);
|
||||
const runtimePresets = retainStoredModelPresetForCatalog(
|
||||
const runtimePresets = appendComposerCustomModelPresets(
|
||||
catalogPresets,
|
||||
appendComposerCustomModelPresets(
|
||||
catalogPresets,
|
||||
collectCustomModelIds(sendAgentId, catalogPresets),
|
||||
),
|
||||
agentModelMapRef.current[sendAgentId],
|
||||
currentAgentConfig,
|
||||
Boolean(catalog.warning),
|
||||
collectCustomModelIds(sendAgentId, catalogPresets),
|
||||
);
|
||||
const storedModelId = agentModelMapRef.current[sendAgentId];
|
||||
const defaultModelId = resolveSdkRuntimeCatalogDefaultModelId(catalog, currentAgentConfig);
|
||||
if (
|
||||
defaultModelId
|
||||
&& shouldAdoptSdkCurrentModel(defaultModelId, storedModelId, runtimePresets, currentAgentConfig)
|
||||
catalog.currentModelId
|
||||
&& shouldAdoptSdkCurrentModel(catalog.currentModelId, storedModelId, runtimePresets)
|
||||
) {
|
||||
sendSelectedAgentModel = defaultModelId;
|
||||
} else if (shouldUseStoredAgentModel(storedModelId, runtimePresets, currentAgentConfig)) {
|
||||
sendSelectedAgentModel = catalog.currentModelId;
|
||||
} else if (shouldUseStoredAgentModel(storedModelId, runtimePresets)) {
|
||||
sendSelectedAgentModel = normalizeStoredAgentModelSelection(
|
||||
storedModelId,
|
||||
runtimePresets,
|
||||
@@ -2073,18 +1994,14 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
canSendCurrentAgent={canSendCurrentAgent}
|
||||
providerDisplayName={providerDisplayName}
|
||||
modelDisplayName={modelDisplayName}
|
||||
modelCatalogWarning={!hasCodexCustomConfig
|
||||
&& runtimeModelWarnings[currentAgentId]
|
||||
modelCatalogWarning={runtimeModelWarnings[currentAgentId]
|
||||
&& runtimeModelWarnings[currentAgentId].cacheKey === buildExternalAgentRuntimeModelTarget(currentAgentConfig)?.cacheKey
|
||||
? runtimeModelWarnings[currentAgentId].message
|
||||
: undefined}
|
||||
modelCatalogLoading={
|
||||
!hasCodexCustomConfig
|
||||
&& Boolean(runtimeModelLoading[currentAgentId])
|
||||
getExternalAgentSdkBackend(currentAgentConfig) === 'opencode'
|
||||
&& runtimeModelLoading[currentAgentId]?.cacheKey === buildExternalAgentRuntimeModelTarget(currentAgentConfig)?.cacheKey
|
||||
}
|
||||
modelCatalogSource={modelCatalogSource}
|
||||
modelCatalogFetchedAt={modelCatalogFetchedAt}
|
||||
handleModelCatalogRetry={handleRetrySdkModelCatalog}
|
||||
agentModelPresets={agentModelPresets}
|
||||
// A managed Codex config's `model` field overrides every selection on
|
||||
|
||||
@@ -40,7 +40,6 @@ export interface AIChatSidePanelProps {
|
||||
/** Non-destructively branch before the last user turn; returns the branch id + restored composer content. */
|
||||
undoLastTurnInSession?: (
|
||||
sessionId: string,
|
||||
viewingScope?: Pick<AISessionScope, 'type' | 'targetId'>,
|
||||
) => Promise<{ sessionId: string; restored: { text: string; attachments: import('../infrastructure/ai/types').UploadedFile[]; selectedUserSkillSlugs: string[] } } | null>;
|
||||
deleteSession: (sessionId: string, scopeKey?: string) => void;
|
||||
updateSessionTitle: (sessionId: string, title: string) => void;
|
||||
|
||||
@@ -1,28 +1,20 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
import {
|
||||
appendRetainedStoredModelPreset,
|
||||
retainStoredModelPresetForCatalog,
|
||||
buildCursorListModelsAgentEnv,
|
||||
buildSdkRuntimeModelCacheKey,
|
||||
canonicalizeEffortEncodedModelId,
|
||||
createSdkRuntimeModelCache,
|
||||
agentModelPresetsShallowEqual,
|
||||
mergeFallbackThinkingLevels,
|
||||
MODEL_CACHE_ENV_HINTS,
|
||||
modelPresetsContainId,
|
||||
normalizeStoredAgentModelSelection,
|
||||
normalizeSdkRuntimeModelPresets,
|
||||
resolveSdkRuntimeCatalogDefaultModelId,
|
||||
reconcileRuntimeModelWarning,
|
||||
toSdkRuntimeModelCatalog,
|
||||
shouldAdoptSdkCurrentModel,
|
||||
shouldLoadSdkRuntimeModels,
|
||||
shouldUseStoredAgentModel,
|
||||
} from './AIChatSidePanelHelpers';
|
||||
import { createRequire } from 'node:module';
|
||||
import type { AgentModelPreset, ExternalAgentConfig } from '../infrastructure/ai/types';
|
||||
|
||||
test('buildCursorListModelsAgentEnv injects cli-login auth mode for list-models', () => {
|
||||
@@ -306,157 +298,6 @@ test('shouldUseStoredAgentModel trusts SDK defaults when no runtime list is retu
|
||||
);
|
||||
});
|
||||
|
||||
test('stored claude alias selections keep resolving against a full-id catalog', () => {
|
||||
const claudeAgent: ExternalAgentConfig = {
|
||||
id: 'managed_claude',
|
||||
name: 'Claude Code',
|
||||
command: 'claude',
|
||||
enabled: true,
|
||||
sdkBackend: 'claude',
|
||||
};
|
||||
const fullIdPresets: AgentModelPreset[] = [
|
||||
{ id: 'claude-sonnet-5-5', name: 'Sonnet 5.5' },
|
||||
{ id: 'claude-haiku-5-5', name: 'Haiku 5.5' },
|
||||
];
|
||||
|
||||
// Legacy persisted alias ids (pre-2026-10 preset refresh) still resolve for
|
||||
// the claude backend, with or without an effort suffix.
|
||||
assert.equal(shouldUseStoredAgentModel('sonnet', fullIdPresets, claudeAgent), true);
|
||||
assert.equal(shouldUseStoredAgentModel('sonnet/high', fullIdPresets, claudeAgent), true);
|
||||
// ...and are never silently replaced by the catalog's current model.
|
||||
assert.equal(shouldAdoptSdkCurrentModel('claude-sonnet-5-5', 'sonnet', fullIdPresets, claudeAgent), false);
|
||||
assert.equal(shouldAdoptSdkCurrentModel('claude-sonnet-5-5', 'sonnet/high', fullIdPresets, claudeAgent), false);
|
||||
|
||||
// Without agent context the previous behavior is unchanged.
|
||||
assert.equal(shouldUseStoredAgentModel('sonnet', fullIdPresets), false);
|
||||
assert.equal(shouldAdoptSdkCurrentModel('claude-sonnet-5-5', 'sonnet', fullIdPresets), true);
|
||||
|
||||
// Non-claude backends and non-alias stored ids are untouched.
|
||||
const opencodeAgent: ExternalAgentConfig = {
|
||||
id: 'managed_opencode',
|
||||
name: 'OpenCode',
|
||||
command: 'opencode',
|
||||
enabled: true,
|
||||
sdkBackend: 'opencode',
|
||||
};
|
||||
assert.equal(shouldUseStoredAgentModel('sonnet', fullIdPresets, opencodeAgent), false);
|
||||
assert.equal(shouldAdoptSdkCurrentModel('claude-sonnet-5-5', 'gpt-5.5', fullIdPresets, claudeAgent), true);
|
||||
});
|
||||
|
||||
test('a saved Copilot model survives the auto-only degraded fallback', () => {
|
||||
const copilotAgent: ExternalAgentConfig = {
|
||||
id: 'managed_copilot',
|
||||
name: 'GitHub Copilot',
|
||||
command: 'copilot',
|
||||
enabled: true,
|
||||
sdkBackend: 'copilot',
|
||||
};
|
||||
const autoOnlyFallback: AgentModelPreset[] = [{ id: 'auto', name: 'Auto' }];
|
||||
|
||||
// Live discovery failed (no last-known store yet): the saved explicit model
|
||||
// must keep resolving instead of silently switching to `auto`.
|
||||
assert.equal(shouldUseStoredAgentModel('claude-sonnet-4.5', autoOnlyFallback, copilotAgent, true), true);
|
||||
assert.equal(shouldUseStoredAgentModel('claude-sonnet-4.5/high', autoOnlyFallback, copilotAgent, true), true);
|
||||
// Other backends with the same shape are unaffected.
|
||||
const opencodeAgent: ExternalAgentConfig = {
|
||||
id: 'managed_opencode',
|
||||
name: 'OpenCode',
|
||||
command: 'opencode',
|
||||
enabled: true,
|
||||
sdkBackend: 'opencode',
|
||||
};
|
||||
assert.equal(shouldUseStoredAgentModel('claude-sonnet-4.5', autoOnlyFallback, opencodeAgent), false);
|
||||
// Composer custom ids are mixed into the same picker list; the degraded
|
||||
// fallback must still be detected with extra rows present.
|
||||
const mixedFallback: AgentModelPreset[] = [
|
||||
{ id: 'auto', name: 'Auto', description: 'Automatic model selection' },
|
||||
{ id: 'gpt-custom', name: 'gpt-custom' },
|
||||
];
|
||||
assert.equal(shouldUseStoredAgentModel('claude-sonnet-4.5', mixedFallback, copilotAgent, true), true);
|
||||
assert.equal(modelPresetsContainId(
|
||||
appendRetainedStoredModelPreset(mixedFallback, 'claude-sonnet-4.5', copilotAgent, true),
|
||||
'claude-sonnet-4.5',
|
||||
), true);
|
||||
// A real Copilot catalog (multiple entries with named rows) does not
|
||||
// trigger the fallback, mixed or not.
|
||||
assert.equal(
|
||||
shouldUseStoredAgentModel('claude-sonnet-4.5', [
|
||||
{ id: 'auto', name: 'Auto' },
|
||||
{ id: 'gpt-5', name: 'GPT-5' },
|
||||
], copilotAgent),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
shouldUseStoredAgentModel('claude-sonnet-4.5', [
|
||||
{ id: 'auto', name: 'Auto' },
|
||||
{ id: 'gpt-5', name: 'GPT-5' },
|
||||
{ id: 'gpt-custom', name: 'gpt-custom' },
|
||||
], copilotAgent),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('appendRetainedStoredModelPreset makes preserved saved models visible', () => {
|
||||
const claudeAgent: ExternalAgentConfig = {
|
||||
id: 'managed_claude',
|
||||
name: 'Claude Code',
|
||||
command: 'claude',
|
||||
enabled: true,
|
||||
sdkBackend: 'claude',
|
||||
};
|
||||
const fullIdPresets: AgentModelPreset[] = [{ id: 'claude-sonnet-5-5', name: 'Sonnet 5.5' }];
|
||||
|
||||
// A stored claude alias absent from a full-id catalog gains a preset row
|
||||
// (reusing the build-time preset so thinking levels come along).
|
||||
const withAlias = appendRetainedStoredModelPreset(fullIdPresets, 'sonnet/high', claudeAgent);
|
||||
assert.equal(withAlias.length, 2);
|
||||
assert.equal(withAlias[1].id, 'sonnet');
|
||||
assert.equal(modelPresetsContainId(withAlias, 'sonnet/high'), true);
|
||||
|
||||
// The copilot auto-only degraded fallback keeps a saved explicit model
|
||||
// selectable as its own row.
|
||||
const copilotAgent: ExternalAgentConfig = {
|
||||
id: 'managed_copilot',
|
||||
name: 'GitHub Copilot',
|
||||
command: 'copilot',
|
||||
enabled: true,
|
||||
sdkBackend: 'copilot',
|
||||
};
|
||||
const withCopilot = appendRetainedStoredModelPreset(
|
||||
[{ id: 'auto', name: 'Auto' }],
|
||||
'claude-sonnet-4.5',
|
||||
copilotAgent,
|
||||
true,
|
||||
);
|
||||
assert.deepEqual(withCopilot[1], { id: 'claude-sonnet-4.5', name: 'claude-sonnet-4.5' });
|
||||
|
||||
// An effort-suffixed saved id keeps its full spelling so the appended row
|
||||
// matches the selection the send preflight passes.
|
||||
const withCopilotSuffix = appendRetainedStoredModelPreset(
|
||||
[{ id: 'auto', name: 'Auto' }],
|
||||
'claude-sonnet-4.5/high',
|
||||
copilotAgent,
|
||||
true,
|
||||
);
|
||||
assert.deepEqual(withCopilotSuffix[1], { id: 'claude-sonnet-4.5/high', name: 'claude-sonnet-4.5/high' });
|
||||
assert.equal(modelPresetsContainId(withCopilotSuffix, 'claude-sonnet-4.5/high'), true);
|
||||
|
||||
// A base-only custom row (no thinking levels) does not cover the stored
|
||||
// suffixed id, so the exact retained id is appended beside it.
|
||||
const baseOnly: AgentModelPreset[] = [
|
||||
{ id: 'auto', name: 'Auto' },
|
||||
{ id: 'claude-sonnet-4.5', name: 'claude-sonnet-4.5' },
|
||||
];
|
||||
const besideBase = appendRetainedStoredModelPreset(baseOnly, 'claude-sonnet-4.5/high', copilotAgent, true);
|
||||
assert.equal(besideBase.length, 3);
|
||||
assert.equal(modelPresetsContainId(besideBase, 'claude-sonnet-4.5/high'), true);
|
||||
|
||||
// Listed or non-retained selections are untouched.
|
||||
assert.equal(appendRetainedStoredModelPreset(fullIdPresets, 'claude-sonnet-5-5', claudeAgent), fullIdPresets);
|
||||
assert.equal(appendRetainedStoredModelPreset(fullIdPresets, 'gpt-5.5', claudeAgent), fullIdPresets);
|
||||
assert.equal(appendRetainedStoredModelPreset(fullIdPresets, undefined, claudeAgent), fullIdPresets);
|
||||
});
|
||||
|
||||
test('SDK runtime model cache coalesces concurrent refreshes', async () => {
|
||||
const cache = createSdkRuntimeModelCache();
|
||||
let calls = 0;
|
||||
@@ -599,213 +440,3 @@ test('SDK runtime model cache stays bounded under agent configuration churn', as
|
||||
assert.equal(cache.read('agent:0'), null);
|
||||
assert.equal(cache.read('agent:19')?.currentModelId, 'model-19');
|
||||
});
|
||||
|
||||
test('SDK runtime model cache preserves degraded warnings until a successful retry', async () => {
|
||||
const cache = createSdkRuntimeModelCache();
|
||||
const degraded = {
|
||||
currentModelId: 'auto',
|
||||
models: [{ id: 'auto', name: 'Auto' }],
|
||||
warning: 'Live discovery failed; serving last-known-good models',
|
||||
};
|
||||
assert.equal((await cache.refresh('copilot', async () => degraded)).warning, degraded.warning);
|
||||
assert.equal(cache.read('copilot')?.warning, degraded.warning);
|
||||
assert.equal((await cache.refresh('copilot', async () => {
|
||||
assert.fail('A second panel should use the cached catalog within the TTL');
|
||||
})).warning, degraded.warning);
|
||||
|
||||
await cache.refresh('copilot', async () => ({
|
||||
currentModelId: 'auto',
|
||||
models: [{ id: 'auto', name: 'Auto' }],
|
||||
}), { force: true });
|
||||
assert.equal(cache.read('copilot')?.warning, undefined);
|
||||
});
|
||||
|
||||
// #3584 alignment: OpenCode must render build-time presets while its live
|
||||
// catalog load is pending, exactly like every other backend. The old host
|
||||
// code suppressed presets for opencode while `runtimeModelLoading` was set,
|
||||
// leaving the picker empty until the pull resolved. Guard against it coming
|
||||
// back: the preset fallback in the panel must not gate on opencode loading.
|
||||
test('host preset fallback does not suppress presets for a loading opencode catalog', () => {
|
||||
const source = readFileSync(new URL('./AIChatSidePanel.tsx', import.meta.url), 'utf8');
|
||||
assert.doesNotMatch(source, /getExternalAgentSdkBackend\(currentAgentConfig\) === 'opencode'[\s\S]*?runtimeModelLoading/);
|
||||
// Build-time presets remain the fallback whenever no runtime catalog is
|
||||
// active for the agent (loading included).
|
||||
assert.match(source, /const presets = getAgentModelPresets\(/);
|
||||
});
|
||||
|
||||
test('reconcileRuntimeModelWarning adds the banner for a warned catalog and keeps unrelated agents', () => {
|
||||
const current = { other: { cacheKey: 'k-other', message: 'x' } };
|
||||
const next = reconcileRuntimeModelWarning(current, 'copilot', 'k1', true, 'warn');
|
||||
assert.deepEqual(next, {
|
||||
other: { cacheKey: 'k-other', message: 'x' },
|
||||
copilot: { cacheKey: 'k1', message: 'warn' },
|
||||
});
|
||||
});
|
||||
|
||||
test('reconcileRuntimeModelWarning returns the same object when nothing changes', () => {
|
||||
const current = { copilot: { cacheKey: 'k1', message: 'warn' } };
|
||||
assert.equal(reconcileRuntimeModelWarning(current, 'copilot', 'k1', true, 'warn'), current);
|
||||
assert.equal(reconcileRuntimeModelWarning({}, 'copilot', 'k1', false, 'warn').copilot, undefined);
|
||||
});
|
||||
|
||||
test('reconcileRuntimeModelWarning clears only the banner that belongs to this cache key', () => {
|
||||
const current = { copilot: { cacheKey: 'k1', message: 'warn' } };
|
||||
assert.deepEqual(reconcileRuntimeModelWarning(current, 'copilot', 'k1', false, 'warn'), {});
|
||||
// A banner that belongs to another cache key (another profile) is not ours to clear.
|
||||
assert.equal(reconcileRuntimeModelWarning(current, 'copilot', 'k2', false, 'warn'), current);
|
||||
});
|
||||
|
||||
test('renderer model cache env hints cover every key the main-process catalog cache fingerprints', () => {
|
||||
// Both caches must split on the same profile-affecting environment: a key that
|
||||
// only the main process knows lets the renderer serve one profile's catalog to another.
|
||||
const require = createRequire(import.meta.url);
|
||||
const { SDK_MODEL_CACHE_ENV_KEYS } = require('../electron/bridges/aiBridge/sdk/sdkStreamHandlers.cjs') as {
|
||||
SDK_MODEL_CACHE_ENV_KEYS: string[];
|
||||
};
|
||||
const hints = new Set<string>(MODEL_CACHE_ENV_HINTS);
|
||||
const missing = SDK_MODEL_CACHE_ENV_KEYS.filter((key) => !hints.has(key));
|
||||
assert.deepEqual(missing, []);
|
||||
});
|
||||
|
||||
test('toSdkRuntimeModelCatalog keeps the provenance main reported for a last-known-good serve', () => {
|
||||
const catalog = toSdkRuntimeModelCatalog({
|
||||
ok: true,
|
||||
currentModelId: 'm-1',
|
||||
models: [{ id: 'm-1', name: 'M1' }],
|
||||
warning: 'live fetch failed',
|
||||
source: 'last-known-good',
|
||||
fetchedAt: '2026-10-10T08:00:00.000Z',
|
||||
});
|
||||
assert.deepEqual(catalog, {
|
||||
currentModelId: 'm-1',
|
||||
models: [{ id: 'm-1', name: 'M1' }],
|
||||
warning: 'live fetch failed',
|
||||
source: 'last-known-good',
|
||||
fetchedAt: '2026-10-10T08:00:00.000Z',
|
||||
});
|
||||
});
|
||||
|
||||
test('toSdkRuntimeModelCatalog tolerates an older main without provenance or with unknown values', () => {
|
||||
assert.deepEqual(
|
||||
toSdkRuntimeModelCatalog({ ok: true, models: [{ id: 'a', name: 'A' }] }),
|
||||
{ currentModelId: null, models: [{ id: 'a', name: 'A' }], warning: null },
|
||||
);
|
||||
const odd = toSdkRuntimeModelCatalog({
|
||||
ok: true,
|
||||
models: [],
|
||||
source: 'something-else' as never,
|
||||
fetchedAt: 42 as never,
|
||||
});
|
||||
assert.equal(odd.source, undefined);
|
||||
assert.equal(odd.fetchedAt, undefined);
|
||||
});
|
||||
|
||||
test('retainStoredModelPresetForCatalog leaves the built-in fallback list alone when no catalog arrived', () => {
|
||||
const claudeAgent = { id: 'claude', command: 'claude', sdkBackend: 'claude' } as unknown as ExternalAgentConfig;
|
||||
// The first Claude catalog request failed: nothing to extend. Appending only
|
||||
// the saved alias would make a one-row list authoritative and hide the
|
||||
// built-in presets, so the empty list must stay empty.
|
||||
assert.deepEqual(retainStoredModelPresetForCatalog([], [], 'sonnet', claudeAgent), []);
|
||||
});
|
||||
|
||||
test('retainStoredModelPresetForCatalog drops composer custom rows too when no catalog arrived', () => {
|
||||
const claudeAgent = { id: 'claude', command: 'claude', sdkBackend: 'claude' } as unknown as ExternalAgentConfig;
|
||||
// The callers wrap the empty catalog with the user's custom composer models, so
|
||||
// the list is non-empty even though no catalog arrived. Stored as the runtime
|
||||
// list it would still hide the built-in presets; the panel appends custom
|
||||
// models on top of the fallback list itself.
|
||||
const withCustom = [{ id: 'my-custom-model', name: 'my-custom-model' }];
|
||||
assert.deepEqual(retainStoredModelPresetForCatalog([], withCustom, 'sonnet', claudeAgent), []);
|
||||
});
|
||||
|
||||
test('retainStoredModelPresetForCatalog still retains a saved selection on top of a real catalog', () => {
|
||||
const claudeAgent = { id: 'claude', command: 'claude', sdkBackend: 'claude' } as unknown as ExternalAgentConfig;
|
||||
const catalog = [{ id: 'claude-opus-5-5', name: 'Opus 5.5' }];
|
||||
const retained = retainStoredModelPresetForCatalog(catalog, catalog, 'sonnet', claudeAgent);
|
||||
assert.deepEqual(retained, appendRetainedStoredModelPreset(catalog, 'sonnet', claudeAgent));
|
||||
});
|
||||
|
||||
test('catalog source adaptation preserves explicit Copilot failure retention', () => {
|
||||
const agent = { id: 'copilot', command: 'copilot', sdkBackend: 'copilot' } as ExternalAgentConfig;
|
||||
const catalog = toSdkRuntimeModelCatalog({
|
||||
ok: true,
|
||||
models: [{ id: 'auto', name: 'Auto' }],
|
||||
warning: 'live discovery unavailable',
|
||||
source: 'last-known-good',
|
||||
fetchedAt: '2026-10-15T09:00:00.000Z',
|
||||
});
|
||||
const presets = retainStoredModelPresetForCatalog(
|
||||
catalog.models, catalog.models, 'saved-model', agent, Boolean(catalog.warning),
|
||||
);
|
||||
assert.deepEqual(presets.map(model => model.id), ['auto', 'saved-model']);
|
||||
assert.deepEqual(retainStoredModelPresetForCatalog(
|
||||
catalog.models, catalog.models, 'saved-model', agent, false,
|
||||
).map(model => model.id), ['auto']);
|
||||
});
|
||||
|
||||
test('SDK runtime model cache keeps the retry warning when a degraded refresh retains the cached catalog', async () => {
|
||||
let now = 1_000;
|
||||
const cache = createSdkRuntimeModelCache({ now: () => now });
|
||||
const key = 'copilot:/opt/bin/copilot';
|
||||
|
||||
await cache.refresh(key, async () => ({
|
||||
currentModelId: 'gpt-5',
|
||||
models: [{ id: 'gpt-5', name: 'GPT-5' }],
|
||||
source: 'live',
|
||||
fetchedAt: '2026-10-15T09:00:00.000Z',
|
||||
}));
|
||||
|
||||
now = 2_000;
|
||||
const retried = await cache.refresh(
|
||||
key,
|
||||
async () => ({ currentModelId: null, models: [], warning: 'catalog unavailable' }),
|
||||
{ force: true },
|
||||
);
|
||||
|
||||
assert.deepEqual(retried.models, [{ id: 'gpt-5', name: 'GPT-5' }]);
|
||||
assert.equal(retried.warning, 'catalog unavailable');
|
||||
assert.equal(retried.source, 'last-known-good');
|
||||
assert.equal(retried.fetchedAt, '2026-10-15T09:00:00.000Z');
|
||||
// Later reads retain the warning without extending the good catalog's age.
|
||||
assert.equal(cache.read(key)?.warning, 'catalog unavailable');
|
||||
assert.equal(cache.read(key)?.updatedAt, 1_000);
|
||||
const nextRead = await cache.refresh(key, async () => { throw new Error('fresh cache should be reused'); });
|
||||
assert.equal(nextRead.warning, 'catalog unavailable');
|
||||
assert.equal(nextRead.source, 'last-known-good');
|
||||
});
|
||||
|
||||
|
||||
test('degraded Copilot selection survives custom rows while live auto-only remains authoritative', () => {
|
||||
const agent: ExternalAgentConfig = { id: 'copilot', name: 'Copilot', command: 'copilot', enabled: true, sdkBackend: 'copilot' };
|
||||
const customRows = [{ id: 'manual-model', name: 'manual-model' }];
|
||||
const retained = appendRetainedStoredModelPreset(customRows, 'saved-model', agent, true);
|
||||
assert.equal(modelPresetsContainId(retained, 'saved-model'), true);
|
||||
assert.equal(shouldUseStoredAgentModel('saved-model', retained, agent, true), true);
|
||||
assert.equal(shouldAdoptSdkCurrentModel('auto', 'saved-model', retained, agent), false);
|
||||
const live = [{ id: 'auto', name: 'auto' }];
|
||||
assert.equal(appendRetainedStoredModelPreset(live, 'saved-model', agent, false), live);
|
||||
assert.equal(shouldUseStoredAgentModel('saved-model', live, agent, false), false);
|
||||
assert.equal(shouldAdoptSdkCurrentModel('auto', 'saved-model', live, agent), true);
|
||||
});
|
||||
|
||||
test('renderer catalogs separate supported credential and profile overrides', () => {
|
||||
const agent = { id: 'agent', command: '/same/cli', sdkBackend: 'copilot' };
|
||||
for (const name of ['COPILOT_GITHUB_TOKEN', 'GH_TOKEN', 'GITHUB_TOKEN', 'GH_CONFIG_DIR', 'CODEBUDDY_API_KEY', 'CODEBUDDY_AUTH_TOKEN', 'CODEBUDDY_INTERNET_ENVIRONMENT', 'XAI_API_KEY', 'GROK_CONFIG_DIR']) {
|
||||
const key = buildSdkRuntimeModelCacheKey({ ...agent, env: { [name]: 'fixture-profile-a' } });
|
||||
assert.notEqual(key, buildSdkRuntimeModelCacheKey({ ...agent, env: { [name]: 'fixture-profile-b' } }), name);
|
||||
assert.doesNotMatch(key, /fixture-profile-a/);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
test('Copilot successful catalog without current id replaces an unlisted saved choice before failure', () => {
|
||||
const agent: ExternalAgentConfig = { id: 'copilot', name: 'Copilot', command: 'copilot', enabled: true, sdkBackend: 'copilot' };
|
||||
// Copilot returns an array, so IPC has no currentModelId even on success.
|
||||
const live = { models: [{ id: 'auto', name: 'auto' }], currentModelId: null };
|
||||
const next = resolveSdkRuntimeCatalogDefaultModelId(live, agent);
|
||||
assert.equal(next, 'auto');
|
||||
assert.equal(shouldAdoptSdkCurrentModel(next, 'saved-model', live.models, agent), true);
|
||||
const laterFailure = appendRetainedStoredModelPreset(live.models, next, agent, true);
|
||||
assert.deepEqual(laterFailure, live.models);
|
||||
assert.equal(resolveSdkRuntimeCatalogDefaultModelId({ ...live, warning: 'unavailable' }, agent), null);
|
||||
});
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
getAgentModelPresets,
|
||||
resolveAgentModelSelection,
|
||||
type AgentModelPreset,
|
||||
type ExternalAgentConfig,
|
||||
@@ -19,22 +18,9 @@ export {
|
||||
modelPresetsContainId,
|
||||
};
|
||||
|
||||
export type SdkRuntimeModelCatalogSource = 'live' | 'last-known-good' | 'presets';
|
||||
|
||||
export type SdkRuntimeModelCatalog = {
|
||||
currentModelId: string | null;
|
||||
models: AgentModelPreset[];
|
||||
// Degraded loads (e.g. last-known-good serve) carry their warning so a
|
||||
// cached hit in another panel or after a remount still shows the retry
|
||||
// banner instead of presenting stale models as live.
|
||||
warning?: string | null;
|
||||
// Provenance of the models list: 'live' when the SDK fetch succeeded,
|
||||
// 'last-known-good' when main served the persisted previous success.
|
||||
// Absent (older main) behaves like a live fetch for display purposes.
|
||||
source?: Exclude<SdkRuntimeModelCatalogSource, 'presets'>;
|
||||
// ISO timestamp of the successful fetch backing this catalog (live fetch
|
||||
// time, or the persisted last-known-good fetchedAt).
|
||||
fetchedAt?: string;
|
||||
};
|
||||
|
||||
export type SdkRuntimeModelCacheEntry = SdkRuntimeModelCatalog & {
|
||||
@@ -55,7 +41,7 @@ const SDK_RUNTIME_MODEL_CACHE_TTL_MS = 5 * 60 * 1000;
|
||||
const SDK_RUNTIME_MODEL_CACHE_MAX_ENTRIES = 64;
|
||||
// Keep in sync with main-process SDK_MODEL_CACHE_ENV_KEYS: profile-affecting
|
||||
// env must bust the renderer cache so we re-query after OpenCode config switches.
|
||||
export const MODEL_CACHE_ENV_HINTS = [
|
||||
const MODEL_CACHE_ENV_HINTS = [
|
||||
'HOME',
|
||||
'USERPROFILE',
|
||||
'XDG_CONFIG_HOME',
|
||||
@@ -63,7 +49,6 @@ export const MODEL_CACHE_ENV_HINTS = [
|
||||
'CLAUDE_CONFIG_DIR',
|
||||
'ANTHROPIC_API_KEY',
|
||||
'ANTHROPIC_AUTH_TOKEN',
|
||||
'ANTHROPIC_BASE_URL',
|
||||
'CLAUDE_CODE_OAUTH_TOKEN',
|
||||
'OPENCODE_BIN',
|
||||
'OPENCODE_CONFIG',
|
||||
@@ -79,41 +64,15 @@ export const MODEL_CACHE_ENV_HINTS = [
|
||||
'XDG_CACHE_HOME',
|
||||
'CLAUDE_CODE_EXECUTABLE',
|
||||
'CODEBUDDY_CODE_PATH',
|
||||
'CODEBUDDY_API_KEY',
|
||||
'CODEBUDDY_AUTH_TOKEN',
|
||||
'CODEBUDDY_INTERNET_ENVIRONMENT',
|
||||
'XAI_API_KEY',
|
||||
'GROK_CONFIG_DIR',
|
||||
'COPILOT_GITHUB_TOKEN',
|
||||
'GH_TOKEN',
|
||||
'GITHUB_TOKEN',
|
||||
'GH_CONFIG_DIR',
|
||||
'CURSOR_API_KEY',
|
||||
'NETCATTY_CURSOR_AUTH_MODE',
|
||||
'NETCATTY_CURSOR_CLI_BIN',
|
||||
] as const;
|
||||
|
||||
const SDK_RUNTIME_MODEL_CATALOG_SOURCES = new Set(['live', 'last-known-good']);
|
||||
|
||||
function normalizeCatalogSource(
|
||||
source: unknown,
|
||||
): SdkRuntimeModelCatalog['source'] {
|
||||
return typeof source === 'string' && SDK_RUNTIME_MODEL_CATALOG_SOURCES.has(source)
|
||||
? source as SdkRuntimeModelCatalog['source']
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function normalizeCatalogFetchedAt(fetchedAt: unknown): string | undefined {
|
||||
return typeof fetchedAt === 'string' && fetchedAt ? fetchedAt : undefined;
|
||||
}
|
||||
|
||||
function cloneCatalog(catalog: SdkRuntimeModelCatalog): SdkRuntimeModelCatalog {
|
||||
return {
|
||||
currentModelId: catalog.currentModelId ?? null,
|
||||
models: [...catalog.models],
|
||||
...(catalog.warning ? { warning: catalog.warning } : {}),
|
||||
...(catalog.source ? { source: catalog.source } : {}),
|
||||
...(catalog.fetchedAt ? { fetchedAt: catalog.fetchedAt } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -123,36 +82,6 @@ function normalizeSdkRuntimeModelCatalog(catalog: SdkRuntimeModelCatalog): SdkRu
|
||||
models: Array.isArray(catalog.models)
|
||||
? catalog.models.filter((model): model is AgentModelPreset => Boolean(model?.id))
|
||||
: [],
|
||||
...(catalog.warning ? { warning: catalog.warning } : {}),
|
||||
...(normalizeCatalogSource(catalog.source) ? { source: normalizeCatalogSource(catalog.source) } : {}),
|
||||
...(normalizeCatalogFetchedAt(catalog.fetchedAt) ? { fetchedAt: normalizeCatalogFetchedAt(catalog.fetchedAt) } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
/** The list-models IPC result as the renderer receives it. */
|
||||
export type SdkListModelsResult = {
|
||||
ok: boolean;
|
||||
models?: AgentModelPreset[];
|
||||
currentModelId?: string | null;
|
||||
warning?: string;
|
||||
error?: string;
|
||||
// Provenance reported by main (absent on an older main).
|
||||
source?: Exclude<SdkRuntimeModelCatalogSource, 'presets'>;
|
||||
fetchedAt?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adapt a successful list-models result to a catalog while keeping the
|
||||
* provenance main reported. Dropping source/fetchedAt would make the picker
|
||||
* label a persisted last-known-good list as a live catalog.
|
||||
*/
|
||||
export function toSdkRuntimeModelCatalog(result: SdkListModelsResult): SdkRuntimeModelCatalog {
|
||||
return {
|
||||
currentModelId: result.currentModelId ?? null,
|
||||
models: result.models ?? [],
|
||||
warning: result.warning ?? null,
|
||||
...(normalizeCatalogSource(result.source) ? { source: normalizeCatalogSource(result.source) } : {}),
|
||||
...(normalizeCatalogFetchedAt(result.fetchedAt) ? { fetchedAt: normalizeCatalogFetchedAt(result.fetchedAt) } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -258,16 +187,7 @@ export function createSdkRuntimeModelCache(options: SdkRuntimeModelCacheOptions
|
||||
.then((catalog) => {
|
||||
const normalized = normalizeSdkRuntimeModelCatalog(catalog);
|
||||
if (normalized.models.length === 0 && !normalized.currentModelId) {
|
||||
// A degraded retry keeps the older catalog usable but must still
|
||||
// report its own warning, or the banner and Retry would vanish.
|
||||
if (!cached) return cloneCatalog(normalized);
|
||||
const retained = cloneCatalog(cached);
|
||||
if (normalized.warning) {
|
||||
retained.warning = normalized.warning;
|
||||
retained.source = 'last-known-good';
|
||||
touchEntry(key, { ...retained, updatedAt: cached.updatedAt });
|
||||
}
|
||||
return retained;
|
||||
return cached ? cloneCatalog(cached) : cloneCatalog(normalized);
|
||||
}
|
||||
touchEntry(key, { ...cloneCatalog(normalized), updatedAt: now() });
|
||||
pruneEntries();
|
||||
@@ -287,32 +207,6 @@ export function createSdkRuntimeModelCache(options: SdkRuntimeModelCacheOptions
|
||||
|
||||
export const sdkRuntimeModelCache = createSdkRuntimeModelCache();
|
||||
|
||||
export type RuntimeModelWarnings = Record<string, { cacheKey: string; message: string }>;
|
||||
|
||||
/**
|
||||
* Make the per-agent catalog warning banner match a catalog result. Used both
|
||||
* for cache reads and after a refresh settles: a refresh that coalesced onto
|
||||
* another panel's in-flight load never runs its own loader callback, so
|
||||
* the caller must reconcile the banner from the shared result itself.
|
||||
* Returns the same object when nothing changes (no extra render). A banner
|
||||
* that belongs to a different cache key is never cleared.
|
||||
*/
|
||||
export function reconcileRuntimeModelWarning(
|
||||
current: RuntimeModelWarnings,
|
||||
agentId: string,
|
||||
cacheKey: string,
|
||||
hasWarning: boolean,
|
||||
message: string,
|
||||
): RuntimeModelWarnings {
|
||||
const existing = current[agentId];
|
||||
if (hasWarning) {
|
||||
return existing?.cacheKey === cacheKey ? current : { ...current, [agentId]: { cacheKey, message } };
|
||||
}
|
||||
if (existing?.cacheKey !== cacheKey) return current;
|
||||
const { [agentId]: _removed, ...rest } = current;
|
||||
return rest;
|
||||
}
|
||||
|
||||
export function mergeFallbackThinkingLevels(
|
||||
runtime: AgentModelPreset[],
|
||||
fallbacks: AgentModelPreset[],
|
||||
@@ -384,71 +278,12 @@ export function shouldLoadSdkRuntimeModels(agent?: ExternalAgentConfig): boolean
|
||||
|| sdkBackend === 'mimo';
|
||||
}
|
||||
|
||||
// Alias ids the claude CLI itself still resolves: its alias table maps
|
||||
// opus/sonnet/haiku -> claude-*-5-5 and fable -> claude-fable-5-1. Preset
|
||||
// lists before the 2026-10 catalog refresh persisted `sonnet`/`haiku` as
|
||||
// preset ids, so a stored alias must keep resolving instead of being
|
||||
// silently replaced by the live catalog's full id.
|
||||
const CLAUDE_CLI_MODEL_ALIASES = new Set(['opus', 'sonnet', 'haiku', 'fable']);
|
||||
|
||||
function isStillValidClaudeAlias(
|
||||
storedModelId: string | null | undefined,
|
||||
agent?: ExternalAgentConfig,
|
||||
): boolean {
|
||||
if (!storedModelId) return false;
|
||||
if (getExternalAgentSdkBackend(agent) !== 'claude') return false;
|
||||
const baseId = canonicalizeEffortEncodedModelId(storedModelId).split('/')[0];
|
||||
return CLAUDE_CLI_MODEL_ALIASES.has(baseId);
|
||||
}
|
||||
|
||||
// Retain unlisted Copilot choices while discovery is pending or failed.
|
||||
// A successful auto-only catalog is authoritative, regardless of row names.
|
||||
function shouldRetainUnlistedCopilotModel(
|
||||
agent: ExternalAgentConfig | undefined,
|
||||
retainUnlistedModel: boolean,
|
||||
): boolean {
|
||||
return retainUnlistedModel && getExternalAgentSdkBackend(agent) === 'copilot';
|
||||
}
|
||||
|
||||
/**
|
||||
* True when a stored selection still resolves even though it is absent from
|
||||
* the given presets: either the presets list it under an effort-suffixed
|
||||
* spelling, or it is a claude CLI alias the backend accepts verbatim.
|
||||
*/
|
||||
export function storedModelStillResolvesForAgent(
|
||||
storedModelId: string | null | undefined,
|
||||
presets: AgentModelPreset[],
|
||||
agent?: ExternalAgentConfig,
|
||||
): boolean {
|
||||
if (!storedModelId) return false;
|
||||
return modelPresetsContainId(presets, storedModelId)
|
||||
|| isStillValidClaudeAlias(storedModelId, agent);
|
||||
}
|
||||
|
||||
export function resolveSdkRuntimeCatalogDefaultModelId(
|
||||
catalog: SdkRuntimeModelCatalog,
|
||||
agent?: ExternalAgentConfig,
|
||||
): string | null {
|
||||
if (catalog.currentModelId) return catalog.currentModelId;
|
||||
// Copilot lists models without a current id. Commit the same visible
|
||||
// default on live success, so a later failed refresh cannot revive an
|
||||
// unlisted saved choice that the live catalog has already replaced.
|
||||
if (!catalog.warning && getExternalAgentSdkBackend(agent) === 'copilot' && catalog.models[0]) {
|
||||
return resolveAgentModelSelection(catalog.models[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function shouldAdoptSdkCurrentModel(
|
||||
currentModelId: string | null | undefined,
|
||||
storedModelId: string | null | undefined,
|
||||
runtimePresets: AgentModelPreset[],
|
||||
agent?: ExternalAgentConfig,
|
||||
): boolean {
|
||||
if (!currentModelId) return false;
|
||||
// A stored claude alias the CLI still resolves is a user choice: never
|
||||
// overwrite it with the catalog's current model.
|
||||
if (isStillValidClaudeAlias(storedModelId, agent)) return false;
|
||||
return !storedModelId
|
||||
|| runtimePresets.length === 0
|
||||
|| !modelPresetsContainId(runtimePresets, storedModelId);
|
||||
@@ -467,63 +302,10 @@ export function shouldUseStoredAgentModel(
|
||||
storedModelId: string | null | undefined,
|
||||
presets: AgentModelPreset[],
|
||||
agent?: ExternalAgentConfig,
|
||||
retainUnlistedModel = false,
|
||||
): boolean {
|
||||
if (!storedModelId) return false;
|
||||
return storedModelStillResolvesForAgent(storedModelId, presets, agent)
|
||||
|| (presets.length === 0 && shouldLoadSdkRuntimeModels(agent))
|
||||
|| shouldRetainUnlistedCopilotModel(agent, retainUnlistedModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* A stored selection preserved through the claude-alias or copilot
|
||||
* degraded fallback has no preset row of its own; append one (reusing the
|
||||
* build-time preset when it defines the id) so the picker can render and
|
||||
* check the selection while the send preflight passes the same value.
|
||||
*/
|
||||
export function appendRetainedStoredModelPreset(
|
||||
presets: AgentModelPreset[],
|
||||
storedModelId: string | null | undefined,
|
||||
agent?: ExternalAgentConfig,
|
||||
retainUnlistedModel = false,
|
||||
): AgentModelPreset[] {
|
||||
if (!storedModelId || modelPresetsContainId(presets, storedModelId)) return presets;
|
||||
if (!isStillValidClaudeAlias(storedModelId, agent)
|
||||
&& !shouldRetainUnlistedCopilotModel(agent, retainUnlistedModel)) {
|
||||
return presets;
|
||||
}
|
||||
const canonical = canonicalizeEffortEncodedModelId(storedModelId);
|
||||
const baseId = canonical.split('/')[0];
|
||||
if (presets.some((preset) => preset.id === baseId)) {
|
||||
// The base row did not cover the stored id (checked above), so a suffixed
|
||||
// selection needs its own exact row; a bare id is already present.
|
||||
return canonical === baseId ? presets : [...presets, { id: canonical, name: canonical }];
|
||||
}
|
||||
const fallback = getAgentModelPresets(agent?.command, getExternalAgentSdkBackend(agent))
|
||||
.find((preset) => preset.id === baseId);
|
||||
// Keep the exact stored id (including any effort suffix) so the appended
|
||||
// row still matches the selection the send preflight passes.
|
||||
return [...presets, fallback ?? { id: canonical, name: canonical }];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retain the saved selection on top of the presets built for a catalog, but
|
||||
* only when a catalog actually arrived. When none did (the request failed
|
||||
* before any last-known-good entry existed) the result is empty so the agent
|
||||
* keeps its whole built-in fallback list: a lone retained row, or only the
|
||||
* user's custom composer models, would be stored as the authoritative runtime
|
||||
* list and hide every built-in preset. The panel appends custom models on top
|
||||
* of the fallback list itself.
|
||||
*/
|
||||
export function retainStoredModelPresetForCatalog(
|
||||
catalogPresets: AgentModelPreset[],
|
||||
presets: AgentModelPreset[],
|
||||
storedModelId: string | null | undefined,
|
||||
agent?: ExternalAgentConfig,
|
||||
retainUnlistedModel = false,
|
||||
): AgentModelPreset[] {
|
||||
if (catalogPresets.length === 0) return [];
|
||||
return appendRetainedStoredModelPreset(presets, storedModelId, agent, retainUnlistedModel);
|
||||
return modelPresetsContainId(presets, storedModelId)
|
||||
|| (presets.length === 0 && shouldLoadSdkRuntimeModels(agent));
|
||||
}
|
||||
|
||||
export function generateId(): string {
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
import { I18nProvider } from '../application/i18n/I18nProvider';
|
||||
import { createDomRenderer, dispatchDomEvent, flushEffects, installDomEnvironment, runWithAct } from './test-support/renderReactDom';
|
||||
|
||||
test('provider disconnect waits for completion, reports failure and permits retry', async () => {
|
||||
const dom = installDomEnvironment();
|
||||
const globals = {
|
||||
localStorage: dom.window.localStorage,
|
||||
MutationObserver: dom.window.MutationObserver,
|
||||
NodeFilter: dom.window.NodeFilter,
|
||||
HTMLInputElement: dom.window.HTMLInputElement,
|
||||
};
|
||||
const previous = new Map(Object.keys(globals).map((key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)]));
|
||||
for (const [key, value] of Object.entries(globals)) Object.defineProperty(globalThis, key, { configurable: true, value });
|
||||
const { ProviderCard } = await import('./cloud-sync/CloudSyncControls');
|
||||
const { toast } = await import('./ui/toast');
|
||||
const renderer = await createDomRenderer(dom.document);
|
||||
const notices: string[] = [];
|
||||
const info = toast.info;
|
||||
const error = toast.error;
|
||||
toast.info = (message) => { notices.push(`info:${message}`); };
|
||||
toast.error = (message) => { notices.push(`error:${message}`); };
|
||||
let finish: (() => void) | undefined;
|
||||
let fail = true;
|
||||
let calls = 0;
|
||||
try {
|
||||
await renderer.render(
|
||||
<I18nProvider locale="en">
|
||||
<ProviderCard provider="webdav" name="WebDAV" icon={null} isConnected isSyncing={false}
|
||||
onConnect={() => {}} onSync={() => {}}
|
||||
onDisconnect={() => {
|
||||
calls += 1;
|
||||
if (fail) throw new Error('fixture failure');
|
||||
return new Promise<void>((resolve) => { finish = resolve; });
|
||||
}} />
|
||||
</I18nProvider>,
|
||||
);
|
||||
const click = async (node: Element) => {
|
||||
await dispatchDomEvent(node, new dom.window.MouseEvent('click', { bubbles: true }));
|
||||
await flushEffects();
|
||||
};
|
||||
const button = dom.document.querySelector('button[aria-label="Disconnect"]');
|
||||
assert.ok(button);
|
||||
assert.equal(button.textContent, 'Disconnect');
|
||||
await click(button);
|
||||
let dialog = dom.document.querySelector('[role="dialog"]');
|
||||
assert.ok(dialog);
|
||||
assert.match(dialog.textContent ?? '', /backup history and sync encryption password stay here/);
|
||||
const confirm = () => {
|
||||
const node = [...dom.document.querySelectorAll('[role="dialog"] button')].find((el) => el.textContent === 'Disconnect');
|
||||
assert.ok(node);
|
||||
return node as HTMLButtonElement;
|
||||
};
|
||||
await click(confirm());
|
||||
assert.equal(calls, 1);
|
||||
assert.equal(notices.length, 1);
|
||||
assert.match(notices[0], /^error:Could not finish disconnecting from WebDAV/);
|
||||
assert.ok(dom.document.querySelector('[role="dialog"]'));
|
||||
assert.equal(confirm().disabled, false);
|
||||
fail = false;
|
||||
await click(confirm());
|
||||
assert.equal(calls, 2);
|
||||
assert.equal(confirm().disabled, true);
|
||||
assert.equal(notices.length, 1);
|
||||
await runWithAct(async () => { finish?.(); });
|
||||
await flushEffects();
|
||||
assert.equal(dom.document.querySelector('[role="dialog"]'), null);
|
||||
assert.equal(notices.length, 2);
|
||||
assert.match(notices[1], /^info:Encrypted sync copies may still exist in your WebDAV storage/);
|
||||
assert.doesNotMatch(notices[1], /\{name\}/);
|
||||
// Cancelling a new confirmation never calls the disconnect callback.
|
||||
await click(button);
|
||||
dialog = dom.document.querySelector('[role="dialog"]');
|
||||
assert.ok(dialog);
|
||||
const cancel = [...dialog.querySelectorAll('button')].find((el) => el.textContent === 'Cancel');
|
||||
assert.ok(cancel);
|
||||
await click(cancel);
|
||||
assert.equal(calls, 2);
|
||||
} finally {
|
||||
toast.info = info;
|
||||
toast.error = error;
|
||||
await renderer.unmount();
|
||||
// Radix restores focus on a timer after unmount. Keep the DOM globals
|
||||
// installed until that cleanup has dispatched its final event.
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
for (const [key, descriptor] of previous) {
|
||||
if (descriptor) Object.defineProperty(globalThis, key, descriptor);
|
||||
else Reflect.deleteProperty(globalThis, key);
|
||||
}
|
||||
dom.cleanup();
|
||||
}
|
||||
});
|
||||
@@ -27,9 +27,8 @@ import {
|
||||
toGlobalHistoryDisplayEntries,
|
||||
} from '../domain/globalHistory';
|
||||
import type { Host, RemoteHistoryEntry, ShellHistoryEntry } from '../domain/models';
|
||||
import { removeCommandHistoryEntry } from '../application/state/commandHistoryStore';
|
||||
import { removeCommandHistoryEntry } from './terminal/autocomplete/commandHistoryStore';
|
||||
import { cn } from '../lib/utils';
|
||||
import { ConfirmDialog } from './ui/confirm-dialog';
|
||||
import type { RemoteHistoryHostState } from '../application/state/useRemoteHistoryState';
|
||||
import {
|
||||
VariableSizeVirtualList,
|
||||
@@ -47,7 +46,6 @@ export interface HistorySidePanelProps {
|
||||
globalEntries: ShellHistoryEntry[];
|
||||
onFetch: (sessionId: string, hostId: string) => void;
|
||||
onDeleteGlobalEntry?: (entryId: string) => void;
|
||||
onClearGlobalHistory?: () => void;
|
||||
/** Paste into the terminal without executing (no trailing Enter). */
|
||||
onPasteToTerminal: (command: string) => void;
|
||||
/** Write to the terminal and execute (append Enter). */
|
||||
@@ -117,7 +115,6 @@ const HistorySidePanelInner: React.FC<HistorySidePanelProps> = ({
|
||||
globalEntries,
|
||||
onFetch,
|
||||
onDeleteGlobalEntry,
|
||||
onClearGlobalHistory,
|
||||
onPasteToTerminal,
|
||||
onRunInTerminal,
|
||||
isVisible = true,
|
||||
@@ -126,7 +123,6 @@ const HistorySidePanelInner: React.FC<HistorySidePanelProps> = ({
|
||||
const [scope, setScope] = useState<HistoryPanelScope>('host');
|
||||
const [search, setSearch] = useState('');
|
||||
const [selectedEntryId, setSelectedEntryId] = useState<string | null>(null);
|
||||
const [clearAllOpen, setClearAllOpen] = useState(false);
|
||||
const listRef = useRef<VariableSizeVirtualListHandle>(null);
|
||||
|
||||
const protocol = focusedHost?.protocol;
|
||||
@@ -212,14 +208,6 @@ const HistorySidePanelInner: React.FC<HistorySidePanelProps> = ({
|
||||
setSelectedEntryId(null);
|
||||
}, [globalEntries, onDeleteGlobalEntry, scope, sourceEntries]);
|
||||
|
||||
const handleClearAll = useCallback(() => {
|
||||
// The application-state action clears both the global shell history and the
|
||||
// autocomplete history, and fans the clear out to every renderer.
|
||||
onClearGlobalHistory?.();
|
||||
setClearAllOpen(false);
|
||||
setSelectedEntryId(null);
|
||||
}, [onClearGlobalHistory]);
|
||||
|
||||
const handleRowClick = useCallback((entryId: string) => {
|
||||
setSelectedEntryId((current) => {
|
||||
const next = current === entryId ? null : entryId;
|
||||
@@ -306,18 +294,6 @@ const HistorySidePanelInner: React.FC<HistorySidePanelProps> = ({
|
||||
<RefreshCw size={14} className={cn(state.loading && 'animate-spin')} />
|
||||
</button>
|
||||
)}
|
||||
{scope === 'global' && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setClearAllOpen(true)}
|
||||
disabled={!onClearGlobalHistory}
|
||||
title={t('history.action.clearAll')}
|
||||
aria-label={t('history.action.clearAll')}
|
||||
className="shrink-0 h-6 w-6 flex items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors disabled:opacity-40 disabled:hover:text-muted-foreground disabled:hover:bg-transparent"
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="shrink-0 flex items-center gap-2 px-3 py-1.5 text-[11px] text-muted-foreground border-b border-border/30 min-h-[28px]">
|
||||
@@ -435,16 +411,6 @@ const HistorySidePanelInner: React.FC<HistorySidePanelProps> = ({
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
open={clearAllOpen}
|
||||
onOpenChange={setClearAllOpen}
|
||||
title={t('history.clearAll.dialog.title')}
|
||||
message={t('history.clearAll.dialog.desc')}
|
||||
confirmLabel={t('history.clearAll.dialog.confirm')}
|
||||
destructive
|
||||
onConfirm={handleClearAll}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -239,7 +239,6 @@ const TerminalLayerInner: React.FC<TerminalLayerProps> = ({
|
||||
onAddKnownHost,
|
||||
onCommandExecuted,
|
||||
onDeleteShellHistoryEntry,
|
||||
onClearCommandHistory,
|
||||
onTerminalDataCapture,
|
||||
onCreateWorkspaceFromSessions,
|
||||
onAddSessionToWorkspace,
|
||||
@@ -2534,7 +2533,6 @@ const TerminalLayerInner: React.FC<TerminalLayerProps> = ({
|
||||
handleCloseSidePanel,
|
||||
handleCommandExecuted,
|
||||
handleHistoryDelete: onDeleteShellHistoryEntry,
|
||||
handleHistoryClear: onClearCommandHistory,
|
||||
handleCommandSubmitted,
|
||||
handleComposeSend,
|
||||
handleHistoryPaste,
|
||||
|
||||
@@ -107,7 +107,7 @@ export const TopTabsQuickControls: React.FC<TopTabsQuickControlsProps> = ({
|
||||
onClick={() => setIsOpacityExpanded((current) => !current)}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-2 text-sm">
|
||||
<Droplets size={14} className={cn("shrink-0", windowOpacity < 1.0 ? "text-primary" : "text-muted-foreground")} />
|
||||
<Droplets size={14} className="shrink-0 text-muted-foreground" />
|
||||
<span className="truncate">{t('topTabs.windowOpacity')}</span>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-1.5">
|
||||
|
||||
@@ -51,7 +51,6 @@ import { useStoredString } from "../application/state/useStoredString";
|
||||
import type { VaultLockHandle } from "../application/state/vaultManagedImportLock";
|
||||
import { useTreeExpandedState } from "../application/state/useTreeExpandedState";
|
||||
import { useVaultGroupDeletion } from "../application/state/useVaultGroupDeletion";
|
||||
import { useVaultHostDeletion } from "../application/state/useVaultHostDeletion";
|
||||
import type { VaultHostPersistenceResult } from "../application/state/vaultImportProgress";
|
||||
import type {
|
||||
VaultGroupMutationResult,
|
||||
@@ -981,19 +980,15 @@ const VaultViewInner: React.FC<VaultViewProps> = ({
|
||||
setIsMultiSelectMode(false);
|
||||
}, []);
|
||||
|
||||
const deleteVaultHosts = useVaultHostDeletion(onCommitVaultGroupMutation);
|
||||
const deleteSelectedHosts = useCallback(async () => {
|
||||
const deleteSelectedHosts = useCallback(() => {
|
||||
if (selectedHostIds.size === 0) return;
|
||||
try {
|
||||
await deleteVaultHosts(selectedHostIds);
|
||||
clearHostSelection();
|
||||
toast.success(
|
||||
t("vault.hosts.deleteMultiple.success", { count: selectedHostIds.size }),
|
||||
);
|
||||
} catch {
|
||||
toast.error(t("common.error"));
|
||||
}
|
||||
}, [selectedHostIds, deleteVaultHosts, clearHostSelection, t]);
|
||||
const updatedHosts = hosts.filter((h) => !selectedHostIds.has(h.id));
|
||||
onUpdateHosts(updatedHosts);
|
||||
clearHostSelection();
|
||||
toast.success(
|
||||
t("vault.hosts.deleteMultiple.success", { count: selectedHostIds.size }),
|
||||
);
|
||||
}, [selectedHostIds, hosts, onUpdateHosts, clearHostSelection, t]);
|
||||
|
||||
const connectSelectedHosts = useCallback(() => {
|
||||
if (selectedHostIds.size === 0) return;
|
||||
@@ -1363,7 +1358,6 @@ const VaultViewInner: React.FC<VaultViewProps> = ({
|
||||
handleUnmanageGroup,
|
||||
managedGroupPaths,
|
||||
moveHostToGroup,
|
||||
moveHostsToGroup,
|
||||
setDragOverDropTarget,
|
||||
setGroupDragOverDropTarget,
|
||||
} = useVaultGroupDragHandlers({
|
||||
@@ -1608,7 +1602,6 @@ const VaultViewInner: React.FC<VaultViewProps> = ({
|
||||
managedSources,
|
||||
moveGroup,
|
||||
moveHostToGroup,
|
||||
moveHostsToGroup,
|
||||
Network,
|
||||
newFolderName,
|
||||
newHostGroupPath,
|
||||
|
||||
@@ -206,12 +206,8 @@ interface ChatInputProps {
|
||||
placeholder?: string;
|
||||
/** Available model presets for the current agent */
|
||||
modelPresets?: AgentModelPreset[];
|
||||
/** Live agent model catalog is still loading. */
|
||||
/** Live agent model catalog (OpenCode) is still loading. */
|
||||
modelCatalogLoading?: boolean;
|
||||
/** Provenance of the active model list, rendered as the picker status chip. */
|
||||
modelCatalogSource?: 'live' | 'last-known-good' | 'presets';
|
||||
/** ISO timestamp of the successful fetch backing `modelCatalogSource`. */
|
||||
modelCatalogFetchedAt?: string;
|
||||
/**
|
||||
* Offer the picker's "use custom model" action. Disable when the current
|
||||
* agent locks the model (e.g. managed Codex `model` config overrides the
|
||||
@@ -284,8 +280,6 @@ const ChatInput: React.FC<ChatInputProps> = ({
|
||||
placeholder,
|
||||
modelPresets = [],
|
||||
modelCatalogLoading = false,
|
||||
modelCatalogSource,
|
||||
modelCatalogFetchedAt,
|
||||
allowCustomModelEntry = true,
|
||||
selectedModelId,
|
||||
onModelSelect,
|
||||
@@ -1006,9 +1000,8 @@ const ChatInput: React.FC<ChatInputProps> = ({
|
||||
? providerSwitcherChipLabel
|
||||
: (selectedPreset?.name || modelName || providerName || t('ai.chat.noModel'));
|
||||
const modelChipMaxWidth = hasProviderSwitcher ? 'max-w-[168px]' : 'max-w-[96px]';
|
||||
// Keep the picker open-able while an SDK catalog load is pending: the host
|
||||
// now shows build-time presets during loading, with the loading row when
|
||||
// presets are still empty (#3584).
|
||||
// Keep the picker open-able while an OpenCode catalog load is pending so
|
||||
// the user sees the loading row instead of stale built-in presets (#3584).
|
||||
const hasModelPicker = hasProviderSwitcher
|
||||
|| ((modelPresets.length > 0 || modelCatalogLoading) && !!onModelSelect);
|
||||
const thinkingLevels = useMemo(
|
||||
@@ -1606,8 +1599,6 @@ const ChatInput: React.FC<ChatInputProps> = ({
|
||||
selectedModelId={hasProviderSwitcher ? providerSwitcher?.selectedModelId : selectedBaseModelId}
|
||||
modelPresets={hasProviderSwitcher ? undefined : modelPresets}
|
||||
loading={!hasProviderSwitcher ? modelCatalogLoading : undefined}
|
||||
catalogSource={!hasProviderSwitcher ? modelCatalogSource : undefined}
|
||||
catalogFetchedAt={!hasProviderSwitcher ? modelCatalogFetchedAt : undefined}
|
||||
allowCustomEntry={allowCustomModelEntry}
|
||||
prefs={modelPrefs}
|
||||
onSelectProviderModel={(providerId, modelId, contextWindow) => {
|
||||
@@ -1822,8 +1813,6 @@ function chatInputPropsAreEqual(prev: ChatInputProps, next: ChatInputProps): boo
|
||||
&& prev.placeholder === next.placeholder
|
||||
&& prev.modelPresets === next.modelPresets
|
||||
&& prev.modelCatalogLoading === next.modelCatalogLoading
|
||||
&& prev.modelCatalogSource === next.modelCatalogSource
|
||||
&& prev.modelCatalogFetchedAt === next.modelCatalogFetchedAt
|
||||
&& prev.allowCustomModelEntry === next.allowCustomModelEntry
|
||||
&& prev.selectedModelId === next.selectedModelId
|
||||
&& prev.onModelSelect === next.onModelSelect
|
||||
|
||||
@@ -22,48 +22,6 @@ const makeMessage = (index: number): ChatMessage => ({
|
||||
timestamp: index,
|
||||
});
|
||||
|
||||
for (const field of ["attachments", "images"] as const) {
|
||||
test(`ChatMessageList shows unavailable restored ${field} without broken image previews`, () => {
|
||||
const messages: ChatMessage[] = [{
|
||||
id: "restored-user", role: "user", content: "restored request", timestamp: 1,
|
||||
[field]: [
|
||||
{ base64Data: "", contentUnavailable: true, mediaType: "image/png", filename: "screenshot.png" },
|
||||
{ base64Data: "", contentUnavailable: true, mediaType: "application/pdf", filename: "report.pdf" },
|
||||
{ base64Data: "", contentUnavailable: true, mediaType: "text/plain", filename: "selection.log", terminalSelection: true },
|
||||
],
|
||||
}];
|
||||
const markup = renderToStaticMarkup(
|
||||
<I18nProvider locale="en">
|
||||
<TooltipProvider><ChatMessageList messages={messages} /></TooltipProvider>
|
||||
</I18nProvider>,
|
||||
);
|
||||
assert.match(markup, /screenshot\.png/);
|
||||
assert.match(markup, /report\.pdf/);
|
||||
assert.match(markup, /selection\.log/);
|
||||
assert.match(markup, /Content not available on this device/);
|
||||
assert.doesNotMatch(markup, /<img|data:image/);
|
||||
});
|
||||
}
|
||||
|
||||
test("ChatMessageList retains local image previews and synced note identities", () => {
|
||||
const messages: ChatMessage[] = [{
|
||||
id: "user", role: "user", content: "look", timestamp: 1,
|
||||
attachments: [
|
||||
{ base64Data: "cGljdHVyZQ==", mediaType: "image/png", filename: "local.png" },
|
||||
{ base64Data: "", contentUnavailable: true, mediaType: "text/markdown", vaultNoteId: "note-1", vaultNoteTitle: "Runbook" },
|
||||
],
|
||||
}];
|
||||
const markup = renderToStaticMarkup(
|
||||
<I18nProvider locale="en">
|
||||
<TooltipProvider><ChatMessageList messages={messages} /></TooltipProvider>
|
||||
</I18nProvider>,
|
||||
);
|
||||
assert.match(markup, /<img/);
|
||||
assert.match(markup, /data:image\/png;base64,cGljdHVyZQ==/);
|
||||
assert.match(markup, /Runbook/);
|
||||
assert.doesNotMatch(markup, /Content not available on this device/);
|
||||
});
|
||||
|
||||
test("resolved approval state retains only tool calls still present in messages", () => {
|
||||
const previous = new Map<string, boolean>();
|
||||
for (let index = 0; index < 1_000; index += 1) previous.set(`old-${index}`, true);
|
||||
|
||||
@@ -710,19 +710,7 @@ const ChatMessageList: React.FC<ChatMessageListProps> = ({
|
||||
{isUser && !hideAttachments && (message.attachments ?? message.images)?.length && (
|
||||
<div className="flex gap-1.5 flex-wrap mb-1">
|
||||
{(message.attachments ?? message.images)!.map((att, i) => (
|
||||
!att.vaultNoteId && (att.contentUnavailable || !att.base64Data) ? (
|
||||
<div
|
||||
key={att.filename ? `${att.filename}-${i}` : `att-${message.id}-${i}`}
|
||||
className="inline-flex items-center gap-1.5 min-h-7 px-2 py-1 rounded-md bg-muted/20 border border-border/20 text-[11px] text-foreground/70"
|
||||
title={t('ai.chat.attachmentContentUnavailable')}
|
||||
>
|
||||
{att.terminalSelection
|
||||
? <SquareTerminal size={12} className="text-muted-foreground/60 shrink-0" />
|
||||
: <FileText size={12} className="text-muted-foreground/60 shrink-0" />}
|
||||
<span className="truncate max-w-[150px]">{att.filename || (att.terminalSelection ? 'terminal selection' : 'file')}</span>
|
||||
<span className="text-muted-foreground">{t('ai.chat.attachmentContentUnavailable')}</span>
|
||||
</div>
|
||||
) : att.terminalSelection ? (
|
||||
att.terminalSelection ? (
|
||||
<div
|
||||
key={att.filename ? `${att.filename}-${i}` : `att-${message.id}-${i}`}
|
||||
className="inline-flex items-center gap-1.5 h-7 px-2 rounded-md bg-muted/20 border border-border/20 text-[11px] text-foreground/70"
|
||||
|
||||
@@ -5,35 +5,6 @@ import React from 'react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
|
||||
import { ComposerModelPicker } from './ComposerModelPicker';
|
||||
import { I18nProvider } from '../../application/i18n/I18nProvider';
|
||||
|
||||
for (const [locale, cachedLabel] of [
|
||||
['en', 'Cached'],
|
||||
['zh-CN', '缓存'],
|
||||
['zh-TW', '快取'],
|
||||
['es', 'En caché'],
|
||||
['ru', 'Кэш'],
|
||||
]) {
|
||||
test(`cached catalog without a usable timestamp has a clean label in ${locale}`, () => {
|
||||
for (const fetchedAt of [undefined, 'invalid-date']) {
|
||||
const html = renderToStaticMarkup(
|
||||
<I18nProvider locale={locale}>
|
||||
<ComposerModelPicker
|
||||
modelPresets={[{ id: 'saved-model', name: 'Saved model' }]}
|
||||
selectedModelId="saved-model"
|
||||
catalogSource="last-known-good"
|
||||
catalogFetchedAt={fetchedAt}
|
||||
prefs={{ recent: [], pinned: [] }}
|
||||
onSelectModel={() => {}}
|
||||
onTogglePinned={() => {}}
|
||||
/>
|
||||
</I18nProvider>,
|
||||
);
|
||||
assert.ok(html.includes(`title="${cachedLabel}"`));
|
||||
assert.doesNotMatch(html, /\{time\}|ai\.chat\.modelCatalog/);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
test('Catty picker keeps a single model list and hides other providers until the submenu opens', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
@@ -152,7 +123,6 @@ test('external agent picker shows the loading row while the live catalog is pend
|
||||
);
|
||||
|
||||
assert.match(html, /ai\.chat\.loadingModels/);
|
||||
// With no presets the picker renders only the loading row; the host now
|
||||
// keeps built-in presets visible during loading and passes them through.
|
||||
// The host no longer renders built-in presets while loading (#3584).
|
||||
assert.doesNotMatch(html, /gpt-5\.1/);
|
||||
});
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
type ComposerPickerModel,
|
||||
} from '../../infrastructure/ai/composerPicker';
|
||||
import type { AgentModelPreset, ProviderConfig } from '../../infrastructure/ai/types';
|
||||
import { formatRelativeTime } from '../AIChatSessionHistoryDrawer';
|
||||
import { ProviderIconBadge } from '../settings/tabs/ai/ProviderIconBadge';
|
||||
import { useProviderModelCatalog } from './useProviderModelCatalog';
|
||||
|
||||
@@ -28,15 +27,6 @@ export interface ComposerModelPickerProps {
|
||||
* loading. Show the loading row instead of an empty/placeholder list.
|
||||
*/
|
||||
loading?: boolean;
|
||||
/**
|
||||
* Provenance of the model list behind this picker: a live SDK fetch, the
|
||||
* persisted last-known-good catalog, or the build-time preset fallback.
|
||||
* Rendered as a small muted status footer; omit (provider switcher mode)
|
||||
* to hide the chip.
|
||||
*/
|
||||
catalogSource?: 'live' | 'last-known-good' | 'presets';
|
||||
/** ISO timestamp of the successful fetch backing `catalogSource`. */
|
||||
catalogFetchedAt?: string;
|
||||
prefs: ComposerModelPrefs;
|
||||
/**
|
||||
* Offer the "use custom model" action. Disable when the host locks the
|
||||
@@ -105,8 +95,6 @@ export const ComposerModelPicker: React.FC<ComposerModelPickerProps> = ({
|
||||
selectedModelId,
|
||||
modelPresets = [],
|
||||
loading = false,
|
||||
catalogSource,
|
||||
catalogFetchedAt,
|
||||
prefs,
|
||||
allowCustomEntry = true,
|
||||
onSelectProviderModel,
|
||||
@@ -159,21 +147,6 @@ export const ComposerModelPicker: React.FC<ComposerModelPickerProps> = ({
|
||||
);
|
||||
|
||||
const trimmedQuery = query.trim();
|
||||
// Uniform catalog status chip (all SDK backends). While the live fetch is
|
||||
// in flight the spinner row replaces the chip, so it renders only for a
|
||||
// resolved list; an unknown source renders nothing (provider mode).
|
||||
const catalogChipText = useMemo(() => {
|
||||
if (loading || !catalogSource) return null;
|
||||
if (catalogSource === 'live') return t('ai.chat.modelCatalogSourceLive');
|
||||
if (catalogSource === 'presets') return t('ai.chat.modelCatalogSourcePresets');
|
||||
const parsed = catalogFetchedAt ? new Date(catalogFetchedAt) : null;
|
||||
const time = parsed && !Number.isNaN(parsed.getTime())
|
||||
? formatRelativeTime(parsed, t)
|
||||
: '';
|
||||
return time
|
||||
? t('ai.chat.modelCatalogSourceCached').replace('{time}', time)
|
||||
: t('ai.chat.modelCatalogSourceCachedNoTime');
|
||||
}, [loading, catalogSource, catalogFetchedAt, t]);
|
||||
// Manual model ids are accepted in both modes: provider-bound catalogs and
|
||||
// preset lists from external CLI agents whose catalogs lag new models.
|
||||
const showCustom = Boolean(
|
||||
@@ -383,12 +356,6 @@ export const ComposerModelPicker: React.FC<ComposerModelPickerProps> = ({
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{catalogChipText && (
|
||||
<div className="border-t border-border/40 px-2.5 py-1 text-[10px] text-muted-foreground/45" title={catalogChipText}>
|
||||
{catalogChipText}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { buildExternalBridgeContextMessages } from "../../infrastructure/ai/harness/externalBridgeContext.ts";
|
||||
import { ToolOutputStore } from "../../infrastructure/ai/harness/toolOutputStore.ts";
|
||||
import {
|
||||
buildCattySdkMessages,
|
||||
createContinuationContext,
|
||||
} from "../../infrastructure/ai/harness/turnDrivers/cattyMessageBuilder.ts";
|
||||
|
||||
import type { ChatMessageAttachment, ToolCall, ToolResult } from "../../infrastructure/ai/types.ts";
|
||||
import {
|
||||
@@ -236,59 +231,6 @@ test("buildHistoricalUserReplayContent replaces historical vault note mentions w
|
||||
assert.doesNotMatch(result, /AAAAAA/);
|
||||
});
|
||||
|
||||
for (const field of ["attachments", "images"] as const) {
|
||||
test(`restored ${field} keep image, file and terminal metadata usable when continuing a chat`, () => {
|
||||
const attachments: ChatMessageAttachment[] = [
|
||||
{ base64Data: "", contentUnavailable: true, mediaType: "image/png", filename: "screenshot.png" },
|
||||
{ base64Data: "", contentUnavailable: true, mediaType: "application/pdf", filename: "report.pdf" },
|
||||
{ base64Data: "", contentUnavailable: true, mediaType: "text/plain", filename: "selection.log", terminalSelection: true, lineCount: 3 },
|
||||
];
|
||||
const messages: ChatMessage[] = [{
|
||||
id: "restored-user", role: "user", content: "Inspect these files", timestamp: 1,
|
||||
[field]: attachments,
|
||||
}];
|
||||
const catty = buildCattySdkMessages({
|
||||
allMessages: messages,
|
||||
includeCurrentUserMessage: true,
|
||||
trimmed: "Please continue",
|
||||
continuationContext: createContinuationContext("provider", "openai", "model", false),
|
||||
chatSessionId: "restored-chat",
|
||||
toolOutputStore: new ToolOutputStore(),
|
||||
fieldsByMessage: new Map(),
|
||||
});
|
||||
const external = buildExternalBridgeContextMessages(messages);
|
||||
for (const history of [catty, external]) {
|
||||
const content = String(history.find((message) => message.role === "user")?.content);
|
||||
assert.match(content, /screenshot\.png/);
|
||||
assert.match(content, /report\.pdf/);
|
||||
assert.match(content, /selection\.log/);
|
||||
assert.match(content, /lines=3/);
|
||||
assert.equal(content.match(/content unavailable on this device/g)?.length, 3);
|
||||
assert.doesNotMatch(content, /0 base64 chars|undefined/);
|
||||
}
|
||||
assert.equal(catty.at(-1)?.content, "Please continue");
|
||||
});
|
||||
}
|
||||
|
||||
test("synced note metadata retains the reference needed to read the note", () => {
|
||||
const replay = buildHistoricalUserReplayContent("check this note", [{
|
||||
base64Data: "", contentUnavailable: true, mediaType: "text/markdown",
|
||||
vaultNoteId: "note-123", vaultNoteTitle: "Runbook",
|
||||
}]);
|
||||
assert.match(replay, /"noteId":"note-123"/);
|
||||
assert.match(replay, /vault_notes_get/);
|
||||
});
|
||||
|
||||
test("unavailable attachment placeholders do not expose stale local content fields", () => {
|
||||
const replay = buildHistoricalUserReplayContent("check", [{
|
||||
base64Data: "", contentUnavailable: true, mediaType: "text/plain", terminalSelection: true,
|
||||
previewText: "private terminal output",
|
||||
}, {
|
||||
base64Data: "", contentUnavailable: true, mediaType: "application/pdf", filePath: "/private/report.pdf",
|
||||
}]);
|
||||
assert.doesNotMatch(replay, /private terminal output|\/private\//);
|
||||
});
|
||||
|
||||
test("external recovery retains note identity before truncating a long user request", () => {
|
||||
const history = buildExternalBridgeContextMessages([{
|
||||
id: "long-note-request", role: "user", timestamp: 1, content: "x".repeat(2500),
|
||||
|
||||
@@ -15,9 +15,6 @@ function truncateInline(value: string, maxChars: number): string {
|
||||
}
|
||||
|
||||
function describeAttachmentSize(attachment: ChatMessageAttachment): string {
|
||||
if (attachment.contentUnavailable || !attachment.base64Data) {
|
||||
return "content unavailable on this device";
|
||||
}
|
||||
return `${attachment.base64Data.length} base64 chars`;
|
||||
}
|
||||
|
||||
@@ -28,7 +25,7 @@ function formatTerminalSelectionPlaceholder(
|
||||
const details = [
|
||||
`filename=${attachment.filename || `terminal-selection-${index + 1}.log`}`,
|
||||
attachment.lineCount != null ? `lines=${attachment.lineCount}` : undefined,
|
||||
!attachment.contentUnavailable && attachment.previewText ? `preview=${truncateInline(attachment.previewText, MAX_ATTACHMENT_PLACEHOLDER_DETAIL_CHARS)}` : undefined,
|
||||
attachment.previewText ? `preview=${truncateInline(attachment.previewText, MAX_ATTACHMENT_PLACEHOLDER_DETAIL_CHARS)}` : undefined,
|
||||
describeAttachmentSize(attachment),
|
||||
].filter(Boolean).join(", ");
|
||||
|
||||
@@ -42,7 +39,7 @@ function formatAttachmentPlaceholder(
|
||||
const label = attachment.mediaType.startsWith("image/") ? "image" : "file";
|
||||
const details = [
|
||||
attachment.filename ? `filename=${attachment.filename}` : undefined,
|
||||
!attachment.contentUnavailable && attachment.filePath ? `path=${attachment.filePath}` : undefined,
|
||||
attachment.filePath ? `path=${attachment.filePath}` : undefined,
|
||||
`mediaType=${attachment.mediaType}`,
|
||||
describeAttachmentSize(attachment),
|
||||
].filter(Boolean).join(", ");
|
||||
|
||||
@@ -279,7 +279,7 @@ interface ProviderCardProps {
|
||||
onEdit?: () => void;
|
||||
onConnect: () => void;
|
||||
onCancelConnect?: () => void;
|
||||
onDisconnect: () => void | Promise<void>;
|
||||
onDisconnect: () => void;
|
||||
onSync: () => void;
|
||||
extraActions?: React.ReactNode;
|
||||
}
|
||||
@@ -304,7 +304,6 @@ export const ProviderCard: React.FC<ProviderCardProps> = ({
|
||||
}) => {
|
||||
const { t } = useI18n();
|
||||
const [disconnectConfirmOpen, setDisconnectConfirmOpen] = useState(false);
|
||||
const [disconnecting, setDisconnecting] = useState(false);
|
||||
const formatLastSyncLabel = (timestamp?: number): string => {
|
||||
if (!timestamp) return t('cloudSync.lastSync.never');
|
||||
const now = Date.now();
|
||||
@@ -412,12 +411,10 @@ export const ProviderCard: React.FC<ProviderCardProps> = ({
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => setDisconnectConfirmOpen(true)}
|
||||
disabled={disconnecting}
|
||||
className="gap-1 text-muted-foreground hover:text-red-500"
|
||||
className="text-muted-foreground hover:text-red-500"
|
||||
aria-label={t('cloudSync.provider.disconnect')}
|
||||
>
|
||||
<CloudOff size={14} />
|
||||
{t('cloudSync.provider.disconnect')}
|
||||
</Button>
|
||||
</>
|
||||
) : isConnecting && onCancelConnect ? (
|
||||
@@ -448,25 +445,10 @@ export const ProviderCard: React.FC<ProviderCardProps> = ({
|
||||
message={t('cloudSync.provider.disconnect.confirmMessage', { name })}
|
||||
confirmLabel={t('cloudSync.provider.disconnect.confirmAction')}
|
||||
destructive
|
||||
busy={disconnecting}
|
||||
onOpenChange={(open) => {
|
||||
if (!disconnecting) setDisconnectConfirmOpen(open);
|
||||
}}
|
||||
onOpenChange={setDisconnectConfirmOpen}
|
||||
onConfirm={() => {
|
||||
setDisconnecting(true);
|
||||
void Promise.resolve()
|
||||
.then(() => onDisconnect())
|
||||
.then(() => {
|
||||
setDisconnectConfirmOpen(false);
|
||||
toast.info(t('cloudSync.provider.disconnect.cloudRemains', { name }), {
|
||||
title: t('cloudSync.provider.disconnect.toastTitle'),
|
||||
duration: 8000,
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
toast.error(t('cloudSync.provider.disconnect.failed', { name }));
|
||||
})
|
||||
.finally(() => setDisconnecting(false));
|
||||
setDisconnectConfirmOpen(false);
|
||||
onDisconnect();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
@@ -576,7 +558,6 @@ const CONFLICT_ENTITY_LABEL_KEYS: Record<SyncChangeEntityKey, string> = {
|
||||
snippetPackages: 'cloudSync.conflict.entity.snippetPackages',
|
||||
portForwardingRules: 'cloudSync.conflict.entity.portForwardingRules',
|
||||
groupConfigs: 'cloudSync.conflict.entity.groupConfigs',
|
||||
aiSessions: 'cloudSync.aiSessions.title',
|
||||
settings: 'cloudSync.conflict.entity.settings',
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import type { useCloudSync } from '../../application/state/useCloudSync';
|
||||
import { storePluginSyncSecretsThenConnect } from '../../application/pluginSyncConnectWithSecrets';
|
||||
import { cleanOneDriveErrorMessage, isProviderReadyForSync } from '../../domain/sync';
|
||||
import { pluginExtensionBridge } from '../../application/state/pluginExtensionBridge';
|
||||
import { Switch } from '../ui/switch';
|
||||
import { cn } from '../../lib/utils';
|
||||
import { Button } from '../ui/button';
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '../ui/dialog';
|
||||
@@ -93,8 +92,6 @@ export const CloudSyncDashboardTabs: React.FC<CloudSyncDashboardTabsProps> = ({
|
||||
onDowngradeConvergent,
|
||||
disconnectOtherProviders,
|
||||
}) => {
|
||||
const [aiSessionsSyncBusy, setAiSessionsSyncBusy] = useState(false);
|
||||
|
||||
const [pluginSyncProviders, setPluginSyncProviders] = useState<Array<{
|
||||
id: string;
|
||||
title: string;
|
||||
@@ -557,9 +554,7 @@ export const CloudSyncDashboardTabs: React.FC<CloudSyncDashboardTabsProps> = ({
|
||||
? t('cloudSync.strategy.preferCloud')
|
||||
: sync.syncStrategy === 'preferLocal'
|
||||
? t('cloudSync.strategy.preferLocal')
|
||||
: sync.syncStrategy === 'smartMergePreserve'
|
||||
? t('cloudSync.strategy.smartMergePreserve')
|
||||
: t('cloudSync.strategy.smartMerge')}
|
||||
: t('cloudSync.strategy.smartMerge')}
|
||||
</SelectTrigger>
|
||||
<SelectContent className="max-w-[min(520px,var(--radix-select-trigger-width))]">
|
||||
<SelectItem value="smartMerge" className="items-start py-2">
|
||||
@@ -570,14 +565,6 @@ export const CloudSyncDashboardTabs: React.FC<CloudSyncDashboardTabsProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
</SelectItem>
|
||||
<SelectItem value="smartMergePreserve" className="items-start py-2">
|
||||
<div className="space-y-0.5">
|
||||
<div>{t('cloudSync.strategy.smartMergePreserve')}</div>
|
||||
<div className="text-xs text-muted-foreground leading-snug">
|
||||
{t('cloudSync.strategy.smartMergePreserveDesc')}
|
||||
</div>
|
||||
</div>
|
||||
</SelectItem>
|
||||
<SelectItem value="preferCloud" className="items-start py-2">
|
||||
<div className="space-y-0.5">
|
||||
<div>{t('cloudSync.strategy.preferCloud')}</div>
|
||||
@@ -598,29 +585,6 @@ export const CloudSyncDashboardTabs: React.FC<CloudSyncDashboardTabsProps> = ({
|
||||
</Select>
|
||||
</SettingsAnchor>
|
||||
|
||||
<SettingsAnchor anchorId="sync-ai-sessions" className="p-4 rounded-lg border bg-card">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="text-sm font-medium">{t('cloudSync.aiSessions.title')}</div>
|
||||
<div className="text-xs text-muted-foreground mt-1">
|
||||
{t('cloudSync.aiSessions.desc')}
|
||||
{' '}{t('cloudSync.aiSessions.compatibility')}
|
||||
</div>
|
||||
</div>
|
||||
<Switch
|
||||
aria-label={t('cloudSync.aiSessions.title')}
|
||||
checked={sync.aiSessionsSyncEnabled}
|
||||
disabled={aiSessionsSyncBusy}
|
||||
onCheckedChange={(enabled) => {
|
||||
setAiSessionsSyncBusy(true);
|
||||
void sync.setAiSessionsSyncEnabled(enabled).catch(() => {
|
||||
toast.error(t('cloudSync.aiSessions.enableFailed'));
|
||||
}).finally(() => setAiSessionsSyncBusy(false));
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</SettingsAnchor>
|
||||
|
||||
{sync.hasAnyConnectedProvider && (
|
||||
<div className="space-y-3">
|
||||
{/* Version Info Cards */}
|
||||
|
||||
@@ -158,7 +158,7 @@ export interface NetcattyAiBridge {
|
||||
aiCodexCancelLogin?: (sessionId: string) => Promise<{ ok: boolean; found?: boolean; session?: CodexLoginSession; error?: string }>;
|
||||
aiCodexLogout?: (options?: { codexPath?: string; agentEnv?: Record<string, string> }) => Promise<{ ok: boolean; state?: CodexIntegrationState; isConnected?: boolean; rawOutput?: string; logoutOutput?: string; error?: string }>;
|
||||
aiResolveCli?: (params: { command: string; customPath?: string; refreshShellEnv?: boolean; apiKeyPresent?: boolean }) => Promise<AgentPathInfo>;
|
||||
aiSdkAgentListModels?: (sdkBackend: string, cwd?: string, providerId?: string, chatSessionId?: string, agentEnv?: Record<string, string>, agentCommand?: string, codexRuntime?: 'sdk' | 'app-server') => Promise<{ ok: boolean; models?: Array<{ id: string; name: string; description?: string; thinkingLevels?: string[]; defaultThinkingLevel?: string }>; currentModelId?: string | null; warning?: string; source?: 'live' | 'last-known-good'; fetchedAt?: string; error?: string }>;
|
||||
aiSdkAgentListModels?: (sdkBackend: string, cwd?: string, providerId?: string, chatSessionId?: string, agentEnv?: Record<string, string>, agentCommand?: string, codexRuntime?: 'sdk' | 'app-server') => Promise<{ ok: boolean; models?: Array<{ id: string; name: string; description?: string; thinkingLevels?: string[]; defaultThinkingLevel?: string }>; currentModelId?: string | null; error?: string }>;
|
||||
codexAppServerGetStatus?: (agentCommand?: string, agentEnv?: Record<string, string>) => Promise<{ ok: boolean; available: boolean; error?: string }>;
|
||||
aiUserSkillsGetStatus?: () => Promise<UserSkillsStatusResult>;
|
||||
aiUserSkillsOpenFolder?: () => Promise<UserSkillsStatusResult>;
|
||||
|
||||
+12
-154
@@ -2,19 +2,11 @@
|
||||
* Persistent command history store for terminal autocomplete.
|
||||
* Stores commands per host with frequency tracking and timestamp ordering.
|
||||
* Uses localStorageAdapter as the persistence layer (works in renderer process).
|
||||
*
|
||||
* Lives in application state rather than the UI layer so the vault hook and the
|
||||
* terminal UI depend on one lower-layer API, and so every renderer (main window
|
||||
* and detached terminal popups) shares the same clear semantics.
|
||||
*/
|
||||
|
||||
import { localStorageAdapter } from "../../infrastructure/persistence/localStorageAdapter";
|
||||
import {
|
||||
STORAGE_KEY_COMMAND_HISTORY,
|
||||
STORAGE_KEY_COMMAND_HISTORY_CLEARED,
|
||||
} from "../../infrastructure/config/storageKeys";
|
||||
import { localStorageAdapter } from "../../../infrastructure/persistence/localStorageAdapter";
|
||||
|
||||
const STORAGE_KEY = STORAGE_KEY_COMMAND_HISTORY;
|
||||
const STORAGE_KEY = "netcatty:commandHistory";
|
||||
const MAX_ENTRIES = 10000;
|
||||
const MAX_ENTRIES_PER_HOST = 5000;
|
||||
|
||||
@@ -34,21 +26,9 @@ export interface HistoryEntry {
|
||||
interface HistoryStore {
|
||||
entries: HistoryEntry[];
|
||||
version: number;
|
||||
/**
|
||||
* Monotonic counter bumped by every global clear. Other renderers compare it
|
||||
* to detect a clear performed elsewhere, and in-flight histfile imports use
|
||||
* it to discard work that started before the clear.
|
||||
*/
|
||||
clearGeneration?: number;
|
||||
}
|
||||
|
||||
let cachedStore: HistoryStore | null = null;
|
||||
/** Last clear generation this renderer has observed. */
|
||||
let knownClearGeneration: number | null = null;
|
||||
|
||||
function readClearGeneration(store: HistoryStore): number {
|
||||
return typeof store.clearGeneration === "number" ? store.clearGeneration : 0;
|
||||
}
|
||||
|
||||
function loadStore(): HistoryStore {
|
||||
if (cachedStore) return cachedStore;
|
||||
@@ -56,29 +36,18 @@ function loadStore(): HistoryStore {
|
||||
const parsed = localStorageAdapter.read<HistoryStore>(STORAGE_KEY);
|
||||
if (parsed) {
|
||||
cachedStore = parsed;
|
||||
knownClearGeneration = readClearGeneration(parsed);
|
||||
return parsed;
|
||||
}
|
||||
} catch {
|
||||
// Corrupted data, reset
|
||||
}
|
||||
cachedStore = { entries: [], version: 1, clearGeneration: 0 };
|
||||
knownClearGeneration = 0;
|
||||
cachedStore = { entries: [], version: 1 };
|
||||
return cachedStore;
|
||||
}
|
||||
|
||||
let saveTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
function persistStoreNow(store: HistoryStore): boolean {
|
||||
// A peer clear is visible in storage before its queued event is handled.
|
||||
// Never flush a cached pre-clear snapshot over that newer empty store.
|
||||
const persisted = localStorageAdapter.read<HistoryStore>(STORAGE_KEY);
|
||||
if (persisted && readClearGeneration(persisted) > readClearGeneration(store)) {
|
||||
cachedStore = persisted;
|
||||
knownClearGeneration = readClearGeneration(persisted);
|
||||
notifyCommandHistoryCleared();
|
||||
return true;
|
||||
}
|
||||
const ok = localStorageAdapter.write(STORAGE_KEY, store);
|
||||
if (ok) return true;
|
||||
// Storage full — evict lowest scored entries (not just oldest by insertion)
|
||||
@@ -98,13 +67,6 @@ function saveStore(store: HistoryStore): void {
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function cancelPendingSave(): void {
|
||||
if (saveTimer) {
|
||||
clearTimeout(saveTimer);
|
||||
saveTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush any pending debounced history write immediately.
|
||||
* Used after bulk imports (e.g. local histfile seeding) so a seed-complete
|
||||
@@ -113,112 +75,13 @@ function cancelPendingSave(): void {
|
||||
*/
|
||||
export function flushCommandHistoryStore(): boolean {
|
||||
if (!cachedStore) return true;
|
||||
cancelPendingSave();
|
||||
if (saveTimer) {
|
||||
clearTimeout(saveTimer);
|
||||
saveTimer = null;
|
||||
}
|
||||
return persistStoreNow(cachedStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* React to a write performed by another renderer (main window or a detached
|
||||
* terminal popup).
|
||||
*
|
||||
* A bumped clear generation drops the cache and pending save, then notifies
|
||||
* live autocomplete controllers. Ordinary peer writes must not cancel a local
|
||||
* command that is still waiting for its debounced save.
|
||||
*/
|
||||
function applyExternalCommandHistoryWrite(
|
||||
rawNewValue: string | null,
|
||||
rawOldValue: string | null,
|
||||
): void {
|
||||
let incomingGeneration: number | null = null;
|
||||
if (rawNewValue) {
|
||||
try {
|
||||
incomingGeneration = readClearGeneration(JSON.parse(rawNewValue) as HistoryStore);
|
||||
} catch {
|
||||
incomingGeneration = null;
|
||||
}
|
||||
}
|
||||
|
||||
let previousGeneration = knownClearGeneration;
|
||||
if (previousGeneration === null) {
|
||||
// A fresh popup can have compose recall before its first autocomplete query.
|
||||
// The event's old value is its baseline, even after an earlier global clear.
|
||||
try {
|
||||
previousGeneration = rawOldValue
|
||||
? readClearGeneration(JSON.parse(rawOldValue) as HistoryStore)
|
||||
: 0;
|
||||
} catch {
|
||||
previousGeneration = 0;
|
||||
}
|
||||
}
|
||||
if (incomingGeneration !== null && incomingGeneration > previousGeneration) {
|
||||
cancelPendingSave();
|
||||
cachedStore = null;
|
||||
knownClearGeneration = incomingGeneration;
|
||||
notifyCommandHistoryCleared();
|
||||
} else {
|
||||
if (!saveTimer) cachedStore = null;
|
||||
if (incomingGeneration !== null && knownClearGeneration === null) {
|
||||
knownClearGeneration = incomingGeneration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The native `storage` event fires in *other* same-origin windows (main window
|
||||
// and detached terminal popups) when a key changes there.
|
||||
if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
||||
window.addEventListener("storage", (event) => {
|
||||
if (event.key === STORAGE_KEY) applyExternalCommandHistoryWrite(event.newValue, event.oldValue);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Current clear generation. Callers capture this before async work and compare
|
||||
* afterwards to detect a clear that happened while they were waiting.
|
||||
*/
|
||||
export function getCommandHistoryClearGeneration(): number {
|
||||
if (knownClearGeneration === null) loadStore();
|
||||
return knownClearGeneration ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record that the user explicitly cleared all command history.
|
||||
*
|
||||
* Histfile seeding honors this tombstone: a clear is a user decision to delete
|
||||
* locally recorded history, so a later first-time import must not restore the
|
||||
* commands the user deleted (a pre-clear in-flight check alone cannot catch a
|
||||
* clear that happened before the import started).
|
||||
*/
|
||||
export function markCommandHistoryCleared(): void {
|
||||
localStorageAdapter.writeBoolean(STORAGE_KEY_COMMAND_HISTORY_CLEARED, true);
|
||||
}
|
||||
|
||||
/** True once the user has cleared all command history at least once. */
|
||||
export function hasCommandHistoryBeenCleared(): boolean {
|
||||
return localStorageAdapter.readBoolean(STORAGE_KEY_COMMAND_HISTORY_CLEARED) === true;
|
||||
}
|
||||
|
||||
type CommandHistoryClearedListener = () => void;
|
||||
const clearedListeners = new Set<CommandHistoryClearedListener>();
|
||||
|
||||
/**
|
||||
* Subscribe to command-history clears, including clears performed in another
|
||||
* renderer. Live autocomplete controllers use this to drop visible suggestions
|
||||
* and ghost text and abort in-flight completions, so a stale row cannot be
|
||||
* accepted and recorded after the history was cleared.
|
||||
*/
|
||||
export function subscribeCommandHistoryCleared(
|
||||
listener: CommandHistoryClearedListener,
|
||||
): () => void {
|
||||
clearedListeners.add(listener);
|
||||
return () => {
|
||||
clearedListeners.delete(listener);
|
||||
};
|
||||
}
|
||||
|
||||
function notifyCommandHistoryCleared(): void {
|
||||
for (const listener of [...clearedListeners]) listener();
|
||||
}
|
||||
|
||||
/**
|
||||
* Record a command execution. Updates frequency if the command already exists
|
||||
* for this host, otherwise creates a new entry.
|
||||
@@ -286,7 +149,10 @@ export function removeCommandHistoryEntry(command: string, hostId: string): bool
|
||||
if (nextEntries.length === store.entries.length) return false;
|
||||
|
||||
store.entries = nextEntries;
|
||||
cancelPendingSave();
|
||||
if (saveTimer) {
|
||||
clearTimeout(saveTimer);
|
||||
saveTimer = null;
|
||||
}
|
||||
return persistStoreNow(store);
|
||||
}
|
||||
|
||||
@@ -561,8 +427,6 @@ function fuzzyScore(query: string, target: string): number {
|
||||
|
||||
/**
|
||||
* Clear all history for a specific host, or all history if no hostId given.
|
||||
* A global clear also bumps the shared clear generation so other renderers and
|
||||
* in-flight histfile imports can detect it.
|
||||
*/
|
||||
export function clearHistory(hostId?: string): void {
|
||||
const store = loadStore();
|
||||
@@ -570,12 +434,6 @@ export function clearHistory(hostId?: string): void {
|
||||
store.entries = store.entries.filter((e) => e.hostId !== hostId);
|
||||
} else {
|
||||
store.entries = [];
|
||||
store.clearGeneration = readClearGeneration(store) + 1;
|
||||
}
|
||||
// Destructive clears must be durable: cancel any pending debounced write and
|
||||
// persist synchronously so a later stale flush cannot restore the entries.
|
||||
cancelPendingSave();
|
||||
persistStoreNow(store);
|
||||
knownClearGeneration = readClearGeneration(store);
|
||||
if (!hostId) notifyCommandHistoryCleared();
|
||||
saveStore(store);
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
queryRecentHistoryByCommand,
|
||||
fuzzyQueryHistory,
|
||||
type HistoryQueryOptions,
|
||||
} from "../../../application/state/commandHistoryStore";
|
||||
} from "./commandHistoryStore";
|
||||
import {
|
||||
loadSpec,
|
||||
hasSpec,
|
||||
|
||||
@@ -2,5 +2,5 @@ export { useTerminalAutocomplete, DEFAULT_AUTOCOMPLETE_SETTINGS } from "./useTer
|
||||
export type { AutocompleteSettings, AutocompleteState, TerminalAutocompleteHandle } from "./useTerminalAutocomplete";
|
||||
export { default as AutocompletePopup } from "./AutocompletePopup";
|
||||
export type { CompletionSuggestion, SuggestionSource } from "./completionEngine";
|
||||
export { recordCommand, removeCommandHistoryEntry, clearHistory } from "../../../application/state/commandHistoryStore";
|
||||
export { recordCommand, removeCommandHistoryEntry, clearHistory } from "./commandHistoryStore";
|
||||
export { shellEscape } from "./completionEngine";
|
||||
@@ -54,7 +54,7 @@ Object.defineProperty(globalThis, "window", {
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const { clearHistory, queryHistory } = await import("../../../application/state/commandHistoryStore.ts");
|
||||
const { clearHistory, queryHistory } = await import("./commandHistoryStore.ts");
|
||||
const { seedLocalShellHistoryFromHistfiles } = await import("./localShellHistorySeed.ts");
|
||||
const { getCompletions } = await import("./completionEngine.ts");
|
||||
|
||||
|
||||
@@ -20,12 +20,7 @@ import {
|
||||
parseZshHistory,
|
||||
} from "../../../domain/remoteHistory";
|
||||
import { localStorageAdapter } from "../../../infrastructure/persistence/localStorageAdapter";
|
||||
import {
|
||||
flushCommandHistoryStore,
|
||||
getCommandHistoryClearGeneration,
|
||||
hasCommandHistoryBeenCleared,
|
||||
recordCommand,
|
||||
} from "../../../application/state/commandHistoryStore";
|
||||
import { flushCommandHistoryStore, recordCommand } from "./commandHistoryStore";
|
||||
|
||||
const SEED_FLAG_PREFIX = "netcatty:localHistSeeded:";
|
||||
const MAX_SEED_COMMANDS = 500;
|
||||
@@ -98,18 +93,6 @@ async function seedLocalShellHistoryFromHistfilesOnce(
|
||||
): Promise<number> {
|
||||
if (!hostId || alreadySeeded(hostId)) return 0;
|
||||
|
||||
// A clear is a user decision to delete locally recorded history. Never
|
||||
// re-import histfiles for a host that was not seeded before that clear, or
|
||||
// the deleted commands would reappear on the next Local Terminal open.
|
||||
if (hasCommandHistoryBeenCleared()) {
|
||||
markSeeded(hostId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Capture the clear generation before the bridge reads so a clear that lands
|
||||
// while they are in flight can be detected afterwards.
|
||||
const startClearGeneration = getCommandHistoryClearGeneration();
|
||||
|
||||
const bridge = getBridge();
|
||||
if (!bridge?.getHomeDir || !bridge.readLocalFile) return 0;
|
||||
|
||||
@@ -128,17 +111,6 @@ async function seedLocalShellHistoryFromHistfilesOnce(
|
||||
readTextFile(bridge, joinHomePath(home, ".config/fish/fish_history")),
|
||||
]);
|
||||
|
||||
// The user cleared history while the histfile reads were in flight. Discard
|
||||
// the import and mark this host seeded so a later Local Terminal open cannot
|
||||
// resurrect the commands that were just deleted.
|
||||
if (
|
||||
hasCommandHistoryBeenCleared()
|
||||
|| getCommandHistoryClearGeneration() !== startClearGeneration
|
||||
) {
|
||||
markSeeded(hostId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const lists = [
|
||||
zshText ? parseZshHistory(zshText) : [],
|
||||
bashText ? parseBashHistory(bashText) : [],
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Terminal as XTerm } from "@xterm/xterm";
|
||||
import type { GhostTextAddon } from "./GhostTextAddon";
|
||||
import type { AutocompleteSettings } from "./useTerminalAutocomplete";
|
||||
import { getAlignedPrompt } from "./promptDetector";
|
||||
import { recordCommand } from "../../../application/state/commandHistoryStore";
|
||||
import { recordCommand } from "./commandHistoryStore";
|
||||
import { getCommandToRecordOnEnter } from "./terminalAutocompletePrompt";
|
||||
|
||||
interface TerminalAutocompleteInputContext {
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
} from "./promptDetector";
|
||||
import { getCompletions, parseCommandLine, type CompletionSuggestion } from "./completionEngine";
|
||||
import type { Snippet } from "../../../domain/models";
|
||||
import { recordCommand, subscribeCommandHistoryCleared } from "../../../application/state/commandHistoryStore";
|
||||
import { recordCommand } from "./commandHistoryStore";
|
||||
import { seedLocalShellHistoryFromHistfiles } from "./localShellHistorySeed";
|
||||
import { shellEscape } from "./completionEngine";
|
||||
import { preloadCommonSpecs } from "./figSpecLoader";
|
||||
@@ -1313,32 +1313,6 @@ export function useTerminalAutocomplete(
|
||||
});
|
||||
}, [termRef, writeToTerminal, repositionPopup]);
|
||||
|
||||
/**
|
||||
* Drop every trace of the popup when command history is cleared, including a
|
||||
* clear performed in another renderer (e.g. the main window while this
|
||||
* detached popup is open).
|
||||
*
|
||||
* Mirrors the Escape path: live preview writes the highlighted candidate into
|
||||
* the shell line, so hiding the popup alone would leave the deleted command
|
||||
* ready for Enter, with `lastAcceptedCommandRef` still pointing at it.
|
||||
* Restore the typed baseline and reset the refs first.
|
||||
*/
|
||||
const handleCommandHistoryCleared = useCallback(() => {
|
||||
if (previewActiveRef.current) {
|
||||
renderPreviewSelection(-1); // restore the typed baseline
|
||||
}
|
||||
clearState();
|
||||
previewActiveRef.current = false;
|
||||
// Drop a command accepted before the clear so a fast Enter cannot record it
|
||||
// through the accepted-command path (the line buffer is authoritative now).
|
||||
lastAcceptedCommandRef.current = null;
|
||||
}, [clearState, renderPreviewSelection]);
|
||||
|
||||
useEffect(
|
||||
() => subscribeCommandHistoryCleared(handleCommandHistoryCleared),
|
||||
[handleCommandHistoryCleared],
|
||||
);
|
||||
|
||||
/** Accept a snippet: clear the user's typed input, then run it via the
|
||||
* host-canonical send path (onAcceptSnippet). */
|
||||
const acceptSnippet = useCallback((snippet: Snippet): boolean => {
|
||||
|
||||
@@ -114,7 +114,7 @@ const {
|
||||
clearHistory,
|
||||
recordCommand,
|
||||
removeCommandHistoryEntry,
|
||||
} = await import("../../application/state/commandHistoryStore.ts");
|
||||
} = await import("./autocomplete/commandHistoryStore.ts");
|
||||
const {
|
||||
normalizePathTokenForLookup,
|
||||
shouldPreferRemoteShellCwd,
|
||||
|
||||
@@ -81,21 +81,3 @@ test("single-channel / network-device sessions skip remote path listings", () =>
|
||||
assert.match(source, /skipPathCompletion: isNetworkDeviceRef\.current,/);
|
||||
});
|
||||
|
||||
test("clearing command history restores the live-preview baseline (#3632)", () => {
|
||||
const source = readFileSync(
|
||||
fileURLToPath(new URL("./autocomplete/useTerminalAutocomplete.ts", import.meta.url)),
|
||||
"utf8",
|
||||
);
|
||||
// A live-previewed candidate is written into the shell line, so the clear
|
||||
// handler must mirror the Escape path: restore the typed baseline, reset the
|
||||
// preview/accepted refs, and only then hide the popup.
|
||||
assert.match(
|
||||
source,
|
||||
/const handleCommandHistoryCleared = useCallback\(\(\) => \{\s*if \(previewActiveRef\.current\) \{\s*renderPreviewSelection\(-1\);[\s\S]*?clearState\(\);\s*previewActiveRef\.current = false;[\s\S]*?lastAcceptedCommandRef\.current = null;\s*\}, \[clearState, renderPreviewSelection\]\);/,
|
||||
);
|
||||
assert.match(
|
||||
source,
|
||||
/useEffect\(\s*\(\) => subscribeCommandHistoryCleared\(handleCommandHistoryCleared\),\s*\[handleCommandHistoryCleared\],\s*\);/,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -695,7 +695,6 @@ export interface TerminalLayerProps {
|
||||
onAddKnownHost?: (knownHost: KnownHost) => void;
|
||||
onCommandExecuted?: (command: string, hostId: string, hostLabel: string, sessionId: string) => void;
|
||||
onDeleteShellHistoryEntry?: (entryId: string) => void;
|
||||
onClearCommandHistory?: () => void;
|
||||
onTerminalDataCapture?: (sessionId: string, data: string) => void;
|
||||
onCreateWorkspaceFromSessions: (baseSessionId: string, joiningSessionId: string, hint: Exclude<SplitHint, null>) => void;
|
||||
onAddSessionToWorkspace: (workspaceId: string, sessionId: string, hint: Exclude<SplitHint, null>) => void;
|
||||
|
||||
@@ -461,7 +461,6 @@ export function TerminalLayerTabBridge({ stableRef }: { stableRef: StableRef })
|
||||
followAppTerminalTheme: s.followAppTerminalTheme,
|
||||
handleHistoryPaste: s.handleHistoryPaste,
|
||||
handleHistoryDelete: s.handleHistoryDelete,
|
||||
handleHistoryClear: s.handleHistoryClear,
|
||||
handleHistoryRun: s.handleHistoryRun,
|
||||
handleFocusSidePanelPane: s.handleFocusSidePanelPane,
|
||||
handleMagnifySidePanelPane: s.handleMagnifySidePanelPane,
|
||||
|
||||
@@ -493,7 +493,6 @@ function SidePanelHistorySlotInner({
|
||||
HistorySidePanel,
|
||||
handleHistoryPaste,
|
||||
handleHistoryDelete,
|
||||
handleHistoryClear,
|
||||
handleHistoryRun,
|
||||
} = ctx;
|
||||
|
||||
@@ -508,7 +507,6 @@ function SidePanelHistorySlotInner({
|
||||
globalEntries={shellHistory as import('../../domain/models').ShellHistoryEntry[]}
|
||||
onFetch={remoteHistory.fetch}
|
||||
onDeleteGlobalEntry={handleHistoryDelete}
|
||||
onClearGlobalHistory={handleHistoryClear}
|
||||
onPasteToTerminal={handleHistoryPaste}
|
||||
onRunInTerminal={handleHistoryRun}
|
||||
isVisible
|
||||
|
||||
@@ -234,7 +234,6 @@ const SIDE_PANEL_STABLE_CTX_KEYS = [
|
||||
'themeMountedTabIds',
|
||||
'handleHistoryPaste',
|
||||
'handleHistoryDelete',
|
||||
'handleHistoryClear',
|
||||
'handleHistoryRun',
|
||||
'handleOpenHistory',
|
||||
'HistorySidePanel',
|
||||
|
||||
Loaded 100 of 175 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user