ComputeBodyHashFromParsedContent computes a SHA-256 hash of the markdown body (after frontmatter) including the bodies of all transitively imported files. This hash covers changes to the prompt body that are not captured by the frontmatter hash. markdownBody is the raw markdown body (after the front
(markdownBody, frontmatterText, baseDir string, fileReader FileReader)
| 526 | // markdownBody is the raw markdown body (after the frontmatter --- delimiter). |
| 527 | // frontmatterText is the raw frontmatter text, used to resolve imports. |
| 528 | func ComputeBodyHashFromParsedContent(markdownBody, frontmatterText, baseDir string, fileReader FileReader) (string, error) { |
| 529 | frontmatterHashLog.Printf("Computing body hash from parsed content (baseDir=%s)", baseDir) |
| 530 | |
| 531 | normalizedBody := normalizeFrontmatterText(markdownBody) |
| 532 | |
| 533 | visited := make(map[string]struct { |
| 534 | }) |
| 535 | importedBodies, err := collectImportedBodies(frontmatterText, baseDir, visited, fileReader) |
| 536 | if err != nil { |
| 537 | return "", fmt.Errorf("failed to process imports for body hash: %w", err) |
| 538 | } |
| 539 | |
| 540 | allParts := []string{normalizedBody} |
| 541 | |
| 542 | if len(importedBodies) > 0 { |
| 543 | normalizedBodies := make([]string, len(importedBodies)) |
| 544 | for i, b := range importedBodies { |
| 545 | normalizedBodies[i] = normalizeFrontmatterText(b) |
| 546 | } |
| 547 | sort.Strings(normalizedBodies) |
| 548 | allParts = append(allParts, normalizedBodies...) |
| 549 | } |
| 550 | |
| 551 | combined := strings.Join(allParts, "\n---\n") |
| 552 | frontmatterHashLog.Printf("Body hash combined length: %d bytes", len(combined)) |
| 553 | |
| 554 | hash := sha256.Sum256([]byte(combined)) |
| 555 | hashHex := hex.EncodeToString(hash[:]) |
| 556 | frontmatterHashLog.Printf("Computed body hash: %s", hashHex) |
| 557 | return hashHex, nil |
| 558 | } |
| 559 | |
| 560 | // ComputeBodyHashFromFile computes the body hash for a workflow file from disk. |
| 561 | func ComputeBodyHashFromFile(filePath string) (string, error) { |
no test coverage detected