Clear[d,tm,m]

tm[x_]:=x

m[x_]:=d[x]

d[tm[a,b]]

d[tm[a,b,c]]

d[a:t[___]]:=With[{k=Length[a]},(∑_(i=1)^k)(((-1))^((∑_(j=1)^(i-1))deg[a[[j]]]))MapAt[d,a,i]]

d[t[a,b,c]]

d[X_Plus]:=d/@X

d[(((-1))^(n_.)) X_]:=(((-1))^n) d[X]
d[s_σ X_]:=s d[X]

d[d[_]]:=0

tm[___,0,___]:=0

tm[X___,Y_Plus,Z__]:=tm[X,#,Z]&/@Y
tm[X__,Y_Plus,Z___]:=tm[X,#,Z]&/@Y
tm[X___,(((-1))^(n_.))Y_,Z___]:=(((-1))^n)tm[X,Y,Z]

t[X___,Y_Plus,Z__]:=t[X,#,Z]&/@Y
t[X__,Y_Plus,Z___]:=t[X,#,Z]&/@Y
t[X___,(((-1))^(n_.))Y_,Z___]:=(((-1))^n)t[X,Y,Z]
t[X___,s_σ Y_,Z___]:=s t[X,Y,Z]

t[X__,t[Y__],Z___]:=t[X,Y,Z]
t[X___,t[Y__],Z__]:=t[X,Y,Z]

deg[d[X_]]:=deg[X]-1

deg[a_m]:=Length[a]-2+Plus@@(deg/@List@@a)

deg[a_tm]:=Length[a]-1+Plus@@(deg/@List@@a)

d[a:HoldPattern[tm[___]]]:=With[{k=Length[a]},
(∑_(l=1)^(k-1))σ[l,List@@a] t[Take[a,l],Drop[a,l]]+
(∑_(l=1)^k)(∑_(lp=0)^(l-1))With[{l1=lp,l2=k-l+1,l3=l-1-lp},(((-1))^(l2(k-1+(∑_(j=1)^lp)deg[a[[j]]])+(k-l)(lp)))tm@@(Take[List@@a,lp]~Join~{m@@Take[List@@a,{lp+1,lp+k-l+1}]}~Join~Drop[List@@a,lp+k-l+1])]
]

(((-1))^((k-l+1)(k-1+(∑_(j=1)^lp)deg[a[[j]]])+(k-l)(lp)))

(((-1))^((l1+l2)l3+l2 (Plus@@(deg/@Take[List@@a,l1]))))

Collect[d[d[tm[a,b]]],(_tm|_d|_t),Together]

d[tm[a,b]]

Clear[σ]

σ[l_,a_List]:=With[{k=Length[a]},(((-1))^((k-l+1)(Plus@@(deg/@Take[a,l]))+l))]

d[tm[a,b,c]]

Collect[d[d[tm[a,b,c]]],(_tm|_d|_t|_m),(Together[#]/.{(((-1))^(2_))->1})&]

σ[1,{_,_,_,_}]:=-1

σ[2,{a_,b_,_,_}]:=(((-1))^(deg[a]+deg[b]))
σ[3,{_,_,_,_}]:=-1

σ[1,a_List]:=(((-1))^(Length[a]deg[a[[1]]]+1))
σ[2,a_List]:=(((-1))^((Length[a]+1)(deg[a[[1]]]+deg[a[[2]]])))
σ[3,a_List]:=(((-1))^((Length[a])(deg[a[[1]]]+deg[a[[2]]]+deg[a[[3]]])+1))

σ[k_Integer,a_List]:=(((-1))^((Length[a]+k+1)(Plus@@(deg/@Take[a,k]))+k))

Collect[d[d[tm[a,b,c,d]]],(_tm|_d|_t|_m),(Together[#]//.{(((-1))^(n_Integer x_)):>((((((-1))^n)))^x)})&]

Collect[d[d[tm[a,b,c,d,e,f,g]]],(_tm|_d|_t|_m),(Together[#]//.{(((-1))^(n_Integer x_)):>((((((-1))^n)))^x)})&]

d[-tm[a,m[b,c]]]

Collect[d[-t[a,tm[b,c]]],(_tm|_d|_t|_m),Together]

Collect[d[d[tm[a,b,c,d]]],(_tm|_d|_t|_m),Together]

d[a:HoldPattern[m[___]]]:=With[{k=Length[a]},
(∑_(r=0)^k)(∑_(s=1)^(k-r))With[{t=k-r-s},If[t<0∨r+t==0,0,(((-1))^(1+r+s t))(((-1))^(s((∑_(j=1)^r)deg[a[[j]]])))m@@(Take[List@@a,r]~Join~{m@@Take[List@@a,{r+1,r+s}]}~Join~Drop[List@@a,r+s])]]
]

d[m[a,b]]

d[m[a,b,c]]