memory-limits.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Memory size limits and thresholds — shared across daemon, legacy local-runtime plugin, and CLI.
  3. *
  4. * Layered memory architecture:
  5. * - MEMORY.md (hot layer, always injected)
  6. * - memory/<topic>.md (on-demand topic files with frontmatter description)
  7. * - daily/<date>.md (daily digests, 60-day TTL)
  8. */
  9. /** Soft target for MEMORY.md (hot layer). Above this, cleanup is encouraged but not forced. */
  10. export const MEMORY_SOFT_LIMIT_BYTES = 15 * 1024; // 15KB
  11. /** Hard limit for MEMORY.md. Above this, immediate cleanup is triggered. */
  12. export const MEMORY_HARD_LIMIT_BYTES = 20 * 1024; // 20KB
  13. /**
  14. * Threshold above which memory.append triggers an immediate cleanup spawn.
  15. * Sits between soft and hard so we curate proactively before hitting the hard cap.
  16. */
  17. export const MEMORY_CLEANUP_TRIGGER_BYTES = 18 * 1024; // 18KB
  18. /**
  19. * @deprecated No longer used for injection. Replaced by MEMORY_SUMMARY_INJECTION_CAP_CHARS
  20. * and MEMORY_TAIL_INJECTION_CAP_CHARS which provide separate budgets for summary and tail.
  21. * Kept for backward compatibility with any external consumers.
  22. */
  23. export const MEMORY_INJECTION_CAP_CHARS = MEMORY_HARD_LIMIT_BYTES;
  24. /**
  25. * Maximum characters of the .summary.md (compressed index) to inject.
  26. * Kept small so it fits alongside the tail without blowing out the token budget.
  27. */
  28. export const MEMORY_SUMMARY_INJECTION_CAP_CHARS = 4 * 1024; // 4KB
  29. /**
  30. * Maximum characters of the MEMORY.md tail to inject into system prompt.
  31. * After cleanup, MEMORY.md is expected to be ≤ 10KB, so this cap is generous.
  32. * Combined with .summary.md the total budget is ~14KB (vs previous 20KB flat).
  33. */
  34. export const MEMORY_TAIL_INJECTION_CAP_CHARS = 10 * 1024; // 10KB
  35. /** Maximum characters of daily digest content to inject for recent days (day 0-1). */
  36. export const DAILY_RECENT_CAP_CHARS = 10 * 1024; // ~10K chars
  37. /** Maximum topic files allowed per agent. Hard cap enforced by topic CRUD. */
  38. export const MAX_TOPIC_FILES = 10;
  39. /** Maximum size per topic file. */
  40. export const MAX_TOPIC_FILE_BYTES = 30 * 1024; // 30KB
  41. /** Daily digest TTL in days — older daily files get archived. */
  42. export const DAILY_DIGEST_TTL_DAYS = 60;
  43. /**
  44. * Minimum interval (ms) between immediate cleanup spawns for the same agent.
  45. * Prevents storm of cleanup sessions when an agent writes a lot in a short window.
  46. */
  47. export const CLEANUP_DEDUP_WINDOW_MS = 24 * 60 * 60 * 1000; // 24 hours
  48. /**
  49. * Minimum MEMORY.md size (bytes) required before the daily-cron cleanup runs.
  50. * After cleanup, MEMORY.md is expected to be ≤ 10KB — so if memory is already
  51. * under this threshold, running cleanup would be a no-op and waste tokens.
  52. */
  53. export const MEMORY_CLEANUP_MIN_BYTES = 10 * 1024; // 10KB