fix(bridge): workbench.html inline v3 script injection + both-HTML loop patch #task-264
This commit is contained in:
@@ -286,17 +286,24 @@ async function setupApprovalObserver() {
|
||||
logToFile(`[OBSERVER] script written → ${scriptPath} (port=${bridgePort})`);
|
||||
if (!integration.isInstalled()) {
|
||||
patcher.install(combinedScript);
|
||||
logToFile('[OBSERVER] workbench.html patched (needs reload)');
|
||||
logToFile('[OBSERVER] patcher.install() called (needs reload)');
|
||||
}
|
||||
// Also patch workbench-jetski-agent.html (Antigravity's actual entry point!)
|
||||
// IMPORTANT: vscode-file:// does NOT serve custom .js files (silent 404),
|
||||
// so we MUST inline the script directly into the HTML.
|
||||
// Patch BOTH HTML files with inline script injection.
|
||||
// CRITICAL: vscode-file:// does NOT serve custom .js files (silent 404),
|
||||
// so we MUST inline the script directly into BOTH HTML files.
|
||||
// workbench.html — loaded by DevTools/standard mode
|
||||
// workbench-jetski-agent.html — loaded by AG agent mode
|
||||
const scriptDir = path.dirname(scriptPath);
|
||||
const jetskiHtml = path.join(scriptDir, 'workbench-jetski-agent.html');
|
||||
try {
|
||||
if (fs.existsSync(jetskiHtml)) {
|
||||
let html = fs.readFileSync(jetskiHtml, 'utf8');
|
||||
// Remove old external script tag if present
|
||||
const htmlFiles = ['workbench.html', 'workbench-jetski-agent.html'];
|
||||
for (const htmlFileName of htmlFiles) {
|
||||
const htmlPath = path.join(scriptDir, htmlFileName);
|
||||
try {
|
||||
if (!fs.existsSync(htmlPath)) {
|
||||
logToFile(`[OBSERVER] ${htmlFileName} not found — skipping`);
|
||||
continue;
|
||||
}
|
||||
let html = fs.readFileSync(htmlPath, 'utf8');
|
||||
// Remove old external script tag if present (legacy, cannot be served)
|
||||
const extMarkerStart = '<!-- AG SDK [variet-gravity-bridge] -->';
|
||||
const extMarkerEnd = '<!-- /AG SDK [variet-gravity-bridge] -->';
|
||||
if (html.includes(extMarkerStart)) {
|
||||
@@ -304,7 +311,7 @@ async function setupApprovalObserver() {
|
||||
'[\\s\\S]*?' +
|
||||
extMarkerEnd.replace(/[[\]]/g, '\\$&') + '\\n?');
|
||||
html = html.replace(extRe, '');
|
||||
logToFile('[OBSERVER] removed external script tag from jetski HTML');
|
||||
logToFile(`[OBSERVER] removed external script tag from ${htmlFileName}`);
|
||||
}
|
||||
// Insert or update inline script
|
||||
const inlineMarkerStart = '<!-- AG SDK INLINE [variet-gravity-bridge] -->';
|
||||
@@ -314,17 +321,17 @@ async function setupApprovalObserver() {
|
||||
'[\\s\\S]*?' +
|
||||
inlineMarkerEnd.replace(/[[\]]/g, '\\$&'));
|
||||
html = html.replace(re, `${inlineMarkerStart}\n<script>\n${combinedScript}\n</script>\n${inlineMarkerEnd}`);
|
||||
logToFile('[OBSERVER] jetski HTML inline script UPDATED');
|
||||
logToFile(`[OBSERVER] ${htmlFileName} inline script UPDATED`);
|
||||
}
|
||||
else {
|
||||
html = html.replace('</html>', `\n${inlineMarkerStart}\n<script>\n${combinedScript}\n</script>\n${inlineMarkerEnd}\n</html>`);
|
||||
logToFile('[OBSERVER] jetski HTML inline script INSERTED');
|
||||
logToFile(`[OBSERVER] ${htmlFileName} inline script INSERTED`);
|
||||
}
|
||||
fs.writeFileSync(jetskiHtml, html, 'utf8');
|
||||
fs.writeFileSync(htmlPath, html, 'utf8');
|
||||
}
|
||||
catch (e) {
|
||||
logToFile(`[OBSERVER] ${htmlFileName} patch error: ${e.message}`);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
logToFile(`[OBSERVER] jetski patch error: ${e.message}`);
|
||||
}
|
||||
}
|
||||
// 4. Update product.json checksums so vscode-file:// serves our patched files
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -246,19 +246,26 @@ async function setupApprovalObserver() {
|
||||
logToFile(`[OBSERVER] script written → ${scriptPath} (port=${bridgePort})`);
|
||||
if (!integration.isInstalled()) {
|
||||
patcher.install(combinedScript);
|
||||
logToFile('[OBSERVER] workbench.html patched (needs reload)');
|
||||
logToFile('[OBSERVER] patcher.install() called (needs reload)');
|
||||
}
|
||||
|
||||
// Also patch workbench-jetski-agent.html (Antigravity's actual entry point!)
|
||||
// IMPORTANT: vscode-file:// does NOT serve custom .js files (silent 404),
|
||||
// so we MUST inline the script directly into the HTML.
|
||||
// Patch BOTH HTML files with inline script injection.
|
||||
// CRITICAL: vscode-file:// does NOT serve custom .js files (silent 404),
|
||||
// so we MUST inline the script directly into BOTH HTML files.
|
||||
// workbench.html — loaded by DevTools/standard mode
|
||||
// workbench-jetski-agent.html — loaded by AG agent mode
|
||||
const scriptDir = path.dirname(scriptPath);
|
||||
const jetskiHtml = path.join(scriptDir, 'workbench-jetski-agent.html');
|
||||
try {
|
||||
if (fs.existsSync(jetskiHtml)) {
|
||||
let html = fs.readFileSync(jetskiHtml, 'utf8');
|
||||
const htmlFiles = ['workbench.html', 'workbench-jetski-agent.html'];
|
||||
for (const htmlFileName of htmlFiles) {
|
||||
const htmlPath = path.join(scriptDir, htmlFileName);
|
||||
try {
|
||||
if (!fs.existsSync(htmlPath)) {
|
||||
logToFile(`[OBSERVER] ${htmlFileName} not found — skipping`);
|
||||
continue;
|
||||
}
|
||||
let html = fs.readFileSync(htmlPath, 'utf8');
|
||||
|
||||
// Remove old external script tag if present
|
||||
// Remove old external script tag if present (legacy, cannot be served)
|
||||
const extMarkerStart = '<!-- AG SDK [variet-gravity-bridge] -->';
|
||||
const extMarkerEnd = '<!-- /AG SDK [variet-gravity-bridge] -->';
|
||||
if (html.includes(extMarkerStart)) {
|
||||
@@ -268,7 +275,7 @@ async function setupApprovalObserver() {
|
||||
extMarkerEnd.replace(/[[\]]/g, '\\$&') + '\\n?'
|
||||
);
|
||||
html = html.replace(extRe, '');
|
||||
logToFile('[OBSERVER] removed external script tag from jetski HTML');
|
||||
logToFile(`[OBSERVER] removed external script tag from ${htmlFileName}`);
|
||||
}
|
||||
|
||||
// Insert or update inline script
|
||||
@@ -283,16 +290,16 @@ async function setupApprovalObserver() {
|
||||
);
|
||||
html = html.replace(re,
|
||||
`${inlineMarkerStart}\n<script>\n${combinedScript}\n</script>\n${inlineMarkerEnd}`);
|
||||
logToFile('[OBSERVER] jetski HTML inline script UPDATED');
|
||||
logToFile(`[OBSERVER] ${htmlFileName} inline script UPDATED`);
|
||||
} else {
|
||||
html = html.replace('</html>',
|
||||
`\n${inlineMarkerStart}\n<script>\n${combinedScript}\n</script>\n${inlineMarkerEnd}\n</html>`);
|
||||
logToFile('[OBSERVER] jetski HTML inline script INSERTED');
|
||||
logToFile(`[OBSERVER] ${htmlFileName} inline script INSERTED`);
|
||||
}
|
||||
fs.writeFileSync(jetskiHtml, html, 'utf8');
|
||||
fs.writeFileSync(htmlPath, html, 'utf8');
|
||||
} catch (e: any) {
|
||||
logToFile(`[OBSERVER] ${htmlFileName} patch error: ${e.message}`);
|
||||
}
|
||||
} catch (e: any) {
|
||||
logToFile(`[OBSERVER] jetski patch error: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user