@@ -4,22 +4,23 @@ import { CHROME_EXTENSION_HOST_CONTENT_VARIANT } from "./chrome-extension-consta
44
55const contractName = "Chrome plugin content-variant" ;
66const materializerSignals = [
7- ".browserSkillVariant" ,
8- ".computerUseSkillVariant" ,
9- ".pluginRoot" ,
10- ".codex-plugin"
7+ ".codex-plugin" ,
8+ "plugin.json"
119] ;
1210
1311export const linuxChromeExtensionHostContentVariantContract = {
1412 name : "linux-chrome-extension-host-content-variant" ,
1513 find : findContentVariantContract ,
1614 assertBefore ( source ) {
1715 const match = findContentVariantContract ( source ) ;
18- if ( match . status !== "patch" ) throw new Error ( "Linux Chrome content variant is already present" ) ;
16+ if ( match . status !== "patch" ) {
17+ throw new Error ( "Linux Chrome content variant does not require patching" ) ;
18+ }
1919 } ,
2020 apply : patchLinuxChromeExtensionHostContentVariant ,
2121 assertAfter ( source ) {
22- if ( ! hasLinuxChromeExtensionHostContentVariant ( source ) ) {
22+ const match = findContentVariantContract ( source ) ;
23+ if ( ! [ "patched" , "absent" ] . includes ( match . status ) ) {
2324 throw new Error ( "Linux Chrome content variant was not applied" ) ;
2425 }
2526 }
@@ -29,7 +30,7 @@ function findContentVariantContract(source) {
2930 if ( hasLinuxChromeExtensionHostContentVariant ( source ) ) {
3031 return { status : "patched" } ;
3132 }
32- return { status : "patch" , ... findContentVariantMaterializer ( source ) } ;
33+ return findContentVariantMaterializer ( source ) ;
3334}
3435
3536/**
@@ -42,6 +43,10 @@ export function patchLinuxChromeExtensionHostContentVariant(source) {
4243
4344 try {
4445 const match = findContentVariantMaterializer ( source ) ;
46+ // Newer upstream builds materialize only computer-use and visualize here.
47+ // Chrome's manifest is stamped directly in chrome-plugin-patches.mjs.
48+ if ( match . status === "absent" ) return source ;
49+
4550 const variantName = source . slice ( match . property . value . start , match . property . value . end ) ;
4651 const replacement =
4752 `${ match . pluginParameter } .pluginName===\`chrome\`?` +
@@ -84,9 +89,20 @@ function findContentVariantMaterializer(source) {
8489 if ( ! fn || pluginParameter ?. type !== "Identifier" ) return ;
8590
8691 const functionSource = source . slice ( fn . start , fn . end ) ;
87- if ( ! materializerSignals . every ( signal => functionSource . includes ( signal ) ) ) return ;
92+ const pluginParameterSignals = [
93+ `${ pluginParameter . name } .pluginName` ,
94+ `${ pluginParameter . name } .pluginRoot`
95+ ] ;
96+ if (
97+ ! [ ...materializerSignals , ...pluginParameterSignals ] . every ( signal =>
98+ functionSource . includes ( signal )
99+ )
100+ ) {
101+ return ;
102+ }
88103
89104 matches . push ( {
105+ functionSource,
90106 property : node ,
91107 pluginParameter : pluginParameter . name
92108 } ) ;
@@ -96,7 +112,50 @@ function findContentVariantMaterializer(source) {
96112 throw contractError ( `expected one runtime materializer, found ${ matches . length } ` ) ;
97113 }
98114
99- return matches [ 0 ] ;
115+ const [ match ] = matches ;
116+ if (
117+ referencesParameterProperty (
118+ match . functionSource ,
119+ match . pluginParameter ,
120+ "browserSkillVariant"
121+ ) ||
122+ hasPluginNameBranch ( match . functionSource , match . pluginParameter , "chrome" )
123+ ) {
124+ return { status : "patch" , ...match } ;
125+ }
126+
127+ if ( isKnownNonChromeMaterializer ( match . functionSource , match . pluginParameter ) ) {
128+ return { status : "absent" , ...match } ;
129+ }
130+
131+ throw contractError ( "runtime materializer does not prove whether Chrome is handled" ) ;
132+ }
133+
134+ function isKnownNonChromeMaterializer ( functionSource , pluginParameter ) {
135+ return (
136+ referencesParameterProperty (
137+ functionSource ,
138+ pluginParameter ,
139+ "computerUseSkillVariant"
140+ ) &&
141+ referencesParameterProperty (
142+ functionSource ,
143+ pluginParameter ,
144+ "liveVisualizationSkillVariant"
145+ ) &&
146+ hasPluginNameBranch ( functionSource , pluginParameter , "computer-use" ) &&
147+ hasPluginNameBranch ( functionSource , pluginParameter , "visualize" )
148+ ) ;
149+ }
150+
151+ function referencesParameterProperty ( source , parameterName , propertyName ) {
152+ return source . includes ( `${ parameterName } .${ propertyName } ` ) ;
153+ }
154+
155+ function hasPluginNameBranch ( source , parameterName , pluginName ) {
156+ return [ "`" , '"' , "'" ] . some ( quote =>
157+ source . includes ( `${ parameterName } .pluginName===${ quote } ${ pluginName } ${ quote } ` )
158+ ) ;
100159}
101160
102161function isBundledContentVariantProperty ( node ) {
0 commit comments