Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

25.9 KB
Raw Blame
<!doctype html>
<html lang="en">
<head>
<!-- Google tag (gtag.js), Google Ads AW-18388216863. Loaded only when Do Not Track is
     off, so it follows the same rule as the PostHog block on this site. -->
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){ dataLayer.push(arguments); }
  if (navigator.doNotTrack !== '1') {
    var gtagScript = document.createElement('script');
    gtagScript.async = true;
    gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=AW-18388216863';
    document.head.appendChild(gtagScript);
    gtag('js', new Date());
    gtag('config', 'AW-18388216863');
  }
</script>

<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>How to Debug a Multi-Agent System — Munder Difflin Blog</title>
<meta name="description" content="How to debug a multi-agent system: use the event log, per-agent terminals, message trails, and git history to find why a hive of AI agents went sideways." />
<link rel="canonical" href="https://munderdiffl.in/blog/debugging-multi-agent-systems/" />

<link rel="icon" type="image/png" href="https://munderdiffl.in/logo.png" />
<link rel="apple-touch-icon" href="https://munderdiffl.in/logo.png" />
<meta name="theme-color" content="#F5F2E8" />

<!-- Open Graph -->
<meta property="og:site_name" content="Munder Difflin Blog" />
<meta property="og:type" content="article" />
<meta property="og:title" content="How to Debug a Multi-Agent System — Munder Difflin Blog" />
<meta property="og:description" content="How to debug a multi-agent system: use the event log, per-agent terminals, message trails, and git history to find why a hive of AI agents went sideways." />
<meta property="og:url" content="https://munderdiffl.in/blog/debugging-multi-agent-systems/" />
<meta property="og:image" content="https://munderdiffl.in/blog/assets/media/debugging-multi-agent-systems/hero.png" />
<meta property="og:image:width" content="1600" />
<meta property="og:image:height" content="900" />
<meta property="og:image:alt" content="Illustration: How to Debug a Multi-Agent System" />
<meta property="og:locale" content="en_US" />
<meta property="article:published_time" content="2026-06-04T00:00:00.000Z" />
<meta property="article:author" content="Chaitanya Giri" />
<meta property="article:tag" content="Guides" />
<meta property="article:tag" content="Debugging" />
<meta property="article:tag" content="Observability" />
<meta property="article:tag" content="Multi-Agent" />


<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="How to Debug a Multi-Agent System — Munder Difflin Blog" />
<meta name="twitter:description" content="How to debug a multi-agent system: use the event log, per-agent terminals, message trails, and git history to find why a hive of AI agents went sideways." />
<meta name="twitter:image" content="https://munderdiffl.in/blog/assets/media/debugging-multi-agent-systems/hero.png" />
<meta name="twitter:image:alt" content="Illustration: How to Debug a Multi-Agent System" />

