| 1 | package workspaceid |
| 2 | |
| 3 | import ( |
| 4 | "crypto/sha256" |
| 5 | "encoding/hex" |
| 6 | "path/filepath" |
| 7 | "strings" |
| 8 | ) |
| 9 | |
| 10 | // PathFingerprint is the digest of a workspace's resolved absolute path, the |
| 11 | // key MCP launch authorizations and legacy capability activations are filed |
| 12 | // under. Unlike Key it does not follow a repository: two worktrees differ. |
| 13 | func PathFingerprint(path string) string { |
| 14 | path = strings.TrimSpace(path) |
| 15 | if path == "" { |
| 16 | return "" |
| 17 | } |
| 18 | if abs, err := filepath.Abs(path); err == nil { |
| 19 | path = abs |
| 20 | } |
| 21 | if real, err := filepath.EvalSymlinks(path); err == nil { |
| 22 | path = real |
| 23 | } |
| 24 | sum := sha256.Sum256([]byte(filepath.Clean(path))) |
| 25 | return hex.EncodeToString(sum[:]) |
| 26 | } |
| 27 |