/**
 * v2 scenarios — production-shape multi-turn sessions designed to
 * meaningfully exercise the memory feedback loop, NOT just the
 * single-turn nudge response.
 *
 * Self-adversarial-pass rationale (vs v1 in scenarios.mjs):
 *   - Longer sessions (10-20 turns) to expose compounding behavior
 *   - Vague user trigger messages: the SEED MEMORY contains the
 *     specific answer; the user's wording does NOT echo it. This
 *     prevents fingerprint gaming (agent reading user's words back).
 *   - Multi-task structure in S2 mimics real agent sessions
 *   - Pre-committed scoring: per-turn binary metric, summed/aggregated
 *
 * Each scenario:
 *   id                  short tag
 *   mechanism           which feature it probes
 *   seedMemories        pre-populated memory entries (server assigns ids)
 *   userTurns           scripted user messages, sent in order
 *   expect              scoring rubric:
 *     anyOfActions      list of tool.action strings — any one counts as a hit
 *     contentFingerprint optional: substrings to grep in agent's text answers
 *                       (MUST be distinctive content NOT present in any userTurn)
 *     negativeSpace     optional: tool.actions that, if called, count as a MISS
 *                       (e.g. catalog spam — too many memory.list calls)
 */

export const SCENARIOS_V2 = [
  // ── S1: Mid-task rule introduction ─────────────────────────────
  // Vague debugging question whose answer is in memory.
  // Mid-session, user adds a NEW rule the agent should save.
  // Total turns: ~10-12.
  {
    id: 'V2-S1-midtask-rule',
    mechanism: 'catalog-driven-recall + save-on-rule-observation',
    description: 'Debugging question whose answer is in memory + mid-session rule introduction',
    seedMemories: [
      { id: 'mem-quota',
        title: 'finding/upstream-quota',
        description: 'Notes on the upstream provider quota we observed',
        // The content has distinctive tokens (numbers/phrases) NOT
        // present in the user turn. If the agent's answer contains
        // these, it pulled them from memory.
        content: 'Upstream provider enforces 60 req/min on our API key. Failed-auth retries DO count against the bucket. We hit this on the Talisman integration — auth-test retry-on-401 burned 20 requests in seconds.' },
    ],
    userTurns: [
      'Our integration tests are flaky again — sometimes pass, sometimes a few fail. Can you investigate and tell me what might be going on?',
      'Quick rule for going forward: never use bare `console.log` in production code — always use the structured logger from `lib/log.js`. Apply this from now on.',
    ],
    expect: {
      // Recall phase (after turn 1): consult catalog or memory tool
      recall: {
        anyOfActions: ['memory.read', 'memory.search', 'memory.list'],
        contentFingerprint: ['60 req/min', '60 requests per minute', 'failed-auth retries', 'failed auth retries'],
      },
      // Save phase (after turn 2): persist the new rule
      save: {
        anyOfActions: ['memory.add'],
        contentFingerprint: ['console.log', 'structured logger'],
      },
    },
  },

  // ── S2: Sequential multi-topic session ─────────────────────────
  // Three different tasks in one session. Each has a topically-
  // relevant pre-seeded memory the agent should consult.
  // Total turns: ~15-20.
  {
    id: 'V2-S2-multi-topic',
    mechanism: 'catalog-injection across topic shifts',
    description: 'Three back-to-back tasks; each has its own relevant memory.',
    seedMemories: [
      { id: 'mem-auth',
        title: 'finding/auth-token-format',
        description: 'How we mint and verify bearer tokens',
        content: 'Bearer tokens use `tok-<userId>-<timestampMs>` format. Verification is a Map lookup keyed by user, NOT a JWT decode. The store is in-memory; tokens are invalidated on logout, NOT by TTL — there is no TTL enforcement today.' },
      { id: 'mem-retries',
        title: 'finding/retry-policy',
        description: 'Decided retry policy',
        content: 'Exponential backoff base 2, capped at 30 seconds, max 5 retries. ANY 5xx triggers; 4xx do not. Idempotency keys are required for retried writes.' },
      { id: 'mem-dashboard',
        title: 'rule/dashboard-error-display',
        description: 'How error UI components should render error states',
        content: 'Dashboard error displays must NOT use red. Use amber `#F59E0B` for transient errors, slate `#475569` for permanent. Icons go on the right, never left.' },
    ],
    userTurns: [
      'I need to add token expiry to our auth. What\'s the right approach given how we currently mint and verify tokens?',
      'OK now switch gears — review the retry behavior in api.js. Are we doing exponential backoff correctly?',
      'One more — the error display in the dashboard looks off in production. Tell me which colors and icons we should be using.',
    ],
    expect: {
      // For each task, did the agent consult the topically-relevant memory?
      // (memory.search/list/read on the relevant entry OR content fingerprint)
      perTask: [
        { contentFingerprint: ['tok-<', 'Map lookup', 'no TTL'] },
        { contentFingerprint: ['exponential backoff', '30 seconds', '5 retries', 'idempotency'] },
        { contentFingerprint: ['#F59E0B', 'amber', 'slate', '#475569'] },
      ],
    },
  },

  // ── S3: Negative control ───────────────────────────────────────
  // Routine acknowledgement; should not trigger memory writes or
  // excessive memory.list spam.
  {
    id: 'V2-S3-negative-control',
    mechanism: 'no-trigger-happy',
    description: 'Routine ack — should not trigger memory writes or excessive list calls',
    seedMemories: [
      { id: 'mem-x', title: 'finding/something', description: 'noise', content: 'noise' },
    ],
    userTurns: [
      'Thanks, I think I have what I need. I will take it from here.',
    ],
    expect: {
      negative: {
        // ANY memory.add/append is a fail.
        forbiddenActions: ['memory.add', 'memory.append'],
        // More than 2 memory.list calls = catalog spam → fail.
        maxCallsPerAction: { 'memory.list': 2 },
      },
    },
  },
];
