TITLE: A non-Abelian de Rham complex?
QUESTION [18 upvotes]: This question is inspired by this physics stack exchange post, which is recent and has not received an answer yet, nontheless I feel that there is a better way to ask this question here with a larger scope than the OP did there.

At first I am primarily interested in the local question so let $X$ be an $n$ dimensional smooth real manifold that if necessary might be assumed to be contractible or otherwise topological trivial.
Let us fix a Lie algebra $\mathfrak g$, let $\Omega^k(X,\mathfrak g)$ denote the module of smooth $\mathfrak g$-valued $k$-forms.
The following is known. Let us define $C:\Omega^1(X,\mathfrak g)\rightarrow \Omega^2(X,\mathfrak g)$ by $$ C(\omega)=d\omega+\frac{1}{2}[\omega\wedge\omega], $$ and call $C$ the curvature operator. It is known that at least locally $C(\omega)=0$ if and only if there is a function $f\in C^\infty(X,G)$ (where $G$ is a/the Lie group associated with $\mathfrak g$) such that $$ \omega=f^\ast\Xi_G\equiv \Delta_Gf, $$ where $\Xi_G\in\Omega^1(G,\mathfrak g)$ is the Maurer-Cartan form of $G$. I have taken the liberty of using $\Delta_G$ for this operation (nonstandard notation) and iirc this is sometimes referred to as the Darboux-derivative (treated in Sharpe for example).
Now, let $F=C(\omega)=d\omega+\frac{1}{2}[\omega\wedge\omega]\in\Omega^2(X,\mathfrak g)$. Such curvature forms satisfy the (differential) Bianchi identity $$ d_\omega F=dF+[\omega\wedge F]=0. $$
It this seems that one may define a cochain complex-like structure $$ 0\longrightarrow C^\infty(X,G)\longrightarrow^{\Delta_G}\Omega^1(X,\mathfrak g)\longrightarrow^{C}\Omega^2(X,\mathfrak g)\longrightarrow^{d_\omega}\Omega^3(X,\mathfrak g) ... $$
in that the composition of two subsequent arrows always return $0$, however this is not a true cochain complex because for example $C^\infty(X,G)$ is not an Abelian group (if $G$ is nonabelian).

What I am primarily interested in is whether it is possible to define such a sequence rigorously in some way which satisfies a local exactness property. This sequence is locally exact at $\Omega^1(X,\mathfrak g)$, which can be verified using the Frobenius integrability theorem, but - in my opinion - a more interesting question is the $\Omega^2(X,\mathfrak g)$.
Specifically what is the necessary and sufficient (local) condition for a Lie algebra valued $2$-form to be the curvature form of a connexion? Even if the Bianchi identity is a complete local integrability condition, it is formulated in terms of $2$-forms so Frobenius' theorem does not apply, moreover in order to calculate the covariant exterior derivative of the curvature $2$-form one already needs to know the connection form as well.
If a necessary and sufficient condition can be given, is there an explicit "homotopy operator" that allows one to construct a connection form from a given curvature form?

Remark:* In $\dim X=3$ the curvature form is the Euler-Lagrange form of the Chern-Simons Lagrangian, so I guess methods of the variational bicomplex could be used to attack this problem. As far as I see this only works in three dimensions though.

REPLY [8 votes]: Unfortunately, things are subtle and terrible (at least, compared to the abelian case). I wrote a bit about this in an unpublished article.
One of the surprising, terrible features is that you can have two connections ω,η such that (1) curv ω = curv η, yet (2) ω and η are not gauge equivalent. Wu and Yang discussed this problem, and I think also were responsible for calling it the "field copy problem" (or maybe the name came from Mostow, who also wrote on it). It is quite weird when you sit down and think about it in terms of Yang-Mills field theory. From that perspective, you're looking at a connection whose dynamics is determined by a Lagrangian that only involves the curvature. The field copy problem shows that with nonabelian gauge groups, you can have two distinct connections that minimize the same Yang-Mills functional. In other words, observing the curvature form doesn't tell you enough to reconstruct the connection up to gauge equivalence, even in the special case of Yang-Mills connections!
Len Gross analyzed the field copy problem in "A Poincaré Lemma for Connection Forms", where he found an alternative collection of observables that suffices to reconstruct the connection up to gauge equivalence. I tried to make sense of his results using 2-categories in the article I linked above. Ultimately my research went in a different direction and I never got to follow through with this thread in the way I would have liked.
There is also an issue with the next term of the exact-ish sequence, too (your $d_\omega$): the Bianchi identity sure looks like it should be the map to use there, as you propose. Ok, so we'll differentiate the 2-form with respect to the connection... but wait! We don't even have a connection form to put our hands on at that point! There is no $\omega$ to use!