Skip to content

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More

1.1 KB
Raw Blame
import { stripMemoryTags } from '../../utils/tag-stripping.js';
import { retainTextHeadTail } from '../../shared/text-truncation.js';
import { logger } from '../../utils/logger.js';

export const MAX_STORED_PROMPT_CHARS = 4000;

// Stand-in written when a session is initialized with no usable prompt text; later real prompts may replace this durable value.
export const MEDIA_PROMPT_PLACEHOLDER = '[media prompt]';

export function normalizeStoredPromptText(promptText: string): string {
  // Never fall back to the raw text: a prompt that is entirely <private> (or
  // other memory tags) must not be stored, unstripped and unredacted.
  const preferredPrompt = stripMemoryTags(promptText).trim();

  if (preferredPrompt.length <= MAX_STORED_PROMPT_CHARS) {
    return preferredPrompt;
  }

  // Keep stored prompt history bounded; search/timeline views need the user ask, not the full wrapper blob.
  logger.debug('DB', 'Truncated stored prompt text to the configured cap', {
    originalLength: preferredPrompt.length,
    storedLength: MAX_STORED_PROMPT_CHARS,
  });
  return `${retainTextHeadTail(preferredPrompt, MAX_STORED_PROMPT_CHARS - 1, 0).head}…`;
}