<link rel="alternate" type="application/atom+xml" title="Munder Difflin Blog" href="https://munderdiffl.in/blog/feed.xml" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,[email protected],500;9..144,600;9..144,700;9..144,900&amp;family=Source+Serif+4:opsz,[email protected],400;8..60,600;8..60,700&amp;family=Space+Grotesk:wght@500;600;700&amp;family=JetBrains+Mono:wght@400;600&amp;display=swap" rel="stylesheet" />
<link rel="stylesheet" href="/blog/assets/blog-press.css" />

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": "How to Debug a Multi-Agent System",
  "description": "How to debug a multi-agent system: use the event log, per-agent terminals, message trails, and git history to find why a hive of AI agents went sideways.",
  "image": ["https://munderdiffl.in/blog/assets/media/debugging-multi-agent-systems/hero.png"],
  "datePublished": "2026-06-04T00:00:00.000Z",
  "dateModified": "2026-06-04T00:00:00.000Z",
  "author": { "@type": "Person", "name": "Chaitanya Giri" },
  "publisher": {
    "@type": "Organization",
    "name": "Munder Difflin",
    "logo": { "@type": "ImageObject", "url": "https://munderdiffl.in/logo.png" }
  },
  "mainEntityOfPage": { "@type": "WebPage", "@id": "https://munderdiffl.in/blog/debugging-multi-agent-systems/" },
  "keywords": "debug multi-agent system, multi-agent debugging, agent observability, event log",
  "articleSection": "Guides",
  "inLanguage": "en-US",
  "url": "https://munderdiffl.in/blog/debugging-multi-agent-systems/"
}
</script>
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [
    { "@type": "ListItem", "position": 1, "name": "Home", "item": "https://munderdiffl.in/" },
    { "@type": "ListItem", "position": 2, "name": "Blog", "item": "https://munderdiffl.in/blog/" },
    { "@type": "ListItem", "position": 3, "name": "How to Debug a Multi-Agent System", "item": "https://munderdiffl.in/blog/debugging-multi-agent-systems/" }
  ]
}
</script>

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    { "@type": "Question", "name": "How do you debug a multi-agent system?", "acceptedAnswer": { "@type": "Answer", "text": "Start from the timeline, not a single agent. Read the append-only event log to find when things diverged, follow the message trail between the agents involved, then drop into the specific agent's terminal for the byte-level detail. The order — log, messages, terminal — keeps you from guessing." } },
    { "@type": "Question", "name": "Why is debugging multiple agents harder than one?", "acceptedAnswer": { "@type": "Answer", "text": "Concurrency and interaction. A bug may not live in any one agent but in how two of them coordinated — a misrouted message, a missed handoff, a shared assumption that was wrong. You need the cross-agent view, not just per-agent logs." } },
    { "@type": "Question", "name": "What's the single most useful artifact for multi-agent debugging?", "acceptedAnswer": { "@type": "Answer", "text": "The append-only event log. It's the ordered, immutable timeline of everything that happened — who spawned, who messaged whom, what escalated — so you can replay the run and find the exact event where it went wrong." } }
    
  ]
}
</script>


<script>
  // Anonymous blog analytics (PostHog) — same posture as the main site and the
  // app's TELEMETRY.md: public write-only token ('' = inert), anonymous-only
  // (person_profiles 'never'), no autocapture/recording, DNT respected.
  (function () {
    var PH_KEY = 'phc_qJzsokwcbtTGHemnvywR3nSqivNNgMjHeNVEWkZNydFB';
    if (!PH_KEY || navigator.doNotTrack === '1') return;
    var s = document.createElement('script');
    s.async = true;
    s.src = 'https://us-assets.i.posthog.com/static/array.js';
    s.onload = function () {
      if (!window.posthog) return;
      window.posthog.init(PH_KEY, {
        api_host: 'https://us.i.posthog.com',
        person_profiles: 'never',
        autocapture: false,
        before_send: function (event) {
          // PostHog fills $ip from the connection unless the event carries one.
          // Null it here and disable the GeoIP lookup so no IP, city, postal
          // code or lat/long is ever derived or stored for this page view.
          if (event && event.properties) {
            event.properties.$ip = null;
            event.properties.$geoip_disable = true;
          }
          return event;
        },
        disable_session_recording: true,
        respect_dnt: true
      });
    };
    document.head.appendChild(s);
  })();
</script>
</head>
<body class="theme-press">
<a class="skip-link" href="#main">Skip to content</a>
<nav id="nav">
  <a class="brand" href="https://munderdiffl.in" aria-label="Munder Difflin home">
    <img class="brand-logo" src="https://munderdiffl.in/logo.png" width="1318" height="840" alt="Munder Difflin, Inc. — Multi-Agent Harness" />
  </a>
  <span class="spacer"></span>
  <div class="links">
    <a href="/blog/">Latest</a>
    <a href="/blog/topics/">Topics</a>
    <a href="/blog/about/">About</a>
    <a href="https://munderdiffl.in">↗ Product</a>
  </div>
  <div class="nav-actions">
    <a class="btn sm" href="https://munderdiffl.in/blog/feed.xml" aria-label="RSS feed">⤵ RSS</a>
    <a class="btn sm primary" href="https://munderdiffl.in/#install">⤓ Download</a>
  </div>
</nav>

<main id="main">

