fix(panel): harden 2.33.0+ context window override injection and pending-restart status

- Inject backend pre-resolved MODEL_* fallback rules into syncHostContextWindows so
  context window overrides remain active even when window.__APP_CONFIG__.csrfToken is
  omitted, and extend request interception to cover StartCascade, URL inputs, Uint8Array
  JSON bodies, and application/connect+json 5-byte envelopes
- Trigger shortcut/launcher provisioning on modelContextWindows updates and surface the
  context-mode BridgeStatusNotice banner in App.js even when windowMountMode is 'sidebar'
- Show explicit '待重启生效' / 'Pending Restart' meta badge in SettingsOtherTab model
  dropdown and reveal ctxBridgeNotice immediately upon unlocking when CDP is inactive

Closes #27
This commit is contained in:
fish
2026-11-18 22:08:39 +09:00
parent 955dfeebb7
commit d665fb0c34
11 changed files with 293 additions and 37 deletions
@@ -210,3 +210,97 @@ test('host requests apply a rule only to the exact model across App and IDE tran
assert.equal(window.fetch, nativeFetch);
assert.equal(WebSocket.prototype.send, nativeSend);
});
test('Issue #27: syncHostContextWindows falls back to backend pre-resolved rules without __APP_CONFIG__.csrfToken and intercepts StartCascade + Uint8Array / connect+json frames', async () => {
const sendPath = '/exa.language_server_pb.LanguageServerService/SendUserCascadeMessage';
const startPath = '/exa.language_server_pb.LanguageServerService/StartCascade';
const host = 'https://127.0.0.1:26190';
const nativeFetch = async (_url, init) => init;
class WebSocket {
constructor(url) {
this.url = url;
}
send(data) {
return data;
}
}
const window = {
location: new URL(host),
fetch: nativeFetch,
WebSocket,
__APP_CONFIG__: {}, // Simulate 2.33.0+ environment without exposed csrfToken on window
};
const context = vm.createContext({
window,
URL,
TextEncoder,
TextDecoder,
Headers,
Uint8Array,
AbortSignal,
setTimeout,
clearTimeout,
});
const prefs = { [carbonGroup]: '256000' };
const fallbackRules = { [carbon]: 256000, [carbonLow]: 256000 };
const syncResult = await vm.runInContext(
createContextWindowSyncExpression(prefs, 'boot-233', fallbackRules),
context
);
assert.deepEqual({ ...syncResult }, { attached: true, ruleCount: 2 });
try {
// 1. StartCascade on new conversation creation with Uint8Array JSON body
const startPayload = {
cascadeConfig: {
plannerConfig: { planModel: carbon },
checkpointConfig: { maxTokenLimit: 512000 },
},
};
const uint8Body = new TextEncoder().encode(JSON.stringify(startPayload));
const startOut = await window.fetch(new URL(host + startPath), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: uint8Body,
});
assert.equal(startOut.body instanceof Uint8Array, true);
assert.equal(
JSON.parse(new TextDecoder().decode(startOut.body)).cascadeConfig.checkpointConfig
.maxTokenLimit,
256000
);
// 2. application/connect+json 5-byte envelope on SendUserCascadeMessage
const msgBytes = Buffer.from(JSON.stringify(startPayload), 'utf8');
const connectFrame = new Uint8Array(5 + msgBytes.length);
new DataView(connectFrame.buffer).setUint32(1, msgBytes.length);
connectFrame.set(msgBytes, 5);
const framedOut = await window.fetch(host + sendPath, {
method: 'POST',
headers: { 'Content-Type': 'application/connect+json' },
body: connectFrame,
});
const decodedJson = JSON.parse(
new TextDecoder().decode(framedOut.body.subarray(5))
);
assert.equal(decodedJson.cascadeConfig.checkpointConfig.maxTokenLimit, 256000);
// 3. WebSocket StartCascade frame
const ws = new WebSocket('wss://127.0.0.1:26190/connect-websocket');
const wsFrame = JSON.parse(
ws.send(
JSON.stringify({
type: 'start',
stream: false,
procedure: startPath,
payload: startPayload,
})
)
);
assert.equal(wsFrame.payload.cascadeConfig.checkpointConfig.maxTokenLimit, 256000);
} finally {
await vm.runInContext(createContextWindowSyncExpression({}, 'boot-233', {}), context);
}
assert.equal(window.fetch, nativeFetch);
});
+40 -5
View File
@@ -5306,26 +5306,61 @@ test('Issue #26: Antigravity Desktop 2.33.0+ automatic shortcut/launcher provisi
);
assert.equal(noticeEl.hasAttribute('hidden'), true);
// SettingsOtherTab context window override notice
// SettingsOtherTab context window override notice & pending-restart meta state (Issue #27)
setI18nLanguage('zh-CN');
const othTab = SettingsOtherTab({ onLayoutChange: () => {} });
const ctxNoticeEl = othTab.refs.ctxBridgeNotice.el;
const mockCtxModels = [
{
id: 'model:gemini-4-carbon',
label: 'Gemini 4 Carbon',
capacity: 786432,
members: ['MODEL_PLACEHOLDER_M427'],
options: [{ name: '256000', tokens: 256000 }, { name: '512000', tokens: 512000 }],
},
];
// Locked risk mask -> notice stays hidden
othTab.refs.renderSettings(
{ contextWindowRiskAccepted: true, modelContextWindows: { 'group:gemini-pro': '384000' } },
[],
{ contextWindowRiskAccepted: false, modelContextWindows: {} },
mockCtxModels,
{ state: 'no_devtools_port', launcherConfigured: true, canRelaunch: true },
'win32'
);
assert.equal(ctxNoticeEl.hasAttribute('hidden'), true);
// Unlocked + no_devtools_port -> notice immediately visible AND saved option meta shows "待重启生效" instead of "已设置"
othTab.refs.renderSettings(
{
contextWindowRiskAccepted: true,
modelContextWindows: { 'model:gemini-4-carbon': '256000' },
},
mockCtxModels,
{ state: 'no_devtools_port', launcherConfigured: true, canRelaunch: true },
'win32'
);
assert.equal(ctxNoticeEl.hasAttribute('hidden'), false);
assert.match(ctxNoticeEl.textContent, /激活上下文覆写/);
othTab.refs.ctxModelSelect.refs.triggerBtn.dispatchEvent({
type: 'click',
stopPropagation() {},
});
assert.match(
othTab.refs.ctxModelSelect.refs.menuEl.textContent,
/256,000 token · 待重启生效/
);
othTab.refs.renderSettings(
{ contextWindowRiskAccepted: true, modelContextWindows: { 'group:gemini-pro': '384000' } },
[],
{
contextWindowRiskAccepted: true,
modelContextWindows: { 'model:gemini-4-carbon': '256000' },
},
mockCtxModels,
{ state: 'active', aliveCount: 1, launcherConfigured: true, canRelaunch: true },
'win32'
);
assert.equal(ctxNoticeEl.hasAttribute('hidden'), true);
assert.match(othTab.refs.ctxModelSelect.refs.menuEl.textContent, /256,000 token · 已设置/);
globalBanner.destroy();
strTab.destroy();