A non-Abelian de Rham complex? 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.
 A: 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!
A: What is being described in the main post is simply the de Rham (crossed) complex valued in a Lie group (not necessarily commutative).
See, for example, Section 6.2 in Anders Kock's Synthetic Geometry of Manifolds.
One easy way to see what is going on is as follows.
Consider the usual singular simplicial set of a smooth manifold M.
One can construct singular cochains on M valued in an abelian group A
by applying the functor S↦Map(S,A) in each simplicial degree
and then invoking the Dold–Kan correspondence to convert the resulting
cosimplicial abelian group to a cochain complex.
The Dold–Kan correspondence is an equivalence of categories
(in fact, an equivalence of model categories),
so we can omit it and work with the original cosimplicial group instead.
The advantage of this is that the group A can now be nonabelian,
producing a cosimplicial group.
There is a generalized Dold–Kan correspondence for cosimplicial groups,
it produces crossed complexes,
which is the “cochain complex-like structure” from the main post.
In our case, to get the de Rham (crossed) complex, we must impose the following additional conditions:

*

*singular simplices must be smooth (as maps Δ^n→M);


*cochains must be smooth (as maps C^∞(Δ^n,M)→G);


*singular simplices must be infinitesimal: their vertices must be infinitesimally close to each other to the first order.
In coordinates, this means that the difference of coordinates
of any pair of vertices must be a real number that squares to zero.
The last condition can (must) be encoded using the formalism of functor of points, working on the site of C^∞-rings or just the Cahiers site.
(See Moerdijk and Reyes, Models for smooth infinitesimal analysis.)
If G is a real vector space, the resulting cochain complex
is precisely the de Rham complex valued in the real vector space G.
If G is an abelian Lie group, we get the Deligne complex,
used to define bundle n-gerbes with connection, alias Deligne cohomology.
If G is nonabelian, we get the de Rham (crossed) complex of differential forms
valued in a Lie group.
Its first terms are as described in the main post, but this crossed complex extends indefinitely, to arbitrary degrees.
In degree k>0, we have differential k-forms valued
in the Lie algebra of G.
The differential, however, is not the usual de Rham differential.
In particular, this crossed complex can be used to answer your question about Lie-algebra valued 2-forms in the expected way.
(For a textbook-length treatment of crossed complexes,
see Brown–Higgins–Sivera, Nonabelian Algebraic Topology.)
