mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
feat(panel): add opt-in cross-client session migration for CLI, Desktop App, and Legacy IDE
This commit is contained in:
+868
-2
@@ -843,6 +843,16 @@ const BRIDGE_API_ROUTE_DEFS = Object.freeze([
|
|||||||
Object.freeze({ path: '/api/cloud-sync', method: 'POST', action: 'cloud_sync' }),
|
Object.freeze({ path: '/api/cloud-sync', method: 'POST', action: 'cloud_sync' }),
|
||||||
Object.freeze({ path: '/api/plugin-update', method: 'POST', action: 'plugin_update' }),
|
Object.freeze({ path: '/api/plugin-update', method: 'POST', action: 'plugin_update' }),
|
||||||
Object.freeze({ path: '/api/bridge/relaunch', method: 'POST', action: 'bridge_relaunch' }),
|
Object.freeze({ path: '/api/bridge/relaunch', method: 'POST', action: 'bridge_relaunch' }),
|
||||||
|
Object.freeze({
|
||||||
|
path: '/api/session-migration/catalog',
|
||||||
|
method: 'GET',
|
||||||
|
action: 'session_migration_catalog',
|
||||||
|
}),
|
||||||
|
Object.freeze({
|
||||||
|
path: '/api/session-migration/migrate',
|
||||||
|
method: 'POST',
|
||||||
|
action: 'session_migration_migrate',
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const BRIDGE_API_PATHS = Object.freeze(BRIDGE_API_ROUTE_DEFS.map((r) => r.path));
|
const BRIDGE_API_PATHS = Object.freeze(BRIDGE_API_ROUTE_DEFS.map((r) => r.path));
|
||||||
@@ -1809,6 +1819,41 @@ const I18N_MESSAGES_ZH_CN = Object.freeze({
|
|||||||
'settings.oth.exportDone': '配置 JSON 已导出',
|
'settings.oth.exportDone': '配置 JSON 已导出',
|
||||||
'settings.oth.importDone': '已恢复 {count} 项偏好设置',
|
'settings.oth.importDone': '已恢复 {count} 项偏好设置',
|
||||||
'settings.oth.importInvalid': '导入失败:JSON 无效或未包含可识别的偏好项',
|
'settings.oth.importInvalid': '导入失败:JSON 无效或未包含可识别的偏好项',
|
||||||
|
'settings.oth.migTitle': '跨端会话迁移',
|
||||||
|
'settings.oth.migDesc': '按需把选定会话迁往另一端,迁移前自动备份摘要库和源库',
|
||||||
|
'settings.oth.migRefreshBtn': '刷新列表',
|
||||||
|
'settings.oth.migSourceLabel': '来源端',
|
||||||
|
'settings.oth.migTargetLabel': '目标端',
|
||||||
|
'settings.oth.migModeLabel': '迁移方式',
|
||||||
|
'settings.oth.migModeMove': '完整迁移(推荐)',
|
||||||
|
'settings.oth.migModeClone': '克隆副本',
|
||||||
|
'settings.oth.migModeMoveHint': '保留原 ID 和全部历史步序明细,备份后移出源端(零重复计费)',
|
||||||
|
'settings.oth.migModeCloneHint': '保留源会话并生成新 ID,新副本仅统计迁入后的新步骤',
|
||||||
|
'settings.oth.migProjectLabel': '绑定目标项目',
|
||||||
|
'settings.oth.migProjectOutside': '独立会话(无所属项目)',
|
||||||
|
'settings.oth.migClientDesktop': '桌面端 App / 新版 IDE',
|
||||||
|
'settings.oth.migClientCli': 'Antigravity CLI',
|
||||||
|
'settings.oth.migClientIdeLegacy': '旧版 IDE (.db)',
|
||||||
|
'settings.oth.migSearchPlaceholder': '按标题或工作区筛选会话…',
|
||||||
|
'settings.oth.migSelectAll': '全选',
|
||||||
|
'settings.oth.migClearSel': '清空',
|
||||||
|
'settings.oth.migSelectedCount': '已选 {selected} / {total}',
|
||||||
|
'settings.oth.migRunningTag': '运行中',
|
||||||
|
'settings.oth.migStepsUnit': '{count} 步',
|
||||||
|
'settings.oth.migEmpty': '当前来源端暂无可迁移会话',
|
||||||
|
'settings.oth.migNoMatch': '没有匹配的会话',
|
||||||
|
'settings.oth.migActionBtn': '迁移选定会话 ({count})',
|
||||||
|
'settings.oth.migRunningBtn': '迁移中…',
|
||||||
|
'settings.oth.migDoneDesktop': '已成功迁移 {count} 条会话到「{project}」,在桌面端按 Ctrl+R 即可在左侧看到',
|
||||||
|
'settings.oth.migDoneCli': '已成功迁移 {count} 条会话到 CLI,可使用下方命令恢复对话',
|
||||||
|
'settings.oth.migPartialWarn': '(另有 {failed} 条跳过或失败)',
|
||||||
|
'settings.oth.migReloadBtn': '刷新窗口',
|
||||||
|
'settings.oth.migCopyCmd': '复制命令',
|
||||||
|
'settings.oth.migCopied': '已复制',
|
||||||
|
'settings.oth.migErrLocked': '源会话文件正被原端占用,请先关闭对应终端/窗口后重试,或切换为「克隆副本」',
|
||||||
|
'settings.oth.migErrExists': '目标端已存在同 ID 会话,无需重复移动(可切换为「克隆副本」)',
|
||||||
|
'settings.oth.migErrRunning': '该会话正在运行中,请待空闲后再迁移',
|
||||||
|
'settings.oth.migFailed': '迁移失败:{reason}',
|
||||||
|
|
||||||
// Structured Live Activity Actions
|
// Structured Live Activity Actions
|
||||||
'live.act.run_command': '执行命令',
|
'live.act.run_command': '执行命令',
|
||||||
@@ -2571,6 +2616,41 @@ const I18N_MESSAGES_EN_US = Object.freeze({
|
|||||||
'settings.oth.exportDone': 'Preferences JSON exported',
|
'settings.oth.exportDone': 'Preferences JSON exported',
|
||||||
'settings.oth.importDone': 'Restored {count} preference settings',
|
'settings.oth.importDone': 'Restored {count} preference settings',
|
||||||
'settings.oth.importInvalid': 'Import failed: invalid JSON or no recognized settings',
|
'settings.oth.importInvalid': 'Import failed: invalid JSON or no recognized settings',
|
||||||
|
'settings.oth.migTitle': 'Cross-Client Session Migration',
|
||||||
|
'settings.oth.migDesc': 'Migrate selected sessions on demand with automatic source and summary backups',
|
||||||
|
'settings.oth.migRefreshBtn': 'Refresh',
|
||||||
|
'settings.oth.migSourceLabel': 'Source Client',
|
||||||
|
'settings.oth.migTargetLabel': 'Target Client',
|
||||||
|
'settings.oth.migModeLabel': 'Migration Mode',
|
||||||
|
'settings.oth.migModeMove': 'Full Move (Recommended)',
|
||||||
|
'settings.oth.migModeClone': 'Clone Copy',
|
||||||
|
'settings.oth.migModeMoveHint': 'Preserves original ID and full historical steps/details; archives source backup before moving',
|
||||||
|
'settings.oth.migModeCloneHint': 'Keeps source intact with a fresh UUID; only counts new steps generated after cloning',
|
||||||
|
'settings.oth.migProjectLabel': 'Target Project',
|
||||||
|
'settings.oth.migProjectOutside': 'Standalone (No Project)',
|
||||||
|
'settings.oth.migClientDesktop': 'Desktop App / Modern IDE',
|
||||||
|
'settings.oth.migClientCli': 'Antigravity CLI',
|
||||||
|
'settings.oth.migClientIdeLegacy': 'Legacy IDE (.db)',
|
||||||
|
'settings.oth.migSearchPlaceholder': 'Filter sessions by title or workspace…',
|
||||||
|
'settings.oth.migSelectAll': 'Select all',
|
||||||
|
'settings.oth.migClearSel': 'Clear',
|
||||||
|
'settings.oth.migSelectedCount': '{selected} / {total} selected',
|
||||||
|
'settings.oth.migRunningTag': 'Running',
|
||||||
|
'settings.oth.migStepsUnit': '{count} steps',
|
||||||
|
'settings.oth.migEmpty': 'No migratable sessions in this source client',
|
||||||
|
'settings.oth.migNoMatch': 'No matching sessions',
|
||||||
|
'settings.oth.migActionBtn': 'Migrate Selected ({count})',
|
||||||
|
'settings.oth.migRunningBtn': 'Migrating…',
|
||||||
|
'settings.oth.migDoneDesktop': 'Migrated {count} session(s) to "{project}". Press Ctrl+R in Desktop App to refresh the sidebar',
|
||||||
|
'settings.oth.migDoneCli': 'Migrated {count} session(s) to CLI. Use the command below to resume',
|
||||||
|
'settings.oth.migPartialWarn': ' ({failed} skipped or failed)',
|
||||||
|
'settings.oth.migReloadBtn': 'Reload Window',
|
||||||
|
'settings.oth.migCopyCmd': 'Copy',
|
||||||
|
'settings.oth.migCopied': 'Copied',
|
||||||
|
'settings.oth.migErrLocked': 'Source database is locked by its open client. Close that terminal/window first, or switch to Clone Copy',
|
||||||
|
'settings.oth.migErrExists': 'A session with the same ID already exists in target (switch to Clone Copy if you want a duplicate)',
|
||||||
|
'settings.oth.migErrRunning': 'Session is currently running; wait until idle before migrating',
|
||||||
|
'settings.oth.migFailed': 'Migration failed: {reason}',
|
||||||
|
|
||||||
// Structured Live Activity Actions
|
// Structured Live Activity Actions
|
||||||
'live.act.run_command': 'Run Command',
|
'live.act.run_command': 'Run Command',
|
||||||
@@ -5527,7 +5607,7 @@ return { getViewTabs, uiStore, getVisibleMonitorView };
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
// --- src/store/telemetryStore.js ---
|
// --- src/store/telemetryStore.js ---
|
||||||
const { extractHostRouteCascadeId, telemetryStore, clearConsumptionRangeCache, clearConversationViewCache, CLIENT_TOPBAR_SLOT_KEYS, DEFAULT_CLIENT_TOPBAR_SLOTS, CLIENT_CLI_STATUSLINE_PRESETS, DEFAULT_CLIENT_CLI_STATUSLINE_SLOTS, CLIENT_OVERVIEW_MODULE_KEYS, DEFAULT_CLIENT_OVERVIEW_MODULES, DEFAULT_CLIENT_HOVER_MODULES, CLIENT_OVERVIEW_METRIC_KEYS, DEFAULT_CLIENT_OVERVIEW_METRICS, CLIENT_STEP_COLUMN_KEYS, DEFAULT_CLIENT_STEP_COLUMNS, DEFAULT_CLIENT_STEP_TOKEN_COMBO_FORMAT, MIN_CLIENT_POPOVER_WIDTH, MAX_CLIENT_POPOVER_WIDTH, DEFAULT_CLIENT_POPOVER_WIDTH, parseClientStepTokenComboSegments, normalizeClientStepTokenComboFormat, normalizeClientPopoverWidthMode, normalizeClientPopoverWidth, normalizeClientModelDisplayMode, normalizeClientTopbarSlots, normalizeClientCliStatusLineSlots, resolveEffectiveClientCliStatusLineSlots, normalizeClientHoverModules, normalizeClientOverviewModules, normalizeClientOverviewMetrics, normalizeClientStepColumns, normalizeClientUpdateMode, normalizeClientOrchestratorIdMode, normalizeClientWindowMountMode, isEquivalentTelemetry, resetTelemetryForEndpointSwitch, fetchTelemetry, selectConversation, selectConsumptionTimeRange, prefetchConsumptionPresets, saveSettingsPatch, saveModelContextWindow, resetAllSettings, rebuildTrajectoryCache, triggerCloudSync, triggerBridgeHostRelaunch, triggerCliStatusLineAction, triggerPluginUpdate, startAsyncTelemetryLoop, stopAsyncTelemetryLoop, resolveHostRouteMatch, resolveScopedConversation, isMacHostPlatform } = (() => {
|
const { extractHostRouteCascadeId, telemetryStore, clearConsumptionRangeCache, clearConversationViewCache, CLIENT_TOPBAR_SLOT_KEYS, DEFAULT_CLIENT_TOPBAR_SLOTS, CLIENT_CLI_STATUSLINE_PRESETS, DEFAULT_CLIENT_CLI_STATUSLINE_SLOTS, CLIENT_OVERVIEW_MODULE_KEYS, DEFAULT_CLIENT_OVERVIEW_MODULES, DEFAULT_CLIENT_HOVER_MODULES, CLIENT_OVERVIEW_METRIC_KEYS, DEFAULT_CLIENT_OVERVIEW_METRICS, CLIENT_STEP_COLUMN_KEYS, DEFAULT_CLIENT_STEP_COLUMNS, DEFAULT_CLIENT_STEP_TOKEN_COMBO_FORMAT, MIN_CLIENT_POPOVER_WIDTH, MAX_CLIENT_POPOVER_WIDTH, DEFAULT_CLIENT_POPOVER_WIDTH, parseClientStepTokenComboSegments, normalizeClientStepTokenComboFormat, normalizeClientPopoverWidthMode, normalizeClientPopoverWidth, normalizeClientModelDisplayMode, normalizeClientTopbarSlots, normalizeClientCliStatusLineSlots, resolveEffectiveClientCliStatusLineSlots, normalizeClientHoverModules, normalizeClientOverviewModules, normalizeClientOverviewMetrics, normalizeClientStepColumns, normalizeClientUpdateMode, normalizeClientOrchestratorIdMode, normalizeClientWindowMountMode, isEquivalentTelemetry, resetTelemetryForEndpointSwitch, fetchTelemetry, selectConversation, selectConsumptionTimeRange, prefetchConsumptionPresets, saveSettingsPatch, saveModelContextWindow, resetAllSettings, rebuildTrajectoryCache, triggerCloudSync, triggerBridgeHostRelaunch, triggerCliStatusLineAction, fetchSessionMigrationCatalog, executeSessionMigration, triggerPluginUpdate, startAsyncTelemetryLoop, stopAsyncTelemetryLoop, resolveHostRouteMatch, resolveScopedConversation, isMacHostPlatform } = (() => {
|
||||||
/**
|
/**
|
||||||
* @fileoverview Reactive telemetry store with async non-overlapping poll scheduler
|
* @fileoverview Reactive telemetry store with async non-overlapping poll scheduler
|
||||||
* and granular slice updates.
|
* and granular slice updates.
|
||||||
@@ -7466,6 +7546,36 @@ async function triggerCliStatusLineAction(action) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchSessionMigrationCatalog() {
|
||||||
|
try {
|
||||||
|
return await callSidecarApi('/api/session-migration/catalog', { method: 'GET' });
|
||||||
|
} catch {
|
||||||
|
return callSidecarApi('/api/settings', {
|
||||||
|
method: 'POST',
|
||||||
|
body: { __sessionMigrationAction: 'catalog' },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function executeSessionMigration(payload) {
|
||||||
|
let res;
|
||||||
|
try {
|
||||||
|
res = await callSidecarApi('/api/session-migration/migrate', {
|
||||||
|
method: 'POST',
|
||||||
|
body: payload || {},
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
res = await callSidecarApi('/api/settings', {
|
||||||
|
method: 'POST',
|
||||||
|
body: { __sessionMigrationAction: 'migrate', payload: payload || {} },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (res?.migratedCount > 0) {
|
||||||
|
void fetchTelemetry({ force: true }).catch(() => {});
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
async function triggerPluginUpdate() {
|
async function triggerPluginUpdate() {
|
||||||
const res = await callSidecarApi('/api/plugin-update', { method: 'POST', body: {} });
|
const res = await callSidecarApi('/api/plugin-update', { method: 'POST', body: {} });
|
||||||
if (res?.ok && res?.restarting) {
|
if (res?.ok && res?.restarting) {
|
||||||
@@ -7723,7 +7833,7 @@ function isMacHostPlatform(telemetry) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return { extractHostRouteCascadeId, telemetryStore, clearConsumptionRangeCache, clearConversationViewCache, CLIENT_TOPBAR_SLOT_KEYS, DEFAULT_CLIENT_TOPBAR_SLOTS, CLIENT_CLI_STATUSLINE_PRESETS, DEFAULT_CLIENT_CLI_STATUSLINE_SLOTS, CLIENT_OVERVIEW_MODULE_KEYS, DEFAULT_CLIENT_OVERVIEW_MODULES, DEFAULT_CLIENT_HOVER_MODULES, CLIENT_OVERVIEW_METRIC_KEYS, DEFAULT_CLIENT_OVERVIEW_METRICS, CLIENT_STEP_COLUMN_KEYS, DEFAULT_CLIENT_STEP_COLUMNS, DEFAULT_CLIENT_STEP_TOKEN_COMBO_FORMAT, MIN_CLIENT_POPOVER_WIDTH, MAX_CLIENT_POPOVER_WIDTH, DEFAULT_CLIENT_POPOVER_WIDTH, parseClientStepTokenComboSegments, normalizeClientStepTokenComboFormat, normalizeClientPopoverWidthMode, normalizeClientPopoverWidth, normalizeClientModelDisplayMode, normalizeClientTopbarSlots, normalizeClientCliStatusLineSlots, resolveEffectiveClientCliStatusLineSlots, normalizeClientHoverModules, normalizeClientOverviewModules, normalizeClientOverviewMetrics, normalizeClientStepColumns, normalizeClientUpdateMode, normalizeClientOrchestratorIdMode, normalizeClientWindowMountMode, isEquivalentTelemetry, resetTelemetryForEndpointSwitch, fetchTelemetry, selectConversation, selectConsumptionTimeRange, prefetchConsumptionPresets, saveSettingsPatch, saveModelContextWindow, resetAllSettings, rebuildTrajectoryCache, triggerCloudSync, triggerBridgeHostRelaunch, triggerCliStatusLineAction, triggerPluginUpdate, startAsyncTelemetryLoop, stopAsyncTelemetryLoop, resolveHostRouteMatch, resolveScopedConversation, isMacHostPlatform };
|
return { extractHostRouteCascadeId, telemetryStore, clearConsumptionRangeCache, clearConversationViewCache, CLIENT_TOPBAR_SLOT_KEYS, DEFAULT_CLIENT_TOPBAR_SLOTS, CLIENT_CLI_STATUSLINE_PRESETS, DEFAULT_CLIENT_CLI_STATUSLINE_SLOTS, CLIENT_OVERVIEW_MODULE_KEYS, DEFAULT_CLIENT_OVERVIEW_MODULES, DEFAULT_CLIENT_HOVER_MODULES, CLIENT_OVERVIEW_METRIC_KEYS, DEFAULT_CLIENT_OVERVIEW_METRICS, CLIENT_STEP_COLUMN_KEYS, DEFAULT_CLIENT_STEP_COLUMNS, DEFAULT_CLIENT_STEP_TOKEN_COMBO_FORMAT, MIN_CLIENT_POPOVER_WIDTH, MAX_CLIENT_POPOVER_WIDTH, DEFAULT_CLIENT_POPOVER_WIDTH, parseClientStepTokenComboSegments, normalizeClientStepTokenComboFormat, normalizeClientPopoverWidthMode, normalizeClientPopoverWidth, normalizeClientModelDisplayMode, normalizeClientTopbarSlots, normalizeClientCliStatusLineSlots, resolveEffectiveClientCliStatusLineSlots, normalizeClientHoverModules, normalizeClientOverviewModules, normalizeClientOverviewMetrics, normalizeClientStepColumns, normalizeClientUpdateMode, normalizeClientOrchestratorIdMode, normalizeClientWindowMountMode, isEquivalentTelemetry, resetTelemetryForEndpointSwitch, fetchTelemetry, selectConversation, selectConsumptionTimeRange, prefetchConsumptionPresets, saveSettingsPatch, saveModelContextWindow, resetAllSettings, rebuildTrajectoryCache, triggerCloudSync, triggerBridgeHostRelaunch, triggerCliStatusLineAction, fetchSessionMigrationCatalog, executeSessionMigration, triggerPluginUpdate, startAsyncTelemetryLoop, stopAsyncTelemetryLoop, resolveHostRouteMatch, resolveScopedConversation, isMacHostPlatform };
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// --- src/components/ui/TopLongPillNav.js ---
|
// --- src/components/ui/TopLongPillNav.js ---
|
||||||
@@ -20351,6 +20461,751 @@ const BridgeStatusNotice = defineComponent({
|
|||||||
return { BridgeStatusNotice };
|
return { BridgeStatusNotice };
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// --- src/components/settings/SessionMigrationCard.js ---
|
||||||
|
const { SessionMigrationCard } = (() => {
|
||||||
|
/**
|
||||||
|
* @fileoverview 跨端会话按需迁移设置卡片 (`SessionMigrationCard.js`)。
|
||||||
|
* 仅当本机检测到 ≥2 个 Antigravity 客户端目录时展示,支持自由勾选根会话以新 UUID 无损克隆到目标端。
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
const SMIG_OUTSIDE_PROJECT_ID = 'outside-of-project';
|
||||||
|
|
||||||
|
async function smigCopyText(text) {
|
||||||
|
try {
|
||||||
|
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
|
||||||
|
await navigator.clipboard.writeText(text);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// 退回受限 Webview 的隐藏文本域复制
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (typeof document === 'undefined' || !document.body) return false;
|
||||||
|
const area = document.createElement('textarea');
|
||||||
|
area.value = text;
|
||||||
|
area.setAttribute('readonly', 'true');
|
||||||
|
area.style.cssText = 'position:fixed;left:-9999px;top:-9999px;opacity:0;';
|
||||||
|
document.body.appendChild(area);
|
||||||
|
area.select?.();
|
||||||
|
const ok = Boolean(document.execCommand?.('copy'));
|
||||||
|
document.body.removeChild(area);
|
||||||
|
return ok;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function smigGetClientLabel(clientId) {
|
||||||
|
if (clientId === 'cli') return t('settings.oth.migClientCli');
|
||||||
|
if (clientId === 'ide_legacy') return t('settings.oth.migClientIdeLegacy');
|
||||||
|
return t('settings.oth.migClientDesktop');
|
||||||
|
}
|
||||||
|
|
||||||
|
function smigFormatAge(epochMs) {
|
||||||
|
const ts = Number(epochMs || 0);
|
||||||
|
if (!Number.isFinite(ts) || ts <= 0) return '';
|
||||||
|
const diffSec = Math.max(0, Math.floor((Date.now() - ts) / 1000));
|
||||||
|
const isEn = isEnglishLocale();
|
||||||
|
if (diffSec < 60) return isEn ? 'just now' : '刚刚';
|
||||||
|
const diffMin = Math.floor(diffSec / 60);
|
||||||
|
if (diffMin < 60) return isEn ? `${diffMin}m ago` : `${diffMin}分钟前`;
|
||||||
|
const diffHr = Math.floor(diffMin / 60);
|
||||||
|
if (diffHr < 24) return isEn ? `${diffHr}h ago` : `${diffHr}小时前`;
|
||||||
|
const diffDay = Math.floor(diffHr / 24);
|
||||||
|
return isEn ? `${diffDay}d ago` : `${diffDay}天前`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SessionMigrationCard = defineComponent({
|
||||||
|
name: 'SessionMigrationCard',
|
||||||
|
setup({ props, onCleanup }) {
|
||||||
|
const loadCatalogFn =
|
||||||
|
typeof props?.loadCatalog === 'function' ? props.loadCatalog : fetchSessionMigrationCatalog;
|
||||||
|
const runMigrateFn =
|
||||||
|
typeof props?.runMigrate === 'function' ? props.runMigrate : executeSessionMigration;
|
||||||
|
|
||||||
|
let catalog = null;
|
||||||
|
let hasLoadedOnce = false;
|
||||||
|
let isLoading = false;
|
||||||
|
let isMigrating = false;
|
||||||
|
let destroyed = false;
|
||||||
|
let bodyMounted = false;
|
||||||
|
let sourceClient = '';
|
||||||
|
let targetClient = '';
|
||||||
|
let migrationMode = 'move';
|
||||||
|
let targetProjectId = '';
|
||||||
|
let searchQuery = '';
|
||||||
|
const selectedIds = new Set();
|
||||||
|
let lastResult = null;
|
||||||
|
let copiedCmdId = '';
|
||||||
|
let copiedTimer = null;
|
||||||
|
|
||||||
|
let titleEl = null;
|
||||||
|
let descEl = null;
|
||||||
|
let refreshBtnText = null;
|
||||||
|
let refreshBtn = null;
|
||||||
|
let sourceLabelEl = null;
|
||||||
|
let targetLabelEl = null;
|
||||||
|
let modeLabelEl = null;
|
||||||
|
let modeMoveBtn = null;
|
||||||
|
let modeCloneBtn = null;
|
||||||
|
let modeHintEl = null;
|
||||||
|
let projectLabelEl = null;
|
||||||
|
let sourceSelect = null;
|
||||||
|
let targetSelect = null;
|
||||||
|
let projectSelect = null;
|
||||||
|
let projectFieldWrap = null;
|
||||||
|
let searchInput = null;
|
||||||
|
let toggleAllBtn = null;
|
||||||
|
let selectedCountEl = null;
|
||||||
|
let listEl = null;
|
||||||
|
let migrateBtnText = null;
|
||||||
|
let migrateBtn = null;
|
||||||
|
let resultBoxEl = null;
|
||||||
|
|
||||||
|
const rootEl = h('section', { className: 'panel smig-panel', hidden: true });
|
||||||
|
|
||||||
|
function ensureBodyMounted() {
|
||||||
|
if (bodyMounted) return;
|
||||||
|
bodyMounted = true;
|
||||||
|
|
||||||
|
titleEl = h('span', { text: t('settings.oth.migTitle') });
|
||||||
|
descEl = h('p', { className: 'smig-desc', text: t('settings.oth.migDesc') });
|
||||||
|
refreshBtnText = h('span', { text: t('settings.oth.migRefreshBtn') });
|
||||||
|
refreshBtn = h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
className: 'btn-ghost-sm smig-refresh-btn',
|
||||||
|
onClick: () => {
|
||||||
|
void loadCatalog(true);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[createSvgIcon('refresh', { size: 12 }), refreshBtnText]
|
||||||
|
);
|
||||||
|
|
||||||
|
sourceLabelEl = h('span', { className: 'smig-field-label', text: t('settings.oth.migSourceLabel') });
|
||||||
|
targetLabelEl = h('span', { className: 'smig-field-label', text: t('settings.oth.migTargetLabel') });
|
||||||
|
modeLabelEl = h('span', { className: 'smig-field-label', text: t('settings.oth.migModeLabel') });
|
||||||
|
modeMoveBtn = h('button', {
|
||||||
|
type: 'button',
|
||||||
|
className: 'smig-mode-btn is-active',
|
||||||
|
text: t('settings.oth.migModeMove'),
|
||||||
|
onClick: () => {
|
||||||
|
if (migrationMode === 'move') return;
|
||||||
|
migrationMode = 'move';
|
||||||
|
lastResult = null;
|
||||||
|
syncModeControls();
|
||||||
|
renderResultBox();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
modeCloneBtn = h('button', {
|
||||||
|
type: 'button',
|
||||||
|
className: 'smig-mode-btn',
|
||||||
|
text: t('settings.oth.migModeClone'),
|
||||||
|
onClick: () => {
|
||||||
|
if (migrationMode === 'clone') return;
|
||||||
|
migrationMode = 'clone';
|
||||||
|
lastResult = null;
|
||||||
|
syncModeControls();
|
||||||
|
renderResultBox();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
modeHintEl = h('span', {
|
||||||
|
className: 'smig-mode-hint',
|
||||||
|
text: t('settings.oth.migModeMoveHint'),
|
||||||
|
});
|
||||||
|
projectLabelEl = h('span', { className: 'smig-field-label', text: t('settings.oth.migProjectLabel') });
|
||||||
|
|
||||||
|
sourceSelect = CustomSelect({
|
||||||
|
ariaLabel: t('settings.oth.migSourceLabel'),
|
||||||
|
modelValue: '',
|
||||||
|
options: [],
|
||||||
|
onUpdateModelValue: (val) => {
|
||||||
|
if (!val || val === sourceClient) return;
|
||||||
|
sourceClient = val;
|
||||||
|
selectedIds.clear();
|
||||||
|
lastResult = null;
|
||||||
|
ensureValidTarget();
|
||||||
|
syncControlsAndList();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
targetSelect = CustomSelect({
|
||||||
|
ariaLabel: t('settings.oth.migTargetLabel'),
|
||||||
|
modelValue: '',
|
||||||
|
options: [],
|
||||||
|
onUpdateModelValue: (val) => {
|
||||||
|
if (!val || val === targetClient) return;
|
||||||
|
targetClient = val;
|
||||||
|
lastResult = null;
|
||||||
|
syncControlsAndList();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
projectSelect = CustomSelect({
|
||||||
|
ariaLabel: t('settings.oth.migProjectLabel'),
|
||||||
|
modelValue: '',
|
||||||
|
options: [],
|
||||||
|
className: 'smig-project-select',
|
||||||
|
onUpdateModelValue: (val) => {
|
||||||
|
targetProjectId = String(val || '');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
projectFieldWrap = h('div', { className: 'smig-field' }, [
|
||||||
|
projectLabelEl,
|
||||||
|
projectSelect.el,
|
||||||
|
]);
|
||||||
|
|
||||||
|
searchInput = h('input', {
|
||||||
|
type: 'text',
|
||||||
|
className: 'settings-text-input smig-search-input',
|
||||||
|
placeholder: t('settings.oth.migSearchPlaceholder'),
|
||||||
|
value: '',
|
||||||
|
});
|
||||||
|
searchInput.addEventListener?.('input', () => {
|
||||||
|
searchQuery = String(searchInput.value || '').trim();
|
||||||
|
renderSessionList();
|
||||||
|
});
|
||||||
|
|
||||||
|
toggleAllBtn = h('button', {
|
||||||
|
type: 'button',
|
||||||
|
className: 'btn-ghost-sm smig-toggle-all-btn',
|
||||||
|
text: t('settings.oth.migSelectAll'),
|
||||||
|
onClick: () => {
|
||||||
|
const selectable = getFilteredSessions().filter((s) => !s.isRunning);
|
||||||
|
if (selectable.length === 0) return;
|
||||||
|
const allSelected = selectable.every((s) => selectedIds.has(s.cascadeId));
|
||||||
|
if (allSelected) {
|
||||||
|
for (const s of selectable) selectedIds.delete(s.cascadeId);
|
||||||
|
} else {
|
||||||
|
for (const s of selectable) selectedIds.add(s.cascadeId);
|
||||||
|
}
|
||||||
|
renderSessionList();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
selectedCountEl = h('span', { className: 'smig-count-meta', text: '' });
|
||||||
|
listEl = h('div', { className: 'smig-list', role: 'list' });
|
||||||
|
|
||||||
|
migrateBtnText = h('span', {
|
||||||
|
text: t('settings.oth.migActionBtn', { count: 0 }),
|
||||||
|
});
|
||||||
|
migrateBtn = h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
className: 'btn-secondary smig-migrate-btn',
|
||||||
|
disabled: true,
|
||||||
|
onClick: () => {
|
||||||
|
void handleMigrate();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[createSvgIcon('copy', { size: 12 }), migrateBtnText]
|
||||||
|
);
|
||||||
|
|
||||||
|
resultBoxEl = h('div', { className: 'smig-result', hidden: true });
|
||||||
|
|
||||||
|
const children = [
|
||||||
|
h('div', { className: 'panel-header' }, [
|
||||||
|
h('span', { className: 'panel-title' }, [
|
||||||
|
createSvgIcon('layers', { size: 13 }),
|
||||||
|
titleEl,
|
||||||
|
]),
|
||||||
|
refreshBtn,
|
||||||
|
]),
|
||||||
|
descEl,
|
||||||
|
h('div', { className: 'smig-direction-grid' }, [
|
||||||
|
h('div', { className: 'smig-field' }, [sourceLabelEl, sourceSelect.el]),
|
||||||
|
h('div', { className: 'smig-field' }, [targetLabelEl, targetSelect.el]),
|
||||||
|
]),
|
||||||
|
h('div', { className: 'smig-field' }, [
|
||||||
|
modeLabelEl,
|
||||||
|
h('div', { className: 'smig-mode-bar' }, [modeMoveBtn, modeCloneBtn]),
|
||||||
|
modeHintEl,
|
||||||
|
]),
|
||||||
|
projectFieldWrap,
|
||||||
|
h('div', { className: 'smig-toolbar' }, [
|
||||||
|
searchInput,
|
||||||
|
toggleAllBtn,
|
||||||
|
selectedCountEl,
|
||||||
|
]),
|
||||||
|
listEl,
|
||||||
|
h('div', { className: 'smig-footer' }, [migrateBtn]),
|
||||||
|
resultBoxEl,
|
||||||
|
];
|
||||||
|
for (const child of children) {
|
||||||
|
rootEl.appendChild(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDetectedClients() {
|
||||||
|
return Array.isArray(catalog?.clients) ? catalog.clients.filter((c) => c.exists) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTargetClientsFor(srcId) {
|
||||||
|
return getDetectedClients().filter((c) => c.canBeTarget && c.id !== srcId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureValidSelectionDefaults() {
|
||||||
|
const detected = getDetectedClients();
|
||||||
|
if (detected.length < 2) {
|
||||||
|
sourceClient = '';
|
||||||
|
targetClient = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const validSources = detected.filter((c) => getTargetClientsFor(c.id).length > 0);
|
||||||
|
if (!validSources.some((c) => c.id === sourceClient)) {
|
||||||
|
const cliClient = validSources.find((c) => c.id === 'cli' && c.sessionCount > 0);
|
||||||
|
const firstWithSessions = validSources.find((c) => c.sessionCount > 0);
|
||||||
|
sourceClient = (cliClient || firstWithSessions || validSources[0])?.id || '';
|
||||||
|
}
|
||||||
|
ensureValidTarget();
|
||||||
|
|
||||||
|
const projects = Array.isArray(catalog?.desktopProjects) ? catalog.desktopProjects : [];
|
||||||
|
if (!projects.some((p) => p.projectId === targetProjectId)) {
|
||||||
|
const preferred = projects.find((p) => !p.isOutsideProject) || projects[0];
|
||||||
|
targetProjectId = preferred?.projectId || SMIG_OUTSIDE_PROJECT_ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureValidTarget() {
|
||||||
|
const targets = getTargetClientsFor(sourceClient);
|
||||||
|
if (!targets.some((c) => c.id === targetClient)) {
|
||||||
|
const preferDesktop = targets.find((c) => c.id === 'desktop');
|
||||||
|
targetClient = (preferDesktop || targets[0])?.id || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCurrentSourceSessions() {
|
||||||
|
const list = catalog?.sessionsByClient?.[sourceClient];
|
||||||
|
return Array.isArray(list) ? list : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFilteredSessions() {
|
||||||
|
const all = getCurrentSourceSessions();
|
||||||
|
if (!searchQuery) return all;
|
||||||
|
const needle = searchQuery.toLowerCase();
|
||||||
|
return all.filter((item) => {
|
||||||
|
const haystack = [
|
||||||
|
item.title,
|
||||||
|
item.workspaceName,
|
||||||
|
item.workspacePath,
|
||||||
|
item.cascadeId,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' ')
|
||||||
|
.toLowerCase();
|
||||||
|
return haystack.includes(needle);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveProjectDisplayLabel(projectId) {
|
||||||
|
if (!projectId || projectId === SMIG_OUTSIDE_PROJECT_ID) {
|
||||||
|
return t('settings.oth.migProjectOutside');
|
||||||
|
}
|
||||||
|
const projects = Array.isArray(catalog?.desktopProjects) ? catalog.desktopProjects : [];
|
||||||
|
const found = projects.find((p) => p.projectId === projectId);
|
||||||
|
return found?.name || projectId.slice(0, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncModeControls() {
|
||||||
|
if (!bodyMounted) return;
|
||||||
|
patchClasses(modeMoveBtn, { 'is-active': migrationMode === 'move' });
|
||||||
|
patchClasses(modeCloneBtn, { 'is-active': migrationMode === 'clone' });
|
||||||
|
patchText(
|
||||||
|
modeHintEl,
|
||||||
|
migrationMode === 'clone'
|
||||||
|
? t('settings.oth.migModeCloneHint')
|
||||||
|
: t('settings.oth.migModeMoveHint')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatMigrationError(code) {
|
||||||
|
if (code === 'source_locked') return t('settings.oth.migErrLocked');
|
||||||
|
if (code === 'target_already_exists') return t('settings.oth.migErrExists');
|
||||||
|
if (code === 'session_running') return t('settings.oth.migErrRunning');
|
||||||
|
return t('settings.oth.migFailed', { reason: code || 'unknown_error' });
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncControlsAndList() {
|
||||||
|
const visible = Boolean(catalog?.available);
|
||||||
|
patchAttr(rootEl, 'hidden', !visible);
|
||||||
|
if (!visible) {
|
||||||
|
props?.onLayoutChange?.();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ensureBodyMounted();
|
||||||
|
syncModeControls();
|
||||||
|
|
||||||
|
const detected = getDetectedClients();
|
||||||
|
const sourceOptions = detected
|
||||||
|
.filter((c) => getTargetClientsFor(c.id).length > 0)
|
||||||
|
.map((c) => ({
|
||||||
|
value: c.id,
|
||||||
|
label: smigGetClientLabel(c.id),
|
||||||
|
meta: String(c.sessionCount),
|
||||||
|
}));
|
||||||
|
const targetOptions = getTargetClientsFor(sourceClient).map((c) => ({
|
||||||
|
value: c.id,
|
||||||
|
label: smigGetClientLabel(c.id),
|
||||||
|
}));
|
||||||
|
const projectOptions = (catalog?.desktopProjects || []).map((p) =>
|
||||||
|
p.isOutsideProject
|
||||||
|
? { value: p.projectId, label: t('settings.oth.migProjectOutside') }
|
||||||
|
: {
|
||||||
|
value: p.projectId,
|
||||||
|
label: p.name || p.projectId.slice(0, 8),
|
||||||
|
meta: p.workspacePath || '',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
sourceSelect.setProps({
|
||||||
|
ariaLabel: t('settings.oth.migSourceLabel'),
|
||||||
|
modelValue: sourceClient,
|
||||||
|
options: sourceOptions,
|
||||||
|
});
|
||||||
|
targetSelect.setProps({
|
||||||
|
ariaLabel: t('settings.oth.migTargetLabel'),
|
||||||
|
modelValue: targetClient,
|
||||||
|
options: targetOptions,
|
||||||
|
});
|
||||||
|
projectSelect.setProps({
|
||||||
|
ariaLabel: t('settings.oth.migProjectLabel'),
|
||||||
|
modelValue: targetProjectId,
|
||||||
|
options: projectOptions,
|
||||||
|
});
|
||||||
|
patchAttr(projectFieldWrap, 'hidden', targetClient !== 'desktop');
|
||||||
|
|
||||||
|
renderSessionList();
|
||||||
|
renderResultBox();
|
||||||
|
props?.onLayoutChange?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderSessionList() {
|
||||||
|
const all = getCurrentSourceSessions();
|
||||||
|
const filtered = getFilteredSessions();
|
||||||
|
|
||||||
|
// 清理已不在当前来源中的选中 ID
|
||||||
|
const validSet = new Set(all.filter((s) => !s.isRunning).map((s) => s.cascadeId));
|
||||||
|
for (const id of [...selectedIds]) {
|
||||||
|
if (!validSet.has(id)) selectedIds.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectableFiltered = filtered.filter((s) => !s.isRunning);
|
||||||
|
const allSelected =
|
||||||
|
selectableFiltered.length > 0 &&
|
||||||
|
selectableFiltered.every((s) => selectedIds.has(s.cascadeId));
|
||||||
|
patchText(
|
||||||
|
toggleAllBtn,
|
||||||
|
allSelected ? t('settings.oth.migClearSel') : t('settings.oth.migSelectAll')
|
||||||
|
);
|
||||||
|
patchAttr(toggleAllBtn, 'disabled', selectableFiltered.length === 0 || isMigrating);
|
||||||
|
patchText(
|
||||||
|
selectedCountEl,
|
||||||
|
t('settings.oth.migSelectedCount', {
|
||||||
|
selected: selectedIds.size,
|
||||||
|
total: filtered.length,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
while (listEl.firstChild) {
|
||||||
|
listEl.removeChild(listEl.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (all.length === 0) {
|
||||||
|
listEl.appendChild(h('div', { className: 'smig-empty', text: t('settings.oth.migEmpty') }));
|
||||||
|
} else if (filtered.length === 0) {
|
||||||
|
listEl.appendChild(
|
||||||
|
h('div', { className: 'smig-empty', text: t('settings.oth.migNoMatch') })
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
for (const item of filtered) {
|
||||||
|
const checked = selectedIds.has(item.cascadeId);
|
||||||
|
const checkboxEl = h('input', {
|
||||||
|
type: 'checkbox',
|
||||||
|
className: 'smig-checkbox',
|
||||||
|
checked,
|
||||||
|
disabled: Boolean(item.isRunning || isMigrating),
|
||||||
|
});
|
||||||
|
checkboxEl.checked = checked;
|
||||||
|
const toggleItem = () => {
|
||||||
|
if (item.isRunning || isMigrating) return;
|
||||||
|
if (selectedIds.has(item.cascadeId)) {
|
||||||
|
selectedIds.delete(item.cascadeId);
|
||||||
|
} else {
|
||||||
|
selectedIds.add(item.cascadeId);
|
||||||
|
}
|
||||||
|
renderSessionList();
|
||||||
|
};
|
||||||
|
checkboxEl.addEventListener?.('change', toggleItem);
|
||||||
|
|
||||||
|
const metaParts = [t('settings.oth.migStepsUnit', { count: item.stepCount })];
|
||||||
|
const age = smigFormatAge(item.lastModifiedMs);
|
||||||
|
if (age) metaParts.push(age);
|
||||||
|
|
||||||
|
const subChildren = [];
|
||||||
|
if (item.workspacePath || item.workspaceName) {
|
||||||
|
subChildren.push(
|
||||||
|
h('span', {
|
||||||
|
className: 'smig-item-ws',
|
||||||
|
text: item.workspacePath || item.workspaceName,
|
||||||
|
title: item.workspacePath || item.workspaceName,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (item.isRunning) {
|
||||||
|
subChildren.push(
|
||||||
|
h('span', {
|
||||||
|
className: 'smig-item-running',
|
||||||
|
text: t('settings.oth.migRunningTag'),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rowEl = h(
|
||||||
|
'div',
|
||||||
|
{
|
||||||
|
className: `smig-item${checked ? ' is-selected' : ''}${item.isRunning ? ' is-running' : ''}`,
|
||||||
|
role: 'listitem',
|
||||||
|
onClick: (ev) => {
|
||||||
|
if (ev?.target === checkboxEl) return;
|
||||||
|
toggleItem();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[
|
||||||
|
checkboxEl,
|
||||||
|
h('div', { className: 'smig-item-body' }, [
|
||||||
|
h('div', { className: 'smig-item-top' }, [
|
||||||
|
h('span', {
|
||||||
|
className: 'smig-item-title',
|
||||||
|
text: item.title || item.cascadeId.slice(0, 8),
|
||||||
|
title: item.title || item.cascadeId,
|
||||||
|
}),
|
||||||
|
h('span', { className: 'smig-item-meta', text: metaParts.join(' · ') }),
|
||||||
|
]),
|
||||||
|
...(subChildren.length > 0
|
||||||
|
? [h('div', { className: 'smig-item-sub' }, subChildren)]
|
||||||
|
: []),
|
||||||
|
]),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
listEl.appendChild(rowEl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
patchAttr(migrateBtn, 'disabled', isMigrating || selectedIds.size === 0 || !targetClient);
|
||||||
|
patchText(
|
||||||
|
migrateBtnText,
|
||||||
|
isMigrating
|
||||||
|
? t('settings.oth.migRunningBtn')
|
||||||
|
: t('settings.oth.migActionBtn', { count: selectedIds.size })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderResultBox() {
|
||||||
|
if (!lastResult) {
|
||||||
|
patchAttr(resultBoxEl, 'hidden', true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
patchAttr(resultBoxEl, 'hidden', false);
|
||||||
|
patchClasses(resultBoxEl, {
|
||||||
|
'is-ok': Boolean(lastResult.ok),
|
||||||
|
'is-err': !lastResult.ok,
|
||||||
|
});
|
||||||
|
|
||||||
|
while (resultBoxEl.firstChild) {
|
||||||
|
resultBoxEl.removeChild(resultBoxEl.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lastResult.ok) {
|
||||||
|
resultBoxEl.appendChild(
|
||||||
|
h('div', {
|
||||||
|
className: 'smig-result-msg',
|
||||||
|
text: formatMigrationError(lastResult.error),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const partialSuffix =
|
||||||
|
lastResult.failedCount > 0
|
||||||
|
? t('settings.oth.migPartialWarn', { failed: lastResult.failedCount })
|
||||||
|
: '';
|
||||||
|
const baseMsg =
|
||||||
|
lastResult.targetClient === 'cli'
|
||||||
|
? t('settings.oth.migDoneCli', { count: lastResult.migratedCount })
|
||||||
|
: t('settings.oth.migDoneDesktop', {
|
||||||
|
count: lastResult.migratedCount,
|
||||||
|
project: resolveProjectDisplayLabel(lastResult.targetProjectId),
|
||||||
|
});
|
||||||
|
|
||||||
|
resultBoxEl.appendChild(
|
||||||
|
h('div', { className: 'smig-result-msg', text: `${baseMsg}${partialSuffix}` })
|
||||||
|
);
|
||||||
|
|
||||||
|
if (lastResult.targetClient === 'desktop' && isWindowOverlayMode()) {
|
||||||
|
resultBoxEl.appendChild(
|
||||||
|
h('div', { className: 'smig-result-actions' }, [
|
||||||
|
h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
className: 'btn-secondary smig-result-btn',
|
||||||
|
onClick: () => {
|
||||||
|
if (typeof window !== 'undefined' && typeof window.location?.reload === 'function') {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[createSvgIcon('refresh', { size: 11 }), h('span', { text: t('settings.oth.migReloadBtn') })]
|
||||||
|
),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastResult.targetClient === 'cli') {
|
||||||
|
const okItems = (lastResult.results || []).filter((r) => r.ok && r.resumeCommand);
|
||||||
|
if (okItems.length > 0) {
|
||||||
|
const cmdWrap = h('div', { className: 'smig-cmd-list' });
|
||||||
|
for (const item of okItems.slice(0, 6)) {
|
||||||
|
const isCopied = copiedCmdId === item.newCascadeId;
|
||||||
|
const copyBtn = h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
className: 'btn-ghost-sm smig-cmd-copy',
|
||||||
|
text: isCopied ? t('settings.oth.migCopied') : t('settings.oth.migCopyCmd'),
|
||||||
|
onClick: async () => {
|
||||||
|
const ok = await smigCopyText(item.resumeCommand);
|
||||||
|
if (!ok || destroyed) return;
|
||||||
|
copiedCmdId = item.newCascadeId;
|
||||||
|
renderResultBox();
|
||||||
|
if (copiedTimer) clearTimeout(copiedTimer);
|
||||||
|
copiedTimer = setTimeout(() => {
|
||||||
|
copiedTimer = null;
|
||||||
|
if (!destroyed && copiedCmdId === item.newCascadeId) {
|
||||||
|
copiedCmdId = '';
|
||||||
|
renderResultBox();
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
cmdWrap.appendChild(
|
||||||
|
h('div', { className: 'smig-cmd-row' }, [
|
||||||
|
h('code', { className: 'smig-cmd-code', text: item.resumeCommand }),
|
||||||
|
copyBtn,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
resultBoxEl.appendChild(cmdWrap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadCatalog(force = false) {
|
||||||
|
if (isLoading || (hasLoadedOnce && !force)) return;
|
||||||
|
isLoading = true;
|
||||||
|
if (refreshBtn) patchAttr(refreshBtn, 'disabled', true);
|
||||||
|
try {
|
||||||
|
const res = await loadCatalogFn();
|
||||||
|
if (destroyed) return;
|
||||||
|
hasLoadedOnce = true;
|
||||||
|
if (res && typeof res === 'object') {
|
||||||
|
catalog = res;
|
||||||
|
ensureValidSelectionDefaults();
|
||||||
|
syncControlsAndList();
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// 本地目录或 API 暂不可用时静默隐藏卡片,避免干扰其他设置项
|
||||||
|
if (!destroyed && !catalog) {
|
||||||
|
patchAttr(rootEl, 'hidden', true);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
isLoading = false;
|
||||||
|
if (refreshBtn) patchAttr(refreshBtn, 'disabled', false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleMigrate() {
|
||||||
|
if (isMigrating || selectedIds.size === 0 || !sourceClient || !targetClient) return;
|
||||||
|
isMigrating = true;
|
||||||
|
lastResult = null;
|
||||||
|
renderSessionList();
|
||||||
|
renderResultBox();
|
||||||
|
try {
|
||||||
|
const payload = {
|
||||||
|
sourceClient,
|
||||||
|
targetClient,
|
||||||
|
mode: migrationMode,
|
||||||
|
cascadeIds: [...selectedIds],
|
||||||
|
...(targetClient === 'desktop' ? { targetProjectId } : {}),
|
||||||
|
};
|
||||||
|
const res = await runMigrateFn(payload);
|
||||||
|
if (destroyed) return;
|
||||||
|
lastResult = res || { ok: false, error: 'empty_response' };
|
||||||
|
if (res?.ok) {
|
||||||
|
selectedIds.clear();
|
||||||
|
void loadCatalog(true);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (!destroyed) {
|
||||||
|
lastResult = { ok: false, error: err?.message || 'request_failed' };
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
isMigrating = false;
|
||||||
|
if (!destroyed) {
|
||||||
|
renderSessionList();
|
||||||
|
renderResultBox();
|
||||||
|
props?.onLayoutChange?.();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshLabels() {
|
||||||
|
if (!bodyMounted) return;
|
||||||
|
patchText(titleEl, t('settings.oth.migTitle'));
|
||||||
|
patchText(descEl, t('settings.oth.migDesc'));
|
||||||
|
patchText(refreshBtnText, t('settings.oth.migRefreshBtn'));
|
||||||
|
patchText(sourceLabelEl, t('settings.oth.migSourceLabel'));
|
||||||
|
patchText(targetLabelEl, t('settings.oth.migTargetLabel'));
|
||||||
|
patchText(modeLabelEl, t('settings.oth.migModeLabel'));
|
||||||
|
patchText(modeMoveBtn, t('settings.oth.migModeMove'));
|
||||||
|
patchText(modeCloneBtn, t('settings.oth.migModeClone'));
|
||||||
|
syncModeControls();
|
||||||
|
patchText(projectLabelEl, t('settings.oth.migProjectLabel'));
|
||||||
|
patchAttr(searchInput, 'placeholder', t('settings.oth.migSearchPlaceholder'));
|
||||||
|
if (catalog?.available) {
|
||||||
|
syncControlsAndList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
destroyed = true;
|
||||||
|
if (copiedTimer) {
|
||||||
|
clearTimeout(copiedTimer);
|
||||||
|
copiedTimer = null;
|
||||||
|
}
|
||||||
|
sourceSelect?.destroy?.();
|
||||||
|
targetSelect?.destroy?.();
|
||||||
|
projectSelect?.destroy?.();
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
el: rootEl,
|
||||||
|
refs: {
|
||||||
|
ensureLoaded: () => loadCatalog(false),
|
||||||
|
reload: () => loadCatalog(true),
|
||||||
|
refreshLabels,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return { SessionMigrationCard };
|
||||||
|
})();
|
||||||
|
|
||||||
// --- src/views/settings/SettingsGeneralTab.js ---
|
// --- src/views/settings/SettingsGeneralTab.js ---
|
||||||
const { SettingsGeneralTab } = (() => {
|
const { SettingsGeneralTab } = (() => {
|
||||||
/**
|
/**
|
||||||
@@ -22935,10 +23790,17 @@ const SettingsOtherTab = defineComponent({
|
|||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const sessionMigrationCard = SessionMigrationCard({
|
||||||
|
onLayoutChange: () => {
|
||||||
|
getProps()?.onLayoutChange?.();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const rootEl = h('div', { className: 'settings-tab-stack' }, [
|
const rootEl = h('div', { className: 'settings-tab-stack' }, [
|
||||||
modelPanel,
|
modelPanel,
|
||||||
baselinePanel,
|
baselinePanel,
|
||||||
maintPanel,
|
maintPanel,
|
||||||
|
sessionMigrationCard.el,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function renderSettings(
|
function renderSettings(
|
||||||
@@ -22969,6 +23831,7 @@ const SettingsOtherTab = defineComponent({
|
|||||||
options: getOrchestratorIdDisplayOptions(),
|
options: getOrchestratorIdDisplayOptions(),
|
||||||
});
|
});
|
||||||
renderContextWindows();
|
renderContextWindows();
|
||||||
|
void sessionMigrationCard.refs.ensureLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshLabels() {
|
function refreshLabels() {
|
||||||
@@ -23005,6 +23868,7 @@ const SettingsOtherTab = defineComponent({
|
|||||||
modelValue: draftOrchestratorIdMode,
|
modelValue: draftOrchestratorIdMode,
|
||||||
options: getOrchestratorIdDisplayOptions(),
|
options: getOrchestratorIdDisplayOptions(),
|
||||||
});
|
});
|
||||||
|
sessionMigrationCard.refs.refreshLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
onCleanup(() => {
|
onCleanup(() => {
|
||||||
@@ -23016,6 +23880,7 @@ const SettingsOtherTab = defineComponent({
|
|||||||
ctxBridgeNotice.destroy();
|
ctxBridgeNotice.destroy();
|
||||||
ctxModelSelect.destroy();
|
ctxModelSelect.destroy();
|
||||||
ctxWindowSelect.destroy();
|
ctxWindowSelect.destroy();
|
||||||
|
sessionMigrationCard.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -23026,6 +23891,7 @@ const SettingsOtherTab = defineComponent({
|
|||||||
ctxBridgeNotice,
|
ctxBridgeNotice,
|
||||||
ctxModelSelect,
|
ctxModelSelect,
|
||||||
ctxWindowSelect,
|
ctxWindowSelect,
|
||||||
|
sessionMigrationCard,
|
||||||
rebuildCacheBtn,
|
rebuildCacheBtn,
|
||||||
resetAllBtn,
|
resetAllBtn,
|
||||||
exportJsonBtn,
|
exportJsonBtn,
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ import {
|
|||||||
resolveDevToolsPortCandidates,
|
resolveDevToolsPortCandidates,
|
||||||
startDefaultWindowBridge,
|
startDefaultWindowBridge,
|
||||||
} from './window-bridge.mjs';
|
} from './window-bridge.mjs';
|
||||||
|
import { getSessionMigrationCatalog, migrateSessions } from './session-migrator.mjs';
|
||||||
import {
|
import {
|
||||||
ensureCliStatusLineConfigured,
|
ensureCliStatusLineConfigured,
|
||||||
getCliStatusLineRuntimeStatus,
|
getCliStatusLineRuntimeStatus,
|
||||||
@@ -678,6 +679,62 @@ export function executeCliStatusLineAction(rawAction) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function executeSessionMigrationCatalogAction(data = undefined, opts = {}) {
|
||||||
|
const epCtx = resolveActionEndpoint(data, opts);
|
||||||
|
if (!epCtx.ok) {
|
||||||
|
return buildEndpointErrorResponse(epCtx);
|
||||||
|
}
|
||||||
|
if (epCtx.isRemote) {
|
||||||
|
return {
|
||||||
|
status: 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
headers: { 'Cache-Control': 'no-store' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
available: false,
|
||||||
|
sqliteSupported: false,
|
||||||
|
clients: [],
|
||||||
|
sessionsByClient: {},
|
||||||
|
desktopProjects: [],
|
||||||
|
error: 'unsupported_remote',
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const catalog = getSessionMigrationCatalog();
|
||||||
|
return {
|
||||||
|
status: 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
headers: { 'Cache-Control': 'no-store' },
|
||||||
|
body: JSON.stringify(catalog),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function executeSessionMigrationMigrateAction(data = undefined, opts = {}) {
|
||||||
|
const epCtx = resolveActionEndpoint(data, opts);
|
||||||
|
if (!epCtx.ok) {
|
||||||
|
return buildEndpointErrorResponse(epCtx);
|
||||||
|
}
|
||||||
|
if (epCtx.isRemote) {
|
||||||
|
return {
|
||||||
|
status: 400,
|
||||||
|
contentType: 'application/json',
|
||||||
|
headers: { 'Cache-Control': 'no-store' },
|
||||||
|
body: JSON.stringify({ ok: false, error: 'unsupported_remote', results: [] }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const cleanData = stripEndpointField(data);
|
||||||
|
const result = migrateSessions(cleanData);
|
||||||
|
if (result.migratedCount > 0) {
|
||||||
|
clearScannerRuntimeMemos(LOCAL_ENDPOINT_ID);
|
||||||
|
clearTelemetryBuilderMemo(LOCAL_ENDPOINT_ID);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: Number(result.status || (result.ok ? 200 : 400)),
|
||||||
|
contentType: 'application/json',
|
||||||
|
headers: { 'Cache-Control': 'no-store' },
|
||||||
|
body: JSON.stringify(result),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const BRIDGE_ROUTE_LOOKUP = new Map(
|
const BRIDGE_ROUTE_LOOKUP = new Map(
|
||||||
BRIDGE_API_ROUTE_DEFS.map((r) => [`${r.method}:${r.path}`, r.action])
|
BRIDGE_API_ROUTE_DEFS.map((r) => [`${r.method}:${r.path}`, r.action])
|
||||||
);
|
);
|
||||||
@@ -694,6 +751,12 @@ export async function dispatchBridgeApiRequest(pathname, method, data, opts = un
|
|||||||
if (isPlainObject(data) && typeof data.__cliStatusLineAction === 'string') {
|
if (isPlainObject(data) && typeof data.__cliStatusLineAction === 'string') {
|
||||||
return executeCliStatusLineAction(data.__cliStatusLineAction);
|
return executeCliStatusLineAction(data.__cliStatusLineAction);
|
||||||
}
|
}
|
||||||
|
if (isPlainObject(data) && data.__sessionMigrationAction === 'catalog') {
|
||||||
|
return executeSessionMigrationCatalogAction(data, opts);
|
||||||
|
}
|
||||||
|
if (isPlainObject(data) && data.__sessionMigrationAction === 'migrate') {
|
||||||
|
return executeSessionMigrationMigrateAction(data.payload || data, opts);
|
||||||
|
}
|
||||||
return executeSettingsAction(data);
|
return executeSettingsAction(data);
|
||||||
case 'accounts_get':
|
case 'accounts_get':
|
||||||
return executeAccountCredentialAction(undefined, opts);
|
return executeAccountCredentialAction(undefined, opts);
|
||||||
@@ -711,6 +774,10 @@ export async function dispatchBridgeApiRequest(pathname, method, data, opts = un
|
|||||||
return executePluginUpdateAction();
|
return executePluginUpdateAction();
|
||||||
case 'bridge_relaunch':
|
case 'bridge_relaunch':
|
||||||
return executeBridgeRelaunchAction();
|
return executeBridgeRelaunchAction();
|
||||||
|
case 'session_migration_catalog':
|
||||||
|
return executeSessionMigrationCatalogAction(data, opts);
|
||||||
|
case 'session_migration_migrate':
|
||||||
|
return executeSessionMigrationMigrateAction(data, opts);
|
||||||
default:
|
default:
|
||||||
return {
|
return {
|
||||||
status: 404,
|
status: 404,
|
||||||
|
|||||||
@@ -208,3 +208,132 @@ export function decodeProtoMapStringEntry(buf, state, end) {
|
|||||||
state.off = end;
|
state.off = end;
|
||||||
return [key, val];
|
return [key, val];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// 无损 Protobuf Wire 编码及按字段号定向修补原语(保留所有未知/未触碰字段原字节)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export function encodeProtoVarint(value) {
|
||||||
|
let n = typeof value === 'bigint' ? value : BigInt(Math.trunc(Number(value) || 0));
|
||||||
|
if (n < 0n) n = BigInt.asUintN(64, n);
|
||||||
|
const bytes = [];
|
||||||
|
do {
|
||||||
|
let b = Number(n & 0x7fn);
|
||||||
|
n >>= 7n;
|
||||||
|
if (n > 0n) b |= 0x80;
|
||||||
|
bytes.push(b);
|
||||||
|
} while (n > 0n);
|
||||||
|
return Buffer.from(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function encodeProtoTag(fieldNumber, wireType) {
|
||||||
|
return encodeProtoVarint((BigInt(fieldNumber) << 3n) | BigInt(wireType & 7));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function encodeProtoVarintField(fieldNumber, value) {
|
||||||
|
return Buffer.concat([encodeProtoTag(fieldNumber, 0), encodeProtoVarint(value)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function encodeProtoBytesField(fieldNumber, payload) {
|
||||||
|
const buf = payload instanceof Buffer ? payload : Buffer.from(payload || []);
|
||||||
|
return Buffer.concat([encodeProtoTag(fieldNumber, 2), encodeProtoVarint(buf.length), buf]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function encodeProtoStringField(fieldNumber, text) {
|
||||||
|
return encodeProtoBytesField(fieldNumber, Buffer.from(String(text ?? ''), 'utf8'));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function encodeProtoTimestamp(epochMs) {
|
||||||
|
const ms = Number(epochMs);
|
||||||
|
if (!Number.isFinite(ms) || ms <= 0) return Buffer.alloc(0);
|
||||||
|
const seconds = Math.floor(ms / 1000);
|
||||||
|
const nanos = Math.floor((ms - seconds * 1000) * 1_000_000);
|
||||||
|
const parts = [encodeProtoVarintField(1, seconds)];
|
||||||
|
if (nanos > 0) {
|
||||||
|
parts.push(encodeProtoVarintField(2, nanos));
|
||||||
|
}
|
||||||
|
return Buffer.concat(parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将原始 Protobuf 二进制消息拆分为顶层原始字段切片,确保未知字段零损透传。
|
||||||
|
*
|
||||||
|
* @param {Uint8Array | Buffer} raw
|
||||||
|
* @returns {Array<{ fn: number, wt: number, raw: Buffer, payload: Buffer }>}
|
||||||
|
*/
|
||||||
|
export function splitProtoRawFields(raw) {
|
||||||
|
const u8 = toUint8Array(raw);
|
||||||
|
if (!u8 || u8.byteLength === 0) return [];
|
||||||
|
const buf = Buffer.from(u8.buffer, u8.byteOffset, u8.byteLength);
|
||||||
|
const state = { off: 0 };
|
||||||
|
const limit = buf.length;
|
||||||
|
const fields = [];
|
||||||
|
while (state.off < limit) {
|
||||||
|
const start = state.off;
|
||||||
|
const tag = Number(BigInt.asUintN(32, readProtoVarint(buf, state, limit)));
|
||||||
|
const fn = tag >>> 3;
|
||||||
|
const wt = tag & 7;
|
||||||
|
if (fn === 0) break;
|
||||||
|
let payloadStart = state.off;
|
||||||
|
let payloadEnd = state.off;
|
||||||
|
if (wt === 0) {
|
||||||
|
readProtoVarint(buf, state, limit);
|
||||||
|
payloadEnd = state.off;
|
||||||
|
} else if (wt === 1) {
|
||||||
|
state.off = Math.min(limit, state.off + 8);
|
||||||
|
payloadEnd = state.off;
|
||||||
|
} else if (wt === 5) {
|
||||||
|
state.off = Math.min(limit, state.off + 4);
|
||||||
|
payloadEnd = state.off;
|
||||||
|
} else if (wt === 2) {
|
||||||
|
const end = readSubEnd(buf, state, limit);
|
||||||
|
payloadStart = state.off;
|
||||||
|
state.off = end;
|
||||||
|
payloadEnd = end;
|
||||||
|
} else if (wt === 3) {
|
||||||
|
skipProtoField(buf, state, 3, limit);
|
||||||
|
payloadEnd = state.off;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fields.push({
|
||||||
|
fn,
|
||||||
|
wt,
|
||||||
|
raw: buf.subarray(start, state.off),
|
||||||
|
payload: buf.subarray(payloadStart, payloadEnd),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按字段号定向替换、删除(传 `null`)或追加 Protobuf 顶层字段,其余未知字段原字节无损保留。
|
||||||
|
*
|
||||||
|
* @param {Uint8Array | Buffer} raw
|
||||||
|
* @param {Map<number, Buffer | Uint8Array | null>} replacements
|
||||||
|
* @returns {Buffer}
|
||||||
|
*/
|
||||||
|
export function patchProtoMessageFields(raw, replacements) {
|
||||||
|
const fields = splitProtoRawFields(raw);
|
||||||
|
const handled = new Set();
|
||||||
|
const out = [];
|
||||||
|
for (const field of fields) {
|
||||||
|
if (replacements.has(field.fn)) {
|
||||||
|
if (!handled.has(field.fn)) {
|
||||||
|
handled.add(field.fn);
|
||||||
|
const rep = replacements.get(field.fn);
|
||||||
|
if (rep && rep.length > 0) {
|
||||||
|
out.push(Buffer.from(rep));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out.push(field.raw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const [fn, rep] of replacements.entries()) {
|
||||||
|
if (!handled.has(fn) && rep && rep.length > 0) {
|
||||||
|
out.push(Buffer.from(rep));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Buffer.concat(out);
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -4,11 +4,11 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>用量监控</title>
|
<title>用量监控</title>
|
||||||
<link rel="stylesheet" href="/styles.css?v=1795263723880">
|
<link rel="stylesheet" href="/styles.css?v=1795270570107">
|
||||||
<script src="/preload.js"></script>
|
<script src="/preload.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app-root"></div>
|
<div id="app-root"></div>
|
||||||
<script src="/app.js?v=1795263723880"></script>
|
<script src="/app.js?v=1795270570107"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -558,6 +558,7 @@ export function buildBundle(panelDir = PANEL_DIR) {
|
|||||||
'src/components/settings/EditableSlotList.js',
|
'src/components/settings/EditableSlotList.js',
|
||||||
'src/components/settings/ThemeColorPicker.js',
|
'src/components/settings/ThemeColorPicker.js',
|
||||||
'src/components/settings/BridgeStatusNotice.js',
|
'src/components/settings/BridgeStatusNotice.js',
|
||||||
|
'src/components/settings/SessionMigrationCard.js',
|
||||||
'src/views/settings/SettingsGeneralTab.js',
|
'src/views/settings/SettingsGeneralTab.js',
|
||||||
'src/views/settings/SettingsStructureTab.js',
|
'src/views/settings/SettingsStructureTab.js',
|
||||||
'src/views/settings/SettingsOtherTab.js',
|
'src/views/settings/SettingsOtherTab.js',
|
||||||
|
|||||||
@@ -28,6 +28,16 @@ export const BRIDGE_API_ROUTE_DEFS = Object.freeze([
|
|||||||
Object.freeze({ path: '/api/cloud-sync', method: 'POST', action: 'cloud_sync' }),
|
Object.freeze({ path: '/api/cloud-sync', method: 'POST', action: 'cloud_sync' }),
|
||||||
Object.freeze({ path: '/api/plugin-update', method: 'POST', action: 'plugin_update' }),
|
Object.freeze({ path: '/api/plugin-update', method: 'POST', action: 'plugin_update' }),
|
||||||
Object.freeze({ path: '/api/bridge/relaunch', method: 'POST', action: 'bridge_relaunch' }),
|
Object.freeze({ path: '/api/bridge/relaunch', method: 'POST', action: 'bridge_relaunch' }),
|
||||||
|
Object.freeze({
|
||||||
|
path: '/api/session-migration/catalog',
|
||||||
|
method: 'GET',
|
||||||
|
action: 'session_migration_catalog',
|
||||||
|
}),
|
||||||
|
Object.freeze({
|
||||||
|
path: '/api/session-migration/migrate',
|
||||||
|
method: 'POST',
|
||||||
|
action: 'session_migration_migrate',
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const BRIDGE_API_PATHS = Object.freeze(BRIDGE_API_ROUTE_DEFS.map((r) => r.path));
|
export const BRIDGE_API_PATHS = Object.freeze(BRIDGE_API_ROUTE_DEFS.map((r) => r.path));
|
||||||
|
|||||||
@@ -0,0 +1,750 @@
|
|||||||
|
/**
|
||||||
|
* @fileoverview 跨端会话按需迁移设置卡片 (`SessionMigrationCard.js`)。
|
||||||
|
* 仅当本机检测到 ≥2 个 Antigravity 客户端目录时展示,支持自由勾选根会话以新 UUID 无损克隆到目标端。
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { defineComponent } from '../../core/component.js';
|
||||||
|
import { h, patchAttr, patchClasses, patchText } from '../../core/domPatch.js';
|
||||||
|
import { isWindowOverlayMode } from '../../core/httpClient.js';
|
||||||
|
import { createSvgIcon } from '../../icons/SvgIcon.js';
|
||||||
|
import { isEnglishLocale, t } from '../../i18n/index.js';
|
||||||
|
import {
|
||||||
|
executeSessionMigration,
|
||||||
|
fetchSessionMigrationCatalog,
|
||||||
|
} from '../../store/telemetryStore.js';
|
||||||
|
import { CustomSelect } from '../ui/CustomSelect.js';
|
||||||
|
|
||||||
|
const SMIG_OUTSIDE_PROJECT_ID = 'outside-of-project';
|
||||||
|
|
||||||
|
async function smigCopyText(text) {
|
||||||
|
try {
|
||||||
|
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
|
||||||
|
await navigator.clipboard.writeText(text);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// 退回受限 Webview 的隐藏文本域复制
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (typeof document === 'undefined' || !document.body) return false;
|
||||||
|
const area = document.createElement('textarea');
|
||||||
|
area.value = text;
|
||||||
|
area.setAttribute('readonly', 'true');
|
||||||
|
area.style.cssText = 'position:fixed;left:-9999px;top:-9999px;opacity:0;';
|
||||||
|
document.body.appendChild(area);
|
||||||
|
area.select?.();
|
||||||
|
const ok = Boolean(document.execCommand?.('copy'));
|
||||||
|
document.body.removeChild(area);
|
||||||
|
return ok;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function smigGetClientLabel(clientId) {
|
||||||
|
if (clientId === 'cli') return t('settings.oth.migClientCli');
|
||||||
|
if (clientId === 'ide_legacy') return t('settings.oth.migClientIdeLegacy');
|
||||||
|
return t('settings.oth.migClientDesktop');
|
||||||
|
}
|
||||||
|
|
||||||
|
function smigFormatAge(epochMs) {
|
||||||
|
const ts = Number(epochMs || 0);
|
||||||
|
if (!Number.isFinite(ts) || ts <= 0) return '';
|
||||||
|
const diffSec = Math.max(0, Math.floor((Date.now() - ts) / 1000));
|
||||||
|
const isEn = isEnglishLocale();
|
||||||
|
if (diffSec < 60) return isEn ? 'just now' : '刚刚';
|
||||||
|
const diffMin = Math.floor(diffSec / 60);
|
||||||
|
if (diffMin < 60) return isEn ? `${diffMin}m ago` : `${diffMin}分钟前`;
|
||||||
|
const diffHr = Math.floor(diffMin / 60);
|
||||||
|
if (diffHr < 24) return isEn ? `${diffHr}h ago` : `${diffHr}小时前`;
|
||||||
|
const diffDay = Math.floor(diffHr / 24);
|
||||||
|
return isEn ? `${diffDay}d ago` : `${diffDay}天前`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SessionMigrationCard = defineComponent({
|
||||||
|
name: 'SessionMigrationCard',
|
||||||
|
setup({ props, onCleanup }) {
|
||||||
|
const loadCatalogFn =
|
||||||
|
typeof props?.loadCatalog === 'function' ? props.loadCatalog : fetchSessionMigrationCatalog;
|
||||||
|
const runMigrateFn =
|
||||||
|
typeof props?.runMigrate === 'function' ? props.runMigrate : executeSessionMigration;
|
||||||
|
|
||||||
|
let catalog = null;
|
||||||
|
let hasLoadedOnce = false;
|
||||||
|
let isLoading = false;
|
||||||
|
let isMigrating = false;
|
||||||
|
let destroyed = false;
|
||||||
|
let bodyMounted = false;
|
||||||
|
let sourceClient = '';
|
||||||
|
let targetClient = '';
|
||||||
|
let migrationMode = 'move';
|
||||||
|
let targetProjectId = '';
|
||||||
|
let searchQuery = '';
|
||||||
|
const selectedIds = new Set();
|
||||||
|
let lastResult = null;
|
||||||
|
let copiedCmdId = '';
|
||||||
|
let copiedTimer = null;
|
||||||
|
|
||||||
|
let titleEl = null;
|
||||||
|
let descEl = null;
|
||||||
|
let refreshBtnText = null;
|
||||||
|
let refreshBtn = null;
|
||||||
|
let sourceLabelEl = null;
|
||||||
|
let targetLabelEl = null;
|
||||||
|
let modeLabelEl = null;
|
||||||
|
let modeMoveBtn = null;
|
||||||
|
let modeCloneBtn = null;
|
||||||
|
let modeHintEl = null;
|
||||||
|
let projectLabelEl = null;
|
||||||
|
let sourceSelect = null;
|
||||||
|
let targetSelect = null;
|
||||||
|
let projectSelect = null;
|
||||||
|
let projectFieldWrap = null;
|
||||||
|
let searchInput = null;
|
||||||
|
let toggleAllBtn = null;
|
||||||
|
let selectedCountEl = null;
|
||||||
|
let listEl = null;
|
||||||
|
let migrateBtnText = null;
|
||||||
|
let migrateBtn = null;
|
||||||
|
let resultBoxEl = null;
|
||||||
|
|
||||||
|
const rootEl = h('section', { className: 'panel smig-panel', hidden: true });
|
||||||
|
|
||||||
|
function ensureBodyMounted() {
|
||||||
|
if (bodyMounted) return;
|
||||||
|
bodyMounted = true;
|
||||||
|
|
||||||
|
titleEl = h('span', { text: t('settings.oth.migTitle') });
|
||||||
|
descEl = h('p', { className: 'smig-desc', text: t('settings.oth.migDesc') });
|
||||||
|
refreshBtnText = h('span', { text: t('settings.oth.migRefreshBtn') });
|
||||||
|
refreshBtn = h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
className: 'btn-ghost-sm smig-refresh-btn',
|
||||||
|
onClick: () => {
|
||||||
|
void loadCatalog(true);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[createSvgIcon('refresh', { size: 12 }), refreshBtnText]
|
||||||
|
);
|
||||||
|
|
||||||
|
sourceLabelEl = h('span', { className: 'smig-field-label', text: t('settings.oth.migSourceLabel') });
|
||||||
|
targetLabelEl = h('span', { className: 'smig-field-label', text: t('settings.oth.migTargetLabel') });
|
||||||
|
modeLabelEl = h('span', { className: 'smig-field-label', text: t('settings.oth.migModeLabel') });
|
||||||
|
modeMoveBtn = h('button', {
|
||||||
|
type: 'button',
|
||||||
|
className: 'smig-mode-btn is-active',
|
||||||
|
text: t('settings.oth.migModeMove'),
|
||||||
|
onClick: () => {
|
||||||
|
if (migrationMode === 'move') return;
|
||||||
|
migrationMode = 'move';
|
||||||
|
lastResult = null;
|
||||||
|
syncModeControls();
|
||||||
|
renderResultBox();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
modeCloneBtn = h('button', {
|
||||||
|
type: 'button',
|
||||||
|
className: 'smig-mode-btn',
|
||||||
|
text: t('settings.oth.migModeClone'),
|
||||||
|
onClick: () => {
|
||||||
|
if (migrationMode === 'clone') return;
|
||||||
|
migrationMode = 'clone';
|
||||||
|
lastResult = null;
|
||||||
|
syncModeControls();
|
||||||
|
renderResultBox();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
modeHintEl = h('span', {
|
||||||
|
className: 'smig-mode-hint',
|
||||||
|
text: t('settings.oth.migModeMoveHint'),
|
||||||
|
});
|
||||||
|
projectLabelEl = h('span', { className: 'smig-field-label', text: t('settings.oth.migProjectLabel') });
|
||||||
|
|
||||||
|
sourceSelect = CustomSelect({
|
||||||
|
ariaLabel: t('settings.oth.migSourceLabel'),
|
||||||
|
modelValue: '',
|
||||||
|
options: [],
|
||||||
|
onUpdateModelValue: (val) => {
|
||||||
|
if (!val || val === sourceClient) return;
|
||||||
|
sourceClient = val;
|
||||||
|
selectedIds.clear();
|
||||||
|
lastResult = null;
|
||||||
|
ensureValidTarget();
|
||||||
|
syncControlsAndList();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
targetSelect = CustomSelect({
|
||||||
|
ariaLabel: t('settings.oth.migTargetLabel'),
|
||||||
|
modelValue: '',
|
||||||
|
options: [],
|
||||||
|
onUpdateModelValue: (val) => {
|
||||||
|
if (!val || val === targetClient) return;
|
||||||
|
targetClient = val;
|
||||||
|
lastResult = null;
|
||||||
|
syncControlsAndList();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
projectSelect = CustomSelect({
|
||||||
|
ariaLabel: t('settings.oth.migProjectLabel'),
|
||||||
|
modelValue: '',
|
||||||
|
options: [],
|
||||||
|
className: 'smig-project-select',
|
||||||
|
onUpdateModelValue: (val) => {
|
||||||
|
targetProjectId = String(val || '');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
projectFieldWrap = h('div', { className: 'smig-field' }, [
|
||||||
|
projectLabelEl,
|
||||||
|
projectSelect.el,
|
||||||
|
]);
|
||||||
|
|
||||||
|
searchInput = h('input', {
|
||||||
|
type: 'text',
|
||||||
|
className: 'settings-text-input smig-search-input',
|
||||||
|
placeholder: t('settings.oth.migSearchPlaceholder'),
|
||||||
|
value: '',
|
||||||
|
});
|
||||||
|
searchInput.addEventListener?.('input', () => {
|
||||||
|
searchQuery = String(searchInput.value || '').trim();
|
||||||
|
renderSessionList();
|
||||||
|
});
|
||||||
|
|
||||||
|
toggleAllBtn = h('button', {
|
||||||
|
type: 'button',
|
||||||
|
className: 'btn-ghost-sm smig-toggle-all-btn',
|
||||||
|
text: t('settings.oth.migSelectAll'),
|
||||||
|
onClick: () => {
|
||||||
|
const selectable = getFilteredSessions().filter((s) => !s.isRunning);
|
||||||
|
if (selectable.length === 0) return;
|
||||||
|
const allSelected = selectable.every((s) => selectedIds.has(s.cascadeId));
|
||||||
|
if (allSelected) {
|
||||||
|
for (const s of selectable) selectedIds.delete(s.cascadeId);
|
||||||
|
} else {
|
||||||
|
for (const s of selectable) selectedIds.add(s.cascadeId);
|
||||||
|
}
|
||||||
|
renderSessionList();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
selectedCountEl = h('span', { className: 'smig-count-meta', text: '' });
|
||||||
|
listEl = h('div', { className: 'smig-list', role: 'list' });
|
||||||
|
|
||||||
|
migrateBtnText = h('span', {
|
||||||
|
text: t('settings.oth.migActionBtn', { count: 0 }),
|
||||||
|
});
|
||||||
|
migrateBtn = h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
className: 'btn-secondary smig-migrate-btn',
|
||||||
|
disabled: true,
|
||||||
|
onClick: () => {
|
||||||
|
void handleMigrate();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[createSvgIcon('copy', { size: 12 }), migrateBtnText]
|
||||||
|
);
|
||||||
|
|
||||||
|
resultBoxEl = h('div', { className: 'smig-result', hidden: true });
|
||||||
|
|
||||||
|
const children = [
|
||||||
|
h('div', { className: 'panel-header' }, [
|
||||||
|
h('span', { className: 'panel-title' }, [
|
||||||
|
createSvgIcon('layers', { size: 13 }),
|
||||||
|
titleEl,
|
||||||
|
]),
|
||||||
|
refreshBtn,
|
||||||
|
]),
|
||||||
|
descEl,
|
||||||
|
h('div', { className: 'smig-direction-grid' }, [
|
||||||
|
h('div', { className: 'smig-field' }, [sourceLabelEl, sourceSelect.el]),
|
||||||
|
h('div', { className: 'smig-field' }, [targetLabelEl, targetSelect.el]),
|
||||||
|
]),
|
||||||
|
h('div', { className: 'smig-field' }, [
|
||||||
|
modeLabelEl,
|
||||||
|
h('div', { className: 'smig-mode-bar' }, [modeMoveBtn, modeCloneBtn]),
|
||||||
|
modeHintEl,
|
||||||
|
]),
|
||||||
|
projectFieldWrap,
|
||||||
|
h('div', { className: 'smig-toolbar' }, [
|
||||||
|
searchInput,
|
||||||
|
toggleAllBtn,
|
||||||
|
selectedCountEl,
|
||||||
|
]),
|
||||||
|
listEl,
|
||||||
|
h('div', { className: 'smig-footer' }, [migrateBtn]),
|
||||||
|
resultBoxEl,
|
||||||
|
];
|
||||||
|
for (const child of children) {
|
||||||
|
rootEl.appendChild(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDetectedClients() {
|
||||||
|
return Array.isArray(catalog?.clients) ? catalog.clients.filter((c) => c.exists) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTargetClientsFor(srcId) {
|
||||||
|
return getDetectedClients().filter((c) => c.canBeTarget && c.id !== srcId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureValidSelectionDefaults() {
|
||||||
|
const detected = getDetectedClients();
|
||||||
|
if (detected.length < 2) {
|
||||||
|
sourceClient = '';
|
||||||
|
targetClient = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const validSources = detected.filter((c) => getTargetClientsFor(c.id).length > 0);
|
||||||
|
if (!validSources.some((c) => c.id === sourceClient)) {
|
||||||
|
const cliClient = validSources.find((c) => c.id === 'cli' && c.sessionCount > 0);
|
||||||
|
const firstWithSessions = validSources.find((c) => c.sessionCount > 0);
|
||||||
|
sourceClient = (cliClient || firstWithSessions || validSources[0])?.id || '';
|
||||||
|
}
|
||||||
|
ensureValidTarget();
|
||||||
|
|
||||||
|
const projects = Array.isArray(catalog?.desktopProjects) ? catalog.desktopProjects : [];
|
||||||
|
if (!projects.some((p) => p.projectId === targetProjectId)) {
|
||||||
|
const preferred = projects.find((p) => !p.isOutsideProject) || projects[0];
|
||||||
|
targetProjectId = preferred?.projectId || SMIG_OUTSIDE_PROJECT_ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureValidTarget() {
|
||||||
|
const targets = getTargetClientsFor(sourceClient);
|
||||||
|
if (!targets.some((c) => c.id === targetClient)) {
|
||||||
|
const preferDesktop = targets.find((c) => c.id === 'desktop');
|
||||||
|
targetClient = (preferDesktop || targets[0])?.id || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCurrentSourceSessions() {
|
||||||
|
const list = catalog?.sessionsByClient?.[sourceClient];
|
||||||
|
return Array.isArray(list) ? list : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFilteredSessions() {
|
||||||
|
const all = getCurrentSourceSessions();
|
||||||
|
if (!searchQuery) return all;
|
||||||
|
const needle = searchQuery.toLowerCase();
|
||||||
|
return all.filter((item) => {
|
||||||
|
const haystack = [
|
||||||
|
item.title,
|
||||||
|
item.workspaceName,
|
||||||
|
item.workspacePath,
|
||||||
|
item.cascadeId,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' ')
|
||||||
|
.toLowerCase();
|
||||||
|
return haystack.includes(needle);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveProjectDisplayLabel(projectId) {
|
||||||
|
if (!projectId || projectId === SMIG_OUTSIDE_PROJECT_ID) {
|
||||||
|
return t('settings.oth.migProjectOutside');
|
||||||
|
}
|
||||||
|
const projects = Array.isArray(catalog?.desktopProjects) ? catalog.desktopProjects : [];
|
||||||
|
const found = projects.find((p) => p.projectId === projectId);
|
||||||
|
return found?.name || projectId.slice(0, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncModeControls() {
|
||||||
|
if (!bodyMounted) return;
|
||||||
|
patchClasses(modeMoveBtn, { 'is-active': migrationMode === 'move' });
|
||||||
|
patchClasses(modeCloneBtn, { 'is-active': migrationMode === 'clone' });
|
||||||
|
patchText(
|
||||||
|
modeHintEl,
|
||||||
|
migrationMode === 'clone'
|
||||||
|
? t('settings.oth.migModeCloneHint')
|
||||||
|
: t('settings.oth.migModeMoveHint')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatMigrationError(code) {
|
||||||
|
if (code === 'source_locked') return t('settings.oth.migErrLocked');
|
||||||
|
if (code === 'target_already_exists') return t('settings.oth.migErrExists');
|
||||||
|
if (code === 'session_running') return t('settings.oth.migErrRunning');
|
||||||
|
return t('settings.oth.migFailed', { reason: code || 'unknown_error' });
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncControlsAndList() {
|
||||||
|
const visible = Boolean(catalog?.available);
|
||||||
|
patchAttr(rootEl, 'hidden', !visible);
|
||||||
|
if (!visible) {
|
||||||
|
props?.onLayoutChange?.();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ensureBodyMounted();
|
||||||
|
syncModeControls();
|
||||||
|
|
||||||
|
const detected = getDetectedClients();
|
||||||
|
const sourceOptions = detected
|
||||||
|
.filter((c) => getTargetClientsFor(c.id).length > 0)
|
||||||
|
.map((c) => ({
|
||||||
|
value: c.id,
|
||||||
|
label: smigGetClientLabel(c.id),
|
||||||
|
meta: String(c.sessionCount),
|
||||||
|
}));
|
||||||
|
const targetOptions = getTargetClientsFor(sourceClient).map((c) => ({
|
||||||
|
value: c.id,
|
||||||
|
label: smigGetClientLabel(c.id),
|
||||||
|
}));
|
||||||
|
const projectOptions = (catalog?.desktopProjects || []).map((p) =>
|
||||||
|
p.isOutsideProject
|
||||||
|
? { value: p.projectId, label: t('settings.oth.migProjectOutside') }
|
||||||
|
: {
|
||||||
|
value: p.projectId,
|
||||||
|
label: p.name || p.projectId.slice(0, 8),
|
||||||
|
meta: p.workspacePath || '',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
sourceSelect.setProps({
|
||||||
|
ariaLabel: t('settings.oth.migSourceLabel'),
|
||||||
|
modelValue: sourceClient,
|
||||||
|
options: sourceOptions,
|
||||||
|
});
|
||||||
|
targetSelect.setProps({
|
||||||
|
ariaLabel: t('settings.oth.migTargetLabel'),
|
||||||
|
modelValue: targetClient,
|
||||||
|
options: targetOptions,
|
||||||
|
});
|
||||||
|
projectSelect.setProps({
|
||||||
|
ariaLabel: t('settings.oth.migProjectLabel'),
|
||||||
|
modelValue: targetProjectId,
|
||||||
|
options: projectOptions,
|
||||||
|
});
|
||||||
|
patchAttr(projectFieldWrap, 'hidden', targetClient !== 'desktop');
|
||||||
|
|
||||||
|
renderSessionList();
|
||||||
|
renderResultBox();
|
||||||
|
props?.onLayoutChange?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderSessionList() {
|
||||||
|
const all = getCurrentSourceSessions();
|
||||||
|
const filtered = getFilteredSessions();
|
||||||
|
|
||||||
|
// 清理已不在当前来源中的选中 ID
|
||||||
|
const validSet = new Set(all.filter((s) => !s.isRunning).map((s) => s.cascadeId));
|
||||||
|
for (const id of [...selectedIds]) {
|
||||||
|
if (!validSet.has(id)) selectedIds.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectableFiltered = filtered.filter((s) => !s.isRunning);
|
||||||
|
const allSelected =
|
||||||
|
selectableFiltered.length > 0 &&
|
||||||
|
selectableFiltered.every((s) => selectedIds.has(s.cascadeId));
|
||||||
|
patchText(
|
||||||
|
toggleAllBtn,
|
||||||
|
allSelected ? t('settings.oth.migClearSel') : t('settings.oth.migSelectAll')
|
||||||
|
);
|
||||||
|
patchAttr(toggleAllBtn, 'disabled', selectableFiltered.length === 0 || isMigrating);
|
||||||
|
patchText(
|
||||||
|
selectedCountEl,
|
||||||
|
t('settings.oth.migSelectedCount', {
|
||||||
|
selected: selectedIds.size,
|
||||||
|
total: filtered.length,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
while (listEl.firstChild) {
|
||||||
|
listEl.removeChild(listEl.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (all.length === 0) {
|
||||||
|
listEl.appendChild(h('div', { className: 'smig-empty', text: t('settings.oth.migEmpty') }));
|
||||||
|
} else if (filtered.length === 0) {
|
||||||
|
listEl.appendChild(
|
||||||
|
h('div', { className: 'smig-empty', text: t('settings.oth.migNoMatch') })
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
for (const item of filtered) {
|
||||||
|
const checked = selectedIds.has(item.cascadeId);
|
||||||
|
const checkboxEl = h('input', {
|
||||||
|
type: 'checkbox',
|
||||||
|
className: 'smig-checkbox',
|
||||||
|
checked,
|
||||||
|
disabled: Boolean(item.isRunning || isMigrating),
|
||||||
|
});
|
||||||
|
checkboxEl.checked = checked;
|
||||||
|
const toggleItem = () => {
|
||||||
|
if (item.isRunning || isMigrating) return;
|
||||||
|
if (selectedIds.has(item.cascadeId)) {
|
||||||
|
selectedIds.delete(item.cascadeId);
|
||||||
|
} else {
|
||||||
|
selectedIds.add(item.cascadeId);
|
||||||
|
}
|
||||||
|
renderSessionList();
|
||||||
|
};
|
||||||
|
checkboxEl.addEventListener?.('change', toggleItem);
|
||||||
|
|
||||||
|
const metaParts = [t('settings.oth.migStepsUnit', { count: item.stepCount })];
|
||||||
|
const age = smigFormatAge(item.lastModifiedMs);
|
||||||
|
if (age) metaParts.push(age);
|
||||||
|
|
||||||
|
const subChildren = [];
|
||||||
|
if (item.workspacePath || item.workspaceName) {
|
||||||
|
subChildren.push(
|
||||||
|
h('span', {
|
||||||
|
className: 'smig-item-ws',
|
||||||
|
text: item.workspacePath || item.workspaceName,
|
||||||
|
title: item.workspacePath || item.workspaceName,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (item.isRunning) {
|
||||||
|
subChildren.push(
|
||||||
|
h('span', {
|
||||||
|
className: 'smig-item-running',
|
||||||
|
text: t('settings.oth.migRunningTag'),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rowEl = h(
|
||||||
|
'div',
|
||||||
|
{
|
||||||
|
className: `smig-item${checked ? ' is-selected' : ''}${item.isRunning ? ' is-running' : ''}`,
|
||||||
|
role: 'listitem',
|
||||||
|
onClick: (ev) => {
|
||||||
|
if (ev?.target === checkboxEl) return;
|
||||||
|
toggleItem();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[
|
||||||
|
checkboxEl,
|
||||||
|
h('div', { className: 'smig-item-body' }, [
|
||||||
|
h('div', { className: 'smig-item-top' }, [
|
||||||
|
h('span', {
|
||||||
|
className: 'smig-item-title',
|
||||||
|
text: item.title || item.cascadeId.slice(0, 8),
|
||||||
|
title: item.title || item.cascadeId,
|
||||||
|
}),
|
||||||
|
h('span', { className: 'smig-item-meta', text: metaParts.join(' · ') }),
|
||||||
|
]),
|
||||||
|
...(subChildren.length > 0
|
||||||
|
? [h('div', { className: 'smig-item-sub' }, subChildren)]
|
||||||
|
: []),
|
||||||
|
]),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
listEl.appendChild(rowEl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
patchAttr(migrateBtn, 'disabled', isMigrating || selectedIds.size === 0 || !targetClient);
|
||||||
|
patchText(
|
||||||
|
migrateBtnText,
|
||||||
|
isMigrating
|
||||||
|
? t('settings.oth.migRunningBtn')
|
||||||
|
: t('settings.oth.migActionBtn', { count: selectedIds.size })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderResultBox() {
|
||||||
|
if (!lastResult) {
|
||||||
|
patchAttr(resultBoxEl, 'hidden', true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
patchAttr(resultBoxEl, 'hidden', false);
|
||||||
|
patchClasses(resultBoxEl, {
|
||||||
|
'is-ok': Boolean(lastResult.ok),
|
||||||
|
'is-err': !lastResult.ok,
|
||||||
|
});
|
||||||
|
|
||||||
|
while (resultBoxEl.firstChild) {
|
||||||
|
resultBoxEl.removeChild(resultBoxEl.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lastResult.ok) {
|
||||||
|
resultBoxEl.appendChild(
|
||||||
|
h('div', {
|
||||||
|
className: 'smig-result-msg',
|
||||||
|
text: formatMigrationError(lastResult.error),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const partialSuffix =
|
||||||
|
lastResult.failedCount > 0
|
||||||
|
? t('settings.oth.migPartialWarn', { failed: lastResult.failedCount })
|
||||||
|
: '';
|
||||||
|
const baseMsg =
|
||||||
|
lastResult.targetClient === 'cli'
|
||||||
|
? t('settings.oth.migDoneCli', { count: lastResult.migratedCount })
|
||||||
|
: t('settings.oth.migDoneDesktop', {
|
||||||
|
count: lastResult.migratedCount,
|
||||||
|
project: resolveProjectDisplayLabel(lastResult.targetProjectId),
|
||||||
|
});
|
||||||
|
|
||||||
|
resultBoxEl.appendChild(
|
||||||
|
h('div', { className: 'smig-result-msg', text: `${baseMsg}${partialSuffix}` })
|
||||||
|
);
|
||||||
|
|
||||||
|
if (lastResult.targetClient === 'desktop' && isWindowOverlayMode()) {
|
||||||
|
resultBoxEl.appendChild(
|
||||||
|
h('div', { className: 'smig-result-actions' }, [
|
||||||
|
h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
className: 'btn-secondary smig-result-btn',
|
||||||
|
onClick: () => {
|
||||||
|
if (typeof window !== 'undefined' && typeof window.location?.reload === 'function') {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[createSvgIcon('refresh', { size: 11 }), h('span', { text: t('settings.oth.migReloadBtn') })]
|
||||||
|
),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastResult.targetClient === 'cli') {
|
||||||
|
const okItems = (lastResult.results || []).filter((r) => r.ok && r.resumeCommand);
|
||||||
|
if (okItems.length > 0) {
|
||||||
|
const cmdWrap = h('div', { className: 'smig-cmd-list' });
|
||||||
|
for (const item of okItems.slice(0, 6)) {
|
||||||
|
const isCopied = copiedCmdId === item.newCascadeId;
|
||||||
|
const copyBtn = h(
|
||||||
|
'button',
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
className: 'btn-ghost-sm smig-cmd-copy',
|
||||||
|
text: isCopied ? t('settings.oth.migCopied') : t('settings.oth.migCopyCmd'),
|
||||||
|
onClick: async () => {
|
||||||
|
const ok = await smigCopyText(item.resumeCommand);
|
||||||
|
if (!ok || destroyed) return;
|
||||||
|
copiedCmdId = item.newCascadeId;
|
||||||
|
renderResultBox();
|
||||||
|
if (copiedTimer) clearTimeout(copiedTimer);
|
||||||
|
copiedTimer = setTimeout(() => {
|
||||||
|
copiedTimer = null;
|
||||||
|
if (!destroyed && copiedCmdId === item.newCascadeId) {
|
||||||
|
copiedCmdId = '';
|
||||||
|
renderResultBox();
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
cmdWrap.appendChild(
|
||||||
|
h('div', { className: 'smig-cmd-row' }, [
|
||||||
|
h('code', { className: 'smig-cmd-code', text: item.resumeCommand }),
|
||||||
|
copyBtn,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
resultBoxEl.appendChild(cmdWrap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadCatalog(force = false) {
|
||||||
|
if (isLoading || (hasLoadedOnce && !force)) return;
|
||||||
|
isLoading = true;
|
||||||
|
if (refreshBtn) patchAttr(refreshBtn, 'disabled', true);
|
||||||
|
try {
|
||||||
|
const res = await loadCatalogFn();
|
||||||
|
if (destroyed) return;
|
||||||
|
hasLoadedOnce = true;
|
||||||
|
if (res && typeof res === 'object') {
|
||||||
|
catalog = res;
|
||||||
|
ensureValidSelectionDefaults();
|
||||||
|
syncControlsAndList();
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// 本地目录或 API 暂不可用时静默隐藏卡片,避免干扰其他设置项
|
||||||
|
if (!destroyed && !catalog) {
|
||||||
|
patchAttr(rootEl, 'hidden', true);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
isLoading = false;
|
||||||
|
if (refreshBtn) patchAttr(refreshBtn, 'disabled', false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleMigrate() {
|
||||||
|
if (isMigrating || selectedIds.size === 0 || !sourceClient || !targetClient) return;
|
||||||
|
isMigrating = true;
|
||||||
|
lastResult = null;
|
||||||
|
renderSessionList();
|
||||||
|
renderResultBox();
|
||||||
|
try {
|
||||||
|
const payload = {
|
||||||
|
sourceClient,
|
||||||
|
targetClient,
|
||||||
|
mode: migrationMode,
|
||||||
|
cascadeIds: [...selectedIds],
|
||||||
|
...(targetClient === 'desktop' ? { targetProjectId } : {}),
|
||||||
|
};
|
||||||
|
const res = await runMigrateFn(payload);
|
||||||
|
if (destroyed) return;
|
||||||
|
lastResult = res || { ok: false, error: 'empty_response' };
|
||||||
|
if (res?.ok) {
|
||||||
|
selectedIds.clear();
|
||||||
|
void loadCatalog(true);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (!destroyed) {
|
||||||
|
lastResult = { ok: false, error: err?.message || 'request_failed' };
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
isMigrating = false;
|
||||||
|
if (!destroyed) {
|
||||||
|
renderSessionList();
|
||||||
|
renderResultBox();
|
||||||
|
props?.onLayoutChange?.();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshLabels() {
|
||||||
|
if (!bodyMounted) return;
|
||||||
|
patchText(titleEl, t('settings.oth.migTitle'));
|
||||||
|
patchText(descEl, t('settings.oth.migDesc'));
|
||||||
|
patchText(refreshBtnText, t('settings.oth.migRefreshBtn'));
|
||||||
|
patchText(sourceLabelEl, t('settings.oth.migSourceLabel'));
|
||||||
|
patchText(targetLabelEl, t('settings.oth.migTargetLabel'));
|
||||||
|
patchText(modeLabelEl, t('settings.oth.migModeLabel'));
|
||||||
|
patchText(modeMoveBtn, t('settings.oth.migModeMove'));
|
||||||
|
patchText(modeCloneBtn, t('settings.oth.migModeClone'));
|
||||||
|
syncModeControls();
|
||||||
|
patchText(projectLabelEl, t('settings.oth.migProjectLabel'));
|
||||||
|
patchAttr(searchInput, 'placeholder', t('settings.oth.migSearchPlaceholder'));
|
||||||
|
if (catalog?.available) {
|
||||||
|
syncControlsAndList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
destroyed = true;
|
||||||
|
if (copiedTimer) {
|
||||||
|
clearTimeout(copiedTimer);
|
||||||
|
copiedTimer = null;
|
||||||
|
}
|
||||||
|
sourceSelect?.destroy?.();
|
||||||
|
targetSelect?.destroy?.();
|
||||||
|
projectSelect?.destroy?.();
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
el: rootEl,
|
||||||
|
refs: {
|
||||||
|
ensureLoaded: () => loadCatalog(false),
|
||||||
|
reload: () => loadCatalog(true),
|
||||||
|
refreshLabels,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -659,6 +659,41 @@ export const I18N_MESSAGES_EN_US = Object.freeze({
|
|||||||
'settings.oth.exportDone': 'Preferences JSON exported',
|
'settings.oth.exportDone': 'Preferences JSON exported',
|
||||||
'settings.oth.importDone': 'Restored {count} preference settings',
|
'settings.oth.importDone': 'Restored {count} preference settings',
|
||||||
'settings.oth.importInvalid': 'Import failed: invalid JSON or no recognized settings',
|
'settings.oth.importInvalid': 'Import failed: invalid JSON or no recognized settings',
|
||||||
|
'settings.oth.migTitle': 'Cross-Client Session Migration',
|
||||||
|
'settings.oth.migDesc': 'Migrate selected sessions on demand with automatic source and summary backups',
|
||||||
|
'settings.oth.migRefreshBtn': 'Refresh',
|
||||||
|
'settings.oth.migSourceLabel': 'Source Client',
|
||||||
|
'settings.oth.migTargetLabel': 'Target Client',
|
||||||
|
'settings.oth.migModeLabel': 'Migration Mode',
|
||||||
|
'settings.oth.migModeMove': 'Full Move (Recommended)',
|
||||||
|
'settings.oth.migModeClone': 'Clone Copy',
|
||||||
|
'settings.oth.migModeMoveHint': 'Preserves original ID and full historical steps/details; archives source backup before moving',
|
||||||
|
'settings.oth.migModeCloneHint': 'Keeps source intact with a fresh UUID; only counts new steps generated after cloning',
|
||||||
|
'settings.oth.migProjectLabel': 'Target Project',
|
||||||
|
'settings.oth.migProjectOutside': 'Standalone (No Project)',
|
||||||
|
'settings.oth.migClientDesktop': 'Desktop App / Modern IDE',
|
||||||
|
'settings.oth.migClientCli': 'Antigravity CLI',
|
||||||
|
'settings.oth.migClientIdeLegacy': 'Legacy IDE (.db)',
|
||||||
|
'settings.oth.migSearchPlaceholder': 'Filter sessions by title or workspace…',
|
||||||
|
'settings.oth.migSelectAll': 'Select all',
|
||||||
|
'settings.oth.migClearSel': 'Clear',
|
||||||
|
'settings.oth.migSelectedCount': '{selected} / {total} selected',
|
||||||
|
'settings.oth.migRunningTag': 'Running',
|
||||||
|
'settings.oth.migStepsUnit': '{count} steps',
|
||||||
|
'settings.oth.migEmpty': 'No migratable sessions in this source client',
|
||||||
|
'settings.oth.migNoMatch': 'No matching sessions',
|
||||||
|
'settings.oth.migActionBtn': 'Migrate Selected ({count})',
|
||||||
|
'settings.oth.migRunningBtn': 'Migrating…',
|
||||||
|
'settings.oth.migDoneDesktop': 'Migrated {count} session(s) to "{project}". Press Ctrl+R in Desktop App to refresh the sidebar',
|
||||||
|
'settings.oth.migDoneCli': 'Migrated {count} session(s) to CLI. Use the command below to resume',
|
||||||
|
'settings.oth.migPartialWarn': ' ({failed} skipped or failed)',
|
||||||
|
'settings.oth.migReloadBtn': 'Reload Window',
|
||||||
|
'settings.oth.migCopyCmd': 'Copy',
|
||||||
|
'settings.oth.migCopied': 'Copied',
|
||||||
|
'settings.oth.migErrLocked': 'Source database is locked by its open client. Close that terminal/window first, or switch to Clone Copy',
|
||||||
|
'settings.oth.migErrExists': 'A session with the same ID already exists in target (switch to Clone Copy if you want a duplicate)',
|
||||||
|
'settings.oth.migErrRunning': 'Session is currently running; wait until idle before migrating',
|
||||||
|
'settings.oth.migFailed': 'Migration failed: {reason}',
|
||||||
|
|
||||||
// Structured Live Activity Actions
|
// Structured Live Activity Actions
|
||||||
'live.act.run_command': 'Run Command',
|
'live.act.run_command': 'Run Command',
|
||||||
|
|||||||
@@ -659,6 +659,41 @@ export const I18N_MESSAGES_ZH_CN = Object.freeze({
|
|||||||
'settings.oth.exportDone': '配置 JSON 已导出',
|
'settings.oth.exportDone': '配置 JSON 已导出',
|
||||||
'settings.oth.importDone': '已恢复 {count} 项偏好设置',
|
'settings.oth.importDone': '已恢复 {count} 项偏好设置',
|
||||||
'settings.oth.importInvalid': '导入失败:JSON 无效或未包含可识别的偏好项',
|
'settings.oth.importInvalid': '导入失败:JSON 无效或未包含可识别的偏好项',
|
||||||
|
'settings.oth.migTitle': '跨端会话迁移',
|
||||||
|
'settings.oth.migDesc': '按需把选定会话迁往另一端,迁移前自动备份摘要库和源库',
|
||||||
|
'settings.oth.migRefreshBtn': '刷新列表',
|
||||||
|
'settings.oth.migSourceLabel': '来源端',
|
||||||
|
'settings.oth.migTargetLabel': '目标端',
|
||||||
|
'settings.oth.migModeLabel': '迁移方式',
|
||||||
|
'settings.oth.migModeMove': '完整迁移(推荐)',
|
||||||
|
'settings.oth.migModeClone': '克隆副本',
|
||||||
|
'settings.oth.migModeMoveHint': '保留原 ID 和全部历史步序明细,备份后移出源端(零重复计费)',
|
||||||
|
'settings.oth.migModeCloneHint': '保留源会话并生成新 ID,新副本仅统计迁入后的新步骤',
|
||||||
|
'settings.oth.migProjectLabel': '绑定目标项目',
|
||||||
|
'settings.oth.migProjectOutside': '独立会话(无所属项目)',
|
||||||
|
'settings.oth.migClientDesktop': '桌面端 App / 新版 IDE',
|
||||||
|
'settings.oth.migClientCli': 'Antigravity CLI',
|
||||||
|
'settings.oth.migClientIdeLegacy': '旧版 IDE (.db)',
|
||||||
|
'settings.oth.migSearchPlaceholder': '按标题或工作区筛选会话…',
|
||||||
|
'settings.oth.migSelectAll': '全选',
|
||||||
|
'settings.oth.migClearSel': '清空',
|
||||||
|
'settings.oth.migSelectedCount': '已选 {selected} / {total}',
|
||||||
|
'settings.oth.migRunningTag': '运行中',
|
||||||
|
'settings.oth.migStepsUnit': '{count} 步',
|
||||||
|
'settings.oth.migEmpty': '当前来源端暂无可迁移会话',
|
||||||
|
'settings.oth.migNoMatch': '没有匹配的会话',
|
||||||
|
'settings.oth.migActionBtn': '迁移选定会话 ({count})',
|
||||||
|
'settings.oth.migRunningBtn': '迁移中…',
|
||||||
|
'settings.oth.migDoneDesktop': '已成功迁移 {count} 条会话到「{project}」,在桌面端按 Ctrl+R 即可在左侧看到',
|
||||||
|
'settings.oth.migDoneCli': '已成功迁移 {count} 条会话到 CLI,可使用下方命令恢复对话',
|
||||||
|
'settings.oth.migPartialWarn': '(另有 {failed} 条跳过或失败)',
|
||||||
|
'settings.oth.migReloadBtn': '刷新窗口',
|
||||||
|
'settings.oth.migCopyCmd': '复制命令',
|
||||||
|
'settings.oth.migCopied': '已复制',
|
||||||
|
'settings.oth.migErrLocked': '源会话文件正被原端占用,请先关闭对应终端/窗口后重试,或切换为「克隆副本」',
|
||||||
|
'settings.oth.migErrExists': '目标端已存在同 ID 会话,无需重复移动(可切换为「克隆副本」)',
|
||||||
|
'settings.oth.migErrRunning': '该会话正在运行中,请待空闲后再迁移',
|
||||||
|
'settings.oth.migFailed': '迁移失败:{reason}',
|
||||||
|
|
||||||
// Structured Live Activity Actions
|
// Structured Live Activity Actions
|
||||||
'live.act.run_command': '执行命令',
|
'live.act.run_command': '执行命令',
|
||||||
|
|||||||
@@ -1997,6 +1997,36 @@ export async function triggerCliStatusLineAction(action) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchSessionMigrationCatalog() {
|
||||||
|
try {
|
||||||
|
return await callSidecarApi('/api/session-migration/catalog', { method: 'GET' });
|
||||||
|
} catch {
|
||||||
|
return callSidecarApi('/api/settings', {
|
||||||
|
method: 'POST',
|
||||||
|
body: { __sessionMigrationAction: 'catalog' },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function executeSessionMigration(payload) {
|
||||||
|
let res;
|
||||||
|
try {
|
||||||
|
res = await callSidecarApi('/api/session-migration/migrate', {
|
||||||
|
method: 'POST',
|
||||||
|
body: payload || {},
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
res = await callSidecarApi('/api/settings', {
|
||||||
|
method: 'POST',
|
||||||
|
body: { __sessionMigrationAction: 'migrate', payload: payload || {} },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (res?.migratedCount > 0) {
|
||||||
|
void fetchTelemetry({ force: true }).catch(() => {});
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
export async function triggerPluginUpdate() {
|
export async function triggerPluginUpdate() {
|
||||||
const res = await callSidecarApi('/api/plugin-update', { method: 'POST', body: {} });
|
const res = await callSidecarApi('/api/plugin-update', { method: 'POST', body: {} });
|
||||||
if (res?.ok && res?.restarting) {
|
if (res?.ok && res?.restarting) {
|
||||||
|
|||||||
@@ -996,6 +996,334 @@
|
|||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --- 其他页:跨端会话按需迁移卡片 (.smig-panel) --- */
|
||||||
|
.smig-panel[hidden] {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-desc {
|
||||||
|
margin: 0 0 var(--space-3);
|
||||||
|
font-size: var(--fs-sm);
|
||||||
|
line-height: 1.48;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-refresh-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-direction-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: var(--space-2);
|
||||||
|
margin-bottom: var(--space-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-field {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
min-width: 0;
|
||||||
|
margin-bottom: var(--space-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-direction-grid .smig-field {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-field[hidden] {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-field-label {
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-mode-bar {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-mode-btn {
|
||||||
|
min-height: calc(26px * var(--ui-font-scale, 1));
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: var(--radius-xs);
|
||||||
|
border: 1px solid var(--border-hairline);
|
||||||
|
background: var(--surface-subtle);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
transition:
|
||||||
|
border-color var(--dur-instant) var(--ease-fast),
|
||||||
|
background-color var(--dur-instant) var(--ease-fast),
|
||||||
|
color var(--dur-instant) var(--ease-fast);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-mode-btn:hover {
|
||||||
|
border-color: var(--border-default);
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-mode-btn.is-active {
|
||||||
|
border-color: var(--accent-primary-border);
|
||||||
|
background: var(--accent-primary-soft);
|
||||||
|
color: var(--accent-primary);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-mode-hint {
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
line-height: 1.4;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-project-select .select-option-meta {
|
||||||
|
max-width: 58%;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-toolbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-2);
|
||||||
|
margin-bottom: var(--space-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-search-input {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-toggle-all-btn {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-count-meta {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
max-height: 220px;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 6px;
|
||||||
|
border-radius: var(--radius-xs);
|
||||||
|
border: 1px solid var(--border-hairline);
|
||||||
|
background: var(--surface-subtle);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-empty {
|
||||||
|
padding: var(--space-4) var(--space-2);
|
||||||
|
text-align: center;
|
||||||
|
font-size: var(--fs-sm);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 6px 8px;
|
||||||
|
border-radius: var(--radius-xs);
|
||||||
|
border: 1px solid transparent;
|
||||||
|
background: var(--surface-panel);
|
||||||
|
cursor: pointer;
|
||||||
|
transition:
|
||||||
|
border-color var(--dur-instant) var(--ease-fast),
|
||||||
|
background-color var(--dur-instant) var(--ease-fast);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item:hover:not(.is-running) {
|
||||||
|
border-color: var(--border-default);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item.is-selected {
|
||||||
|
border-color: var(--accent-primary-border);
|
||||||
|
background: var(--accent-primary-soft);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item.is-running {
|
||||||
|
opacity: 0.62;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-checkbox {
|
||||||
|
margin-top: 2px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
accent-color: var(--accent-primary);
|
||||||
|
cursor: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-top {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 8px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-title {
|
||||||
|
font-size: var(--fs-sm);
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text-primary);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-meta {
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
white-space: nowrap;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-sub {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 6px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-ws {
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
|
||||||
|
color: var(--text-muted);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-running {
|
||||||
|
flex-shrink: 0;
|
||||||
|
padding: 0 5px;
|
||||||
|
border-radius: var(--radius-xs);
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--metric-warn);
|
||||||
|
background: color-mix(in srgb, var(--metric-warn) 14%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-footer {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: var(--space-2);
|
||||||
|
margin-top: var(--space-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-migrate-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result {
|
||||||
|
margin-top: var(--space-2);
|
||||||
|
padding: var(--space-2) var(--space-3);
|
||||||
|
border-radius: var(--radius-xs);
|
||||||
|
border: 1px solid var(--border-hairline);
|
||||||
|
background: var(--surface-subtle);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result[hidden] {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result.is-ok {
|
||||||
|
border-color: color-mix(in srgb, var(--metric-good) 42%, var(--border-hairline));
|
||||||
|
background: color-mix(in srgb, var(--surface-panel) 90%, var(--metric-good) 7%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result.is-err {
|
||||||
|
border-color: color-mix(in srgb, var(--metric-danger) 42%, var(--border-hairline));
|
||||||
|
background: color-mix(in srgb, var(--surface-panel) 90%, var(--metric-danger) 7%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result-msg {
|
||||||
|
font-size: var(--fs-sm);
|
||||||
|
line-height: 1.45;
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result-actions {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-cmd-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-cmd-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 4px 6px;
|
||||||
|
border-radius: var(--radius-xs);
|
||||||
|
background: var(--surface-panel);
|
||||||
|
border: 1px solid var(--border-hairline);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-cmd-code {
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
|
||||||
|
color: var(--text-primary);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-cmd-copy {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
}
|
||||||
|
|
||||||
/* --- Antigravity CLI 底部状态胶囊专属配置块(仅检测到 CLI 时展示) --- */
|
/* --- Antigravity CLI 底部状态胶囊专属配置块(仅检测到 CLI 时展示) --- */
|
||||||
.cli-statusline-group {
|
.cli-statusline-group {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
} from '../../store/telemetryStore.js';
|
} from '../../store/telemetryStore.js';
|
||||||
import { CustomSelect } from '../../components/ui/CustomSelect.js';
|
import { CustomSelect } from '../../components/ui/CustomSelect.js';
|
||||||
import { BridgeStatusNotice } from '../../components/settings/BridgeStatusNotice.js';
|
import { BridgeStatusNotice } from '../../components/settings/BridgeStatusNotice.js';
|
||||||
|
import { SessionMigrationCard } from '../../components/settings/SessionMigrationCard.js';
|
||||||
|
|
||||||
function getStepModelDisplayOptions() {
|
function getStepModelDisplayOptions() {
|
||||||
return [
|
return [
|
||||||
@@ -597,10 +598,17 @@ export const SettingsOtherTab = defineComponent({
|
|||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const sessionMigrationCard = SessionMigrationCard({
|
||||||
|
onLayoutChange: () => {
|
||||||
|
getProps()?.onLayoutChange?.();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const rootEl = h('div', { className: 'settings-tab-stack' }, [
|
const rootEl = h('div', { className: 'settings-tab-stack' }, [
|
||||||
modelPanel,
|
modelPanel,
|
||||||
baselinePanel,
|
baselinePanel,
|
||||||
maintPanel,
|
maintPanel,
|
||||||
|
sessionMigrationCard.el,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function renderSettings(
|
function renderSettings(
|
||||||
@@ -631,6 +639,7 @@ export const SettingsOtherTab = defineComponent({
|
|||||||
options: getOrchestratorIdDisplayOptions(),
|
options: getOrchestratorIdDisplayOptions(),
|
||||||
});
|
});
|
||||||
renderContextWindows();
|
renderContextWindows();
|
||||||
|
void sessionMigrationCard.refs.ensureLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshLabels() {
|
function refreshLabels() {
|
||||||
@@ -667,6 +676,7 @@ export const SettingsOtherTab = defineComponent({
|
|||||||
modelValue: draftOrchestratorIdMode,
|
modelValue: draftOrchestratorIdMode,
|
||||||
options: getOrchestratorIdDisplayOptions(),
|
options: getOrchestratorIdDisplayOptions(),
|
||||||
});
|
});
|
||||||
|
sessionMigrationCard.refs.refreshLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
onCleanup(() => {
|
onCleanup(() => {
|
||||||
@@ -678,6 +688,7 @@ export const SettingsOtherTab = defineComponent({
|
|||||||
ctxBridgeNotice.destroy();
|
ctxBridgeNotice.destroy();
|
||||||
ctxModelSelect.destroy();
|
ctxModelSelect.destroy();
|
||||||
ctxWindowSelect.destroy();
|
ctxWindowSelect.destroy();
|
||||||
|
sessionMigrationCard.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -688,6 +699,7 @@ export const SettingsOtherTab = defineComponent({
|
|||||||
ctxBridgeNotice,
|
ctxBridgeNotice,
|
||||||
ctxModelSelect,
|
ctxModelSelect,
|
||||||
ctxWindowSelect,
|
ctxWindowSelect,
|
||||||
|
sessionMigrationCard,
|
||||||
rebuildCacheBtn,
|
rebuildCacheBtn,
|
||||||
resetAllBtn,
|
resetAllBtn,
|
||||||
exportJsonBtn,
|
exportJsonBtn,
|
||||||
|
|||||||
@@ -5704,6 +5704,334 @@ html[data-standalone="true"] .app-shell {
|
|||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --- 其他页:跨端会话按需迁移卡片 (.smig-panel) --- */
|
||||||
|
.smig-panel[hidden] {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-desc {
|
||||||
|
margin: 0 0 var(--space-3);
|
||||||
|
font-size: var(--fs-sm);
|
||||||
|
line-height: 1.48;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-refresh-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-direction-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: var(--space-2);
|
||||||
|
margin-bottom: var(--space-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-field {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
min-width: 0;
|
||||||
|
margin-bottom: var(--space-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-direction-grid .smig-field {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-field[hidden] {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-field-label {
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-mode-bar {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-mode-btn {
|
||||||
|
min-height: calc(26px * var(--ui-font-scale, 1));
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: var(--radius-xs);
|
||||||
|
border: 1px solid var(--border-hairline);
|
||||||
|
background: var(--surface-subtle);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
transition:
|
||||||
|
border-color var(--dur-instant) var(--ease-fast),
|
||||||
|
background-color var(--dur-instant) var(--ease-fast),
|
||||||
|
color var(--dur-instant) var(--ease-fast);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-mode-btn:hover {
|
||||||
|
border-color: var(--border-default);
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-mode-btn.is-active {
|
||||||
|
border-color: var(--accent-primary-border);
|
||||||
|
background: var(--accent-primary-soft);
|
||||||
|
color: var(--accent-primary);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-mode-hint {
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
line-height: 1.4;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-project-select .select-option-meta {
|
||||||
|
max-width: 58%;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-toolbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-2);
|
||||||
|
margin-bottom: var(--space-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-search-input {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-toggle-all-btn {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-count-meta {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
max-height: 220px;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 6px;
|
||||||
|
border-radius: var(--radius-xs);
|
||||||
|
border: 1px solid var(--border-hairline);
|
||||||
|
background: var(--surface-subtle);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-empty {
|
||||||
|
padding: var(--space-4) var(--space-2);
|
||||||
|
text-align: center;
|
||||||
|
font-size: var(--fs-sm);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 6px 8px;
|
||||||
|
border-radius: var(--radius-xs);
|
||||||
|
border: 1px solid transparent;
|
||||||
|
background: var(--surface-panel);
|
||||||
|
cursor: pointer;
|
||||||
|
transition:
|
||||||
|
border-color var(--dur-instant) var(--ease-fast),
|
||||||
|
background-color var(--dur-instant) var(--ease-fast);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item:hover:not(.is-running) {
|
||||||
|
border-color: var(--border-default);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item.is-selected {
|
||||||
|
border-color: var(--accent-primary-border);
|
||||||
|
background: var(--accent-primary-soft);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item.is-running {
|
||||||
|
opacity: 0.62;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-checkbox {
|
||||||
|
margin-top: 2px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
accent-color: var(--accent-primary);
|
||||||
|
cursor: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-top {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 8px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-title {
|
||||||
|
font-size: var(--fs-sm);
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text-primary);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-meta {
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
white-space: nowrap;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-sub {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 6px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-ws {
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
|
||||||
|
color: var(--text-muted);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-item-running {
|
||||||
|
flex-shrink: 0;
|
||||||
|
padding: 0 5px;
|
||||||
|
border-radius: var(--radius-xs);
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--metric-warn);
|
||||||
|
background: color-mix(in srgb, var(--metric-warn) 14%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-footer {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: var(--space-2);
|
||||||
|
margin-top: var(--space-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-migrate-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result {
|
||||||
|
margin-top: var(--space-2);
|
||||||
|
padding: var(--space-2) var(--space-3);
|
||||||
|
border-radius: var(--radius-xs);
|
||||||
|
border: 1px solid var(--border-hairline);
|
||||||
|
background: var(--surface-subtle);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result[hidden] {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result.is-ok {
|
||||||
|
border-color: color-mix(in srgb, var(--metric-good) 42%, var(--border-hairline));
|
||||||
|
background: color-mix(in srgb, var(--surface-panel) 90%, var(--metric-good) 7%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result.is-err {
|
||||||
|
border-color: color-mix(in srgb, var(--metric-danger) 42%, var(--border-hairline));
|
||||||
|
background: color-mix(in srgb, var(--surface-panel) 90%, var(--metric-danger) 7%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result-msg {
|
||||||
|
font-size: var(--fs-sm);
|
||||||
|
line-height: 1.45;
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result-actions {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-result-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-cmd-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-cmd-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 4px 6px;
|
||||||
|
border-radius: var(--radius-xs);
|
||||||
|
background: var(--surface-panel);
|
||||||
|
border: 1px solid var(--border-hairline);
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-cmd-code {
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
|
||||||
|
color: var(--text-primary);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smig-cmd-copy {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
}
|
||||||
|
|
||||||
/* --- Antigravity CLI 底部状态胶囊专属配置块(仅检测到 CLI 时展示) --- */
|
/* --- Antigravity CLI 底部状态胶囊专属配置块(仅检测到 CLI 时展示) --- */
|
||||||
.cli-statusline-group {
|
.cli-statusline-group {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const BACKEND_MODULE_FILES = [
|
|||||||
'../backend/proto-wire.mjs',
|
'../backend/proto-wire.mjs',
|
||||||
'../backend/cli-sqlite-reader.mjs',
|
'../backend/cli-sqlite-reader.mjs',
|
||||||
'../backend/cli-statusline-config.mjs',
|
'../backend/cli-statusline-config.mjs',
|
||||||
|
'../backend/session-migrator.mjs',
|
||||||
'../backend/ls-discovery.mjs',
|
'../backend/ls-discovery.mjs',
|
||||||
'../backend/pricing-catalog.mjs',
|
'../backend/pricing-catalog.mjs',
|
||||||
'../backend/plugin-updater.mjs',
|
'../backend/plugin-updater.mjs',
|
||||||
|
|||||||
@@ -1126,8 +1126,10 @@ test('P1 audit fixes: shared third-party pool & route single-source, pure frozen
|
|||||||
|
|
||||||
assert.equal(normalizeI18nLanguage('system'), 'auto');
|
assert.equal(normalizeI18nLanguage('system'), 'auto');
|
||||||
assert.equal(typeof isEquivalentTelemetry, 'function');
|
assert.equal(typeof isEquivalentTelemetry, 'function');
|
||||||
assert.equal(BRIDGE_API_ROUTE_DEFS.length, 10);
|
assert.equal(BRIDGE_API_ROUTE_DEFS.length, 12);
|
||||||
assert.ok(BRIDGE_API_ROUTE_DEFS.some((r) => r.path === '/api/bridge/relaunch'));
|
assert.ok(BRIDGE_API_ROUTE_DEFS.some((r) => r.path === '/api/bridge/relaunch'));
|
||||||
|
assert.ok(BRIDGE_API_ROUTE_DEFS.some((r) => r.path === '/api/session-migration/catalog'));
|
||||||
|
assert.ok(BRIDGE_API_ROUTE_DEFS.some((r) => r.path === '/api/session-migration/migrate'));
|
||||||
|
|
||||||
// 1. Third-party pool parity across backend, CLI statusline, and frontend metricRegistry
|
// 1. Third-party pool parity across backend, CLI statusline, and frontend metricRegistry
|
||||||
const h = backendHarness();
|
const h = backendHarness();
|
||||||
|
|||||||
@@ -0,0 +1,655 @@
|
|||||||
|
import test from 'node:test';
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||||
|
import { join } from 'node:path';
|
||||||
|
import { tmpdir } from 'node:os';
|
||||||
|
import { DatabaseSync } from 'node:sqlite';
|
||||||
|
import {
|
||||||
|
encodeProtoBytesField,
|
||||||
|
encodeProtoStringField,
|
||||||
|
encodeProtoTimestamp,
|
||||||
|
encodeProtoVarintField,
|
||||||
|
splitProtoRawFields,
|
||||||
|
} from '../backend/proto-wire.mjs';
|
||||||
|
import {
|
||||||
|
getSessionMigrationCatalog,
|
||||||
|
migrateSessions,
|
||||||
|
migratorParseWorkspaceLabel,
|
||||||
|
migratorToDesktopEncodedUri,
|
||||||
|
migratorToRawFileUri,
|
||||||
|
} from '../backend/session-migrator.mjs';
|
||||||
|
import { readLocalSqliteTrajectory } from '../backend/cli-sqlite-reader.mjs';
|
||||||
|
import { createMockDom } from './mock-dom.mjs';
|
||||||
|
|
||||||
|
function initSummaryDb(dbPath) {
|
||||||
|
const db = new DatabaseSync(dbPath);
|
||||||
|
db.exec(`
|
||||||
|
CREATE TABLE conversation_summaries (
|
||||||
|
conversation_id text PRIMARY KEY,
|
||||||
|
title text NOT NULL DEFAULT "",
|
||||||
|
preview text NOT NULL DEFAULT "",
|
||||||
|
step_count integer NOT NULL DEFAULT 0,
|
||||||
|
last_modified_time datetime NOT NULL,
|
||||||
|
workspace_uris text NOT NULL,
|
||||||
|
status text NOT NULL DEFAULT "",
|
||||||
|
source text NOT NULL DEFAULT "",
|
||||||
|
project_id text NOT NULL DEFAULT "",
|
||||||
|
agent_name text NOT NULL DEFAULT "",
|
||||||
|
parent_conversation_id text NOT NULL DEFAULT "",
|
||||||
|
nesting_depth integer NOT NULL DEFAULT 0,
|
||||||
|
battle_id text NOT NULL DEFAULT "",
|
||||||
|
winning_conversation_id text NOT NULL DEFAULT "",
|
||||||
|
not_fully_idle numeric NOT NULL DEFAULT false,
|
||||||
|
killed numeric NOT NULL DEFAULT false,
|
||||||
|
last_user_input_time datetime NOT NULL,
|
||||||
|
last_user_input_step_index integer NOT NULL DEFAULT -1,
|
||||||
|
app_data_dir text NOT NULL DEFAULT "",
|
||||||
|
raw_summary blob,
|
||||||
|
group_id text NOT NULL DEFAULT ""
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createConvDb(dbPath, { cid, tid, source = 17, projectId = 'default-cli-project', wsUri = 'file:///C:/Users/Test', promptText = 'hello from cli', stepCount = 2, preserveTag15 = true }) {
|
||||||
|
const db = new DatabaseSync(dbPath);
|
||||||
|
db.exec(`
|
||||||
|
CREATE TABLE trajectory_meta (
|
||||||
|
trajectory_id text PRIMARY KEY,
|
||||||
|
cascade_id text,
|
||||||
|
trajectory_type integer,
|
||||||
|
source integer
|
||||||
|
);
|
||||||
|
CREATE TABLE steps (
|
||||||
|
idx integer PRIMARY KEY,
|
||||||
|
step_type integer NOT NULL DEFAULT 0,
|
||||||
|
status integer NOT NULL DEFAULT 0,
|
||||||
|
has_subtrajectory numeric NOT NULL DEFAULT false,
|
||||||
|
metadata blob,
|
||||||
|
error_details blob,
|
||||||
|
permissions blob,
|
||||||
|
task_details blob,
|
||||||
|
render_info blob,
|
||||||
|
step_payload blob,
|
||||||
|
step_format integer NOT NULL DEFAULT 0
|
||||||
|
);
|
||||||
|
CREATE TABLE gen_metadata (
|
||||||
|
idx integer PRIMARY KEY,
|
||||||
|
data blob,
|
||||||
|
size integer NOT NULL DEFAULT 0
|
||||||
|
);
|
||||||
|
CREATE TABLE executor_metadata (idx integer PRIMARY KEY, data blob);
|
||||||
|
CREATE TABLE parent_references (idx integer PRIMARY KEY, data blob);
|
||||||
|
CREATE TABLE trajectory_metadata_blob (id text PRIMARY KEY DEFAULT "main", data blob);
|
||||||
|
CREATE TABLE battle_mode_infos (idx integer PRIMARY KEY, data blob);
|
||||||
|
`);
|
||||||
|
|
||||||
|
db.prepare('INSERT INTO trajectory_meta VALUES (?, ?, 4, ?)').run(tid, cid, source);
|
||||||
|
|
||||||
|
const wsSub = Buffer.concat([encodeProtoStringField(1, wsUri), encodeProtoStringField(3, '')]);
|
||||||
|
const metaParts = [
|
||||||
|
encodeProtoBytesField(1, wsSub),
|
||||||
|
encodeProtoBytesField(2, encodeProtoTimestamp(1795000000000)),
|
||||||
|
encodeProtoStringField(6, cid),
|
||||||
|
encodeProtoStringField(7, wsUri),
|
||||||
|
encodeProtoStringField(18, projectId),
|
||||||
|
];
|
||||||
|
if (preserveTag15) {
|
||||||
|
metaParts.push(encodeProtoBytesField(15, Buffer.from([0xde, 0xad, 0xbe, 0xef])));
|
||||||
|
}
|
||||||
|
db.prepare("INSERT INTO trajectory_metadata_blob (id, data) VALUES ('main', ?)").run(
|
||||||
|
Buffer.concat(metaParts)
|
||||||
|
);
|
||||||
|
|
||||||
|
for (let i = 0; i < stepCount; i++) {
|
||||||
|
const isUser = i % 2 === 0;
|
||||||
|
const srcInfo = Buffer.concat([
|
||||||
|
encodeProtoStringField(1, tid),
|
||||||
|
encodeProtoVarintField(2, i),
|
||||||
|
encodeProtoStringField(4, cid),
|
||||||
|
]);
|
||||||
|
const stepMeta = encodeProtoBytesField(20, srcInfo);
|
||||||
|
const stepPayload = isUser
|
||||||
|
? encodeProtoBytesField(19, encodeProtoStringField(2, promptText))
|
||||||
|
: encodeProtoBytesField(20, encodeProtoStringField(1, 'ok reply'));
|
||||||
|
db.prepare(
|
||||||
|
'INSERT INTO steps (idx, step_type, status, metadata, step_payload) VALUES (?, ?, 3, ?, ?)'
|
||||||
|
).run(i, isUser ? 14 : 15, stepMeta, stepPayload);
|
||||||
|
}
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
test('Cross-client session migration clones CLI/Legacy-IDE/Desktop SQLite sessions safely with fork dedup and rolling backups', () => {
|
||||||
|
const tempRoot = mkdtempSync(join(tmpdir(), 'ag-mig-test-'));
|
||||||
|
const geminiDir = join(tempRoot, '.gemini');
|
||||||
|
const backupDir = join(tempRoot, 'backups');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// URI helper checks
|
||||||
|
assert.equal(
|
||||||
|
migratorToRawFileUri('file:///f%3A/ppt/1111/antigravity-usage-monitor'),
|
||||||
|
'file:///f:/ppt/1111/antigravity-usage-monitor'
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
migratorToDesktopEncodedUri('file:///F:/ppt/1111/antigravity-usage-monitor'),
|
||||||
|
'file:///f%3A/ppt/1111/antigravity-usage-monitor'
|
||||||
|
);
|
||||||
|
assert.deepEqual(
|
||||||
|
migratorParseWorkspaceLabel('file:///f%3A/ppt/1111/antigravity-usage-monitor'),
|
||||||
|
{ name: 'antigravity-usage-monitor', displayPath: 'f:/ppt/1111/antigravity-usage-monitor' }
|
||||||
|
);
|
||||||
|
|
||||||
|
// 1. Single client only -> available must be false
|
||||||
|
const deskRoot = join(geminiDir, 'antigravity');
|
||||||
|
mkdirSync(join(deskRoot, 'conversations'), { recursive: true });
|
||||||
|
mkdirSync(join(deskRoot, 'annotations'), { recursive: true });
|
||||||
|
mkdirSync(join(deskRoot, 'brain'), { recursive: true });
|
||||||
|
|
||||||
|
const deskCid = '11111111-1111-4111-8111-111111111111';
|
||||||
|
const deskTid = '11111111-1111-4111-8111-111111111112';
|
||||||
|
const projId = '99a28d35-a873-4c32-b8d1-81a62e23c33d';
|
||||||
|
const projWsEnc = 'file:///f%3A/ppt/1111/antigravity-usage-monitor';
|
||||||
|
|
||||||
|
createConvDb(join(deskRoot, 'conversations', `${deskCid}.db`), {
|
||||||
|
cid: deskCid,
|
||||||
|
tid: deskTid,
|
||||||
|
source: 1,
|
||||||
|
projectId: projId,
|
||||||
|
wsUri: 'file:///f:/ppt/1111/antigravity-usage-monitor',
|
||||||
|
promptText: 'desktop session prompt',
|
||||||
|
stepCount: 4,
|
||||||
|
});
|
||||||
|
writeFileSync(join(deskRoot, 'annotations', `${deskCid}.pbtxt`), 'title:"Desktop Main Chat"\n', 'utf8');
|
||||||
|
|
||||||
|
const deskSum = initSummaryDb(join(deskRoot, 'conversation_summaries.db'));
|
||||||
|
deskSum
|
||||||
|
.prepare(
|
||||||
|
`INSERT INTO conversation_summaries (
|
||||||
|
conversation_id, title, preview, step_count, last_modified_time,
|
||||||
|
workspace_uris, status, source, project_id, last_user_input_time,
|
||||||
|
last_user_input_step_index, app_data_dir, raw_summary
|
||||||
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||||
|
)
|
||||||
|
.run(
|
||||||
|
deskCid,
|
||||||
|
'Desktop Main Chat',
|
||||||
|
'Desktop Main Chat',
|
||||||
|
4,
|
||||||
|
'2026-11-21 10:00:00.000000+00:00',
|
||||||
|
JSON.stringify([projWsEnc]),
|
||||||
|
'CASCADE_RUN_STATUS_IDLE',
|
||||||
|
'',
|
||||||
|
projId,
|
||||||
|
'2026-11-21 09:59:00.000000+00:00',
|
||||||
|
2,
|
||||||
|
'antigravity',
|
||||||
|
Buffer.concat([
|
||||||
|
encodeProtoStringField(1, 'Desktop Main Chat'),
|
||||||
|
encodeProtoVarintField(2, 4),
|
||||||
|
encodeProtoStringField(4, deskTid),
|
||||||
|
encodeProtoVarintField(5, 1),
|
||||||
|
encodeProtoVarintField(22, 4),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
deskSum.close();
|
||||||
|
|
||||||
|
const singleCat = getSessionMigrationCatalog({ geminiDir });
|
||||||
|
assert.equal(singleCat.available, false, 'Single client hides migration feature');
|
||||||
|
|
||||||
|
// 2. Add CLI client (1 idle untitled, 1 running, 1 subagent, 1 empty 0-step) + Legacy IDE client
|
||||||
|
const cliRoot = join(geminiDir, 'antigravity-cli');
|
||||||
|
mkdirSync(join(cliRoot, 'conversations'), { recursive: true });
|
||||||
|
mkdirSync(join(cliRoot, 'annotations'), { recursive: true });
|
||||||
|
mkdirSync(join(cliRoot, 'brain'), { recursive: true });
|
||||||
|
|
||||||
|
const cliIdleCid = '22222222-2222-4222-8222-222222222221';
|
||||||
|
const cliRunCid = '22222222-2222-4222-8222-222222222222';
|
||||||
|
const cliSubCid = '22222222-2222-4222-8222-222222222223';
|
||||||
|
const cliEmptyCid = '22222222-2222-4222-8222-222222222224';
|
||||||
|
|
||||||
|
createConvDb(join(cliRoot, 'conversations', `${cliIdleCid}.db`), {
|
||||||
|
cid: cliIdleCid,
|
||||||
|
tid: 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaa1',
|
||||||
|
source: 17,
|
||||||
|
promptText: '<USER_REQUEST>Fix Braille progress bar width</USER_REQUEST>',
|
||||||
|
stepCount: 6,
|
||||||
|
});
|
||||||
|
mkdirSync(join(cliRoot, 'brain', cliIdleCid, '.user_uploaded'), { recursive: true });
|
||||||
|
writeFileSync(join(cliRoot, 'brain', cliIdleCid, '.user_uploaded', 'shot.png'), 'pngdata', 'utf8');
|
||||||
|
|
||||||
|
createConvDb(join(cliRoot, 'conversations', `${cliRunCid}.db`), {
|
||||||
|
cid: cliRunCid,
|
||||||
|
tid: 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaa2',
|
||||||
|
source: 17,
|
||||||
|
stepCount: 4,
|
||||||
|
});
|
||||||
|
createConvDb(join(cliRoot, 'conversations', `${cliSubCid}.db`), {
|
||||||
|
cid: cliSubCid,
|
||||||
|
tid: 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaa3',
|
||||||
|
source: 17,
|
||||||
|
stepCount: 2,
|
||||||
|
});
|
||||||
|
createConvDb(join(cliRoot, 'conversations', `${cliEmptyCid}.db`), {
|
||||||
|
cid: cliEmptyCid,
|
||||||
|
tid: 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaa4',
|
||||||
|
source: 17,
|
||||||
|
stepCount: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
const cliSum = initSummaryDb(join(cliRoot, 'conversation_summaries.db'));
|
||||||
|
const insertCliSum = cliSum.prepare(
|
||||||
|
`INSERT INTO conversation_summaries (
|
||||||
|
conversation_id, title, preview, step_count, last_modified_time,
|
||||||
|
workspace_uris, status, source, project_id, parent_conversation_id,
|
||||||
|
nesting_depth, not_fully_idle, killed, last_user_input_time,
|
||||||
|
last_user_input_step_index, app_data_dir, raw_summary
|
||||||
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||||
|
);
|
||||||
|
insertCliSum.run(
|
||||||
|
cliIdleCid,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
6,
|
||||||
|
'2026-11-21 12:00:00.000000+00:00',
|
||||||
|
'["file:///C:/Users/Administrator"]',
|
||||||
|
'CASCADE_RUN_STATUS_IDLE',
|
||||||
|
'',
|
||||||
|
'default-cli-project',
|
||||||
|
'',
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
'2026-11-21 11:58:00.000000+00:00',
|
||||||
|
4,
|
||||||
|
'antigravity-cli',
|
||||||
|
Buffer.concat([
|
||||||
|
encodeProtoVarintField(2, 6),
|
||||||
|
encodeProtoStringField(4, 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaa1'),
|
||||||
|
encodeProtoVarintField(5, 1),
|
||||||
|
encodeProtoVarintField(20, 17), // CLI source tag that must be stripped
|
||||||
|
encodeProtoVarintField(22, 4),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
insertCliSum.run(
|
||||||
|
cliRunCid,
|
||||||
|
'Active CLI Task',
|
||||||
|
'Active CLI Task',
|
||||||
|
4,
|
||||||
|
'2026-11-21 12:05:00.000000+00:00',
|
||||||
|
'["file:///C:/Users/Administrator"]',
|
||||||
|
'CASCADE_RUN_STATUS_RUNNING',
|
||||||
|
'',
|
||||||
|
'default-cli-project',
|
||||||
|
'',
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
'2026-11-21 12:04:00.000000+00:00',
|
||||||
|
2,
|
||||||
|
'antigravity-cli',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
insertCliSum.run(
|
||||||
|
cliSubCid,
|
||||||
|
'Subagent Child',
|
||||||
|
'',
|
||||||
|
2,
|
||||||
|
'2026-11-21 11:50:00.000000+00:00',
|
||||||
|
'["file:///C:/Users/Administrator"]',
|
||||||
|
'CASCADE_RUN_STATUS_IDLE',
|
||||||
|
'',
|
||||||
|
'default-cli-project',
|
||||||
|
cliIdleCid,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
'2026-11-21 11:50:00.000000+00:00',
|
||||||
|
0,
|
||||||
|
'antigravity-cli',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
insertCliSum.run(
|
||||||
|
cliEmptyCid,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
0,
|
||||||
|
'0001-01-01 00:00:00+00:00',
|
||||||
|
'["file:///C:/Users/Administrator"]',
|
||||||
|
'CASCADE_RUN_STATUS_IDLE',
|
||||||
|
'',
|
||||||
|
'default-cli-project',
|
||||||
|
'',
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
'0001-01-01 00:00:00+00:00',
|
||||||
|
-1,
|
||||||
|
'antigravity-cli',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
cliSum.close();
|
||||||
|
|
||||||
|
// Legacy IDE (.db without conversation_summaries.db)
|
||||||
|
const legacyRoot = join(geminiDir, 'antigravity-ide');
|
||||||
|
mkdirSync(join(legacyRoot, 'conversations'), { recursive: true });
|
||||||
|
const legacyCid = '33333333-3333-4333-8333-333333333331';
|
||||||
|
createConvDb(join(legacyRoot, 'conversations', `${legacyCid}.db`), {
|
||||||
|
cid: legacyCid,
|
||||||
|
tid: 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbb1',
|
||||||
|
source: 1,
|
||||||
|
projectId: '',
|
||||||
|
wsUri: 'file:///e:/legacy-app',
|
||||||
|
promptText: 'Refactor legacy sidebar',
|
||||||
|
stepCount: 4,
|
||||||
|
});
|
||||||
|
|
||||||
|
const cat = getSessionMigrationCatalog({ geminiDir });
|
||||||
|
assert.equal(cat.available, true, 'Multi-client setup exposes migration catalog');
|
||||||
|
assert.equal(cat.sessionsByClient.cli.length, 2, 'Excludes subagent and 0-step empty CLI sessions');
|
||||||
|
const idleItem = cat.sessionsByClient.cli.find((s) => s.cascadeId === cliIdleCid);
|
||||||
|
const runItem = cat.sessionsByClient.cli.find((s) => s.cascadeId === cliRunCid);
|
||||||
|
assert.equal(idleItem.title, 'Fix Braille progress bar width', 'Falls back to cleaned first user prompt title');
|
||||||
|
assert.equal(idleItem.isRunning, false);
|
||||||
|
assert.equal(runItem.isRunning, true);
|
||||||
|
assert.equal(cat.sessionsByClient.ide_legacy.length, 1);
|
||||||
|
assert.equal(cat.sessionsByClient.ide_legacy[0].title, 'Refactor legacy sidebar');
|
||||||
|
assert.ok(cat.desktopProjects.some((p) => p.projectId === projId && p.name === 'antigravity-usage-monitor'));
|
||||||
|
assert.ok(cat.desktopProjects.some((p) => p.projectId === 'outside-of-project' && p.isOutsideProject));
|
||||||
|
|
||||||
|
// 3. Default FULL MOVE mode: CLI -> Desktop (1 idle + 1 running -> idle moves with original UUID & ALL historical steps!)
|
||||||
|
const migRes = migrateSessions(
|
||||||
|
{
|
||||||
|
sourceClient: 'cli',
|
||||||
|
targetClient: 'desktop',
|
||||||
|
cascadeIds: [cliIdleCid, cliRunCid],
|
||||||
|
targetProjectId: projId,
|
||||||
|
},
|
||||||
|
{ geminiDir, backupDir }
|
||||||
|
);
|
||||||
|
assert.equal(migRes.ok, true);
|
||||||
|
assert.equal(migRes.mode, 'move');
|
||||||
|
assert.equal(migRes.migratedCount, 1);
|
||||||
|
assert.equal(migRes.failedCount, 1);
|
||||||
|
assert.equal(migRes.needsWindowReload, true);
|
||||||
|
assert.ok(migRes.backupPath && existsSync(migRes.backupPath), 'Creates backup before modifying target summary DB');
|
||||||
|
|
||||||
|
const okItem = migRes.results.find((r) => r.ok);
|
||||||
|
const runErr = migRes.results.find((r) => !r.ok);
|
||||||
|
assert.equal(runErr.error, 'session_running');
|
||||||
|
assert.equal(okItem.newCascadeId, cliIdleCid, 'Full move preserves original cascadeId so historical steps stay intact');
|
||||||
|
assert.ok(
|
||||||
|
okItem.archivedSourcePath && existsSync(okItem.archivedSourcePath),
|
||||||
|
'Archives source DB snapshot before removing from source client'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify source CLI .db removed & summary deleted, while brain media remains readable
|
||||||
|
assert.equal(existsSync(join(cliRoot, 'conversations', `${cliIdleCid}.db`)), false);
|
||||||
|
assert.ok(existsSync(join(cliRoot, 'brain', cliIdleCid, '.user_uploaded', 'shot.png')));
|
||||||
|
const checkCliSumDb = new DatabaseSync(join(cliRoot, 'conversation_summaries.db'), { readOnly: true });
|
||||||
|
assert.equal(
|
||||||
|
checkCliSumDb
|
||||||
|
.prepare('SELECT count(*) as c FROM conversation_summaries WHERE conversation_id = ?')
|
||||||
|
.get(cliIdleCid).c,
|
||||||
|
0,
|
||||||
|
'Removes moved session from source client summary DB'
|
||||||
|
);
|
||||||
|
checkCliSumDb.close();
|
||||||
|
|
||||||
|
// Verify moved Desktop artifacts
|
||||||
|
const movedDbPath = join(deskRoot, 'conversations', `${okItem.newCascadeId}.db`);
|
||||||
|
assert.ok(existsSync(movedDbPath));
|
||||||
|
assert.ok(existsSync(join(deskRoot, 'brain', okItem.newCascadeId, '.user_uploaded', 'shot.png')));
|
||||||
|
const annText = readFileSync(join(deskRoot, 'annotations', `${okItem.newCascadeId}.pbtxt`), 'utf8');
|
||||||
|
assert.ok(annText.includes('Fix Braille progress bar width'));
|
||||||
|
|
||||||
|
// Inspect moved DB metadata & unknown field 15 preservation
|
||||||
|
const movedDb = new DatabaseSync(movedDbPath, { readOnly: true });
|
||||||
|
const metaRow = movedDb.prepare('SELECT * FROM trajectory_meta').get();
|
||||||
|
assert.equal(metaRow.cascade_id, cliIdleCid);
|
||||||
|
assert.equal(metaRow.trajectory_id, 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaa1');
|
||||||
|
assert.equal(metaRow.source, 1);
|
||||||
|
const blobRow = movedDb.prepare("SELECT data FROM trajectory_metadata_blob WHERE id = 'main'").get();
|
||||||
|
const blobFields = splitProtoRawFields(blobRow.data);
|
||||||
|
assert.equal(blobFields.find((f) => f.fn === 6)?.payload.toString('utf8'), cliIdleCid);
|
||||||
|
assert.equal(blobFields.find((f) => f.fn === 7)?.payload.toString('utf8'), projWsEnc);
|
||||||
|
assert.equal(blobFields.find((f) => f.fn === 18)?.payload.toString('utf8'), projId);
|
||||||
|
assert.deepEqual(
|
||||||
|
blobFields.find((f) => f.fn === 15)?.payload,
|
||||||
|
Buffer.from([0xde, 0xad, 0xbe, 0xef]),
|
||||||
|
'Preserves unknown protobuf fields byte-for-byte'
|
||||||
|
);
|
||||||
|
movedDb.close();
|
||||||
|
|
||||||
|
// Verify ALL historical steps (#0..#5, including #1/#3/#5 planner responses) are preserved in telemetry!
|
||||||
|
const decodedMoved = readLocalSqliteTrajectory(movedDbPath, { cascadeId: cliIdleCid });
|
||||||
|
assert.ok(decodedMoved, 'Moved session decodes cleanly via cli-sqlite-reader');
|
||||||
|
assert.equal(decodedMoved.numTotalSteps, 6, 'All 6 historical steps (#0..#5) stay intact after full move');
|
||||||
|
assert.deepEqual(
|
||||||
|
decodedMoved.steps.map((s) => s.idx),
|
||||||
|
[0, 1, 2, 3, 4, 5],
|
||||||
|
'Historical step numbering remains continuous without jumping'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify target summary DB row & stripped fn 20 CLI source tag
|
||||||
|
const checkSumDb = new DatabaseSync(join(deskRoot, 'conversation_summaries.db'), { readOnly: true });
|
||||||
|
const sumRow = checkSumDb
|
||||||
|
.prepare('SELECT * FROM conversation_summaries WHERE conversation_id = ?')
|
||||||
|
.get(cliIdleCid);
|
||||||
|
assert.equal(sumRow.project_id, projId);
|
||||||
|
assert.equal(sumRow.source, '');
|
||||||
|
assert.equal(sumRow.app_data_dir, 'antigravity');
|
||||||
|
assert.equal(sumRow.workspace_uris, JSON.stringify([projWsEnc]));
|
||||||
|
const rawSumFields = splitProtoRawFields(sumRow.raw_summary);
|
||||||
|
assert.equal(rawSumFields.some((f) => f.fn === 20), false, 'Strips CLI source enum from raw_summary');
|
||||||
|
checkSumDb.close();
|
||||||
|
|
||||||
|
// 4. Optional CLONE mode: Desktop -> CLI (fresh UUID, source untouched, zero double-billing)
|
||||||
|
const revRes = migrateSessions(
|
||||||
|
{
|
||||||
|
sourceClient: 'desktop',
|
||||||
|
targetClient: 'cli',
|
||||||
|
mode: 'clone',
|
||||||
|
cascadeIds: [deskCid],
|
||||||
|
},
|
||||||
|
{ geminiDir, backupDir }
|
||||||
|
);
|
||||||
|
assert.equal(revRes.ok, true);
|
||||||
|
assert.equal(revRes.mode, 'clone');
|
||||||
|
assert.equal(revRes.needsWindowReload, false);
|
||||||
|
const cliClone = revRes.results[0];
|
||||||
|
assert.notEqual(cliClone.newCascadeId, deskCid, 'Clone mode assigns fresh UUID');
|
||||||
|
assert.ok(existsSync(join(deskRoot, 'conversations', `${deskCid}.db`)), 'Clone mode leaves source untouched');
|
||||||
|
assert.equal(cliClone.resumeCommand, `agy --conversation ${cliClone.newCascadeId}`);
|
||||||
|
const cliCloneDbPath = join(cliRoot, 'conversations', `${cliClone.newCascadeId}.db`);
|
||||||
|
const cliCloneDb = new DatabaseSync(cliCloneDbPath, { readOnly: true });
|
||||||
|
assert.equal(cliCloneDb.prepare('SELECT source FROM trajectory_meta').get().source, 17);
|
||||||
|
cliCloneDb.close();
|
||||||
|
assert.equal(
|
||||||
|
readLocalSqliteTrajectory(cliCloneDbPath, { cascadeId: cliClone.newCascadeId }),
|
||||||
|
null,
|
||||||
|
'Clone mode deduplicates cloned historical steps so global billing never double-counts'
|
||||||
|
);
|
||||||
|
|
||||||
|
// 5. Legacy IDE (no summary DB) -> Desktop App in clone mode synthesizes valid raw_summary
|
||||||
|
const legRes = migrateSessions(
|
||||||
|
{
|
||||||
|
sourceClient: 'ide_legacy',
|
||||||
|
targetClient: 'desktop',
|
||||||
|
mode: 'clone',
|
||||||
|
cascadeIds: [legacyCid],
|
||||||
|
targetProjectId: 'outside-of-project',
|
||||||
|
},
|
||||||
|
{ geminiDir, backupDir }
|
||||||
|
);
|
||||||
|
assert.equal(legRes.ok, true);
|
||||||
|
const legSumDb = new DatabaseSync(join(deskRoot, 'conversation_summaries.db'), { readOnly: true });
|
||||||
|
const legSumRow = legSumDb
|
||||||
|
.prepare('SELECT project_id, title, raw_summary FROM conversation_summaries WHERE conversation_id = ?')
|
||||||
|
.get(legRes.results[0].newCascadeId);
|
||||||
|
assert.equal(legSumRow.project_id, 'outside-of-project');
|
||||||
|
assert.equal(legSumRow.title, 'Refactor legacy sidebar');
|
||||||
|
assert.ok(legSumRow.raw_summary.byteLength > 20);
|
||||||
|
legSumDb.close();
|
||||||
|
|
||||||
|
// 6. Rolling backups stay capped at <= 5
|
||||||
|
for (let k = 0; k < 6; k++) {
|
||||||
|
migrateSessions(
|
||||||
|
{
|
||||||
|
sourceClient: 'ide_legacy',
|
||||||
|
targetClient: 'desktop',
|
||||||
|
mode: 'clone',
|
||||||
|
cascadeIds: [legacyCid],
|
||||||
|
targetProjectId: 'outside-of-project',
|
||||||
|
},
|
||||||
|
{ geminiDir, backupDir }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const deskBackups = readdirSync(backupDir).filter(
|
||||||
|
(n) => n.startsWith('conversation_summaries_desktop_') && n.endsWith('.db')
|
||||||
|
);
|
||||||
|
assert.ok(deskBackups.length <= 5, `Rolling backup cap enforced (got ${deskBackups.length})`);
|
||||||
|
} finally {
|
||||||
|
rmSync(tempRoot, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('SessionMigrationCard stays hidden for single-client hosts and renders multi-select migration workflow', async () => {
|
||||||
|
const prevDoc = globalThis.document;
|
||||||
|
const prevWin = globalThis.window;
|
||||||
|
const { document: doc } = createMockDom();
|
||||||
|
globalThis.document = doc;
|
||||||
|
globalThis.window = { document: doc };
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { SessionMigrationCard } = await import(
|
||||||
|
'../src/components/settings/SessionMigrationCard.js'
|
||||||
|
);
|
||||||
|
|
||||||
|
// 1. Single client -> hidden
|
||||||
|
const hiddenCard = SessionMigrationCard({
|
||||||
|
loadCatalog: async () => ({
|
||||||
|
available: false,
|
||||||
|
clients: [{ id: 'desktop', exists: true, canBeTarget: true, sessionCount: 5 }],
|
||||||
|
sessionsByClient: { desktop: [] },
|
||||||
|
desktopProjects: [],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
assert.equal(hiddenCard.el.hasAttribute('hidden'), true);
|
||||||
|
await hiddenCard.refs.ensureLoaded();
|
||||||
|
assert.equal(hiddenCard.el.hasAttribute('hidden'), true);
|
||||||
|
hiddenCard.destroy();
|
||||||
|
|
||||||
|
// 2. Multi-client -> visible, selects CLI session, migrates to Desktop project
|
||||||
|
let capturedPayload = null;
|
||||||
|
const card = SessionMigrationCard({
|
||||||
|
loadCatalog: async () => ({
|
||||||
|
available: true,
|
||||||
|
clients: [
|
||||||
|
{ id: 'desktop', exists: true, canBeSource: true, canBeTarget: true, sessionCount: 2 },
|
||||||
|
{ id: 'cli', exists: true, canBeSource: true, canBeTarget: true, sessionCount: 2 },
|
||||||
|
],
|
||||||
|
sessionsByClient: {
|
||||||
|
cli: [
|
||||||
|
{
|
||||||
|
cascadeId: '22222222-2222-4222-8222-222222222221',
|
||||||
|
title: 'CLI Debug Session',
|
||||||
|
stepCount: 12,
|
||||||
|
lastModifiedMs: Date.now() - 120000,
|
||||||
|
workspaceName: 'Administrator',
|
||||||
|
workspacePath: 'C:/Users/Administrator',
|
||||||
|
isRunning: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cascadeId: '22222222-2222-4222-8222-222222222222',
|
||||||
|
title: 'Live Active Session',
|
||||||
|
stepCount: 4,
|
||||||
|
lastModifiedMs: Date.now(),
|
||||||
|
workspaceName: 'Administrator',
|
||||||
|
workspacePath: 'C:/Users/Administrator',
|
||||||
|
isRunning: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
desktop: [],
|
||||||
|
},
|
||||||
|
desktopProjects: [
|
||||||
|
{
|
||||||
|
projectId: '99a28d35-a873-4c32-b8d1-81a62e23c33d',
|
||||||
|
name: 'antigravity-usage-monitor',
|
||||||
|
workspaceUri: 'file:///f%3A/ppt/1111/antigravity-usage-monitor',
|
||||||
|
workspacePath: 'f:/ppt/1111/antigravity-usage-monitor',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
projectId: 'outside-of-project',
|
||||||
|
name: '',
|
||||||
|
isOutsideProject: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
runMigrate: async (payload) => {
|
||||||
|
capturedPayload = payload;
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
sourceClient: payload.sourceClient,
|
||||||
|
targetClient: payload.targetClient,
|
||||||
|
targetProjectId: payload.targetProjectId,
|
||||||
|
migratedCount: payload.cascadeIds.length,
|
||||||
|
failedCount: 0,
|
||||||
|
needsWindowReload: true,
|
||||||
|
results: [
|
||||||
|
{
|
||||||
|
ok: true,
|
||||||
|
sourceCascadeId: payload.cascadeIds[0],
|
||||||
|
newCascadeId: '99999999-9999-4999-8999-999999999999',
|
||||||
|
title: 'CLI Debug Session',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await card.refs.ensureLoaded();
|
||||||
|
assert.equal(card.el.hasAttribute('hidden'), false, 'Card becomes visible when >=2 clients detected');
|
||||||
|
|
||||||
|
const rows = card.el.querySelectorAll('.smig-item');
|
||||||
|
assert.equal(rows.length, 2);
|
||||||
|
const migrateBtn = card.el.querySelector('.smig-migrate-btn');
|
||||||
|
assert.equal(migrateBtn.hasAttribute('disabled'), true);
|
||||||
|
|
||||||
|
// Clicking running session does not select it
|
||||||
|
rows[1].dispatchEvent({ type: 'click', target: rows[1] });
|
||||||
|
assert.equal(migrateBtn.hasAttribute('disabled'), true);
|
||||||
|
|
||||||
|
// Clicking idle session selects it and enables Migrate button
|
||||||
|
rows[0].dispatchEvent({ type: 'click', target: rows[0] });
|
||||||
|
assert.equal(migrateBtn.hasAttribute('disabled'), false);
|
||||||
|
|
||||||
|
// Trigger migration (defaults to full move mode)
|
||||||
|
await migrateBtn.dispatchEvent({ type: 'click', target: migrateBtn });
|
||||||
|
await new Promise((r) => setTimeout(r, 10));
|
||||||
|
assert.deepEqual(capturedPayload, {
|
||||||
|
sourceClient: 'cli',
|
||||||
|
targetClient: 'desktop',
|
||||||
|
mode: 'move',
|
||||||
|
cascadeIds: ['22222222-2222-4222-8222-222222222221'],
|
||||||
|
targetProjectId: '99a28d35-a873-4c32-b8d1-81a62e23c33d',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Switch to clone mode and verify payload reflects mode: 'clone'
|
||||||
|
const modeBtns = card.el.querySelectorAll('.smig-mode-btn');
|
||||||
|
assert.equal(modeBtns.length, 2);
|
||||||
|
modeBtns[1].dispatchEvent({ type: 'click', target: modeBtns[1] });
|
||||||
|
const rows2 = card.el.querySelectorAll('.smig-item');
|
||||||
|
rows2[0].dispatchEvent({ type: 'click', target: rows2[0] });
|
||||||
|
await migrateBtn.dispatchEvent({ type: 'click', target: migrateBtn });
|
||||||
|
await new Promise((r) => setTimeout(r, 10));
|
||||||
|
assert.equal(capturedPayload.mode, 'clone');
|
||||||
|
|
||||||
|
const resultBox = card.el.querySelector('.smig-result');
|
||||||
|
assert.equal(resultBox.hasAttribute('hidden'), false);
|
||||||
|
assert.ok(resultBox.textContent.includes('Ctrl+R'));
|
||||||
|
card.destroy();
|
||||||
|
} finally {
|
||||||
|
globalThis.document = prevDoc;
|
||||||
|
globalThis.window = prevWin;
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user