digest.ts 1010 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * Content identity for workspace instruction duplicate suppression.
  3. *
  4. * @module @deepseek-ai/dsh-workspace-context/digest
  5. */
  6. import { createHash } from 'node:crypto'
  7. /**
  8. * Compute the content identity used across instruction loading and session state.
  9. * @param content - exact UTF-8 instruction text.
  10. * @returns lowercase SHA-1 digest in hexadecimal form.
  11. */
  12. export function instructionContentSha1(content: string): string {
  13. return createHash('sha1').update(content).digest('hex')
  14. }
  15. /**
  16. * Compute the whitespace-insensitive identity used for per-directory duplicate
  17. * suppression. Leading and trailing whitespace is trimmed before hashing so a
  18. * symlinked or byte-copied sibling that differs only by surrounding whitespace
  19. * still collapses to a single rendered file.
  20. * @param content - exact UTF-8 instruction text.
  21. * @returns SHA-1 digest of the trimmed content.
  22. */
  23. export function trimmedInstructionDigest(content: string): string {
  24. return instructionContentSha1(content.trim())
  25. }