---
name: agentic-sales-sync
description: "Deterministic, text-only sync for the /agentic-sales audio guide. INVOKE when the user runs `/agentic-sales-sync`, or when the scheduled Claude Code web routine runs the agentic-sales daily sync (see specs/agentic-sales/SYNC-ROUTINE.md). Runs `node scripts/sync-agentic-sales.mjs` to reconcile the page-served `data/agentic-sales.json` with the authoritative narration in `data/audio/agentic-sales.script.md` (NO re-TTS, NO deploy, audio fields preserved), then: on no change reports 'in sync' and stops; on text-only drift opens ONE review PR via the GitHub MCP tools; on structural drift (chapter count/title mismatch) opens a reconcile PR/issue WITHOUT editing files. Never merges, never deploys, never runs the audio pipeline."
---

<oneliner>
Reconcile the page-served `data/agentic-sales.json` with the authoritative
`data/audio/agentic-sales.script.md` (text only). Open a review PR when they
drift; otherwise report "in sync". Never re-TTS, never deploy, never merge.
</oneliner>

<invocation>
Triggered by `/agentic-sales-sync` or by the daily web routine prompt in
`specs/agentic-sales/SYNC-ROUTINE.md`. No arguments — the slug is pinned to
`agentic-sales`.
</invocation>

<scope>
This skill ONLY runs the deterministic engine `scripts/sync-agentic-sales.mjs`
and turns its result into a PR (or an in-sync report). It does not parse or edit
the JSON itself, does not touch audio, does not run cargo / TTS / the audio
pipeline, and does not deploy. The engine is zero-dependency Node — no Rust
toolchain, no TTS sidecar, no network, no API keys required.
</scope>

<background>
- `app/agentic-sales/page.tsx` imports `data/agentic-sales.json` at **build
  time**. The live site (`https://ai-engineer-roadmap.xyz/agentic-sales`, on
  Cloudflare Workers via OpenNext) only changes on **redeploy** (`pnpm
  cf:deploy`). A merged sync PR updates the repo but NOT the live page — say so
  in every PR body.
- Authoritative narration: `data/audio/agentic-sales.script.md` (26 `## `
  chapters, no H1; title = heading, body = text until the next heading).
- The engine writes text-only changes into BOTH `data/agentic-sales.json`
  (served) and `data/audio/agentic-sales.json` (authoritative mirror),
  preserving every audio field (`audio_url`, `duration_secs`,
  `file_size_bytes`, `start_secs`, `paragraphs`, `voice`, `stitched_*`). This
  mirrors the sanctioned "manual JSON merge for text-only edits" pattern in
  `.claude/skills/agentic-sales-spec/SKILL.md` and the count/title drift guards
  in `crates/ml/src/bin/finalize_audio.rs`.
</background>

<workflow>

### 1. Run the engine
From the app root:
```
node scripts/sync-agentic-sales.mjs
```
Read the **exit code** and the printed JSON summary (it carries the slug,
status, chapter counts, and which chapters changed). Use `--check` first if you
want a dry run that never writes.

### 2. Exit 0 — in sync
Reply with a one-line status: `in sync` + chapter count + `git rev-parse --short
HEAD`. Create no branch, no commit, no PR. Stop. (This is the expected daily
outcome.)

### 3. Exit 1 — text-only drift (the engine already wrote the two JSON files)
1. `git checkout -b sync/agentic-sales-$(date +%F)`
2. Commit exactly the two changed files:
   `git add data/agentic-sales.json data/audio/agentic-sales.json`
   `git commit -m "chore(agentic-sales): sync served audio JSON to script (text-only)"`
3. `git push -u origin sync/agentic-sales-<date>` (retry with exponential
   backoff on network errors only).
4. Open ONE PR with `mcp__github__create_pull_request` against the repo's
   default branch (base = default branch, head = the sync branch). PR body MUST
   include:
   - the engine's JSON summary (changed chapter indices/titles),
   - the explicit note: **"This PR updates the repo only. The live page changes
     after `pnpm cf:deploy` — this routine does not deploy."**
5. Stop. Do NOT merge, enable auto-merge, or deploy.

### 4. Exit 2 — structural drift (chapter count or title mismatch)
The engine did NOT modify any file. This is a real authoring divergence (today
the served JSON has 27 chapters vs 26 in the script) that a human must resolve.
1. Do NOT edit any file or force a fix.
2. Open a PR/issue OR comment (no code change) via the GitHub MCP tools that
   quotes the engine's `problems` list and asks a human to reconcile the
   authoritative script against the served JSON. `mcp__github__issue_write` (or
   a comment on an existing tracking issue) is appropriate when there is no diff
   to PR.
3. Stop.

### 5. Idempotency / no duplicate PRs
Before opening anything, `mcp__github__list_pull_requests` (state=open) and
check for an existing `sync/agentic-sales-*` head. If one already carries this
change, update/comment on it instead of stacking a duplicate. One PR per run
max.

### 6. Exit 3 — engine IO/usage error
Report the stderr message and stop. Do not guess or hand-edit.

</workflow>

<rules>
- Text-only ALWAYS. Never run `knowledge_tts`, never bump `SYNTH_VERSION`, never
  pass `--upload`, never touch `crates/**`.
- Never `pnpm cf:deploy` / `pnpm run deploy`. Never `mcp__github__merge_pull_request`
  or `mcp__github__enable_pr_auto_merge`.
- `scripts/sync-agentic-sales.mjs` is the ONLY thing that writes the JSON. Never
  hand-edit `data/agentic-sales.json` or its mirror to create or erase a diff.
- On structural drift (exit 2), surface for human review — never auto-resolve.
- One PR per run. Commit only the two JSON files the engine touches.
</rules>
