Files
Agent-System/internal/projectinstance/hash.go
T
weichenandCursor 9ba3d51a53 feat(service): implement project workflow plan, preview, and activation flow.
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>
2026-09-12 03:03:34 +00:00

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
}