<article class="t-guides">
  <header class="post-head wrap">
    <nav class="crumbs" aria-label="Breadcrumb">
      <a href="/blog/">Blog</a>
      <span>/</span>
      <a href="/blog/topics/guides/">Guides</a>
    </nav>
    <h1>How to Debug a Multi-Agent System</h1>
    <p class="dek">How to debug a multi-agent system: use the event log, per-agent terminals, message trails, and git history to find why a hive of AI agents went sideways.</p>
    <div class="byline">
      <span class="av" aria-hidden="true">CG</span>
      <strong>Chaitanya Giri</strong>
      <span class="dot" aria-hidden="true">·</span>
      <time datetime="2026-06-04">Jun 4, 2026</time>
      <span class="dot" aria-hidden="true">·</span>
      <span>5 min read</span>
      <span class="tag kind">Guides</span>
    </div>
  </header>

  <div class="hero-wrap wrap"><figure class="fig fig-hero"><img src="/blog/assets/media/debugging-multi-agent-systems/hero.png" alt="Illustration: How to Debug a Multi-Agent System" loading="lazy" decoding="async" /></figure></div>

  <div class="post-wrap wrap">
    <div class="prose">
      <div class="callout tldr"><span class="ic">TL;DR</span><p>To
<strong>debug a multi-agent system</strong>, work from the outside in: read the
<strong>event log</strong> to find when the run diverged, follow the <strong>message trail</strong>
between the agents involved, then open the offending agent's <strong>terminal</strong> for byte-level
detail — and use <strong>git history</strong> to replay the coordination state. The bug often lives in
the interaction between agents, not inside any one of them, so start with the timeline.</p></div>
<p>Debugging one agent is familiar: read its output, find the bad step. Debugging a <em>hive</em> is different,
because the failure is often relational — two agents coordinated wrong, a message went to the wrong
place, a handoff never happened. Staring at a single agent’s terminal won’t show you that. This is a
practical method for finding out why a multi-agent system went sideways, using the observability a
well-built hive already gives you.</p>
<h2 id="start-with-the-timeline-not-an-agent" tabindex="-1">Start with the timeline, not an agent <a class="anchor" href="#start-with-the-timeline-not-an-agent" aria-hidden="true">#</a></h2>
<p>The first instinct — “open the agent that misbehaved” — is usually the slow path. The fast path is the
<a href="/blog/append-only-event-log-agents/">append-only event log</a>: the ordered, immutable record of
everything the hive did. Every spawn, every routed message, every escalation and approval is one
timestamped line. Read it and you get the <em>sequence</em>, which is exactly what a per-agent view hides.</p>
<p>Scan the log for the moment things diverged from what you expected:</p>
<ul>
<li>a message routed to the wrong agent (or never routed),</li>
<li>an escalation that should have fired and didn’t (or fired when it shouldn’t),</li>
<li>an agent that went idle while it still had work,</li>
<li>a burst of activity where there should have been calm.</li>
</ul>
<p>The event where reality and expectation part is your starting point. Now you know <em>which agents</em> and
<em>which moment</em> to investigate — instead of reading six terminals hoping to spot it.</p>
<h2 id="follow-the-message-trail" tabindex="-1">Follow the message trail <a class="anchor" href="#follow-the-message-trail" aria-hidden="true">#</a></h2>
<p>Multi-agent bugs frequently live in the messaging. Once the log points you at the agents involved,
follow the trail their mailboxes leave. Because messaging is file-based
(<a href="/blog/atomic-file-mailboxes-for-agents/">atomic file mailboxes</a>), the evidence is sitting on disk:</p>
<ul>
<li>An agent’s <strong>outbox archive</strong> (sent messages) shows exactly what it asked for, and how it phrased the
request.</li>
<li>An agent’s <strong>inbox</strong> and its <strong>handled folder</strong> show what it received and what it acted on.</li>
<li>The <strong>speech act</strong> on each message (<code>request</code>, <code>inform</code>, <code>done</code>…) tells you whether a reply was even
expected — a common bug is one agent replying to a terminal <code>inform</code> and starting a loop, or <em>not</em>
replying to a <code>request</code> and leaving a peer stuck.</li>
</ul>
<p>Reading the trail answers the relational question: did A actually ask B what you think it did, and did
B get it? Half of “the hive stalled” bugs resolve right here — a message that was malformed, misrouted,
or never sent.</p>
<figure class="fig fig-inline"><img src="/blog/assets/media/debugging-multi-agent-systems/note-1.png" alt="Hand-drawn sketch from “How to Debug a Multi-Agent System”" loading="lazy" decoding="async" /></figure>
<h2 id="drop-into-the-agents-terminal" tabindex="-1">Drop into the agent’s terminal <a class="anchor" href="#drop-into-the-agents-terminal" aria-hidden="true">#</a></h2>
<p>Now — and only now — open the specific agent’s terminal. Because every agent runs in a real
pseudo-terminal, you have its byte-for-byte output, not a summary. With the log and the message trail
having narrowed <em>which</em> agent and <em>which</em> moment, the terminal gives you the detail: the exact command
that failed, the error it hit, the reasoning it printed. This is where a multi-agent bug finally
becomes a single-agent bug you can fix.</p>
<p>The office floor helps here too: the <a href="/blog/visualizing-ai-agents-pixijs/">live visualization</a> shows
you, at a glance, which agent is blocked (waving at the mailbox), which is spinning, and which went
idle — often pointing you at the right terminal before you’ve even opened the log.</p>
<h2 id="replay-with-git" tabindex="-1">Replay with git <a class="anchor" href="#replay-with-git" aria-hidden="true">#</a></h2>
<p>The hive’s coordination state lives in a git repo that the main process commits to as it works (the
<a href="/blog/single-committer-git-pattern/">single-committer pattern</a>). That makes the whole run
<strong>replayable</strong>: each coordination step is a commit, so you can walk the history and reconstruct exactly
what the hive knew at any point — the roster, the pending messages, the board. When “what state was the
system in when it broke?” matters, the git log answers it precisely instead of from memory.</p>
<figure class="fig fig-inline"><img src="/blog/assets/media/debugging-multi-agent-systems/note-2.png" alt="Hand-drawn sketch from “How to Debug a Multi-Agent System”" loading="lazy" decoding="async" /></figure>
<h2 id="check-the-usual-suspects" tabindex="-1">Check the usual suspects <a class="anchor" href="#check-the-usual-suspects" aria-hidden="true">#</a></h2>
<p>Some failure modes recur in multi-agent systems. When you’re stuck, check these directly:</p>
<ul>
<li><strong>Livelock.</strong> Two agents ping-ponging. The log shows a tight back-and-forth; the fix is usually a
message type that shouldn’t have obligated a reply, or a hop cap that should have escalated.</li>
<li><strong>A stuck agent.</strong> One agent waiting on a reply that never came. The message trail shows the unanswered
<code>request</code>; the peer either didn’t receive it or didn’t treat it as needing a reply.</li>
<li><strong>Reprocessing.</strong> An agent acting on the same message twice. Check its cursor and whether handled
messages were moved aside — idempotent handling should make re-seeing a message a no-op.</li>
<li><strong>A silent escalation.</strong> Something critical that should have reached the human but didn’t (or vice
versa). The approvals queue and the log’s escalation events tell you what the policy actually did.</li>
</ul>
<h2 id="build-for-debuggability-up-front" tabindex="-1">Build for debuggability up front <a class="anchor" href="#build-for-debuggability-up-front" aria-hidden="true">#</a></h2>
<p>The reason this method works is that the observability was designed in, not bolted on. If you’re
building a multi-agent system, the lesson is to make it debuggable <em>before</em> you need to debug it:</p>
<ul>
<li>record an <strong>append-only event log</strong> so you always have a timeline,</li>
<li>keep messaging <strong>file-based and archived</strong> so trails persist,</li>
<li>give each agent a <strong>real terminal</strong> so detail is never lost, and</li>
<li>commit coordination state to <strong>git</strong> so any moment is replayable.</li>
</ul>
<p>Get those four right and “why did the hive do that?” stops being a mystery and becomes a query.</p>
<h2 id="faq" tabindex="-1">FAQ <a class="anchor" href="#faq" aria-hidden="true">#</a></h2>
<p><strong>Can I debug without stopping the agents?</strong> Yes — the log, message files, and git history are all
read-only artifacts you can inspect while the hive runs. The visualization is live. You rarely need to
halt the team to understand it.</p>
<p><strong>What if the bug is in my orchestrator’s judgment?</strong> That’s a prompt problem, not a code problem. The
log shows you the routing decision that went wrong; you correct the orchestrator’s instructions (its
escalation and routing policy) rather than patching the mechanism.</p>
<hr>
<p>Munder Difflin makes a hive debuggable by design: an event log, file-based message trails, real
per-agent terminals, a git-committed history, and <a href="https://munderdiffl.in/#how">a live floor</a>. <a href="https://munderdiffl.in/#install">Download Munder Difflin</a>
to run agents you can actually trace; it’s free and open source.</p>


      
      <section class="faq" aria-label="Frequently asked questions">
        <h2 id="faq">FAQ</h2>
        
        <div class="qa">
          <p class="q">How do you debug a multi-agent system?</p>
          <p class="a">Start from the timeline, not a single agent. Read the append-only event log to find when things diverged, follow the message trail between the agents involved, then drop into the specific agent&#39;s terminal for the byte-level detail. The order — log, messages, terminal — keeps you from guessing.</p>
        </div>
        
        <div class="qa">
          <p class="q">Why is debugging multiple agents harder than one?</p>
          <p class="a">Concurrency and interaction. A bug may not live in any one agent but in how two of them coordinated — a misrouted message, a missed handoff, a shared assumption that was wrong. You need the cross-agent view, not just per-agent logs.</p>
        </div>
        
        <div class="qa">
          <p class="q">What&#39;s the single most useful artifact for multi-agent debugging?</p>
          <p class="a">The append-only event log. It&#39;s the ordered, immutable timeline of everything that happened — who spawned, who messaged whom, what escalated — so you can replay the run and find the exact event where it went wrong.</p>
        </div>
        
      </section>
      

      
      <hr />
      <div class="share">
        <span class="lbl">Tags</span>
        <a class="tag" href="/blog/tags/guides/">Guides</a><a class="tag" href="/blog/tags/debugging/">Debugging</a><a class="tag" href="/blog/tags/observability/">Observability</a><a class="tag" href="/blog/tags/multi-agent/">Multi-Agent</a>
      </div>
      
    </div>

    
    <aside class="toc-rail" aria-label="Table of contents">
      <div class="tt">On this page</div>
      <ol>
        <li class="lvl-2"><a href="#start-with-the-timeline-not-an-agent">Start with the timeline, not an agent</a></li><li class="lvl-2"><a href="#follow-the-message-trail">Follow the message trail</a></li><li class="lvl-2"><a href="#drop-into-the-agents-terminal">Drop into the agent’s terminal</a></li><li class="lvl-2"><a href="#replay-with-git">Replay with git</a></li><li class="lvl-2"><a href="#check-the-usual-suspects">Check the usual suspects</a></li><li class="lvl-2"><a href="#build-for-debuggability-up-front">Build for debuggability up front</a></li><li class="lvl-2"><a href="#faq">FAQ</a></li>
      </ol>
    </aside>
    
  </div>

  <footer class="post-foot wrap"><div class="prevnext">
      <a class="pn prev" href="/blog/do-more-with-less-model-routing/"><span class="k">← Older</span><span class="t">Do More With Less: Smart Model Routing Across Agents</span></a>
      <a class="pn next" href="/blog/context-engineering-for-ai-agents/"><span class="k">Newer →</span><span class="t">Context Engineering for AI Agents: Budgeting the Window</span></a>
    </div>
    <section class="related">
      <h2>Related in Guides</h2>
      <div class="post-grid">
        <article class="card t-guides">
  <a class="thumb t-guides" href="/blog/claude-md-best-practices/" aria-hidden="true" tabindex="-1"><img src="/blog/assets/media/claude-md-best-practices/hero.png" alt="" loading="lazy" decoding="async" /></a>
  <div class="body">
    <div class="meta">
      <time datetime="2026-10-26">Oct 26, 2026</time>
      <span class="dot" aria-hidden="true"></span>
      <span>4 min</span>
    </div>
    <h3><a href="/blog/claude-md-best-practices/">CLAUDE.md Best Practices: What to Write, Where It Lives, How Long (Oct 2026)</a></h3>
    <p class="dek">CLAUDE.md best practices from Anthropic&#39;s docs, checked 26 Oct 2026: what to put in it, where each file lives, the 200 line target and how AGENTS.md loads.</p>
    <div class="foot">
      <span class="tag kind">Guides</span>
      <a class="more" href="/blog/claude-md-best-practices/" aria-label="Read: CLAUDE.md Best Practices: What to Write, Where It Lives, How Long (Oct 2026)">Read →</a>
    </div>
  </div>
