{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Module 5 — Claude Code & Repository Context\n",
    "\n",
    "This module is about the Claude Code CLI rather than the Python SDK. The cells below scaffold the three patterns architects need: **path-scoped rules** in `.claude/rules/`, **agent skills** with isolated context, and **non-interactive CI/CD execution** with the `-p` flag.\n",
    "\n",
    "Each cell writes a config file into a `module5_demo/` folder so you can inspect the structure without touching your real project."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Path-scoped rule (`.claude/rules/brand-voice.md`)\n",
    "\n",
    "YAML frontmatter with `globs` ensures these instructions only enter Claude's context when working on matched files — keeps the context window focused."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pathlib import Path\n",
    "\n",
    "rules_dir = Path(\"module5_demo/.claude/rules\")\n",
    "rules_dir.mkdir(parents=True, exist_ok=True)\n",
    "\n",
    "(rules_dir / \"brand-voice.md\").write_text(\n",
    "    \"\"\"---\n",
    "globs: [\"whitepapers/**/*.md\", \"blog/**/*.md\"]\n",
    "---\n",
    "# Brand Voice Rules\n",
    "- Never use industry jargon without defining it.\n",
    "- Always highlight the \\\"AI-human partnership\\\" in every conclusion.\n",
    "- Maintain a professional yet accessible tone.\n",
    "\"\"\",\n",
    "    encoding=\"utf-8\",\n",
    ")\n",
    "\n",
    "print(\"wrote\", rules_dir / \"brand-voice.md\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Agent skill with `context: fork`\n",
    "\n",
    "`context: fork` runs the skill in an isolated execution environment so verbose output (e.g. a full competitor scrape) doesn't pollute your main strategy session.\n",
    "\n",
    "> **ZDR note:** Agent Skills are **not ZDR-eligible**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "skill_dir = Path(\"module5_demo/.claude/skills/competitor-research\")\n",
    "skill_dir.mkdir(parents=True, exist_ok=True)\n",
    "\n",
    "(skill_dir / \"SKILL.md\").write_text(\n",
    "    \"\"\"---\n",
    "name: competitor-research\n",
    "description: Scrapes and summarizes competitor pricing pages\n",
    "context: fork\n",
    "allowed-tools: [web_search, web_fetch]\n",
    "---\n",
    "# Competitor Research Skill\n",
    "1. Search for the target company's pricing page.\n",
    "2. Fetch the full page content.\n",
    "3. Return a structured JSON summary of their tiers and prices.\n",
    "\"\"\",\n",
    "    encoding=\"utf-8\",\n",
    ")\n",
    "\n",
    "print(\"wrote\", skill_dir / \"SKILL.md\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. CI/CD invocation\n",
    "\n",
    "`-p` is print mode: Claude runs non-interactively so the pipeline never hangs waiting for input. `--output-format json` produces structured output you can pipe into downstream automation. The cell below just prints the command — run it in your CI step, not from this notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ci_command = (\n",
    "    'claude -p \"Run the SEO audit skill on /blog and output findings\" '\n",
    "    '--output-format json > audit-results.json'\n",
    ")\n",
    "print(ci_command)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
