mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 09:07:40 +00:00
* fix(orcad): materialize the app's agent-browser driver into the local slot Replaces #34111's ORCA_AGENT_BROWSER_DRIVER hand-off, Windows profile copy and claimed snapshot store. Packaging now references the app's own resources/agent-browser-<target> from the orcad template manifest (packagedBrowser, like packagedRipgrep), so the materialized slot carries it and every local orcad launch finds it beside orcad-server.js. macOS signs the driver before hashing; Windows reseals it after SignPath. The resolver now also tries the musl driver name on Linux. Refs #33846 * build(orcad): let a checkout keep template drivers with ORCAD_OMIT_AGENT_BROWSER=0
57 lines
2.3 KiB
JavaScript
57 lines
2.3 KiB
JavaScript
const { createHash } = require('node:crypto')
|
|
const { existsSync, readFileSync, writeFileSync } = require('node:fs')
|
|
const { join } = require('node:path')
|
|
const { ORCAD_TEMPLATE_MANIFEST_FILENAME } = require('../../src/shared/orcad-artifacts.ts')
|
|
const { orcadAgentBrowserNativeName } = require('../../src/shared/orcad-agent-browser-name.ts')
|
|
const { verifyPackagedOrcadTemplate } = require('./verify-packaged-orcad-template.cjs')
|
|
|
|
function sha256(path) {
|
|
return createHash('sha256').update(readFileSync(path)).digest('hex')
|
|
}
|
|
|
|
function targetBrowserName(target) {
|
|
const [platform, arch] = target.split('-')
|
|
return orcadAgentBrowserNativeName(platform, arch, target.endsWith('-musl') ? 'musl' : 'glibc')
|
|
}
|
|
|
|
function manifestPath(resourcesDir) {
|
|
return join(resourcesDir, 'orcad-template', ORCAD_TEMPLATE_MANIFEST_FILENAME)
|
|
}
|
|
|
|
/** The template omits drivers for size; point a target at the app's own copy so its slot still gets one (#33846). */
|
|
function referencePackagedOrcadBrowser(resourcesDir) {
|
|
const path = manifestPath(resourcesDir)
|
|
const manifest = JSON.parse(readFileSync(path, 'utf8'))
|
|
const referenced = []
|
|
for (const [target, entry] of Object.entries(manifest.targets)) {
|
|
const browserName = targetBrowserName(target)
|
|
if (entry.browserName || !existsSync(join(resourcesDir, browserName))) {
|
|
continue
|
|
}
|
|
entry.browserName = browserName
|
|
entry.browserSha256 = sha256(join(resourcesDir, browserName))
|
|
entry.packagedBrowser = true
|
|
referenced.push(target)
|
|
}
|
|
if (referenced.length > 0) {
|
|
writeFileSync(path, `${JSON.stringify(manifest, null, 2)}\n`)
|
|
}
|
|
verifyPackagedOrcadTemplate(resourcesDir)
|
|
return referenced
|
|
}
|
|
|
|
/** Reseal referenced drivers the Windows signer rewrote; `signedResourcePaths` are resources-relative. */
|
|
function resealSignedPackagedBrowser(resourcesDir, signedResourcePaths) {
|
|
const path = manifestPath(resourcesDir)
|
|
const manifest = JSON.parse(readFileSync(path, 'utf8'))
|
|
const signed = new Set(signedResourcePaths)
|
|
for (const entry of Object.values(manifest.targets)) {
|
|
if (entry.packagedBrowser && signed.has(entry.browserName)) {
|
|
entry.browserSha256 = sha256(join(resourcesDir, entry.browserName))
|
|
}
|
|
}
|
|
writeFileSync(path, `${JSON.stringify(manifest, null, 2)}\n`)
|
|
}
|
|
|
|
module.exports = { referencePackagedOrcadBrowser, resealSignedPackagedBrowser }
|