</article>
<article class="card t-guides">
  <a class="thumb t-guides" href="/blog/codex-computer-use/" aria-hidden="true" tabindex="-1"><img src="/blog/assets/media/codex-computer-use/hero.png" alt="" loading="lazy" decoding="async" /></a>
  <div class="body">
    <div class="meta">
      <time datetime="2026-10-26">Oct 26, 2026</time>
      <span class="dot" aria-hidden="true"></span>
      <span>4 min</span>
    </div>
    <h3><a href="/blog/codex-computer-use/">Codex Computer Use: How to Turn It On, Plans and Limits (Oct 2026)</a></h3>
    <p class="dek">Codex computer use lets the ChatGPT desktop app see and click apps on macOS and Windows. Setup, which plans get it, locked use and how Claude&#39;s compares.</p>
    <div class="foot">
      <span class="tag kind">Guides</span>
      <a class="more" href="/blog/codex-computer-use/" aria-label="Read: Codex Computer Use: How to Turn It On, Plans and Limits (Oct 2026)">Read →</a>
    </div>
  </div>
</article>
<article class="card t-guides">
  <a class="thumb t-guides" href="/blog/cursor-pricing/" aria-hidden="true" tabindex="-1"><img src="/blog/assets/media/cursor-pricing/hero.png" alt="" loading="lazy" decoding="async" /></a>
  <div class="body">
    <div class="meta">
      <time datetime="2026-10-26">Oct 26, 2026</time>
      <span class="dot" aria-hidden="true"></span>
      <span>5 min</span>
    </div>
    <h3><a href="/blog/cursor-pricing/">Cursor Pricing (Oct 2026): Every Plan After the 12 Oct Change</a></h3>
    <p class="dek">Cursor pricing as of 26 Oct 2026: Free, Plus $8, Premium $30, Super $100, Ultra $200, Teams seats, what changed on 12 Oct and what old plans keep.</p>
    <div class="foot">
      <span class="tag kind">Guides</span>
      <a class="more" href="/blog/cursor-pricing/" aria-label="Read: Cursor Pricing (Oct 2026): Every Plan After the 12 Oct Change">Read →</a>
    </div>
  </div>
