Fontspec/unicode-math mixing fonts: math accents

In a project we're using a commercial text font. The project is not a math related project but has some math in it here and there. The text font of course does not have a direct math font. But the XITS Math font (which is a part of standard LaTeX, at least TeX Live) seems a good enough match.

I decided to play with unicode-math to see if you could get it even closer, by changing the font for latin letters in the math font to the italic text font with the numbers being taken from the upright text font. Works surprisingly well.

Here is the catch though: since we are mixing the fonts used in math, math accents aren't placed particularly good.

I've prepared a MWE that is similar to our setup, but using a text font already in TeXLive so most people should be able to test it.

\documentclass[a4paper]{article}
\usepackage{amsmath,unicode-math}
\setmathfont[Scale=MatchUppercase]{XITS Math}
\setmathfont[range=\mathup/{num},Numbers=Lining]{Cochineal-Roman}
\setmathfont[range=it/{latin,Latin},Ligatures={NoCommon, NoDiscretionary, NoHistoric, NoRequired, NoContextual}]{Cochineal-Italic}

\setmainfont{Cochineal}[
UprightFont = *-Roman ,
BoldFont= *-Bold ,
ItalicFont = *-Italic,
BoldItalicFont = *-BoldItalic,
Numbers=Lining,
]

\begin{document}

$p^{\ast}=c\vert \hat{\jmath}\vert ^{1/2}e^{l-\hat{l}}$

\end{document}

Resulting in

As we can see the hats are placed incorrectly

If we use only XITS Math we get

Which is much more reasonably.

So my question is this, given that the accent is probably placed using the top_accent data from the XITS Math font, how can we in Lua patch this font setup such that we can fix the placement of the accent on the chars that needs it? I've seen some examples of code that should be able to do this, but could not get that to work when we are missing fonts like this.

BTW: Yes, I can also fix this on the macro level (adapted from one of egregs answers):

\usepackage{xparse}
\NewDocumentCommand{\myhat}{ m }{\myinnerhat{#1}}
% we are assuming \myhat is only being used in single chars
\ExplSyntaxOn
\NewDocumentCommand{\myinnerhat}{m}
{
\str_case_x:nnF { \tl_item:nn { #1 } { -1 } }
{
{\jmath}{\skew{5}{\hat}{\jmath}\mkern1mu}
{l}{\skew{5}{\hat}{l}}
}{
\hat{#1}
}
}
\ExplSyntaxOff