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);
});