New projectinstance package validates three-duty separation, issues confirmation tokens, and activates immutable workflow instances; new projects start in planning mode. Co-authored-by: Cursor <cursoragent@cursor.com>
32 lines
696 B
Go
32 lines
696 B
Go
package projectinstance
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"sort"
|
|
)
|
|
|
|
func computePlanHash(plan WorkflowPlan) (string, error) {
|
|
normalized := normalizePlan(plan)
|
|
raw, err := json.Marshal(normalized)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
sum := sha256.Sum256(raw)
|
|
return hex.EncodeToString(sum[:]), nil
|
|
}
|
|
|
|
func normalizePlan(plan WorkflowPlan) WorkflowPlan {
|
|
out := plan
|
|
sort.Slice(out.Stages, func(i, j int) bool {
|
|
return out.Stages[i].StageKey < out.Stages[j].StageKey
|
|
})
|
|
for i := range out.Stages {
|
|
sort.Slice(out.Stages[i].DocTasks, func(a, b int) bool {
|
|
return out.Stages[i].DocTasks[a].TaskKey < out.Stages[i].DocTasks[b].TaskKey
|
|
})
|
|
}
|
|
return out
|
|
}
|