Build the MasteryMade Embeddable Agent with Claude Code
A single JavaScript bundle that embeds on any HTML page via a <script> tag. On load, it reads the page content, a JSON config, and a YAML knowledge manifest โ then renders a floating chat panel that guides users through the content. One engine. Three deployment modes. Differentiated by config, not code. Claude Code builds it. You verify it.
Traditional Approach
This Approach
Infrastructure
Infrastructure
โ ๏ธ PREREQUISITES
- Claude Max subscription ($200/month) โ gives Claude Code with generous limits
- Terminal / command line access
- Node.js 18+ installed (
node --versionto check) - Basic comfort with: running terminal commands, reading code output, copy-pasting
- This page URL โ share it with Claude Code as the spec source
#mastery-agent-config JSON โ UI and API settings the JS bundle parses, (2) #mastery-agent-knowledge YAML template โ enrichment data and related-page manifest the LLM reads directly, (3) #mastery-agent-data JSON โ the complete build PRD that Claude Code reads. Share this URL with Claude Code and it gets the full technical spec. The agent you build will read blocks 1 and 2 from future pages.
Create Project & Install Dependencies
SetupSet up the project folder, initialize npm, install esbuild, and create the folder structure. This is the only step you do mostly yourself before handing off to Claude Code.
โ Before
- No project directory
- No build tooling
- No structure for the agent source files
โ After
- Clean project with esbuild configured
- Build + dev scripts ready
- src/, dist/, test/, styles/ folders created
- Open terminal and create project directory:
mkdir mastery-agent && cd mastery-agent - Give Claude Code the initialization prompt (below)
- Verify
package.jsonhas esbuild in devDependencies - Verify build and dev scripts exist in package.json
- Verify src/, dist/, test/, styles/ folders exist
- Run
npm installto install dependencies
Expected package.json{
"name": "mastery-agent",
"version": "1.0.0",
"scripts": {
"build": "esbuild src/agent.js --bundle --outfile=dist/mastery-agent.js --minify --format=iife",
"dev": "esbuild src/agent.js --bundle --outfile=dist/mastery-agent.js --format=iife --watch --servedir=test"
},
"devDependencies": {
"esbuild": "^0.20.0"
}
}
Feed the Full Spec to Claude Code
CoreThe most important step. Claude Code needs the complete technical specification before writing a single line of code. This page has three hidden data blocks โ the config JSON, the YAML knowledge manifest, and the full PRD JSON. Claude Code needs to read all of them.
โ Before
- Claude Code has no context about the project
- Will guess at architecture decisions
- No shared understanding of schemas or specs
โ After
- Claude Code knows the full file structure, all schemas, all specs
- Understands both the YAML knowledge manifest format and the JSON config format
- Can reference specific PRD sections during build
- Share this page's URL with Claude Code (or paste the enrichment JSON)
- Wait for Claude Code to confirm it understood the spec
- Verify Claude Code understands there are THREE data blocks: config JSON, knowledge YAML template, and PRD JSON
- Verify Claude Code's proposed build order: parser (with knowledge manifest loader) โ config โ heuristics + prompt-builder โ API โ progress โ chat UI โ main entry
Build the HTML Parser + Knowledge Manifest Loader
CoreThe parser does two things: (1) reads the host page's HTML and extracts structured content via data-mastery attributes (with generic fallback), and (2) loads the knowledge manifest from the YAML <template> block (with JSON fallback). This is what makes the agent work on ANY page.
- Give Claude Code the parser prompt
- Open src/parser.js โ verify it has
parsePage()function - Verify it has
loadKnowledgeManifest()that checks <template> FIRST, then falls back to <script> JSON - Verify it does NOT import a YAML parsing library โ raw string only
- Verify it queries for ALL data-mastery attributes: title, step, step-title, step-description, substeps, substep, step-links, link, code, content, decision, action-item
- Verify
fallbackParse()function exists for pages without schema - Verify it exports both parsePage and loadKnowledgeManifest
<template> format is ~35% more token-efficient than JSON and easier for content creators to edit. The JSON fallback ensures backward compatibility with pages that haven't migrated. The agent handles both transparently โ future pages use the template, existing pages keep working.
Build Config Loader + Heuristics + Prompt Builder
CoreThree files that work together: config reads the JSON from the page, heuristics contains the "chef's brain" system prompt template, prompt-builder assembles everything โ including the knowledge manifest โ into the final system prompt. The heuristics file is the most important single artifact. The prompt builder must place the knowledge manifest BEFORE page content (order matters for LLM attention).
- Give Claude Code the combined prompt for all three files
- CHECK CAREFULLY: Open src/heuristics.js โ verify ALL 8 anti-slop rules are present
- Verify execution mode has all 5 core behaviors: orient, instruct, verify, advance, adapt
- Verify all 6 progress commands are listed: begin, next, back, step [N], status, help
- Verify prompt-builder takes 4 inputs (config, pageContent, knowledgeManifest, progress) and places manifest BEFORE page content
- Verify prompt-builder includes related-pages awareness instructions for Phase 1
- Verify config.js handles missing/malformed JSON gracefully โ returns defaults, doesn't crash
Build API Client + Progress Tracker
CoreTwo utility modules: the API client calls the Anthropic Messages API (with proxy support for production), and the progress tracker persists state in localStorage keyed by page URL.
- Give Claude Code the combined prompt
- Verify api.js supports
config.api.proxyUrlโ calls proxy when set, direct API when null - Verify api.js has try/catch with user-friendly error messages (never stack traces)
- Verify progress.js caps conversation history at 20 messages
- Verify localStorage key derives from page URL via
btoa(url).slice(0,32)
Build the Chat UI
CoreThe visual component โ a floating chat panel using Shadow DOM for complete CSS isolation from the host page. Collapsed state is a circular button, expanded shows the full chat with messages, code blocks, and progress bar. Must be vanilla JavaScript only โ no React, no frameworks.
โ Before
- No user interface
- All logic but no way to interact
- Engine exists but is invisible
โ After
- Floating chat panel in bottom-right
- Messages, code blocks, links all rendered
- Mobile responsive bottom sheet
- CSS completely isolated from host page
- Give Claude Code the chat UI prompt
- Verify Shadow DOM usage โ look for
attachShadowin the code - Verify CSS is embedded as string, injected into shadow root (not document.head)
- Verify NO React or framework imports โ must be pure
document.createElement - Verify: collapsed/expanded toggle, message rendering, code copy button, link new-tab
- Verify mobile responsive: full-width bottom sheet under 768px
Build Main Entry Point + Bundle
CoreThe main entry point orchestrates everything โ imports all modules, bootstraps on load, handles the message flow from user input through API call to response rendering. Then bundle it all into a single file.
- Give Claude Code the main entry point prompt
- Verify agent.js imports all other modules and has the bootstrap sequence
- Verify bootstrap loads knowledge manifest via loadKnowledgeManifest() and passes to buildPrompt()
- Run:
npm run build - If build fails โ paste the error to Claude Code: "Build failed with [error]. Fix it."
- Verify
dist/mastery-agent.jsexists and is under 100KB
import/export). esbuild handles the conversion to IIFE format. If you get errors about require or module.exports, tell Claude Code to convert to ES module syntax.
Build Test Pages & Run Full Testing
TestFour test pages โ three using the new YAML template format (one per deployment mode) plus one legacy JSON page for backward compatibility. Test every P0 acceptance criterion. Write down every bug, then batch-fix them all.
- Give Claude Code the test pages prompt (below)
- Start dev server:
npm run dev - Open test-playbook.html โ agent button visible in bottom-right
- Click agent, type "begin" โ get step-by-step guidance (not generic)
- Test "status" command โ shows current progress
- Reload page โ open chat โ "status" โ progress persisted from localStorage
- Ask "What's the weather?" โ agent redirects to playbook topic
- Test mobile: devtools โ device toolbar โ verify bottom sheet layout
- Open test-proposal.html โ QA mode, answers about proposal content
- Open test-dashboard.html โ search mode, finds action items by owner
- Open test-legacy.html โ verify agent works with old JSON format (no <template> block)
- Paste ALL bugs to Claude Code: "Here are the issues: [list]. Fix all of them."
- Re-run ALL tests after fixes โ everything passes
Clean Up, Build Production, Deploy
DeployRemove debug code, create production bundle, set up a Cloudflare Worker proxy to protect your API key, and host the test pages for sharing.
- Run cleanup prompt โ remove console.logs, commented code, hardcoded values, TODOs
- Run
npm run buildโ verify clean output, no warnings - Verify
dist/mastery-agent.jsis under 100KB (ideally under 50KB) - Build the Cloudflare Worker API proxy (prompt below)
- Deploy worker, set
ANTHROPIC_API_KEYas Cloudflare secret - Update test page config: set
api.proxyUrlto worker URL - Host test pages (GitHub Pages, Vercel, or Cloudflare Pages)
- Test the hosted version โ agent works through proxy, NO API key in client code
- Create README.md: what it is, how to embed, config schema, knowledge manifest schema, HTML schema
config.api.proxyUrl, the API key stays on the Cloudflare Worker as a secret.
Share With 3-5 People & Measure
ValidateThe entire thesis rests on one question: do users with the AI agent get further through the playbook than users with just the static page? Share with real people and measure.
โ Without Agent
- Users read playbook and get stuck
- No way to ask questions in context
- Drop off at first confusing step
- No data on where people fail
โ With Agent
- Agent walks users through each step
- Answers questions from page content
- Diagnoses errors in real time
- Progress data shows exactly where people drop
- Share hosted URL with 3-5 people from your community
- Ask them to: open page, click agent, say "begin", follow for at least Steps 0-2
- Collect feedback: where confused, where agent helped, where agent failed, where they quit
- Compare: how far do people typically get with just the static playbook?
- If 2x+ completion improvement โ thesis holds โ invest in value ladder tiers
- If similar completion โ iterate heuristics or format, or thesis needs rethinking
โ Validate Your Complete Build
Run through this checklist before sharing with anyone. Every item should pass.
- Agent loads on test-playbook.html via script tag โ no other setup
- Clicking button opens chat panel with smooth animation
- "begin" command starts step-by-step guidance
- Agent gives SPECIFIC instructions (not generic advice)
- Agent asks for confirmation before advancing steps
- "status" command shows current progress
- Progress survives page reload (localStorage)
- Off-topic questions get redirected back to content
- Code blocks in agent responses have copy buttons
- Links in agent responses open in new tabs
- Mobile layout works (full-width bottom sheet)
- No API key exposed in client code (using proxy)
- No errors in browser console on load
- QA mode works on test-proposal.html
- Search mode works on test-dashboard.html
- Fallback parsing works on a page with no data-mastery attributes
- Knowledge manifest loaded from YAML template on test-playbook.html
- Legacy JSON fallback works on test-legacy.html (no template block)
- Agent mentions related pages when user asks about topics covered by them
- README.md exists and documents config, knowledge manifest, and HTML schemas
๐ค All Claude Code Prompts
Every prompt from each step collected here for batch copying.
๐ Resources & Architecture
Architecture Docs
Deployment
File Structure Reference
src/agent.jsโ Main entry point (IIFE bootstrap)src/parser.jsโ HTML parser + knowledge manifest loadersrc/config.jsโ Config loader (JSON only)src/heuristics.jsโ System prompt templatesrc/prompt-builder.jsโ Prompt assembler (manifest + content + progress)src/api.jsโ Anthropic API clientsrc/progress.jsโ localStorage trackersrc/chat.jsโ Chat UI (Shadow DOM)dist/mastery-agent.jsโ Bundled output
Scope Boundaries (Do NOT Build)
- No user accounts or authentication
- No backend server (localStorage only)
- No YAML parsing library (LLM reads YAML as text)
- No voice features
- No browser control or automation
- No sitemap scraping (manifest handles multi-page in Phase 1.5)
- No analytics, payment, or email gating
- No streaming responses (add in v2)