mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
fix(panel): auto-provision Desktop argv.json and surface CDP bridge diagnostics for 2.33.0+ (Refs #26)
This commit is contained in:
+270
-5
@@ -833,6 +833,10 @@ const SVG_ICON_DEFS = Object.freeze({
|
||||
close: [
|
||||
{ tag: 'path', attrs: { d: 'M4.2 4.2l7.6 7.6M11.8 4.2l-7.6 7.6' } },
|
||||
],
|
||||
copy: [
|
||||
{ tag: 'rect', attrs: { x: '5.2', y: '5.2', width: '8.3', height: '8.3', rx: '1.3' } },
|
||||
{ tag: 'path', attrs: { d: 'M3.5 10.8H2.8a1.3 1.3 0 0 1-1.3-1.3V3.3A1.3 1.3 0 0 1 2.8 2h6.2a1.3 1.3 0 0 1 1.3 1.3v.7' } },
|
||||
],
|
||||
grip: [
|
||||
{ tag: 'circle', attrs: { cx: '6', cy: '4', r: '1.05', fill: 'currentColor', stroke: 'none' } },
|
||||
{ tag: 'circle', attrs: { cx: '10', cy: '4', r: '1.05', fill: 'currentColor', stroke: 'none' } },
|
||||
@@ -1456,6 +1460,16 @@ const I18N_MESSAGES_ZH_CN = Object.freeze({
|
||||
'settings.str.mountDual': '双栖挂载 (顶部栏 + 侧边栏)',
|
||||
'settings.str.mountComposer': '输入框挂载 (输入框 + 侧边栏)',
|
||||
'settings.str.mountSidebar': '仅侧边栏',
|
||||
'settings.bridge.restartTitle': '已自动补齐调试端口参数,请重启客户端生效',
|
||||
'settings.bridge.restartBody': '已参照 IDE 方案向本地 argv.json 自动写入 "remote-debugging-port": "0"。请完全退出客户端(含系统托盘后台)后重新启动;若 Antigravity 2.33.0+ 桌面端重启后仍未生效,可在启动时追加下方参数。',
|
||||
'settings.bridge.noPortTitle': '未检测到本地调试端口,主窗口挂载暂未生效',
|
||||
'settings.bridge.unreachableTitle': '本地调试端口不可达,主窗口挂载暂未生效',
|
||||
'settings.bridge.ctxTitle': '未连通本地调试通道,上下文窗口覆写暂未注入',
|
||||
'settings.bridge.guideWin': 'Antigravity 2.33.0+ 默认不再开启调试端口(本地 argv.json 已写入配置)。请先从系统托盘完全退出并重启;若桌面端仍未生效,请在快捷方式「目标」末尾追加 --remote-debugging-port=0 后启动。',
|
||||
'settings.bridge.guideMac': 'Antigravity 2.33.0+ 默认不再开启调试端口(本地 argv.json 已写入配置)。请先完全退出(Cmd+Q)并重启;若桌面端仍未生效,可通过终端执行 open -a "Antigravity" --args --remote-debugging-port=0 启动。',
|
||||
'settings.bridge.guideLinux': 'Antigravity 2.33.0+ 默认不再开启调试端口(本地 argv.json 已写入配置)。请先完全退出并重启;若桌面端仍未生效,请在启动器 .desktop 的 Exec= 末尾追加 --remote-debugging-port=0 后启动。',
|
||||
'settings.bridge.copyFlagBtn': '复制 {cmd}',
|
||||
'settings.bridge.copiedBtn': '已复制启动参数',
|
||||
'settings.str.popoverWidthLabel': '悬浮面板宽度',
|
||||
'settings.str.popoverWidthAuto': '自适应',
|
||||
'settings.str.popoverWidthCustom': '指定宽度',
|
||||
@@ -2070,6 +2084,16 @@ const I18N_MESSAGES_EN_US = Object.freeze({
|
||||
'settings.str.mountDual': 'Dual Mount (Titlebar + Sidebar)',
|
||||
'settings.str.mountComposer': 'Composer Mount (Input Box + Sidebar)',
|
||||
'settings.str.mountSidebar': 'Sidebar Only',
|
||||
'settings.bridge.restartTitle': 'Debug Port Configured — Restart Required',
|
||||
'settings.bridge.restartBody': 'Automatically added "remote-debugging-port": "0" to local argv.json. Quit Antigravity completely (including any tray process) and relaunch; if Desktop 2.33.0+ still has no port after restart, launch with the flag below.',
|
||||
'settings.bridge.noPortTitle': 'Local Debug Port Missing — Window Mount Inactive',
|
||||
'settings.bridge.unreachableTitle': 'Local Debug Port Unreachable — Window Mount Inactive',
|
||||
'settings.bridge.ctxTitle': 'Local Debug Port Inactive — Context Override Pending',
|
||||
'settings.bridge.guideWin': 'Antigravity 2.33.0+ no longer opens a debug port by default (argv.json is already configured). Fully quit from the system tray and relaunch first; if Desktop still fails, append --remote-debugging-port=0 to your shortcut Target.',
|
||||
'settings.bridge.guideMac': 'Antigravity 2.33.0+ no longer opens a debug port by default (argv.json is already configured). Fully quit (Cmd+Q) and relaunch first; if Desktop still fails, launch via open -a "Antigravity" --args --remote-debugging-port=0.',
|
||||
'settings.bridge.guideLinux': 'Antigravity 2.33.0+ no longer opens a debug port by default (argv.json is already configured). Fully quit and relaunch first; if Desktop still fails, append --remote-debugging-port=0 to Exec= in your .desktop launcher.',
|
||||
'settings.bridge.copyFlagBtn': 'Copy {cmd}',
|
||||
'settings.bridge.copiedBtn': 'Copied to Clipboard',
|
||||
'settings.str.popoverWidthLabel': 'Popover Width',
|
||||
'settings.str.popoverWidthAuto': 'Auto Fit',
|
||||
'settings.str.popoverWidthCustom': 'Custom',
|
||||
@@ -3803,7 +3827,17 @@ function isEquivalentTelemetry(prev, next) {
|
||||
if (!sameArr(pSet?.overviewMetrics, nSet?.overviewMetrics)) return false;
|
||||
if (!sameArr(pSet?.stepTableColumns, nSet?.stepTableColumns)) return false;
|
||||
|
||||
// 2. 比对云端状态
|
||||
// 2. 比对云端状态与桥接健康度
|
||||
const pWb = prev.windowBridge;
|
||||
const nWb = next.windowBridge;
|
||||
if (
|
||||
(pWb?.state || '') !== (nWb?.state || '') ||
|
||||
Boolean(pWb?.argvUpdatedThisBoot) !== Boolean(nWb?.argvUpdatedThisBoot) ||
|
||||
Boolean(pWb?.argvConfigured) !== Boolean(nWb?.argvConfigured) ||
|
||||
Number(pWb?.aliveCount || 0) !== Number(nWb?.aliveCount || 0)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const pCloud = prev.cloudStatus;
|
||||
const nCloud = next.cloudStatus;
|
||||
if (
|
||||
@@ -14012,6 +14046,186 @@ const ThemeColorPicker = defineComponent({
|
||||
return { ThemeColorPicker };
|
||||
})();
|
||||
|
||||
// --- src/components/settings/BridgeStatusNotice.js ---
|
||||
const { BridgeStatusNotice } = (() => {
|
||||
/**
|
||||
* @fileoverview Shared CDP / Window Bridge diagnostic notice card (`BridgeStatusNotice.js`).
|
||||
* Surfaces actionable restart or `--remote-debugging-port=0` guidance when Antigravity 2.33.0+
|
||||
* runs without an active `DevToolsActivePort` (`no_devtools_port` / `cdp_unreachable`).
|
||||
*/
|
||||
|
||||
|
||||
const LAUNCH_FLAG_TEXT = '--remote-debugging-port=0';
|
||||
|
||||
async function copyTextToClipboard(text) {
|
||||
try {
|
||||
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
}
|
||||
} catch {
|
||||
// Fallback to temporary textarea inside restricted webview contexts
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
const BridgeStatusNotice = defineComponent({
|
||||
name: 'BridgeStatusNotice',
|
||||
setup({ props, onCleanup }) {
|
||||
const contextMode = Boolean(props?.contextMode);
|
||||
let lastPayload = {
|
||||
visible: false,
|
||||
windowBridge: null,
|
||||
hostPlatform: 'win32',
|
||||
};
|
||||
let copied = false;
|
||||
let copiedTimer = null;
|
||||
let destroyed = false;
|
||||
|
||||
const headIconEl = createSvgIcon('warning', { size: 13, className: 'settings-bridge-icon' });
|
||||
const titleEl = h('strong', { className: 'settings-bridge-title', text: '' });
|
||||
const bodyEl = h('p', { className: 'settings-bridge-desc', text: '' });
|
||||
|
||||
const copyBtnIconEl = createSvgIcon('copy', { size: 11 });
|
||||
const copyBtnTextEl = h('span', {
|
||||
className: 'settings-bridge-copy-text',
|
||||
text: t('settings.bridge.copyFlagBtn', { cmd: LAUNCH_FLAG_TEXT }),
|
||||
});
|
||||
const copyBtnEl = h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
className: 'btn-ghost-sm settings-bridge-copy-btn',
|
||||
onClick: async () => {
|
||||
await copyTextToClipboard(LAUNCH_FLAG_TEXT);
|
||||
if (destroyed) return;
|
||||
copied = true;
|
||||
if (copiedTimer) clearTimeout(copiedTimer);
|
||||
syncCopyBtn();
|
||||
copiedTimer = setTimeout(() => {
|
||||
copiedTimer = null;
|
||||
if (destroyed) return;
|
||||
copied = false;
|
||||
syncCopyBtn();
|
||||
}, 1800);
|
||||
copiedTimer?.unref?.();
|
||||
},
|
||||
},
|
||||
[copyBtnIconEl, copyBtnTextEl]
|
||||
);
|
||||
|
||||
const rootEl = h(
|
||||
'div',
|
||||
{
|
||||
className: 'settings-bridge-notice',
|
||||
role: 'status',
|
||||
hidden: true,
|
||||
},
|
||||
[
|
||||
h('div', { className: 'settings-bridge-head' }, [headIconEl, titleEl]),
|
||||
bodyEl,
|
||||
copyBtnEl,
|
||||
]
|
||||
);
|
||||
|
||||
function syncCopyBtn() {
|
||||
patchSvgIcon(copyBtnIconEl, copied ? 'check' : 'copy');
|
||||
patchText(
|
||||
copyBtnTextEl,
|
||||
copied
|
||||
? t('settings.bridge.copiedBtn')
|
||||
: t('settings.bridge.copyFlagBtn', { cmd: LAUNCH_FLAG_TEXT })
|
||||
);
|
||||
}
|
||||
|
||||
function render() {
|
||||
const wb = lastPayload.windowBridge;
|
||||
const state = String(wb?.state || '').trim();
|
||||
const shouldShow =
|
||||
Boolean(lastPayload.visible) &&
|
||||
!isWindowOverlayMode() &&
|
||||
(state === 'no_devtools_port' || state === 'cdp_unreachable');
|
||||
|
||||
patchAttr(rootEl, 'hidden', !shouldShow);
|
||||
if (!shouldShow) return;
|
||||
|
||||
const isRestartPending = state === 'no_devtools_port' && Boolean(wb?.argvUpdatedThisBoot);
|
||||
patchClasses(rootEl, {
|
||||
'is-restart': isRestartPending,
|
||||
'is-warn': !isRestartPending,
|
||||
});
|
||||
patchSvgIcon(headIconEl, isRestartPending ? 'refresh' : 'warning');
|
||||
|
||||
let titleText = '';
|
||||
if (isRestartPending) {
|
||||
titleText = t('settings.bridge.restartTitle');
|
||||
} else if (contextMode) {
|
||||
titleText = t('settings.bridge.ctxTitle');
|
||||
} else if (state === 'cdp_unreachable') {
|
||||
titleText = t('settings.bridge.unreachableTitle');
|
||||
} else {
|
||||
titleText = t('settings.bridge.noPortTitle');
|
||||
}
|
||||
|
||||
const plat = String(lastPayload.hostPlatform || '').trim().toLowerCase();
|
||||
let bodyText = '';
|
||||
if (isRestartPending) {
|
||||
bodyText = t('settings.bridge.restartBody');
|
||||
} else if (plat === 'darwin') {
|
||||
bodyText = t('settings.bridge.guideMac');
|
||||
} else if (plat === 'linux') {
|
||||
bodyText = t('settings.bridge.guideLinux');
|
||||
} else {
|
||||
bodyText = t('settings.bridge.guideWin');
|
||||
}
|
||||
|
||||
patchText(titleEl, titleText);
|
||||
patchText(bodyEl, bodyText);
|
||||
syncCopyBtn();
|
||||
}
|
||||
|
||||
function update(next = {}) {
|
||||
lastPayload = {
|
||||
...lastPayload,
|
||||
...next,
|
||||
};
|
||||
render();
|
||||
}
|
||||
|
||||
onCleanup(() => {
|
||||
destroyed = true;
|
||||
if (copiedTimer) {
|
||||
clearTimeout(copiedTimer);
|
||||
copiedTimer = null;
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
el: rootEl,
|
||||
refs: {
|
||||
update,
|
||||
refreshLabels: render,
|
||||
copyBtnEl,
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
return { BridgeStatusNotice };
|
||||
})();
|
||||
|
||||
// --- src/views/settings/SettingsGeneralTab.js ---
|
||||
const { SettingsGeneralTab } = (() => {
|
||||
/**
|
||||
@@ -14559,6 +14773,8 @@ const SettingsStructureTab = defineComponent({
|
||||
let rawStepTokenComboText = DEFAULT_CLIENT_STEP_TOKEN_COMBO_FORMAT;
|
||||
let draftStepColumns = [...DEFAULT_CLIENT_STEP_COLUMNS];
|
||||
let latestSettings = null;
|
||||
let latestWindowBridge = null;
|
||||
let latestHostPlatform = 'win32';
|
||||
|
||||
function isStructureVisible() {
|
||||
const st = uiStore.getState();
|
||||
@@ -14769,6 +14985,8 @@ const SettingsStructureTab = defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
const mountBridgeNotice = BridgeStatusNotice({});
|
||||
|
||||
const mountSection = CollapsibleSection({
|
||||
collapsible: false,
|
||||
icon: 'dock',
|
||||
@@ -14802,6 +15020,7 @@ const SettingsStructureTab = defineComponent({
|
||||
mountPreviewCanvas,
|
||||
h('div', { className: 'settings-divider' }),
|
||||
h('div', { className: 'form-row' }, [mountModeLabelEl, windowMountSelect.el]),
|
||||
mountBridgeNotice.el,
|
||||
h('div', { className: 'form-row' }, [
|
||||
h('div', { className: 'settings-inline-row' }, [
|
||||
popoverWidthLabelEl,
|
||||
@@ -14834,6 +15053,11 @@ const SettingsStructureTab = defineComponent({
|
||||
modelValue: draftWindowMountMode,
|
||||
options: getMountModeOptions(),
|
||||
});
|
||||
mountBridgeNotice.refs.update({
|
||||
visible: draftWindowMountMode !== 'sidebar',
|
||||
windowBridge: latestWindowBridge,
|
||||
hostPlatform: latestHostPlatform,
|
||||
});
|
||||
popoverWidthModeToggle.setProps({
|
||||
modelValue: draftPopoverWidthMode,
|
||||
options: getPopoverWidthModeOptions(),
|
||||
@@ -15423,9 +15647,15 @@ const SettingsStructureTab = defineComponent({
|
||||
stepsSection.el,
|
||||
]);
|
||||
|
||||
function renderSettings(settings) {
|
||||
function renderSettings(
|
||||
settings,
|
||||
windowBridge = latestWindowBridge,
|
||||
hostPlatform = latestHostPlatform
|
||||
) {
|
||||
if (!settings) return;
|
||||
latestSettings = settings;
|
||||
if (windowBridge !== undefined) latestWindowBridge = windowBridge;
|
||||
if (hostPlatform) latestHostPlatform = hostPlatform;
|
||||
draftWindowMountMode = normalizeClientWindowMountMode(
|
||||
settings.windowMountMode,
|
||||
settings.enableWindowOverlay
|
||||
@@ -15527,6 +15757,7 @@ const SettingsStructureTab = defineComponent({
|
||||
|
||||
onCleanup(() => {
|
||||
unsubUi();
|
||||
mountBridgeNotice.destroy();
|
||||
capsulePreviewWidget.destroy();
|
||||
hoverPreviewHost.destroy();
|
||||
overviewPreviewHost.destroy();
|
||||
@@ -15555,6 +15786,7 @@ const SettingsStructureTab = defineComponent({
|
||||
refs: {
|
||||
thirdNavBar,
|
||||
capsulePreviewWidget,
|
||||
mountBridgeNotice,
|
||||
hoverPreviewHost,
|
||||
overviewPreviewHost,
|
||||
stepTablePreview,
|
||||
@@ -15614,6 +15846,8 @@ const SettingsOtherTab = defineComponent({
|
||||
let draftContextRiskAccepted = false;
|
||||
let acceptingContextRisk = false;
|
||||
let latestSettings = null;
|
||||
let latestWindowBridge = null;
|
||||
let latestHostPlatform = 'win32';
|
||||
let contextWindowModels = [];
|
||||
let contextModelId = '';
|
||||
let savingContextWindow = false;
|
||||
@@ -15763,9 +15997,11 @@ const SettingsOtherTab = defineComponent({
|
||||
}
|
||||
},
|
||||
});
|
||||
const ctxBridgeNotice = BridgeStatusNotice({ contextMode: true });
|
||||
const ctxModelRow = h('div', { className: 'form-row' }, [ctxModelLabel, ctxModelSelect.el]);
|
||||
const ctxWindowRow = h('div', { className: 'form-row' }, [ctxWindowLabel, ctxWindowSelect.el]);
|
||||
const ctxControlsBody = h('div', { className: 'ctx-controls-body is-locked' }, [
|
||||
ctxBridgeNotice.el,
|
||||
ctxModelRow,
|
||||
ctxWindowRow,
|
||||
h('div', { className: 'form-row' }, [ctxHint]),
|
||||
@@ -15842,6 +16078,11 @@ const SettingsOtherTab = defineComponent({
|
||||
patchAttr(ctxRiskAcceptBtn, 'disabled', acceptingContextRisk);
|
||||
|
||||
const saved = latestSettings?.modelContextWindows || {};
|
||||
ctxBridgeNotice.refs.update({
|
||||
visible: unlocked && Object.keys(saved).length > 0,
|
||||
windowBridge: latestWindowBridge,
|
||||
hostPlatform: latestHostPlatform,
|
||||
});
|
||||
const models = new Map(contextWindowModels.map((model) => [model.id, model]));
|
||||
const knownIds = new Set(contextWindowModels.flatMap(({ id, members = [] }) => [id, ...members]));
|
||||
for (const id of Object.keys(saved)) {
|
||||
@@ -16056,10 +16297,17 @@ const SettingsOtherTab = defineComponent({
|
||||
maintPanel,
|
||||
]);
|
||||
|
||||
function renderSettings(settings, models = contextWindowModels) {
|
||||
function renderSettings(
|
||||
settings,
|
||||
models = contextWindowModels,
|
||||
windowBridge = latestWindowBridge,
|
||||
hostPlatform = latestHostPlatform
|
||||
) {
|
||||
if (!settings) return;
|
||||
latestSettings = settings;
|
||||
contextWindowModels = models;
|
||||
if (windowBridge !== undefined) latestWindowBridge = windowBridge;
|
||||
if (hostPlatform) latestHostPlatform = hostPlatform;
|
||||
draftModelDisplayMode = normalizeClientModelDisplayMode(
|
||||
settings.modelDisplayMode,
|
||||
settings.showUpstreamModel
|
||||
@@ -16117,6 +16365,7 @@ const SettingsOtherTab = defineComponent({
|
||||
if (resetConfirmTimer) clearTimeout(resetConfirmTimer);
|
||||
stepModelSelect.destroy();
|
||||
orchestratorIdSelect.destroy();
|
||||
ctxBridgeNotice.destroy();
|
||||
ctxModelSelect.destroy();
|
||||
ctxWindowSelect.destroy();
|
||||
});
|
||||
@@ -16126,6 +16375,7 @@ const SettingsOtherTab = defineComponent({
|
||||
refs: {
|
||||
stepModelSelect,
|
||||
orchestratorIdSelect,
|
||||
ctxBridgeNotice,
|
||||
ctxModelSelect,
|
||||
ctxWindowSelect,
|
||||
rebuildCacheBtn,
|
||||
@@ -18630,9 +18880,22 @@ const SettingsView = defineComponent({
|
||||
const telemetry = telemetryStore.getState().telemetry;
|
||||
const settings = telemetry?.settings;
|
||||
if (settingsSubTab === 'structure') {
|
||||
if (settings) structureTab.refs.renderSettings(settings);
|
||||
if (settings) {
|
||||
structureTab.refs.renderSettings(
|
||||
settings,
|
||||
telemetry?.windowBridge,
|
||||
telemetry?.hostPlatform
|
||||
);
|
||||
}
|
||||
} else if (settingsSubTab === 'other') {
|
||||
if (settings) otherTab.refs.renderSettings(settings, telemetry.contextWindowModels || []);
|
||||
if (settings) {
|
||||
otherTab.refs.renderSettings(
|
||||
settings,
|
||||
telemetry.contextWindowModels || [],
|
||||
telemetry?.windowBridge,
|
||||
telemetry?.hostPlatform
|
||||
);
|
||||
}
|
||||
} else if (accountTab && settingsSubTab === 'account') {
|
||||
accountTab.refs.renderAccount(telemetry?.account, telemetry?.quotas);
|
||||
} else {
|
||||
@@ -18645,6 +18908,8 @@ const SettingsView = defineComponent({
|
||||
const unsubTelemetry = telemetryStore.subscribe(
|
||||
(st) => ({
|
||||
settings: st.telemetry?.settings,
|
||||
windowBridge: st.telemetry?.windowBridge,
|
||||
hostPlatform: st.telemetry?.hostPlatform,
|
||||
cloudStatus: st.telemetry?.cloudStatus,
|
||||
contextWindowModels: st.telemetry?.contextWindowModels,
|
||||
account: st.telemetry?.account,
|
||||
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
} from './model-pricing.mjs';
|
||||
import { getCloudStatus, getPricingPhaseEpoch, pricingCatalogRevision } from './pricing-catalog.mjs';
|
||||
import { buildOfficialQuotaPools } from './quota-pools.mjs';
|
||||
import { getDefaultWindowBridgeStatus } from './window-bridge.mjs';
|
||||
import {
|
||||
aggregateMultiWindowUsage,
|
||||
buildScopedModelBreakdown,
|
||||
@@ -1581,6 +1582,7 @@ export async function buildTelemetryPayloadInternal(
|
||||
timestamp: new Date().toISOString(),
|
||||
hostPlatform: process.platform || 'unknown',
|
||||
uiBundleVersion,
|
||||
windowBridge: getDefaultWindowBridgeStatus(),
|
||||
settings,
|
||||
contextWindowModels: getContextWindowGroups(getContextWindowModels(clientConfigs, contextModelCatalog)).map((group) => {
|
||||
const latest = group.members.reduce((previous, id) => {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* 3. 完全不触碰宿主 `app.asar` 文件,客户端升级或无调试端口时静默回退至右侧辅助栏。
|
||||
*/
|
||||
|
||||
import { existsSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
||||
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
||||
import { homedir } from 'node:os';
|
||||
import { dirname, join } from 'node:path';
|
||||
import {
|
||||
@@ -102,6 +102,56 @@ export function resolveIdeArgvPath(env = process.env, homeDir = homedir()) {
|
||||
return join(homeDir, '.antigravity-ide', 'argv.json');
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 Antigravity Desktop 2.0 各平台可能的启动参数文件 `argv.json` 候选路径。
|
||||
*
|
||||
* @param {Record<string, string|undefined>} [env=process.env]
|
||||
* @param {string} [platform=process.platform]
|
||||
* @param {string} [homeDir=homedir()]
|
||||
* @returns {{ dotAntigravityArgv: string, userDataArgvPaths: string[], geminiArgvPath: string }}
|
||||
*/
|
||||
export function resolveDesktopArgvCandidates(
|
||||
env = process.env,
|
||||
platform = process.platform,
|
||||
homeDir = homedir()
|
||||
) {
|
||||
const dotAntigravityArgv = join(homeDir, '.antigravity', 'argv.json');
|
||||
const geminiBase = String(env?.ANTIGRAVITY_GEMINI_DIR || '').trim() || join(homeDir, '.gemini');
|
||||
const geminiArgvPath = join(geminiBase, 'antigravity', 'argv.json');
|
||||
|
||||
let userDataDirs = [];
|
||||
if (platform === 'win32') {
|
||||
const appData = env?.APPDATA || join(homeDir, 'AppData', 'Roaming');
|
||||
const localAppData = env?.LOCALAPPDATA || join(homeDir, 'AppData', 'Local');
|
||||
userDataDirs = [join(appData, 'Antigravity'), join(localAppData, 'Antigravity')];
|
||||
} else if (platform === 'darwin') {
|
||||
userDataDirs = [
|
||||
join(homeDir, 'Library', 'Application Support', 'Antigravity'),
|
||||
join(homeDir, '.config', 'Antigravity'),
|
||||
];
|
||||
} else {
|
||||
const configHome = env?.XDG_CONFIG_HOME || join(homeDir, '.config');
|
||||
userDataDirs = [join(configHome, 'Antigravity')];
|
||||
}
|
||||
|
||||
const seen = new Set();
|
||||
const userDataArgvPaths = [];
|
||||
for (const dir of userDataDirs) {
|
||||
const argvPath = join(dir, 'argv.json');
|
||||
const key = platform === 'win32' ? argvPath.toLowerCase() : argvPath;
|
||||
if (!seen.has(key)) {
|
||||
seen.add(key);
|
||||
userDataArgvPaths.push(argvPath);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
dotAntigravityArgv,
|
||||
userDataArgvPaths,
|
||||
geminiArgvPath,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 词法扫描 JSONC 文本(支持 `//`、`/* ... * /` 注释与尾随逗号),提取纯 JSON 字符串及顶层键值坐标。
|
||||
*
|
||||
@@ -266,8 +316,8 @@ function scanJsoncObject(rawText) {
|
||||
*/
|
||||
export function ensureRemoteDebuggingInArgvText(rawText) {
|
||||
if (typeof rawText !== 'string' || !rawText.trim()) {
|
||||
const fresh =
|
||||
'{\n\t// Automatically configured by Antigravity Usage & Speed Monitor for topbar overlay support.\n\t"remote-debugging-port": "0"\n}\n';
|
||||
// 新建文件使用纯 JSON(无注释),同时兼容 VS Code/IDE JSONC 解析器与 Electron 严格 JSON.parse()
|
||||
const fresh = '{\n\t"remote-debugging-port": "0"\n}\n';
|
||||
return { changed: true, valid: true, portValue: '0', text: fresh };
|
||||
}
|
||||
|
||||
@@ -339,25 +389,14 @@ export function ensureRemoteDebuggingInArgvText(rawText) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 当本机存在 `~/.antigravity-ide` 配置目录且开启双栖模式时,自动补齐 `argv.json` 中的
|
||||
* `"remote-debugging-port": "0"`,使 Antigravity IDE 下次启动时自动生成 `DevToolsActivePort`。
|
||||
*
|
||||
* @param {{ env?: Record<string, string|undefined>, homeDir?: string, enabled?: boolean }} [options]
|
||||
*/
|
||||
export function ensureIdeRemoteDebuggingArgv({
|
||||
env = process.env,
|
||||
homeDir = homedir(),
|
||||
enabled = true,
|
||||
} = {}) {
|
||||
if (!enabled) {
|
||||
return { checked: false, updated: false, reason: 'disabled' };
|
||||
}
|
||||
const argvPath = resolveIdeArgvPath(env, homeDir);
|
||||
function patchSingleHostArgvFile(argvPath, { createDir = false, missingReason = 'dir_missing' } = {}) {
|
||||
try {
|
||||
const dirPath = dirname(argvPath);
|
||||
if (!existsSync(dirPath)) {
|
||||
return { checked: true, updated: false, reason: 'ide_dir_missing', argvPath };
|
||||
if (!createDir) {
|
||||
return { checked: true, updated: false, reason: missingReason, argvPath };
|
||||
}
|
||||
mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
const rawText = existsSync(argvPath) ? readFileSync(argvPath, 'utf8') : '';
|
||||
const patched = ensureRemoteDebuggingInArgvText(rawText);
|
||||
@@ -401,6 +440,132 @@ export function ensureIdeRemoteDebuggingArgv({
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当本机存在 `~/.antigravity-ide` 配置目录且开启双栖模式时,自动补齐 `argv.json` 中的
|
||||
* `"remote-debugging-port": "0"`,使 Antigravity IDE 下次启动时自动生成 `DevToolsActivePort`。
|
||||
*
|
||||
* @param {{ env?: Record<string, string|undefined>, homeDir?: string, enabled?: boolean }} [options]
|
||||
*/
|
||||
export function ensureIdeRemoteDebuggingArgv({
|
||||
env = process.env,
|
||||
homeDir = homedir(),
|
||||
enabled = true,
|
||||
} = {}) {
|
||||
if (!enabled) {
|
||||
return { checked: false, updated: false, reason: 'disabled' };
|
||||
}
|
||||
const argvPath = resolveIdeArgvPath(env, homeDir);
|
||||
return patchSingleHostArgvFile(argvPath, {
|
||||
createDir: false,
|
||||
missingReason: 'ide_dir_missing',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 当检测到本机已安装 Antigravity Desktop 2.0(存在 `~/.antigravity`、`~/.gemini/antigravity` 或系统 `Antigravity` 数据目录)时,
|
||||
* 同步参照 IDE 方案自动补齐 `~/.antigravity/argv.json` 与已有桌面端数据目录下的 `argv.json` (`"remote-debugging-port": "0"`)。
|
||||
*
|
||||
* @param {{ env?: Record<string, string|undefined>, platform?: string, homeDir?: string, enabled?: boolean }} [options]
|
||||
*/
|
||||
export function ensureDesktopRemoteDebuggingArgv({
|
||||
env = process.env,
|
||||
platform = process.platform,
|
||||
homeDir = homedir(),
|
||||
enabled = true,
|
||||
} = {}) {
|
||||
if (!enabled) {
|
||||
return { checked: false, updated: false, alreadyConfigured: false, reason: 'disabled', results: [] };
|
||||
}
|
||||
const candidates = resolveDesktopArgvCandidates(env, platform, homeDir);
|
||||
const dotDir = dirname(candidates.dotAntigravityArgv);
|
||||
const probeDirs = [
|
||||
dotDir,
|
||||
...candidates.userDataArgvPaths.map((p) => dirname(p)),
|
||||
dirname(candidates.geminiArgvPath),
|
||||
];
|
||||
const hasDesktopInstall = probeDirs.some((dir) => {
|
||||
try {
|
||||
return existsSync(dir);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (!hasDesktopInstall) {
|
||||
return {
|
||||
checked: true,
|
||||
updated: false,
|
||||
alreadyConfigured: false,
|
||||
reason: 'desktop_dir_missing',
|
||||
results: [],
|
||||
};
|
||||
}
|
||||
|
||||
const results = [
|
||||
patchSingleHostArgvFile(candidates.dotAntigravityArgv, {
|
||||
createDir: true,
|
||||
missingReason: 'desktop_dir_missing',
|
||||
}),
|
||||
...candidates.userDataArgvPaths.map((argvPath) =>
|
||||
patchSingleHostArgvFile(argvPath, {
|
||||
createDir: false,
|
||||
missingReason: 'desktop_dir_missing',
|
||||
})
|
||||
),
|
||||
patchSingleHostArgvFile(candidates.geminiArgvPath, {
|
||||
createDir: false,
|
||||
missingReason: 'desktop_dir_missing',
|
||||
}),
|
||||
];
|
||||
|
||||
const updatedPaths = results.filter((r) => r.updated).map((r) => r.argvPath);
|
||||
const configuredPaths = results
|
||||
.filter((r) => r.updated || r.alreadyConfigured)
|
||||
.map((r) => r.argvPath);
|
||||
return {
|
||||
checked: true,
|
||||
updated: updatedPaths.length > 0,
|
||||
alreadyConfigured: updatedPaths.length === 0 && configuredPaths.length > 0,
|
||||
updatedPaths,
|
||||
configuredPaths,
|
||||
results,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一补齐本机 Antigravity IDE 与 Antigravity Desktop 的 `argv.json` 调试端口参数。
|
||||
*
|
||||
* @param {{ env?: Record<string, string|undefined>, platform?: string, homeDir?: string, enabled?: boolean }} [options]
|
||||
*/
|
||||
export function ensureHostRemoteDebuggingArgv({
|
||||
env = process.env,
|
||||
platform = process.platform,
|
||||
homeDir = homedir(),
|
||||
enabled = true,
|
||||
} = {}) {
|
||||
if (!enabled) {
|
||||
return { checked: false, updated: false, alreadyConfigured: false, reason: 'disabled' };
|
||||
}
|
||||
const ide = ensureIdeRemoteDebuggingArgv({ env, homeDir, enabled: true });
|
||||
const desktop = ensureDesktopRemoteDebuggingArgv({ env, platform, homeDir, enabled: true });
|
||||
const updatedPaths = [
|
||||
...(ide.updated && ide.argvPath ? [ide.argvPath] : []),
|
||||
...(desktop.updatedPaths || []),
|
||||
];
|
||||
const configuredPaths = [
|
||||
...((ide.updated || ide.alreadyConfigured) && ide.argvPath ? [ide.argvPath] : []),
|
||||
...(desktop.configuredPaths || []),
|
||||
];
|
||||
return {
|
||||
checked: true,
|
||||
updated: updatedPaths.length > 0,
|
||||
alreadyConfigured: updatedPaths.length === 0 && configuredPaths.length > 0,
|
||||
updatedPaths,
|
||||
configuredPaths,
|
||||
ide,
|
||||
desktop,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 `DevToolsActivePort` 文件文本首行提取合法的本地调试端口号。
|
||||
*
|
||||
@@ -721,6 +886,18 @@ export function createWindowBridgeController(options) {
|
||||
let hadInjectedChatFrames = false;
|
||||
let cdpFallbackActive = false;
|
||||
let ideArgvProvisioned = false;
|
||||
let argvUpdatedThisBoot = false;
|
||||
let argvConfigured = false;
|
||||
let lastPersistedLeaseSig = '';
|
||||
let lastBridgeStatus = {
|
||||
state: 'pending',
|
||||
enabled: true,
|
||||
aliveCount: 0,
|
||||
targets: 0,
|
||||
argvUpdatedThisBoot: false,
|
||||
argvConfigured: false,
|
||||
updatedAtMs: 0,
|
||||
};
|
||||
let hadContextWindows = false;
|
||||
let contextWindowBootId = `${process.pid}:${Date.now()}`;
|
||||
let nodeDepsPromise = null;
|
||||
@@ -996,6 +1173,17 @@ export function createWindowBridgeController(options) {
|
||||
// 忽略不可读候选文件
|
||||
}
|
||||
}
|
||||
const rawExplicitPorts = String(env?.ANTIGRAVITY_DEVTOOLS_PORT || '').trim();
|
||||
if (rawExplicitPorts) {
|
||||
for (const token of rawExplicitPorts.split(/[\s,]+/)) {
|
||||
if (!/^\d+$/.test(token)) continue;
|
||||
const p = Number(token);
|
||||
if (Number.isInteger(p) && p > 0 && p <= 65535 && !seen.has(p)) {
|
||||
seen.add(p);
|
||||
ports.push(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ports;
|
||||
}
|
||||
|
||||
@@ -1138,6 +1326,36 @@ export function createWindowBridgeController(options) {
|
||||
}
|
||||
}
|
||||
|
||||
function updateBridgeStatus(nextState, { enabled = true, aliveCount = 0, targets = 0, leasedBySelf = false, bundleVersion = '', prevLease = null } = {}) {
|
||||
lastBridgeStatus = {
|
||||
state: nextState,
|
||||
enabled: Boolean(enabled),
|
||||
aliveCount: Number(aliveCount || 0),
|
||||
targets: Number(targets || 0),
|
||||
argvUpdatedThisBoot: Boolean(argvUpdatedThisBoot),
|
||||
argvConfigured: Boolean(argvConfigured),
|
||||
updatedAtMs: Date.now(),
|
||||
};
|
||||
if (leasedBySelf && leaseFilePath) {
|
||||
const sig = `${nextState}:${lastBridgeStatus.aliveCount}:${lastBridgeStatus.targets}:${argvUpdatedThisBoot ? 1 : 0}:${argvConfigured ? 1 : 0}`;
|
||||
if (sig !== lastPersistedLeaseSig) {
|
||||
lastPersistedLeaseSig = sig;
|
||||
saveJson(leaseFilePath, {
|
||||
pid: process.pid,
|
||||
bundleVersion,
|
||||
bridgePort: bridgePort > 0 ? bridgePort : Number(prevLease?.bridgePort || 0) || undefined,
|
||||
bridgeToken: bridgeToken || String(prevLease?.bridgeToken || '') || undefined,
|
||||
syncState: lastBridgeStatus.state,
|
||||
aliveCount: lastBridgeStatus.aliveCount,
|
||||
targets: lastBridgeStatus.targets,
|
||||
argvUpdatedThisBoot: lastBridgeStatus.argvUpdatedThisBoot,
|
||||
argvConfigured: lastBridgeStatus.argvConfigured,
|
||||
updatedAtMs: Date.now(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function runSyncInternal({ forceReinject = false } = {}) {
|
||||
if (stopped) return { ok: false, reason: 'stopped' };
|
||||
const bundleVersion = String(getBundleVersionFn() || '');
|
||||
@@ -1155,14 +1373,25 @@ export function createWindowBridgeController(options) {
|
||||
const contextWindows = curSettings.modelContextWindows || {};
|
||||
const hasContextWindows = Object.keys(contextWindows).length > 0;
|
||||
if ((enabled || hasContextWindows) && autoConfigureIdeArgv && !ideArgvProvisioned) {
|
||||
const prov = ensureIdeRemoteDebuggingArgv({ env, homeDir, enabled: true });
|
||||
if (prov.updated || prov.alreadyConfigured || prov.reason === 'ide_dir_missing') {
|
||||
const prov = ensureHostRemoteDebuggingArgv({ env, platform, homeDir, enabled: true });
|
||||
if (prov.updated) {
|
||||
argvUpdatedThisBoot = true;
|
||||
argvConfigured = true;
|
||||
} else if (prov.alreadyConfigured) {
|
||||
argvConfigured = true;
|
||||
}
|
||||
const noInstallDirs =
|
||||
prov.ide?.reason === 'ide_dir_missing' && prov.desktop?.reason === 'desktop_dir_missing';
|
||||
if (prov.updated || prov.alreadyConfigured || noInstallDirs) {
|
||||
ideArgvProvisioned = true;
|
||||
}
|
||||
}
|
||||
|
||||
let leasedBySelf = false;
|
||||
let currentLease = null;
|
||||
if ((enabled || hasContextWindows) && leaseFilePath && !forceReinject) {
|
||||
const lease = loadJson(leaseFilePath, null);
|
||||
currentLease = lease;
|
||||
const leasePid = Number(lease?.pid || 0);
|
||||
const leaseAgeMs = Date.now() - Number(lease?.updatedAtMs || 0);
|
||||
if (leasePid > 0 && leasePid !== process.pid && leaseAgeMs >= 0 && leaseAgeMs < 9000 && isPidAlive(leasePid)) {
|
||||
@@ -1173,28 +1402,62 @@ export function createWindowBridgeController(options) {
|
||||
return { ok: false, enabled: true, reason: 'older_than_leader', injected: 0 };
|
||||
}
|
||||
if (leaseVerNum === myVerNum || String(lease?.bundleVersion || '') === bundleVersion) {
|
||||
lastBridgeStatus = {
|
||||
state: String(lease?.syncState || 'active'),
|
||||
enabled: Boolean(enabled),
|
||||
aliveCount: Number(lease?.aliveCount || 0),
|
||||
targets: Number(lease?.targets || 0),
|
||||
argvUpdatedThisBoot: Boolean(lease?.argvUpdatedThisBoot || argvUpdatedThisBoot),
|
||||
argvConfigured: Boolean(lease?.argvConfigured || argvConfigured),
|
||||
updatedAtMs: Date.now(),
|
||||
};
|
||||
return { ok: true, enabled: true, reason: 'follower_yield', leaderPid: leasePid, injected: 0 };
|
||||
}
|
||||
}
|
||||
leasedBySelf = true;
|
||||
lastPersistedLeaseSig = '';
|
||||
saveJson(leaseFilePath, {
|
||||
pid: process.pid,
|
||||
bundleVersion,
|
||||
bridgePort: bridgePort > 0 ? bridgePort : Number(lease?.bridgePort || 0) || undefined,
|
||||
bridgeToken: bridgeToken || String(lease?.bridgeToken || '') || undefined,
|
||||
syncState: lastBridgeStatus.state,
|
||||
aliveCount: lastBridgeStatus.aliveCount,
|
||||
targets: lastBridgeStatus.targets,
|
||||
argvUpdatedThisBoot: Boolean(argvUpdatedThisBoot),
|
||||
argvConfigured: Boolean(argvConfigured),
|
||||
updatedAtMs: Date.now(),
|
||||
});
|
||||
}
|
||||
|
||||
const cdpPorts = findActiveDevToolsPorts();
|
||||
if (!cdpPorts.length) {
|
||||
updateBridgeStatus(enabled || hasContextWindows ? 'no_devtools_port' : 'disabled', {
|
||||
enabled,
|
||||
leasedBySelf,
|
||||
bundleVersion,
|
||||
prevLease: currentLease,
|
||||
});
|
||||
return { ok: false, enabled, reason: 'no_devtools_port', injected: 0 };
|
||||
}
|
||||
|
||||
const { reachableCount, targets } = await collectAllMainWindowTargets(cdpPorts);
|
||||
if (reachableCount === 0) {
|
||||
updateBridgeStatus(enabled || hasContextWindows ? 'cdp_unreachable' : 'disabled', {
|
||||
enabled,
|
||||
leasedBySelf,
|
||||
bundleVersion,
|
||||
prevLease: currentLease,
|
||||
});
|
||||
return { ok: false, enabled, reason: 'cdp_unreachable', injected: 0 };
|
||||
}
|
||||
if (!targets.length) {
|
||||
updateBridgeStatus(enabled ? 'no_targets' : 'disabled', {
|
||||
enabled,
|
||||
leasedBySelf,
|
||||
bundleVersion,
|
||||
prevLease: currentLease,
|
||||
});
|
||||
return { ok: true, enabled, reason: 'no_targets', injected: 0 };
|
||||
}
|
||||
|
||||
@@ -1232,6 +1495,13 @@ export function createWindowBridgeController(options) {
|
||||
|
||||
if (!enabled) {
|
||||
if (!hadInjectedTargets && !hadInjectedChatFrames && !forceReinject) {
|
||||
updateBridgeStatus('disabled', {
|
||||
enabled: false,
|
||||
targets: targets.length,
|
||||
leasedBySelf,
|
||||
bundleVersion,
|
||||
prevLease: currentLease,
|
||||
});
|
||||
return { ok: true, enabled: false, removed: 0 };
|
||||
}
|
||||
let removed = 0;
|
||||
@@ -1244,6 +1514,13 @@ export function createWindowBridgeController(options) {
|
||||
}
|
||||
hadInjectedTargets = false;
|
||||
hadInjectedChatFrames = false;
|
||||
updateBridgeStatus('disabled', {
|
||||
enabled: false,
|
||||
targets: targets.length,
|
||||
leasedBySelf,
|
||||
bundleVersion,
|
||||
prevLease: currentLease,
|
||||
});
|
||||
return { ok: true, enabled: false, removed };
|
||||
}
|
||||
|
||||
@@ -1490,6 +1767,14 @@ export function createWindowBridgeController(options) {
|
||||
}
|
||||
|
||||
cdpFallbackActive = sawCdpTransport;
|
||||
updateBridgeStatus(aliveCount > 0 ? 'active' : 'no_targets', {
|
||||
enabled: true,
|
||||
aliveCount,
|
||||
targets: targets.length,
|
||||
leasedBySelf,
|
||||
bundleVersion,
|
||||
prevLease: currentLease,
|
||||
});
|
||||
return {
|
||||
ok: true,
|
||||
enabled: true,
|
||||
@@ -1625,11 +1910,30 @@ export function createWindowBridgeController(options) {
|
||||
start,
|
||||
stop,
|
||||
getBridgeInfo: () => ({ port: bridgePort, token: bridgeToken, running: Boolean(server) }),
|
||||
getBridgeStatus: () => ({ ...lastBridgeStatus }),
|
||||
};
|
||||
}
|
||||
|
||||
let defaultBridgeController = null;
|
||||
|
||||
/**
|
||||
* 读取进程级默认双栖桥接器的最新同步健康度快照(供 `/api/telemetry` 与偏好设置面板诊断使用)。
|
||||
*/
|
||||
export function getDefaultWindowBridgeStatus() {
|
||||
if (!defaultBridgeController) {
|
||||
return {
|
||||
state: 'pending',
|
||||
enabled: true,
|
||||
aliveCount: 0,
|
||||
targets: 0,
|
||||
argvUpdatedThisBoot: false,
|
||||
argvConfigured: false,
|
||||
updatedAtMs: 0,
|
||||
};
|
||||
}
|
||||
return defaultBridgeController.getBridgeStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动进程级默认的双栖窗口桥接控制器(幂等)。
|
||||
*
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>用量监控</title>
|
||||
<link rel="stylesheet" href="/styles.css?v=1794994568891">
|
||||
<link rel="stylesheet" href="/styles.css?v=1795000051709">
|
||||
<script src="/preload.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app-root"></div>
|
||||
<script src="/app.js?v=1794994568891"></script>
|
||||
<script src="/app.js?v=1795000051709"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -554,6 +554,7 @@ export function buildBundle(panelDir = PANEL_DIR) {
|
||||
'src/components/settings/CollapsibleSection.js',
|
||||
'src/components/settings/EditableSlotList.js',
|
||||
'src/components/settings/ThemeColorPicker.js',
|
||||
'src/components/settings/BridgeStatusNotice.js',
|
||||
'src/views/settings/SettingsGeneralTab.js',
|
||||
'src/views/settings/SettingsStructureTab.js',
|
||||
'src/views/settings/SettingsOtherTab.js',
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* @fileoverview Shared CDP / Window Bridge diagnostic notice card (`BridgeStatusNotice.js`).
|
||||
* Surfaces actionable restart or `--remote-debugging-port=0` guidance when Antigravity 2.33.0+
|
||||
* runs without an active `DevToolsActivePort` (`no_devtools_port` / `cdp_unreachable`).
|
||||
*/
|
||||
|
||||
import { defineComponent } from '../../core/component.js';
|
||||
import { h, patchAttr, patchClasses, patchText } from '../../core/domPatch.js';
|
||||
import { isWindowOverlayMode } from '../../core/httpClient.js';
|
||||
import { createSvgIcon, patchSvgIcon } from '../../icons/SvgIcon.js';
|
||||
import { t } from '../../i18n/index.js';
|
||||
|
||||
const LAUNCH_FLAG_TEXT = '--remote-debugging-port=0';
|
||||
|
||||
async function copyTextToClipboard(text) {
|
||||
try {
|
||||
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
}
|
||||
} catch {
|
||||
// Fallback to temporary textarea inside restricted webview contexts
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
export const BridgeStatusNotice = defineComponent({
|
||||
name: 'BridgeStatusNotice',
|
||||
setup({ props, onCleanup }) {
|
||||
const contextMode = Boolean(props?.contextMode);
|
||||
let lastPayload = {
|
||||
visible: false,
|
||||
windowBridge: null,
|
||||
hostPlatform: 'win32',
|
||||
};
|
||||
let copied = false;
|
||||
let copiedTimer = null;
|
||||
let destroyed = false;
|
||||
|
||||
const headIconEl = createSvgIcon('warning', { size: 13, className: 'settings-bridge-icon' });
|
||||
const titleEl = h('strong', { className: 'settings-bridge-title', text: '' });
|
||||
const bodyEl = h('p', { className: 'settings-bridge-desc', text: '' });
|
||||
|
||||
const copyBtnIconEl = createSvgIcon('copy', { size: 11 });
|
||||
const copyBtnTextEl = h('span', {
|
||||
className: 'settings-bridge-copy-text',
|
||||
text: t('settings.bridge.copyFlagBtn', { cmd: LAUNCH_FLAG_TEXT }),
|
||||
});
|
||||
const copyBtnEl = h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
className: 'btn-ghost-sm settings-bridge-copy-btn',
|
||||
onClick: async () => {
|
||||
await copyTextToClipboard(LAUNCH_FLAG_TEXT);
|
||||
if (destroyed) return;
|
||||
copied = true;
|
||||
if (copiedTimer) clearTimeout(copiedTimer);
|
||||
syncCopyBtn();
|
||||
copiedTimer = setTimeout(() => {
|
||||
copiedTimer = null;
|
||||
if (destroyed) return;
|
||||
copied = false;
|
||||
syncCopyBtn();
|
||||
}, 1800);
|
||||
copiedTimer?.unref?.();
|
||||
},
|
||||
},
|
||||
[copyBtnIconEl, copyBtnTextEl]
|
||||
);
|
||||
|
||||
const rootEl = h(
|
||||
'div',
|
||||
{
|
||||
className: 'settings-bridge-notice',
|
||||
role: 'status',
|
||||
hidden: true,
|
||||
},
|
||||
[
|
||||
h('div', { className: 'settings-bridge-head' }, [headIconEl, titleEl]),
|
||||
bodyEl,
|
||||
copyBtnEl,
|
||||
]
|
||||
);
|
||||
|
||||
function syncCopyBtn() {
|
||||
patchSvgIcon(copyBtnIconEl, copied ? 'check' : 'copy');
|
||||
patchText(
|
||||
copyBtnTextEl,
|
||||
copied
|
||||
? t('settings.bridge.copiedBtn')
|
||||
: t('settings.bridge.copyFlagBtn', { cmd: LAUNCH_FLAG_TEXT })
|
||||
);
|
||||
}
|
||||
|
||||
function render() {
|
||||
const wb = lastPayload.windowBridge;
|
||||
const state = String(wb?.state || '').trim();
|
||||
const shouldShow =
|
||||
Boolean(lastPayload.visible) &&
|
||||
!isWindowOverlayMode() &&
|
||||
(state === 'no_devtools_port' || state === 'cdp_unreachable');
|
||||
|
||||
patchAttr(rootEl, 'hidden', !shouldShow);
|
||||
if (!shouldShow) return;
|
||||
|
||||
const isRestartPending = state === 'no_devtools_port' && Boolean(wb?.argvUpdatedThisBoot);
|
||||
patchClasses(rootEl, {
|
||||
'is-restart': isRestartPending,
|
||||
'is-warn': !isRestartPending,
|
||||
});
|
||||
patchSvgIcon(headIconEl, isRestartPending ? 'refresh' : 'warning');
|
||||
|
||||
let titleText = '';
|
||||
if (isRestartPending) {
|
||||
titleText = t('settings.bridge.restartTitle');
|
||||
} else if (contextMode) {
|
||||
titleText = t('settings.bridge.ctxTitle');
|
||||
} else if (state === 'cdp_unreachable') {
|
||||
titleText = t('settings.bridge.unreachableTitle');
|
||||
} else {
|
||||
titleText = t('settings.bridge.noPortTitle');
|
||||
}
|
||||
|
||||
const plat = String(lastPayload.hostPlatform || '').trim().toLowerCase();
|
||||
let bodyText = '';
|
||||
if (isRestartPending) {
|
||||
bodyText = t('settings.bridge.restartBody');
|
||||
} else if (plat === 'darwin') {
|
||||
bodyText = t('settings.bridge.guideMac');
|
||||
} else if (plat === 'linux') {
|
||||
bodyText = t('settings.bridge.guideLinux');
|
||||
} else {
|
||||
bodyText = t('settings.bridge.guideWin');
|
||||
}
|
||||
|
||||
patchText(titleEl, titleText);
|
||||
patchText(bodyEl, bodyText);
|
||||
syncCopyBtn();
|
||||
}
|
||||
|
||||
function update(next = {}) {
|
||||
lastPayload = {
|
||||
...lastPayload,
|
||||
...next,
|
||||
};
|
||||
render();
|
||||
}
|
||||
|
||||
onCleanup(() => {
|
||||
destroyed = true;
|
||||
if (copiedTimer) {
|
||||
clearTimeout(copiedTimer);
|
||||
copiedTimer = null;
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
el: rootEl,
|
||||
refs: {
|
||||
update,
|
||||
refreshLabels: render,
|
||||
copyBtnEl,
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -435,6 +435,16 @@ export const I18N_MESSAGES_EN_US = Object.freeze({
|
||||
'settings.str.mountDual': 'Dual Mount (Titlebar + Sidebar)',
|
||||
'settings.str.mountComposer': 'Composer Mount (Input Box + Sidebar)',
|
||||
'settings.str.mountSidebar': 'Sidebar Only',
|
||||
'settings.bridge.restartTitle': 'Debug Port Configured — Restart Required',
|
||||
'settings.bridge.restartBody': 'Automatically added "remote-debugging-port": "0" to local argv.json. Quit Antigravity completely (including any tray process) and relaunch; if Desktop 2.33.0+ still has no port after restart, launch with the flag below.',
|
||||
'settings.bridge.noPortTitle': 'Local Debug Port Missing — Window Mount Inactive',
|
||||
'settings.bridge.unreachableTitle': 'Local Debug Port Unreachable — Window Mount Inactive',
|
||||
'settings.bridge.ctxTitle': 'Local Debug Port Inactive — Context Override Pending',
|
||||
'settings.bridge.guideWin': 'Antigravity 2.33.0+ no longer opens a debug port by default (argv.json is already configured). Fully quit from the system tray and relaunch first; if Desktop still fails, append --remote-debugging-port=0 to your shortcut Target.',
|
||||
'settings.bridge.guideMac': 'Antigravity 2.33.0+ no longer opens a debug port by default (argv.json is already configured). Fully quit (Cmd+Q) and relaunch first; if Desktop still fails, launch via open -a "Antigravity" --args --remote-debugging-port=0.',
|
||||
'settings.bridge.guideLinux': 'Antigravity 2.33.0+ no longer opens a debug port by default (argv.json is already configured). Fully quit and relaunch first; if Desktop still fails, append --remote-debugging-port=0 to Exec= in your .desktop launcher.',
|
||||
'settings.bridge.copyFlagBtn': 'Copy {cmd}',
|
||||
'settings.bridge.copiedBtn': 'Copied to Clipboard',
|
||||
'settings.str.popoverWidthLabel': 'Popover Width',
|
||||
'settings.str.popoverWidthAuto': 'Auto Fit',
|
||||
'settings.str.popoverWidthCustom': 'Custom',
|
||||
|
||||
@@ -435,6 +435,16 @@ export const I18N_MESSAGES_ZH_CN = Object.freeze({
|
||||
'settings.str.mountDual': '双栖挂载 (顶部栏 + 侧边栏)',
|
||||
'settings.str.mountComposer': '输入框挂载 (输入框 + 侧边栏)',
|
||||
'settings.str.mountSidebar': '仅侧边栏',
|
||||
'settings.bridge.restartTitle': '已自动补齐调试端口参数,请重启客户端生效',
|
||||
'settings.bridge.restartBody': '已参照 IDE 方案向本地 argv.json 自动写入 "remote-debugging-port": "0"。请完全退出客户端(含系统托盘后台)后重新启动;若 Antigravity 2.33.0+ 桌面端重启后仍未生效,可在启动时追加下方参数。',
|
||||
'settings.bridge.noPortTitle': '未检测到本地调试端口,主窗口挂载暂未生效',
|
||||
'settings.bridge.unreachableTitle': '本地调试端口不可达,主窗口挂载暂未生效',
|
||||
'settings.bridge.ctxTitle': '未连通本地调试通道,上下文窗口覆写暂未注入',
|
||||
'settings.bridge.guideWin': 'Antigravity 2.33.0+ 默认不再开启调试端口(本地 argv.json 已写入配置)。请先从系统托盘完全退出并重启;若桌面端仍未生效,请在快捷方式「目标」末尾追加 --remote-debugging-port=0 后启动。',
|
||||
'settings.bridge.guideMac': 'Antigravity 2.33.0+ 默认不再开启调试端口(本地 argv.json 已写入配置)。请先完全退出(Cmd+Q)并重启;若桌面端仍未生效,可通过终端执行 open -a "Antigravity" --args --remote-debugging-port=0 启动。',
|
||||
'settings.bridge.guideLinux': 'Antigravity 2.33.0+ 默认不再开启调试端口(本地 argv.json 已写入配置)。请先完全退出并重启;若桌面端仍未生效,请在启动器 .desktop 的 Exec= 末尾追加 --remote-debugging-port=0 后启动。',
|
||||
'settings.bridge.copyFlagBtn': '复制 {cmd}',
|
||||
'settings.bridge.copiedBtn': '已复制启动参数',
|
||||
'settings.str.popoverWidthLabel': '悬浮面板宽度',
|
||||
'settings.str.popoverWidthAuto': '自适应',
|
||||
'settings.str.popoverWidthCustom': '指定宽度',
|
||||
|
||||
@@ -89,6 +89,10 @@ export const SVG_ICON_DEFS = Object.freeze({
|
||||
close: [
|
||||
{ tag: 'path', attrs: { d: 'M4.2 4.2l7.6 7.6M11.8 4.2l-7.6 7.6' } },
|
||||
],
|
||||
copy: [
|
||||
{ tag: 'rect', attrs: { x: '5.2', y: '5.2', width: '8.3', height: '8.3', rx: '1.3' } },
|
||||
{ tag: 'path', attrs: { d: 'M3.5 10.8H2.8a1.3 1.3 0 0 1-1.3-1.3V3.3A1.3 1.3 0 0 1 2.8 2h6.2a1.3 1.3 0 0 1 1.3 1.3v.7' } },
|
||||
],
|
||||
grip: [
|
||||
{ tag: 'circle', attrs: { cx: '6', cy: '4', r: '1.05', fill: 'currentColor', stroke: 'none' } },
|
||||
{ tag: 'circle', attrs: { cx: '10', cy: '4', r: '1.05', fill: 'currentColor', stroke: 'none' } },
|
||||
|
||||
@@ -262,7 +262,17 @@ export function isEquivalentTelemetry(prev, next) {
|
||||
if (!sameArr(pSet?.overviewMetrics, nSet?.overviewMetrics)) return false;
|
||||
if (!sameArr(pSet?.stepTableColumns, nSet?.stepTableColumns)) return false;
|
||||
|
||||
// 2. 比对云端状态
|
||||
// 2. 比对云端状态与桥接健康度
|
||||
const pWb = prev.windowBridge;
|
||||
const nWb = next.windowBridge;
|
||||
if (
|
||||
(pWb?.state || '') !== (nWb?.state || '') ||
|
||||
Boolean(pWb?.argvUpdatedThisBoot) !== Boolean(nWb?.argvUpdatedThisBoot) ||
|
||||
Boolean(pWb?.argvConfigured) !== Boolean(nWb?.argvConfigured) ||
|
||||
Number(pWb?.aliveCount || 0) !== Number(nWb?.aliveCount || 0)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const pCloud = prev.cloudStatus;
|
||||
const nCloud = next.cloudStatus;
|
||||
if (
|
||||
|
||||
@@ -818,3 +818,73 @@
|
||||
padding: 2px var(--space-3);
|
||||
font-size: var(--fs-md);
|
||||
}
|
||||
|
||||
/* --- CDP / 双栖桥接端口诊断与引导卡片 (.settings-bridge-notice) --- */
|
||||
.settings-bridge-notice {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 5px;
|
||||
padding: var(--space-3) var(--space-4);
|
||||
border-radius: var(--radius-xs);
|
||||
border: 1px solid color-mix(in srgb, var(--metric-warn) 42%, var(--border-hairline));
|
||||
background: color-mix(in srgb, var(--surface-panel) 89%, var(--metric-warn) 7%);
|
||||
}
|
||||
|
||||
.settings-bridge-notice.is-restart {
|
||||
border-color: color-mix(in srgb, var(--metric-info) 42%, var(--border-hairline));
|
||||
background: color-mix(in srgb, var(--surface-panel) 89%, var(--metric-info) 7%);
|
||||
}
|
||||
|
||||
.settings-bridge-notice[hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.settings-bridge-head {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
color: var(--metric-warn);
|
||||
}
|
||||
|
||||
.settings-bridge-notice.is-restart .settings-bridge-head,
|
||||
.settings-bridge-notice.is-restart .settings-bridge-icon,
|
||||
.settings-bridge-notice.is-restart .settings-bridge-title {
|
||||
color: var(--metric-info);
|
||||
}
|
||||
|
||||
.settings-bridge-icon {
|
||||
color: var(--metric-warn);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.settings-bridge-title {
|
||||
font-size: var(--fs-md);
|
||||
font-weight: 600;
|
||||
line-height: 1.35;
|
||||
color: var(--metric-warn);
|
||||
}
|
||||
|
||||
.settings-bridge-desc {
|
||||
margin: 0;
|
||||
font-size: var(--fs-sm);
|
||||
line-height: 1.48;
|
||||
color: var(--text-primary);
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.settings-bridge-copy-btn {
|
||||
margin-top: 2px;
|
||||
min-height: calc(24px * var(--ui-font-scale, 1));
|
||||
padding: 2px var(--space-3);
|
||||
font-size: var(--fs-xs);
|
||||
font-family: var(--font-mono);
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.settings-bridge-copy-text {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
@@ -103,9 +103,22 @@ export const SettingsView = defineComponent({
|
||||
const telemetry = telemetryStore.getState().telemetry;
|
||||
const settings = telemetry?.settings;
|
||||
if (settingsSubTab === 'structure') {
|
||||
if (settings) structureTab.refs.renderSettings(settings);
|
||||
if (settings) {
|
||||
structureTab.refs.renderSettings(
|
||||
settings,
|
||||
telemetry?.windowBridge,
|
||||
telemetry?.hostPlatform
|
||||
);
|
||||
}
|
||||
} else if (settingsSubTab === 'other') {
|
||||
if (settings) otherTab.refs.renderSettings(settings, telemetry.contextWindowModels || []);
|
||||
if (settings) {
|
||||
otherTab.refs.renderSettings(
|
||||
settings,
|
||||
telemetry.contextWindowModels || [],
|
||||
telemetry?.windowBridge,
|
||||
telemetry?.hostPlatform
|
||||
);
|
||||
}
|
||||
} else if (accountTab && settingsSubTab === 'account') {
|
||||
accountTab.refs.renderAccount(telemetry?.account, telemetry?.quotas);
|
||||
} else {
|
||||
@@ -118,6 +131,8 @@ export const SettingsView = defineComponent({
|
||||
const unsubTelemetry = telemetryStore.subscribe(
|
||||
(st) => ({
|
||||
settings: st.telemetry?.settings,
|
||||
windowBridge: st.telemetry?.windowBridge,
|
||||
hostPlatform: st.telemetry?.hostPlatform,
|
||||
cloudStatus: st.telemetry?.cloudStatus,
|
||||
contextWindowModels: st.telemetry?.contextWindowModels,
|
||||
account: st.telemetry?.account,
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
saveSettingsPatch,
|
||||
} from '../../store/telemetryStore.js';
|
||||
import { CustomSelect } from '../../components/ui/CustomSelect.js';
|
||||
import { BridgeStatusNotice } from '../../components/settings/BridgeStatusNotice.js';
|
||||
|
||||
function getStepModelDisplayOptions() {
|
||||
return [
|
||||
@@ -41,6 +42,8 @@ export const SettingsOtherTab = defineComponent({
|
||||
let draftContextRiskAccepted = false;
|
||||
let acceptingContextRisk = false;
|
||||
let latestSettings = null;
|
||||
let latestWindowBridge = null;
|
||||
let latestHostPlatform = 'win32';
|
||||
let contextWindowModels = [];
|
||||
let contextModelId = '';
|
||||
let savingContextWindow = false;
|
||||
@@ -190,9 +193,11 @@ export const SettingsOtherTab = defineComponent({
|
||||
}
|
||||
},
|
||||
});
|
||||
const ctxBridgeNotice = BridgeStatusNotice({ contextMode: true });
|
||||
const ctxModelRow = h('div', { className: 'form-row' }, [ctxModelLabel, ctxModelSelect.el]);
|
||||
const ctxWindowRow = h('div', { className: 'form-row' }, [ctxWindowLabel, ctxWindowSelect.el]);
|
||||
const ctxControlsBody = h('div', { className: 'ctx-controls-body is-locked' }, [
|
||||
ctxBridgeNotice.el,
|
||||
ctxModelRow,
|
||||
ctxWindowRow,
|
||||
h('div', { className: 'form-row' }, [ctxHint]),
|
||||
@@ -269,6 +274,11 @@ export const SettingsOtherTab = defineComponent({
|
||||
patchAttr(ctxRiskAcceptBtn, 'disabled', acceptingContextRisk);
|
||||
|
||||
const saved = latestSettings?.modelContextWindows || {};
|
||||
ctxBridgeNotice.refs.update({
|
||||
visible: unlocked && Object.keys(saved).length > 0,
|
||||
windowBridge: latestWindowBridge,
|
||||
hostPlatform: latestHostPlatform,
|
||||
});
|
||||
const models = new Map(contextWindowModels.map((model) => [model.id, model]));
|
||||
const knownIds = new Set(contextWindowModels.flatMap(({ id, members = [] }) => [id, ...members]));
|
||||
for (const id of Object.keys(saved)) {
|
||||
@@ -483,10 +493,17 @@ export const SettingsOtherTab = defineComponent({
|
||||
maintPanel,
|
||||
]);
|
||||
|
||||
function renderSettings(settings, models = contextWindowModels) {
|
||||
function renderSettings(
|
||||
settings,
|
||||
models = contextWindowModels,
|
||||
windowBridge = latestWindowBridge,
|
||||
hostPlatform = latestHostPlatform
|
||||
) {
|
||||
if (!settings) return;
|
||||
latestSettings = settings;
|
||||
contextWindowModels = models;
|
||||
if (windowBridge !== undefined) latestWindowBridge = windowBridge;
|
||||
if (hostPlatform) latestHostPlatform = hostPlatform;
|
||||
draftModelDisplayMode = normalizeClientModelDisplayMode(
|
||||
settings.modelDisplayMode,
|
||||
settings.showUpstreamModel
|
||||
@@ -544,6 +561,7 @@ export const SettingsOtherTab = defineComponent({
|
||||
if (resetConfirmTimer) clearTimeout(resetConfirmTimer);
|
||||
stepModelSelect.destroy();
|
||||
orchestratorIdSelect.destroy();
|
||||
ctxBridgeNotice.destroy();
|
||||
ctxModelSelect.destroy();
|
||||
ctxWindowSelect.destroy();
|
||||
});
|
||||
@@ -553,6 +571,7 @@ export const SettingsOtherTab = defineComponent({
|
||||
refs: {
|
||||
stepModelSelect,
|
||||
orchestratorIdSelect,
|
||||
ctxBridgeNotice,
|
||||
ctxModelSelect,
|
||||
ctxWindowSelect,
|
||||
rebuildCacheBtn,
|
||||
|
||||
@@ -41,6 +41,7 @@ import {
|
||||
saveSettingsPatch,
|
||||
} from '../../store/telemetryStore.js';
|
||||
import { getVisibleMonitorView, uiStore } from '../../store/uiStore.js';
|
||||
import { BridgeStatusNotice } from '../../components/settings/BridgeStatusNotice.js';
|
||||
import { CollapsibleSection } from '../../components/settings/CollapsibleSection.js';
|
||||
import { EditableSlotList } from '../../components/settings/EditableSlotList.js';
|
||||
import { buildStructurePreviewTelemetry } from '../../components/settings/structurePreviewMock.js';
|
||||
@@ -119,6 +120,8 @@ export const SettingsStructureTab = defineComponent({
|
||||
let rawStepTokenComboText = DEFAULT_CLIENT_STEP_TOKEN_COMBO_FORMAT;
|
||||
let draftStepColumns = [...DEFAULT_CLIENT_STEP_COLUMNS];
|
||||
let latestSettings = null;
|
||||
let latestWindowBridge = null;
|
||||
let latestHostPlatform = 'win32';
|
||||
|
||||
function isStructureVisible() {
|
||||
const st = uiStore.getState();
|
||||
@@ -329,6 +332,8 @@ export const SettingsStructureTab = defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
const mountBridgeNotice = BridgeStatusNotice({});
|
||||
|
||||
const mountSection = CollapsibleSection({
|
||||
collapsible: false,
|
||||
icon: 'dock',
|
||||
@@ -362,6 +367,7 @@ export const SettingsStructureTab = defineComponent({
|
||||
mountPreviewCanvas,
|
||||
h('div', { className: 'settings-divider' }),
|
||||
h('div', { className: 'form-row' }, [mountModeLabelEl, windowMountSelect.el]),
|
||||
mountBridgeNotice.el,
|
||||
h('div', { className: 'form-row' }, [
|
||||
h('div', { className: 'settings-inline-row' }, [
|
||||
popoverWidthLabelEl,
|
||||
@@ -394,6 +400,11 @@ export const SettingsStructureTab = defineComponent({
|
||||
modelValue: draftWindowMountMode,
|
||||
options: getMountModeOptions(),
|
||||
});
|
||||
mountBridgeNotice.refs.update({
|
||||
visible: draftWindowMountMode !== 'sidebar',
|
||||
windowBridge: latestWindowBridge,
|
||||
hostPlatform: latestHostPlatform,
|
||||
});
|
||||
popoverWidthModeToggle.setProps({
|
||||
modelValue: draftPopoverWidthMode,
|
||||
options: getPopoverWidthModeOptions(),
|
||||
@@ -983,9 +994,15 @@ export const SettingsStructureTab = defineComponent({
|
||||
stepsSection.el,
|
||||
]);
|
||||
|
||||
function renderSettings(settings) {
|
||||
function renderSettings(
|
||||
settings,
|
||||
windowBridge = latestWindowBridge,
|
||||
hostPlatform = latestHostPlatform
|
||||
) {
|
||||
if (!settings) return;
|
||||
latestSettings = settings;
|
||||
if (windowBridge !== undefined) latestWindowBridge = windowBridge;
|
||||
if (hostPlatform) latestHostPlatform = hostPlatform;
|
||||
draftWindowMountMode = normalizeClientWindowMountMode(
|
||||
settings.windowMountMode,
|
||||
settings.enableWindowOverlay
|
||||
@@ -1087,6 +1104,7 @@ export const SettingsStructureTab = defineComponent({
|
||||
|
||||
onCleanup(() => {
|
||||
unsubUi();
|
||||
mountBridgeNotice.destroy();
|
||||
capsulePreviewWidget.destroy();
|
||||
hoverPreviewHost.destroy();
|
||||
overviewPreviewHost.destroy();
|
||||
@@ -1115,6 +1133,7 @@ export const SettingsStructureTab = defineComponent({
|
||||
refs: {
|
||||
thirdNavBar,
|
||||
capsulePreviewWidget,
|
||||
mountBridgeNotice,
|
||||
hoverPreviewHost,
|
||||
overviewPreviewHost,
|
||||
stepTablePreview,
|
||||
|
||||
@@ -4181,6 +4181,76 @@ html[data-standalone="true"] .app-shell {
|
||||
font-size: var(--fs-md);
|
||||
}
|
||||
|
||||
/* --- CDP / 双栖桥接端口诊断与引导卡片 (.settings-bridge-notice) --- */
|
||||
.settings-bridge-notice {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 5px;
|
||||
padding: var(--space-3) var(--space-4);
|
||||
border-radius: var(--radius-xs);
|
||||
border: 1px solid color-mix(in srgb, var(--metric-warn) 42%, var(--border-hairline));
|
||||
background: color-mix(in srgb, var(--surface-panel) 89%, var(--metric-warn) 7%);
|
||||
}
|
||||
|
||||
.settings-bridge-notice.is-restart {
|
||||
border-color: color-mix(in srgb, var(--metric-info) 42%, var(--border-hairline));
|
||||
background: color-mix(in srgb, var(--surface-panel) 89%, var(--metric-info) 7%);
|
||||
}
|
||||
|
||||
.settings-bridge-notice[hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.settings-bridge-head {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
color: var(--metric-warn);
|
||||
}
|
||||
|
||||
.settings-bridge-notice.is-restart .settings-bridge-head,
|
||||
.settings-bridge-notice.is-restart .settings-bridge-icon,
|
||||
.settings-bridge-notice.is-restart .settings-bridge-title {
|
||||
color: var(--metric-info);
|
||||
}
|
||||
|
||||
.settings-bridge-icon {
|
||||
color: var(--metric-warn);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.settings-bridge-title {
|
||||
font-size: var(--fs-md);
|
||||
font-weight: 600;
|
||||
line-height: 1.35;
|
||||
color: var(--metric-warn);
|
||||
}
|
||||
|
||||
.settings-bridge-desc {
|
||||
margin: 0;
|
||||
font-size: var(--fs-sm);
|
||||
line-height: 1.48;
|
||||
color: var(--text-primary);
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.settings-bridge-copy-btn {
|
||||
margin-top: 2px;
|
||||
min-height: calc(24px * var(--ui-font-scale, 1));
|
||||
padding: 2px var(--space-3);
|
||||
font-size: var(--fs-xs);
|
||||
font-family: var(--font-mono);
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.settings-bridge-copy-text {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* --- src/styles/overlay.css --- */
|
||||
/*
|
||||
* 双栖模式顶栏胶囊与悬浮面板样式表 (overlay.css).
|
||||
|
||||
@@ -10,6 +10,8 @@ import { MockMutationObserver, createMockDom } from './mock-dom.mjs';
|
||||
import {
|
||||
associateIdeIframeRoutes,
|
||||
createWindowBridgeController,
|
||||
ensureDesktopRemoteDebuggingArgv,
|
||||
ensureHostRemoteDebuggingArgv,
|
||||
ensureIdeRemoteDebuggingArgv,
|
||||
ensureRemoteDebuggingInArgvText,
|
||||
extractIdeExtensionCascadeId,
|
||||
@@ -17,6 +19,7 @@ import {
|
||||
isAntigravityMainPageTarget,
|
||||
isIdeExtensionChatTarget,
|
||||
parseDevToolsPortFile,
|
||||
resolveDesktopArgvCandidates,
|
||||
resolveDevToolsPortCandidates,
|
||||
resolveIdeArgvPath,
|
||||
} from '../backend/window-bridge.mjs';
|
||||
@@ -4846,3 +4849,307 @@ test('WindowOverlayShell macOS (darwin) adaptation: sets data-os="mac", uses 12p
|
||||
winNarrowFlow.ov.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
test('Issue #26: Antigravity Desktop 2.33.0+ argv.json auto-provisioning, ANTIGRAVITY_DEVTOOLS_PORT fallback, and BridgeStatusNotice UI', async () => {
|
||||
// 1. Fresh argv.json is strict-JSON parseable (compatible with both JSONC and JSON.parse)
|
||||
const fresh = ensureRemoteDebuggingInArgvText('');
|
||||
assert.deepEqual(JSON.parse(fresh.text), { 'remote-debugging-port': '0' });
|
||||
|
||||
// 2. Empty home directory creates zero folders for Desktop or IDE
|
||||
const emptyTmp = fs.mkdtempSync(path.join(os.tmpdir(), 'ag-233-empty-'));
|
||||
try {
|
||||
const emptyRes = ensureDesktopRemoteDebuggingArgv({
|
||||
env: {
|
||||
APPDATA: path.join(emptyTmp, 'Roaming'),
|
||||
LOCALAPPDATA: path.join(emptyTmp, 'Local'),
|
||||
ANTIGRAVITY_GEMINI_DIR: path.join(emptyTmp, '.gemini'),
|
||||
},
|
||||
platform: 'win32',
|
||||
homeDir: emptyTmp,
|
||||
enabled: true,
|
||||
});
|
||||
assert.equal(emptyRes.updated, false);
|
||||
assert.equal(emptyRes.reason, 'desktop_dir_missing');
|
||||
assert.equal(fs.existsSync(path.join(emptyTmp, '.antigravity')), false);
|
||||
} finally {
|
||||
fs.rmSync(emptyTmp, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
// 3. Simulated Windows Antigravity Desktop 2.33.0 environment provisions argv.json across Desktop roots & tracks bridge status
|
||||
const simTmp = fs.mkdtempSync(path.join(os.tmpdir(), 'ag-233-desktop-'));
|
||||
const homeDir = path.join(simTmp, 'home');
|
||||
const roamingDir = path.join(homeDir, 'AppData', 'Roaming');
|
||||
const localDir = path.join(homeDir, 'AppData', 'Local');
|
||||
const desktopRoamingDir = path.join(roamingDir, 'Antigravity');
|
||||
const geminiDesktopDir = path.join(homeDir, '.gemini', 'antigravity');
|
||||
const leaseFile = path.join(simTmp, 'window-bridge-lease.json');
|
||||
fs.mkdirSync(desktopRoamingDir, { recursive: true });
|
||||
fs.mkdirSync(geminiDesktopDir, { recursive: true });
|
||||
|
||||
const simEnv = {
|
||||
APPDATA: roamingDir,
|
||||
LOCALAPPDATA: localDir,
|
||||
ANTIGRAVITY_GEMINI_DIR: path.join(homeDir, '.gemini'),
|
||||
};
|
||||
|
||||
try {
|
||||
const candidates = resolveDesktopArgvCandidates(simEnv, 'win32', homeDir);
|
||||
assert.equal(candidates.dotAntigravityArgv, path.join(homeDir, '.antigravity', 'argv.json'));
|
||||
|
||||
// Boot 1: provisions argv.json and reports state='no_devtools_port' + argvUpdatedThisBoot=true
|
||||
const ctrlBoot1 = createWindowBridgeController({
|
||||
handleApiRequest: async () => ({ status: 200, body: '{}' }),
|
||||
readAssetFn: async () => '',
|
||||
getSettingsFn: () => ({ windowMountMode: 'dual', enableWindowOverlay: true, modelContextWindows: {} }),
|
||||
getBundleVersionFn: () => '200',
|
||||
env: simEnv,
|
||||
platform: 'win32',
|
||||
homeDir,
|
||||
leaseFilePath: leaseFile,
|
||||
autoConfigureIdeArgv: true,
|
||||
});
|
||||
const resBoot1 = await ctrlBoot1.syncAllWindows();
|
||||
assert.equal(resBoot1.reason, 'no_devtools_port');
|
||||
const stBoot1 = ctrlBoot1.getBridgeStatus();
|
||||
assert.equal(stBoot1.state, 'no_devtools_port');
|
||||
assert.equal(stBoot1.argvUpdatedThisBoot, true);
|
||||
assert.equal(stBoot1.argvConfigured, true);
|
||||
|
||||
for (const argvPath of [
|
||||
path.join(homeDir, '.antigravity', 'argv.json'),
|
||||
path.join(desktopRoamingDir, 'argv.json'),
|
||||
path.join(geminiDesktopDir, 'argv.json'),
|
||||
]) {
|
||||
assert.equal(fs.existsSync(argvPath), true, `Expected ${argvPath} to exist`);
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(argvPath, 'utf8')), {
|
||||
'remote-debugging-port': '0',
|
||||
});
|
||||
}
|
||||
|
||||
// Follower reading active lease inherits Leader's syncState + argvUpdatedThisBoot
|
||||
const leaseJson = JSON.parse(fs.readFileSync(leaseFile, 'utf8'));
|
||||
fs.writeFileSync(
|
||||
leaseFile,
|
||||
JSON.stringify({ ...leaseJson, pid: process.pid }),
|
||||
'utf8'
|
||||
);
|
||||
await ctrlBoot1.stop();
|
||||
|
||||
// Boot 2 (after restart, argv.json already configured, still no DevToolsActivePort): argvUpdatedThisBoot=false, argvConfigured=true
|
||||
fs.unlinkSync(leaseFile);
|
||||
const hostProv2 = ensureHostRemoteDebuggingArgv({
|
||||
env: simEnv,
|
||||
platform: 'win32',
|
||||
homeDir,
|
||||
enabled: true,
|
||||
});
|
||||
assert.equal(hostProv2.updated, false);
|
||||
assert.equal(hostProv2.alreadyConfigured, true);
|
||||
|
||||
const ctrlBoot2 = createWindowBridgeController({
|
||||
handleApiRequest: async () => ({ status: 200, body: '{}' }),
|
||||
readAssetFn: async () => '',
|
||||
getSettingsFn: () => ({ windowMountMode: 'dual', enableWindowOverlay: true, modelContextWindows: {} }),
|
||||
getBundleVersionFn: () => '200',
|
||||
env: simEnv,
|
||||
platform: 'win32',
|
||||
homeDir,
|
||||
autoConfigureIdeArgv: true,
|
||||
});
|
||||
await ctrlBoot2.syncAllWindows();
|
||||
const stBoot2 = ctrlBoot2.getBridgeStatus();
|
||||
assert.equal(stBoot2.state, 'no_devtools_port');
|
||||
assert.equal(stBoot2.argvUpdatedThisBoot, false);
|
||||
assert.equal(stBoot2.argvConfigured, true);
|
||||
await ctrlBoot2.stop();
|
||||
|
||||
// Boot 3: Explicit ANTIGRAVITY_DEVTOOLS_PORT fallback injects cleanly even when DevToolsActivePort file is absent
|
||||
const cdpSrv = http.createServer((req, res) => {
|
||||
if (req.url === '/json/list') {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(
|
||||
JSON.stringify([
|
||||
{
|
||||
id: 'win-233',
|
||||
type: 'page',
|
||||
url: 'https://127.0.0.1:52100/c/22222222-2222-4222-8222-222222222222',
|
||||
webSocketDebuggerUrl: 'ws://127.0.0.1:52101/devtools/page/win-233',
|
||||
},
|
||||
])
|
||||
);
|
||||
return;
|
||||
}
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
});
|
||||
await new Promise((r) => cdpSrv.listen(0, '127.0.0.1', r));
|
||||
const explicitCdpPort = cdpSrv.address().port;
|
||||
|
||||
class MockCdpWs {
|
||||
constructor() {
|
||||
this._ls = new Map();
|
||||
queueMicrotask(() => {
|
||||
for (const fn of this._ls.get('open') || []) fn();
|
||||
});
|
||||
}
|
||||
addEventListener(type, fn) {
|
||||
if (!this._ls.has(type)) this._ls.set(type, []);
|
||||
this._ls.get(type).push(fn);
|
||||
}
|
||||
send(raw) {
|
||||
const msg = JSON.parse(raw);
|
||||
const expr = String(msg?.params?.expression || '');
|
||||
const isProbe = expr.includes('rpcBatch') && !expr.includes('stylesCss');
|
||||
const value = isProbe
|
||||
? { alive: false, dockKind: '', visible: true, rpcBatch: [] }
|
||||
: { alive: true, dockKind: 'topbar', visible: true };
|
||||
queueMicrotask(() => {
|
||||
for (const fn of this._ls.get('message') || []) {
|
||||
fn({ data: JSON.stringify({ id: msg.id, result: { result: { value } } }) });
|
||||
}
|
||||
});
|
||||
}
|
||||
close() {}
|
||||
}
|
||||
|
||||
const ctrlBoot3 = createWindowBridgeController({
|
||||
handleApiRequest: async () => ({ status: 200, body: '{}' }),
|
||||
readAssetFn: async () => '/* bundle */',
|
||||
getSettingsFn: () => ({ windowMountMode: 'dual', enableWindowOverlay: true, modelContextWindows: {} }),
|
||||
getBundleVersionFn: () => '200',
|
||||
env: { ...simEnv, ANTIGRAVITY_DEVTOOLS_PORT: String(explicitCdpPort) },
|
||||
platform: 'win32',
|
||||
homeDir,
|
||||
autoConfigureIdeArgv: false,
|
||||
WebSocketImpl: MockCdpWs,
|
||||
});
|
||||
const resBoot3 = await ctrlBoot3.syncAllWindows();
|
||||
assert.equal(resBoot3.ok, true);
|
||||
assert.equal(resBoot3.injected, 1);
|
||||
assert.equal(ctrlBoot3.getBridgeStatus().state, 'active');
|
||||
await ctrlBoot3.stop();
|
||||
await new Promise((r) => cdpSrv.close(r));
|
||||
} finally {
|
||||
fs.rmSync(simTmp, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
// 4. Verify zh-CN / en-US i18n parity & BridgeStatusNotice DOM behavior in SettingsStructureTab + SettingsOtherTab
|
||||
const [
|
||||
{ I18N_MESSAGES_ZH_CN },
|
||||
{ I18N_MESSAGES_EN_US },
|
||||
{ setI18nLanguage },
|
||||
{ SettingsStructureTab },
|
||||
{ SettingsOtherTab },
|
||||
] = await Promise.all([
|
||||
import('../src/i18n/zh-CN.js'),
|
||||
import('../src/i18n/en-US.js'),
|
||||
import('../src/i18n/index.js'),
|
||||
import('../src/views/settings/SettingsStructureTab.js'),
|
||||
import('../src/views/settings/SettingsOtherTab.js'),
|
||||
]);
|
||||
|
||||
assert.deepEqual(
|
||||
Object.keys(I18N_MESSAGES_ZH_CN).sort(),
|
||||
Object.keys(I18N_MESSAGES_EN_US).sort()
|
||||
);
|
||||
|
||||
const { document: mockDoc, makeElement } = createMockDom();
|
||||
const prevDoc = globalThis.document;
|
||||
const prevNav = globalThis.navigator;
|
||||
let copiedClipboardText = '';
|
||||
globalThis.document = mockDoc;
|
||||
Object.defineProperty(globalThis, 'navigator', {
|
||||
value: {
|
||||
clipboard: {
|
||||
writeText: async (txt) => {
|
||||
copiedClipboardText = txt;
|
||||
},
|
||||
},
|
||||
},
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
try {
|
||||
setI18nLanguage('zh-CN');
|
||||
const strTab = SettingsStructureTab({});
|
||||
const noticeEl = strTab.refs.mountBridgeNotice.el;
|
||||
assert.equal(noticeEl.hasAttribute('hidden'), true, 'Hidden before bridge status arrives');
|
||||
|
||||
// First boot after auto-writing argv.json -> restart notice (is-restart)
|
||||
strTab.refs.renderSettings(
|
||||
{ windowMountMode: 'dual', enableWindowOverlay: true },
|
||||
{ state: 'no_devtools_port', argvUpdatedThisBoot: true, argvConfigured: true },
|
||||
'win32'
|
||||
);
|
||||
assert.equal(noticeEl.hasAttribute('hidden'), false);
|
||||
assert.equal(noticeEl.classList.contains('is-restart'), true);
|
||||
assert.match(noticeEl.textContent, /重启客户端生效/);
|
||||
|
||||
// Second boot still missing port -> warn notice with OS-specific guidance + copy flag button
|
||||
strTab.refs.renderSettings(
|
||||
{ windowMountMode: 'dual', enableWindowOverlay: true },
|
||||
{ state: 'no_devtools_port', argvUpdatedThisBoot: false, argvConfigured: true },
|
||||
'darwin'
|
||||
);
|
||||
assert.equal(noticeEl.hasAttribute('hidden'), false);
|
||||
assert.equal(noticeEl.classList.contains('is-warn'), true);
|
||||
assert.match(noticeEl.textContent, /open -a "Antigravity" --args --remote-debugging-port=0/);
|
||||
|
||||
strTab.refs.mountBridgeNotice.refs.copyBtnEl.dispatchEvent({ type: 'click' });
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
assert.equal(copiedClipboardText, '--remote-debugging-port=0');
|
||||
assert.match(strTab.refs.mountBridgeNotice.refs.copyBtnEl.textContent, /已复制/);
|
||||
|
||||
// English localization check
|
||||
setI18nLanguage('en-US');
|
||||
strTab.refs.refreshLabels();
|
||||
assert.match(noticeEl.textContent, /Local Debug Port Missing/);
|
||||
|
||||
// Switching to Sidebar Only hides notice immediately
|
||||
strTab.refs.renderSettings(
|
||||
{ windowMountMode: 'sidebar', enableWindowOverlay: false },
|
||||
{ state: 'no_devtools_port', argvUpdatedThisBoot: false, argvConfigured: true },
|
||||
'win32'
|
||||
);
|
||||
assert.equal(noticeEl.hasAttribute('hidden'), true);
|
||||
|
||||
// SettingsOtherTab context window override notice appears only when unlocked + saved override exists + no_devtools_port
|
||||
setI18nLanguage('zh-CN');
|
||||
const othTab = SettingsOtherTab({ onLayoutChange: () => {} });
|
||||
const ctxNoticeEl = othTab.refs.ctxBridgeNotice.el;
|
||||
othTab.refs.renderSettings(
|
||||
{ contextWindowRiskAccepted: true, modelContextWindows: {} },
|
||||
[],
|
||||
{ state: 'no_devtools_port', argvUpdatedThisBoot: false, argvConfigured: true },
|
||||
'win32'
|
||||
);
|
||||
assert.equal(ctxNoticeEl.hasAttribute('hidden'), true, 'Hidden when no context override is saved');
|
||||
|
||||
othTab.refs.renderSettings(
|
||||
{ contextWindowRiskAccepted: true, modelContextWindows: { 'group:gemini-pro': '384000' } },
|
||||
[],
|
||||
{ state: 'no_devtools_port', argvUpdatedThisBoot: false, argvConfigured: true },
|
||||
'win32'
|
||||
);
|
||||
assert.equal(ctxNoticeEl.hasAttribute('hidden'), false, 'Shown when context override is saved but CDP port is missing');
|
||||
assert.match(ctxNoticeEl.textContent, /上下文窗口覆写暂未注入/);
|
||||
|
||||
othTab.refs.renderSettings(
|
||||
{ contextWindowRiskAccepted: true, modelContextWindows: { 'group:gemini-pro': '384000' } },
|
||||
[],
|
||||
{ state: 'active', aliveCount: 1, argvUpdatedThisBoot: false, argvConfigured: true },
|
||||
'win32'
|
||||
);
|
||||
assert.equal(ctxNoticeEl.hasAttribute('hidden'), true, 'Hidden immediately once CDP bridge becomes active');
|
||||
|
||||
strTab.destroy();
|
||||
othTab.destroy();
|
||||
} finally {
|
||||
setI18nLanguage('zh-CN');
|
||||
globalThis.document = prevDoc;
|
||||
Object.defineProperty(globalThis, 'navigator', {
|
||||
value: prevNav,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user