</article>

      </div>
    </section>
    
  </footer>
</article>

</main>
<footer class="site-foot">
  <div class="wrap">
    <div class="foot-top">
      <a class="foot-brand brand" href="https://munderdiffl.in" aria-label="Munder Difflin home">
        <img class="brand-logo" src="https://munderdiffl.in/logo.png" width="1318" height="840" alt="Munder Difflin, Inc. — Multi-Agent Harness" />
      </a>
      <div class="foot-links">
        <a href="/blog/">Latest</a>
        <a href="/blog/topics/">Topics</a>
        <a href="/blog/about/">About</a>
        <a href="https://munderdiffl.in/blog/feed.xml">RSS</a>
        <a href="https://github.com/chaitanyagiri/munder-difflin">GitHub</a>
        <a href="https://munderdiffl.in">munderdiffl.in ↗</a>
      </div>
    </div>
    <div class="foot-meta">
      © 2026 Munder Difflin · Local-first · MIT-licensed ·
      Built on <a href="https://munderdiffl.in">Electron, React, Pixi.js, xterm.js &amp; node-pty</a>.
      Run an office of agents while you sleep.
    </div>
  </div>
</footer>

<script>
  // sticky-nav border on scroll
  (function () {
    var nav = document.getElementById('nav');
    if (!nav) return;
    var onScroll = function () { nav.classList.toggle('scrolled', window.scrollY > 8); };
    onScroll(); window.addEventListener('scroll', onScroll, { passive: true });
  })();
  // YouTube click-to-load: thumbnail button → youtube-nocookie iframe
  (function () {
    document.addEventListener('click', function (e) {
      var btn = e.target.closest('.yt-load');
      if (!btn) return;
      var box = btn.closest('.yt');
      var id = box && box.getAttribute('data-yt');
      // Only an 11 character YouTube video id may reach the iframe URL.
      if (!id || !/^[A-Za-z0-9_-]{11}$/.test(id)) return;
      var frame = document.createElement('iframe');
      frame.src = 'https://www.youtube-nocookie.com/embed/' + encodeURIComponent(id) + '?autoplay=1';
      frame.title = box.getAttribute('data-title') || 'YouTube video';
      frame.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share';
      frame.setAttribute('allowfullscreen', '');
      box.replaceChildren(frame);
    });
  })();
</script>

</body>
</html>