/**
 * slides/05-agents-md-context.js
 * ----------------------------------------------------------------------------
 * Slide 05 -- AGENTS.md convention
 * Context injection pattern.
 */
'use strict';

const { helpers, layouts } = require('../../design-system');

function buildAgentsMdConvention(pres, theme) {
  const slide = pres.addSlide();
  helpers.slideBase(slide, pres, theme);
  helpers.addHeader(slide, pres, theme, {
    eyebrow: 'STAGE 4',
    sectionNumber: 4,
    title: 'AGENTS.md как system prompt',
  });

  helpers.addCodeBlock(slide, pres, theme, {
    x: 0.5, y: layouts.CONTENT_TOP, w: 5.6, h: 1.7,
    language: 'python',
    code: [
      'from pathlib import Path',
      '',
      'def construct_system_prompt(',
      '    repo_dir, base_prompt',
      '):',
      '    agents_md = Path(repo_dir) / "AGENTS.md"',
      '    extra = agents_md.read_text() if',
      '        agents_md.exists() else ""',
      '    return base_prompt + extra',
    ].join('\n'),
    filePath: 'open_swe/prompts.py',
    startLine: 1,
  });

  helpers.addCodeBlock(slide, pres, theme, {
    x: 0.5, y: 3.3, w: 5.6, h: 1.55,
    language: 'markdown',
    code: [
      '# AGENTS.md  (repo root)',
      '',
      '- use uv, not pip',
      '- run pytest before commit',
      '- never push to main directly',
    ].join('\n'),
    filePath: 'AGENTS.md',
    startLine: 1,
  });

  helpers.addCallout(slide, pres, theme, {
    x: 6.3, y: layouts.CONTENT_TOP, w: 3.2, h: 1.7,
    kind: 'info',
    title: 'Convention',
    text:
      'Организационный паттерн. ' +
      'Тот же файл читают Cursor, ' +
      'Aider, Devin.',
  });

  helpers.addCallout(slide, pres, theme, {
    x: 6.3, y: 3.3, w: 3.2, h: 1.55,
    kind: 'warning',
    title: 'Подводный камень',
    text:
      'Open SWE доверяет AGENTS.md. ' +
      'Вредоносный блок попадает ' +
      'в system prompt.',
  });

  helpers.addPageNumber(slide, pres, theme, 5);
  helpers.addSourceLine(slide, pres, theme, {
    source: 'research/per-tech/openswe.md: 113-115, 200-209',
  });
  return slide;
}

module.exports = { buildAgentsMdConvention };
