SHA-256 of (system, user) joined with 0x00 separator, truncated to uint64. Drives deterministic sample-band routing: identical prompt pair → same hash → same local-vs-Claude decision on every call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
22 lines
632 B
Go
22 lines
632 B
Go
package routing
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/binary"
|
|
)
|
|
|
|
// CanonicalHash returns a deterministic 64-bit hash of (system, user).
|
|
// Used to make sample-band routing decisions reproducible: identical input
|
|
// strings produce the same hash on every call, independent of process state.
|
|
//
|
|
// Inputs are joined with a 0x00 byte separator before hashing — distinguishes
|
|
// (system="ab", user="cd") from (system="abcd", user="").
|
|
func CanonicalHash(system, user string) uint64 {
|
|
h := sha256.New()
|
|
h.Write([]byte(system))
|
|
h.Write([]byte{0})
|
|
h.Write([]byte(user))
|
|
sum := h.Sum(nil)
|
|
return binary.BigEndian.Uint64(sum[:8])
|
|
}
|