basant307/AI_Governance_Project
048
1/**2 * @license3 * Copyright 2025 Google LLC4 * SPDX-License-Identifier: Apache-2.05 */6 7/**8 * Days elapsed since mtime. Floor-rounded — 0 for today, 1 for9 * yesterday, 2+ for older. Negative inputs (future mtime, clock skew)10 * clamp to 0.11 */12export function memoryAgeDays(mtimeMs: number): number {13 return Math.max(0, Math.floor((Date.now() - mtimeMs) / 86_400_000));14}15 16/**17 * Human-readable age string. Models are poor at date arithmetic —18 * a raw ISO timestamp doesn't trigger staleness reasoning the way19 * "47 days ago" does.20 */21export function memoryAge(mtimeMs: number): string {22 const d = memoryAgeDays(mtimeMs);23 if (d === 0) return 'today';24 if (d === 1) return 'yesterday';25 return `${d} days ago`;26}27 28/**29 * Plain-text staleness caveat for memories >1 day old. Returns ''30 * for fresh (today/yesterday) memories — warning there is noise.31 */32export function memoryFreshnessText(mtimeMs: number): string {33 const d = memoryAgeDays(mtimeMs);34 if (d <= 1) return '';35 return (36 `This memory is ${d} days old. ` +37 'Memories are point-in-time observations, not live state — ' +38 'claims about code behavior or file:line citations may be outdated. ' +39 'Verify against current code before asserting as fact.'40 );41}42 43/**44 * Per-memory staleness note wrapped in <system-reminder> tags.45 * Returns '' for memories ≤ 1 day old.46 */47export function memoryFreshnessNote(mtimeMs: number): string {48 const text = memoryFreshnessText(mtimeMs);49 if (!text) return '';50 return `<system-reminder>${text}</system-reminder>\n`;51}52 