Derive stable prompt sessions for CLI runs
This commit is contained in:
26
internal/cli/session.go
Normal file
26
internal/cli/session.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const generatedSessionIDPrefix = "notarius:v1:"
|
||||
|
||||
func resolvePromptSessionID(explicitSessionID, inputModule string, rawInput []byte) (string, error) {
|
||||
inputModule = strings.TrimSpace(inputModule)
|
||||
if inputModule == "" {
|
||||
return "", fmt.Errorf("resolve prompt session: input module key must not be empty")
|
||||
}
|
||||
if sessionID := strings.TrimSpace(explicitSessionID); sessionID != "" {
|
||||
return sessionID, nil
|
||||
}
|
||||
|
||||
hasher := sha256.New()
|
||||
_, _ = hasher.Write([]byte(inputModule))
|
||||
_, _ = hasher.Write([]byte{0})
|
||||
_, _ = hasher.Write(rawInput)
|
||||
return generatedSessionIDPrefix + hex.EncodeToString(hasher.Sum(nil)), nil
|
||||
}
|
||||
Reference in New Issue
Block a user