From f034ecd8794e88e010f90e6faaa6c617ded707eb Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 22 Oct 2026 06:26:41 +0000 Subject: [PATCH 01/70] fix(skills): ship a variant's own reference folder in its bundle The migrate group keeps Statsig's mapping and SDK reference under references/statsig/, and its step files point there, but the generator copied only the top-level reference files. Copy references// into each variant's bundle, and nothing of the other variants. Co-Authored-By: Claude Opus 5.5 --- scripts/lib/skill-generator.js | 32 +++++++++++++ .../skill-generator-references-folder.test.js | 47 +++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/scripts/lib/skill-generator.js b/scripts/lib/skill-generator.js index 454142acd..9af3e0455 100644 --- a/scripts/lib/skill-generator.js +++ b/scripts/lib/skill-generator.js @@ -594,6 +594,31 @@ function generateFrontmatter(skill, version) { return '---\n' + yaml.dump(frontmatter) + '---\n\n'; } +/** + * Copy the markdown files of a variant's own folder, `references//`, + * into the bundle. A group keeps what differs per vendor or platform there, so + * each bundle ships only its own variant's files. Returns their listing entries. + */ +function copyVariantReferences({ sourceDir, targetDir, variantId, configDir }) { + if (!fs.existsSync(sourceDir)) return []; + + const files = fs.readdirSync(sourceDir, { withFileTypes: true }) + .filter(entry => entry.isFile() && entry.name.endsWith('.md')) + .sort((a, b) => a.name.localeCompare(b.name)); + fs.mkdirSync(targetDir, { recursive: true }); + + return files.map(file => { + const parsed = matter(fs.readFileSync(path.join(sourceDir, file.name), 'utf8')); + const body = expandPartials(parsed.content, configDir).replace(/^\n+/, '').replace(/\s+$/, ''); + fs.writeFileSync(path.join(targetDir, file.name), body, 'utf8'); + const heading = body.match(/^#\s+(.+)$/m)?.[1]; + return { + filename: `${variantId}/${file.name}`, + description: parsed.data.description || heading || file.name, + }; + }); +} + /** * Generate a complete skill package * @@ -717,6 +742,13 @@ async function generateSkill({ }); } } + + references.push(...copyVariantReferences({ + sourceDir: path.join(sourceReferencesDir, skill._shortId), + targetDir: path.join(referencesDir, skill._shortId), + variantId: skill._shortId, + configDir, + })); } // Helper to process a doc entry (string URL or {url, title} object). diff --git a/scripts/lib/tests/skill-generator-references-folder.test.js b/scripts/lib/tests/skill-generator-references-folder.test.js index d5108e5f8..925f520be 100644 --- a/scripts/lib/tests/skill-generator-references-folder.test.js +++ b/scripts/lib/tests/skill-generator-references-folder.test.js @@ -69,4 +69,51 @@ describe('generateSkill local references', () => { expect(readFileSync(generatedRef, 'utf8')).toBe('# Product analytics best practices\n\nDetails'); expect(readFileSync(generatedSkill, 'utf8')).toContain('references/product-analytics.md'); }); + + it("ships a variant's own reference folder and no other variant's", async () => { + createFixture({ + skills: { + migrate: { + 'description.md': '# Migrate\n\n{references}\n', + references: { + '1-presence.md': '---\nnext_step: null\n---\n\n# Presence\n\nRead `references//mapping.md`.', + statsig: { 'mapping.md': '# Statsig mapping' }, + amplitude: { 'mapping.md': '# Amplitude mapping' }, + }, + }, + }, + }, tmpDir); + + const config = { + migrate: { + type: 'skill', + template: 'description.md', + variants: [ + { id: 'statsig', display_name: 'Statsig' }, + { id: 'amplitude', display_name: 'Amplitude' }, + ], + }, + }; + + const statsig = expandSkillGroups(config, tmpDir).find((skill) => skill.id === 'migrate-statsig'); + const outputDir = join(tmpDir, 'out'); + + await generateSkill({ + skill: statsig, + version: 'test', + repoRoot: tmpDir, + configDir: tmpDir, + outputDir, + skipPatterns: { global: [], examples: {} }, + commandmentsConfig: { commandments: {} }, + skillTemplate: statsig._template, + sharedDocs: [], + }); + + const references = join(outputDir, 'migrate-statsig', 'references'); + expect(readFileSync(join(references, 'statsig', 'mapping.md'), 'utf8')).toBe('# Statsig mapping'); + expect(existsSync(join(references, 'amplitude'))).toBe(false); + expect(readFileSync(join(outputDir, 'migrate-statsig', 'SKILL.md'), 'utf8')) + .toContain('`references/statsig/mapping.md`'); + }); }); From 177e7414815c7dcb830e128647371eadad887d38 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 22 Oct 2026 06:40:11 +0000 Subject: [PATCH 02/70] refactor(skills): share the email sender setup as a partial Move the sender setup of send-transactional-email's STEP 3 into context/shared/email-sender-setup.md, so the email migration skill includes the same text. A partial now takes the indentation of its {{> name}} line on every line, so it nests under a step. The built send skill is unchanged byte for byte. Co-Authored-By: Claude Opus 5.5 --- context/shared/email-sender-setup.md | 15 +++++++++++++++ scripts/lib/skill-generator.js | 10 ++++++---- scripts/lib/tests/partial-includes.test.js | 8 ++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 context/shared/email-sender-setup.md diff --git a/context/shared/email-sender-setup.md b/context/shared/email-sender-setup.md new file mode 100644 index 000000000..bdf95e3c5 --- /dev/null +++ b/context/shared/email-sender-setup.md @@ -0,0 +1,15 @@ +--- +title: Set up an email sender +--- + +- First check that the PostHog MCP has the sender tools: `integrations-email-create`, `integrations-email-verify-create`, `integrations-domain-connect-check-retrieve`, and `integrations-domain-connect-apply-url-create`. When they are missing, go to the last bullet of this step. +- When the `setting-up-an-email-domain` skill is available, follow it. It covers the details. +- Ask which domain to send from. Recommend a subdomain such as `mail.example.com`. Use the person's own domain, never a free mailbox domain such as gmail.com. +- Never create a sender for an address that already has one: creating it again marks it unverified. For an existing unverified sender, skip to its records. +- Create the sender with `integrations-email-create`, then get its DNS records with `integrations-email-verify-create`. +- PostHog never writes DNS. Call `integrations-domain-connect-check-retrieve` with the domain. When `supported` is true, give the person the URL from `integrations-domain-connect-apply-url-create`: they approve the records at their DNS host. Otherwise, give them the records that are not `success` as a table with type, name, value, and priority. +- Always include both SPF records, merged into an existing `v=spf1` record when there is one. Never add a second `_dmarc` record when the domain already has one. +- Call `integrations-email-verify-create` again after the records are published, at least a minute apart. `success` means done. `failed` means fix the records, then verify again. After about 15 minutes of `pending` with every record published, stop and tell the person that DNS is still propagating and they can ask you to check again later. +- A 403 that says the person lacks permissions in the project means a project admin must verify the sender. Do not retry. +- **When the sender tools are missing or refused**, the agent setup for sender domains is not available to this person yet. Do not try other integration tools. Ask the person to verify a sender in PostHog: Workflows, then Channels, then add an email sender on their domain and follow the DNS steps (https://posthog.com/docs/workflows/configure-channels). Wait until they confirm that the sender shows as verified, then continue. + diff --git a/scripts/lib/skill-generator.js b/scripts/lib/skill-generator.js index 9af3e0455..35eb4697e 100644 --- a/scripts/lib/skill-generator.js +++ b/scripts/lib/skill-generator.js @@ -55,16 +55,18 @@ function loadYaml(configPath) { // A line that is exactly `{{> name}}` is replaced at build time with the body // of `/shared/name.md` (frontmatter stripped), so shared prose like // the MCP tool-calling grammar lives in one canonical file and every skill that -// includes it stays in sync. -const PARTIAL_DIRECTIVE = /^[ \t]*\{\{>\s*([a-z0-9-]+)\s*\}\}[ \t]*$/gm; +// includes it stays in sync. The directive's indentation applies to every line +// of the partial, so a partial can nest under a step. +const PARTIAL_DIRECTIVE = /^([ \t]*)\{\{>\s*([a-z0-9-]+)\s*\}\}[ \t]*$/gm; function expandPartials(body, configDir) { - return body.replace(PARTIAL_DIRECTIVE, (_match, name) => { + return body.replace(PARTIAL_DIRECTIVE, (_match, indent, name) => { const partialPath = path.join(configDir, 'shared', `${name}.md`); if (!fs.existsSync(partialPath)) { throw new Error(`Partial include {{> ${name}}} references missing file ${partialPath}`); } - return matter(fs.readFileSync(partialPath, 'utf8')).content.trim(); + const partial = matter(fs.readFileSync(partialPath, 'utf8')).content.trim(); + return partial.replace(/^(?=.)/gm, indent); }); } diff --git a/scripts/lib/tests/partial-includes.test.js b/scripts/lib/tests/partial-includes.test.js index 5ebaa8e66..3741c14a3 100644 --- a/scripts/lib/tests/partial-includes.test.js +++ b/scripts/lib/tests/partial-includes.test.js @@ -42,6 +42,14 @@ describe('expandPartials', () => { expect(out).toContain('After.'); }); + it("indents every line of the partial as far as the directive, so it nests in a step's list", () => { + writeFileSync(join(tmpDir, 'shared', 'sender.md'), '---\ntitle: Sender\n---\n\n- First bullet.\n- Second bullet.\n'); + + const out = expandPartials('STEP 3: Set up a sender.\n {{> sender}}\n\nSTEP 4: Send.', tmpDir); + + expect(out).toBe('STEP 3: Set up a sender.\n - First bullet.\n - Second bullet.\n\nSTEP 4: Send.'); + }); + it('throws when the referenced partial does not exist', () => { expect(() => expandPartials('{{> missing-partial}}', tmpDir)).toThrow(/missing-partial/); }); From 8169d7ec86ab68871010032ea15222f77611d0e6 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 22 Oct 2026 06:40:11 +0000 Subject: [PATCH 03/70] feat(skills): add the migrate-email skill with a Resend variant v0 prepares a move off Resend and changes no send call site. It finds every Resend send, classifies each one as ready to move or staying on Resend with a reason, sets up the PostHog sender next to Resend's DNS records, imports Resend's suppression list when the import tool exists, hands over the project secret key, checks the sending tier, and writes posthog-migrate-email-resend-report.md with a summary block. Steps are provider-neutral; references/resend/ holds what is specific to Resend. Statsig and Resend now publish as wizard migrate subcommands. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 10 +- context/skills/migrate-email/config.yaml | 17 ++++ context/skills/migrate-email/description.md | 55 +++++++++++ .../migrate-email/references/1-detect.md | 38 ++++++++ .../migrate-email/references/2-preflight.md | 41 ++++++++ .../migrate-email/references/3-inventory.md | 61 ++++++++++++ .../migrate-email/references/4-sender.md | 38 ++++++++ .../references/5-suppressions.md | 39 ++++++++ .../skills/migrate-email/references/6-key.md | 32 +++++++ .../migrate-email/references/7-report.md | 76 +++++++++++++++ .../references/resend/account.md | 42 ++++++++ .../references/resend/mapping.md | 46 +++++++++ .../references/resend/sdk-reference.md | 90 +++++++++++++++++ context/skills/migrate/config.yaml | 2 +- scripts/lib/tests/migrate-email-skill.test.js | 96 +++++++++++++++++++ 15 files changed, 681 insertions(+), 2 deletions(-) create mode 100644 context/skills/migrate-email/config.yaml create mode 100644 context/skills/migrate-email/description.md create mode 100644 context/skills/migrate-email/references/1-detect.md create mode 100644 context/skills/migrate-email/references/2-preflight.md create mode 100644 context/skills/migrate-email/references/3-inventory.md create mode 100644 context/skills/migrate-email/references/4-sender.md create mode 100644 context/skills/migrate-email/references/5-suppressions.md create mode 100644 context/skills/migrate-email/references/6-key.md create mode 100644 context/skills/migrate-email/references/7-report.md create mode 100644 context/skills/migrate-email/references/resend/account.md create mode 100644 context/skills/migrate-email/references/resend/mapping.md create mode 100644 context/skills/migrate-email/references/resend/sdk-reference.md create mode 100644 scripts/lib/tests/migrate-email-skill.test.js diff --git a/AGENTS.md b/AGENTS.md index 9bbb4e2c6..2d5c0779e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -72,11 +72,12 @@ longer exist — only some keep an alias. | `wizard integrate` | `wizard` (default flow) | command removed | | `wizard events-audit` | `wizard audit events` | moved into `audit` family | | `wizard audit` (single) | `wizard audit ` | now a family — see audit subcommands below | +| `wizard migrate` (single) | `wizard migrate ` | becomes a family with the wizard's family command — see migrate subcommands below | | `wizard audit-3000` | *removed* | retired | | `wizard revenue` | `wizard revenue-analytics` | renamed (old `revenue` removed) | | `wizard upload-sourcemaps` | `wizard upload-source-maps` | renamed; `upload-sourcemaps` kept as alias | -**Audit subcommands** — the one family today backed by skills from this repo: +**Audit subcommands**, backed by skills from this repo: | Subcommand | Backing skill | |---|---| @@ -88,6 +89,13 @@ longer exist — only some keep an alias. | `wizard audit session-replay` | `audit-session-replay` | | `wizard audit web-analytics` | *(wizard-native, not a skill here)* | +**Migrate subcommands**, published as `cliEntries` with `parentCommand: migrate`. Until the wizard runs `migrate` as a family, bare `wizard migrate` keeps running `migrate-statsig`: + +| Subcommand | Backing skill | +|---|---| +| `wizard migrate statsig` | `migrate-statsig` | +| `wizard migrate resend` | `migrate-email-resend` | + **Commands vs. skills:** those audit subcommands **are** skills, promoted to commands via `cli: role: command`. A `role: skill` skill is reachable only via `wizard skill `. Same machinery, two surfaces — so `wizard audit ` diff --git a/context/skills/migrate-email/config.yaml b/context/skills/migrate-email/config.yaml new file mode 100644 index 000000000..6b0b83c37 --- /dev/null +++ b/context/skills/migrate-email/config.yaml @@ -0,0 +1,17 @@ +# Email migration skill group - move transactional email from another provider to PostHog, one variant per provider +type: skill +template: description.md +category: migrate +description: Migrate transactional email from {display_name} to PostHog. Use when asked to migrate from {display_name}, replace {display_name} with PostHog, or switch email providers. It finds every {display_name} send in the code, sets up the sender and DNS next to {display_name}'s records, imports {display_name}'s suppression list, hands over the PostHog secret key, and writes a migration report. It changes no send call site yet. +tags: [migration, workflows] +cli: + role: command + parentCommand: migrate +references: + preamble: "**Read ONLY this file.** Do not read any other reference file until this one tells you to." +shared_docs: + - https://posthog.com/docs/workflows/transactional-email-api.md +variants: + - id: resend + display_name: Resend + tags: [resend] diff --git a/context/skills/migrate-email/description.md b/context/skills/migrate-email/description.md new file mode 100644 index 000000000..174a82b6a --- /dev/null +++ b/context/skills/migrate-email/description.md @@ -0,0 +1,55 @@ +# Migrate transactional email from {display_name} to PostHog + +Use this skill to move an app's transactional email, such as welcome emails, password resets, and receipts, from {display_name} to PostHog. + +This version prepares the move and changes no send call site. It finds every {display_name} send, sets up the PostHog sender and its DNS records next to {display_name}'s, imports {display_name}'s suppression list, hands over the PostHog secret key, and writes a report. Both providers can send during the cutover. + +The transactional email API is in beta. PostHog enables it per project. + +## Workflow + +{workflow} + +Read the step files in order, one at a time. Each step names the next one. Do not read a step before the one before it tells you to. + +## Provider files + +The folder `references//` holds everything specific to {display_name}. The steps tell you when to read each file: + +- `sdk-reference.md`: how {display_name} looks in code, so you can find every send. +- `mapping.md`: how each send field maps to PostHog, and what keeps a call site on {display_name}. +- `account.md`: {display_name}'s DNS records and how to export its suppression list. + +Everything you need is on disk. Do not fetch {display_name}'s docs. + +## Plan file + +The plan file `.posthog-email-migration-plan.md` lives at the project root. Step 3 writes it, the later steps update it, and the last step writes the report from it and deletes it. + +## Rules + +- Change no send call site. This version only prepares the move. +- Never touch DNS or the {display_name} account. Give the person the records and the links, and let them make the change. +- Never remove the {display_name} package, its client, or its API key. +- Never create, upload, or edit a template in PostHog. +- Never write a recipient's email address into a file in the repository, the plan, or the report. Count addresses instead. +- Keep keys in environment variables. Never hardcode a key, and never ask the person to paste one into the chat. +- Do not commit. The person reviews the diff and commits. + +## Inside the PostHog Wizard + +Read this section only when the Wizard's `wizard_ask` tool exists. Some runtimes name its tools `mcp__wizard-tools__wizard_ask` and `mcp__wizard-tools__set_env_values`: use the names the runtime shows. The Wizard has no chat, so the person answers through its tools. + +- The PostHog tools of this skill run through `posthog_exec`. Check that a tool exists with `search `. +- The Wizard's login may not carry the scopes of the `workflows-*` and `integrations-*` tools, so a missing tool does not mean the API is off. Step 2 says how to tell. +- Ask every question with `wizard_ask`, never in plain text. Batch the questions of one step into one call. +- Emit the `[STATUS]` line each step names when you start it, and the `[ABORT]` line a step names when it stops the run. +- Ask for a key with `wizard_ask` and `sensitive: true`, then pass the answer to `set_env_values` with the variable name the step gives. The answer is a reference that only `set_env_values` can read, so the key never shows in the run. + +Outside the Wizard, skip the `[STATUS]` lines, and tell the person why you stopped instead of an `[ABORT]` line. + +## Reference files + +{references} + +`transactional-email-api.md` is the transactional email API page. It covers senders, the send forms, `posthog-node`, idempotency, and every error code. diff --git a/context/skills/migrate-email/references/1-detect.md b/context/skills/migrate-email/references/1-detect.md new file mode 100644 index 000000000..94881bc9c --- /dev/null +++ b/context/skills/migrate-email/references/1-detect.md @@ -0,0 +1,38 @@ +--- +title: Find the email provider in the code +next_step: 2-preflight.md +--- + +# Step 1, find the email provider in the code + +Discovery only. Do not change any file. + +## Status + +``` +[STATUS] Looking for the email provider +``` + +## Procedure + +Read the provider's `sdk-reference.md`. It lists the provider's packages, imports, clients, and HTTP host, and the packages that look related but are not the provider. + +The provider is in this project when at least one of these is true: + +- Its package is in a dependency manifest, such as `package.json`, `requirements.txt`, `pyproject.toml`, `Gemfile`, `composer.json`, or `go.mod`. +- Source code imports it or creates its client. +- Source code calls its HTTP host. + +Search the source code, not only the manifest: a package without a call site is not a migration. Skip `node_modules`, build output, and lockfiles. + +A rendering package alone, such as `@react-email/components`, is not the provider. It only tells you how some emails are rendered. + +When you find nothing, stop before any change: + +``` +[ABORT] no email provider sends found +``` + +Do not widen the search to other email providers. That outcome is correct, not a failure to work around. + +When you find the provider, note each file that uses it for Step 3, and continue. diff --git a/context/skills/migrate-email/references/2-preflight.md b/context/skills/migrate-email/references/2-preflight.md new file mode 100644 index 000000000..ffd88264d --- /dev/null +++ b/context/skills/migrate-email/references/2-preflight.md @@ -0,0 +1,41 @@ +--- +title: Check that the project can send +next_step: 3-inventory.md +--- + +# Step 2, check that the project can send + +Do not change any file. + +## Status + +``` +[STATUS] Checking the PostHog project +``` + +## The transactional email API + +Check which PostHog MCP tools exist. + +- When there are no PostHog tools at all, the PostHog MCP is not connected or not signed in. Ask the person to connect it, and wait. +- When other PostHog tools exist but `workflows-upload-email-template` and `workflows-send-email` don't, the transactional email API is not enabled for this project. Stop and tell the person: the API is in beta, and they can ask PostHog in-app to enable it for their project. Then emit: + +``` +[ABORT] transactional email api not enabled +``` + +- When both tools exist, the API is on. Record `api: on`. + +Inside the Wizard, a missing tool can mean that the login lacks its scope, so missing tools do not stop the run. Record `api: not confirmed` and continue. The report asks the person to confirm it. + +## The sending tier + +PostHog gives each project a sending allowance: how many emails it sends per hour and per day. A new project starts on a low tier, and the tier grows with low bounce and complaint rates. Emails above the allowance are not dropped, they are sent later. So a cutover with more mail than the tier allows delays email, such as password resets. + +- Ask the person how many emails the app sends in its busiest hour and on its busiest day. +- Ask them to compare these numbers with the "Sending allowance" in PostHog: Workflows, then Messaging, then Reputation. +- Record the answer as `tier: fits`, `tier: too low`, or `tier: not checked` when they don't know. Do not stop on `too low`: the report tells the person to move the sends in parts, or to ask PostHog about a higher tier, before cutover. + +## Write down + +Keep `api` and `tier` for Step 3, which writes them into the plan file. diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md new file mode 100644 index 000000000..1755818f0 --- /dev/null +++ b/context/skills/migrate-email/references/3-inventory.md @@ -0,0 +1,61 @@ +--- +title: List and classify every send +next_step: 4-sender.md +--- + +# Step 3, list and classify every send + +List every place the code sends email through the provider, and decide for each one whether PostHog can send it. Change no source file. The only file you write is the plan file. + +## Status + +``` +[STATUS] Listing every send +[STATUS] Writing the migration plan +``` + +## Find the sends + +Read the provider's `sdk-reference.md` for the call shapes, and its `mapping.md` for the fields. + +A **site** is one place in the code that calls the provider to send, such as one `emails.send(...)` call or one HTTP request to the send endpoint. A helper that wraps the call is one site, however many places call the helper. Read the callers of a helper anyway: they decide values such as how many recipients a send has. + +For each site, read the surrounding code and record: + +- The file and the line of the call. +- How it sends: `sdk`, `http`, or `smtp`. +- The content: `template` for a template stored at the provider, `react` for a component the provider renders, `html`, or `text`. A site that sets both `html` and `text` is `html`. +- Every field the site sets, including fields set on the payload object after it is created and fields set through options, such as an idempotency key. +- Where `from` comes from: the literal address, or the name of the environment variable or config value that holds it. + +Also list every other call to the provider that is not a send, such as reading an email's status, contacts, or domains. These calls stay on the provider. Note what each one does, because a site whose code reads the status back stays on the provider too. + +## Classify each site + +Go through `mapping.md` field by field. A site **moves** when PostHog can send every field it sets. A site **stays** on the provider when any one field or feature keeps it there: record that field or feature as the reason. Never plan to drop a field. + +When the code passes a value you can't read, such as a list of recipients built at run time, follow it to its callers. When you still can't tell, the site stays, and the reason says what you could not check. + +## Write the plan file + +Write `.posthog-email-migration-plan.md` at the project root with three sections. Never write an email address of a recipient into it. A `from` address is fine. + +A phase checklist, in this order. Tick `preflight` with what Step 2 recorded, and `inventory` once the file is written. Later steps tick the rest. + +``` +- [x] preflight — api: — tier: +- [x] inventory — sites, stay on the provider +- [ ] sender +- [ ] suppressions +- [ ] key +``` + +A sites table, one row per site, in source tree order: + +``` +| site | file | line | sends | content | from | moves | reason | +``` + +`moves` is `yes` or `no`. `reason` is empty when the site moves. + +A list of the other provider calls, each with its file, line, and what it does. diff --git a/context/skills/migrate-email/references/4-sender.md b/context/skills/migrate-email/references/4-sender.md new file mode 100644 index 000000000..87a968c06 --- /dev/null +++ b/context/skills/migrate-email/references/4-sender.md @@ -0,0 +1,38 @@ +--- +title: Set up the senders and their DNS records +next_step: 5-suppressions.md +--- + +# Step 4, set up the senders and their DNS records + +PostHog sends from a verified sender: an address on a domain whose DNS records PostHog checked. Set up a sender for each domain the app sends from, next to the provider's records, so both providers can send during the cutover. Never change DNS yourself, and never change the provider account. + +## Status + +``` +[STATUS] Setting up the PostHog sender +``` + +## List the addresses + +Collect every `from` in the plan's sites table. When a `from` comes from an environment variable or a config value, read it from the example env file or the config, or ask the person for the address. A `from` can carry a name, such as `Example `: the sender is the address in it. + +Group the addresses by domain. Each domain needs one verified sender. + +## Check for verified senders + +Call `integrations-list` with `kind=email`, and read every page. A sender with `config.verified: true` can send. When the list shows senders without `config`, call `integrations-email-verify-create` once on the sender for the address: `success` means it is verified, and `pending` or `failed` means you continue from its records below. When the sender tools are missing, or the verify answers 403, ask the person whether a sender is verified for each domain. + +The first sender that verifies becomes the project's default sender. A send without `from` uses it. + +## Set up each domain without a verified sender + +Read the provider's `account.md` first. It lists the records the provider keeps on the domain and the label PostHog must not take. Keep every one of the provider's records: removing one stops the provider's sends before the cutover is done. + +Send from the domain of the existing `from` address, so the emails keep their sender. Ask for another domain only when the person wants one. + +{{> email-sender-setup}} + +## Write down + +Tick the `sender` phase in the plan file: `- [x] sender — / verified — dns_ready: `. `dns_ready` is `true` only when every domain has a verified sender. List each domain that is not verified, with what the person still has to do. diff --git a/context/skills/migrate-email/references/5-suppressions.md b/context/skills/migrate-email/references/5-suppressions.md new file mode 100644 index 000000000..02471b58b --- /dev/null +++ b/context/skills/migrate-email/references/5-suppressions.md @@ -0,0 +1,39 @@ +--- +title: Import the suppression list +next_step: 6-key.md +--- + +# Step 5, import the suppression list + +The provider keeps a suppression list: addresses that hard-bounced or marked an email as spam. It skips them on every send. PostHog keeps its own list and starts empty, so without an import the first PostHog sends go to these addresses again. That hurts the sending reputation of the project and the domain. Import the list before cutover. + +## Status + +``` +[STATUS] Importing the suppression list +``` + +## Check the import tool + +Look for the PostHog MCP tool `email-suppressions-add`, and read its schema with `info`. + +When it is missing, the import is not available to this person yet. Do not try other tools, and do not use the opt-out tools: opt-outs are marketing preferences, and transactional email ignores them. Tick the phase as `- [ ] suppressions — not imported: no import tool`, and continue to the next step. The report tells the person to add the addresses in PostHog (Workflows, then Messaging, then Suppression list) before cutover. + +## Get the list + +Read the provider's `account.md`. It says how to export the list, which entries to take, and how each entry maps to PostHog. + +- Prefer the export the person downloads from the provider's dashboard. Ask them where they saved the file. +- Read the list from the provider's API only when the person gives you a key that can read it, through an environment variable that `account.md` names. The app's own sending key usually can't. +- Keep the list out of the repository. Read the file where the person saved it, or write the API's answer to a file in the system's temporary folder, and delete that file when the import is done. + +## Import it + +- Send the entries to `email-suppressions-add` in batches of the size its schema allows. Give each entry the source and the reason `account.md` names. +- Repeating an import is safe: an address already on the list stays on it. +- Never print the addresses, and never write them into the plan or the report. Count them. +- When a call fails, read its error and fix the call. When it fails again, stop the import and record how many entries you imported. + +## Write down + +Tick the phase in the plan file: `- [x] suppressions — / imported`. When the list is empty, write `- [x] suppressions — empty list`. When the person has no export and no key, write `- [ ] suppressions — not imported: `. diff --git a/context/skills/migrate-email/references/6-key.md b/context/skills/migrate-email/references/6-key.md new file mode 100644 index 000000000..0b4a08208 --- /dev/null +++ b/context/skills/migrate-email/references/6-key.md @@ -0,0 +1,32 @@ +--- +title: Hand over the PostHog secret key +next_step: 7-report.md +--- + +# Step 6, hand over the PostHog secret key + +PostHog's send needs a project secret API key on the server. The provider's key stays where it is until the cutover is done. + +## Status + +``` +[STATUS] Setting up the PostHog secret key +``` + +## The PostHog key + +- Ask the person to create a project secret API key (it starts with `phs_`) with the `hog_flow:write` scope in their PostHog project settings. +- The key goes into `POSTHOG_PROJECT_SECRET_API_KEY`, in the env file the app loads its provider key from, such as `.env` or `.env.local`. Check that git ignores that file. When it doesn't, ask the person where the key goes. +- Ask the person to add the key to that file themselves. Inside the Wizard, ask for it and store it as the "Inside the PostHog Wizard" section of `SKILL.md` says. +- Add the variable name, without a value, to the project's env example file when it has one. +- Never hardcode the key, never commit it, and never ask the person to paste it into the chat. + +## Every other place the provider key lives + +The provider's `sdk-reference.md` names its key's environment variable. Search the whole repository for that name, including CI workflows, deploy and hosting config, Docker and compose files, env example files, and docs. Skip `node_modules` and build output. + +List each place with its file and line. Each one needs `POSTHOG_PROJECT_SECRET_API_KEY` too before the cutover, for example as a CI secret or a hosting environment variable. Do not change these files: the person adds the secret where the platform stores it. + +## Write down + +Tick the phase in the plan file: `- [x] key — POSTHOG_PROJECT_SECRET_API_KEY set in `, or `- [ ] key — not set: `. Under the phase list, add the places of the provider key. diff --git a/context/skills/migrate-email/references/7-report.md b/context/skills/migrate-email/references/7-report.md new file mode 100644 index 000000000..0dfb9a330 --- /dev/null +++ b/context/skills/migrate-email/references/7-report.md @@ -0,0 +1,76 @@ +--- +title: Write the migration report +next_step: null +--- + +# Step 7, write the migration report + +The report comes from the plan file. Invent nothing. + +## Status + +``` +[STATUS] Writing the migration report +``` + +## Write the report + +Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email--report.md` at the project root, where `` is the name of the provider folder under `references/`. Use the structure below, then delete the plan file. Never write a recipient's email address into the report. + +```markdown +# Email migration report: to PostHog + + + +## Send call sites + +| File | Line | Content | Status | +|------|------|---------|--------| + +: ".> + +## Other calls + +.> + +## Sender and DNS + + + +## Suppression list + + + +## PostHog secret key + + + +## Sending tier + + + +## Before cutover + + + +## Summary +``` + +End the report with the summary block, as the last thing in the file. The Wizard reads it, so keep the keys and their order: + +```yaml +from: +sites_found: +sites_rewritten: +sites_left: +dns_ready: +suppressions_ready: +``` + +This version changes no site, so `sites_rewritten` is `0`. Sites that are ready to move count in `sites_found` only. + +After the report is written, print its path: + +``` +Created migration report: +``` diff --git a/context/skills/migrate-email/references/resend/account.md b/context/skills/migrate-email/references/resend/account.md new file mode 100644 index 000000000..dfd42d4b5 --- /dev/null +++ b/context/skills/migrate-email/references/resend/account.md @@ -0,0 +1,42 @@ +# Resend account + +What the migration needs from the person's Resend account. The agent never changes the account: it reads what the person exports or allows. + +## DNS records + +A domain verified at Resend carries these records. Keep all of them until the cutover is done. + +| Record | Name | What it does | +|---|---|---| +| `TXT` (DKIM) | `resend._domainkey` | Signs Resend's mail | +| `MX` | `send` | Return path for Resend's bounces | +| `TXT` (SPF) | `send` | Allows Resend to send for the return path | +| `TXT` (DMARC) | `_dmarc` | Optional, shared by every provider on the domain | + +- `send` is Resend's default return-path label. A domain can use a custom one: the Resend dashboard shows it under Domains. +- PostHog's sender uses its own label for its MAIL FROM, `feedback` by default. Never give PostHog the label Resend uses. +- PostHog's DKIM records have their own names, so they sit next to `resend._domainkey`. +- Keep the one `_dmarc` record. Never add a second one. + +## Suppression list + +Resend suppresses an address after a hard bounce or a spam complaint, and keeps addresses the team added by hand. + +**Export from the dashboard (preferred).** In Resend: Emails, then Suppressions, then **Download CSV**. Read the header row to find the address column and the origin column. + +**Read from the API.** `GET https://api.resend.com/suppressions?limit=100` with `Authorization: Bearer $RESEND_SUPPRESSIONS_API_KEY`. + +- The answer is `{ "object": "list", "has_more": , "data": [{ "id", "email", "origin", "source_id", "created_at" }] }`. +- Page with `after=` until `has_more` is `false`. +- Resend allows 10 requests per second per team. Wait and retry on `429`. +- A sending-only key can't read the list. Ask the person to create a full-access key, store it in `RESEND_SUPPRESSIONS_API_KEY` for the import, and delete the key in Resend afterwards. + +**Map each entry.** + +| Resend `origin` | PostHog source | Reason | +|---|---|---| +| `bounce` | bounce | `Imported from Resend: hard bounce` | +| `complaint` | complaint | `Imported from Resend: spam complaint` | +| `manual` | manual | `Imported from Resend: added by hand` | + +**Leave out unsubscribed contacts.** A Resend contact with `unsubscribed: true` still gets transactional email, and PostHog's opt-outs apply to marketing messages only. They are not suppressions. diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md new file mode 100644 index 000000000..eecb90fb0 --- /dev/null +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -0,0 +1,46 @@ +# Resend to PostHog mapping + +This file decides, field by field, whether PostHog can send a Resend call site. A site moves only when every field it sets moves. Otherwise it stays on Resend, and the reason names the first field or feature that keeps it there. `transactional-email-api.md` has the PostHog side in full. + +## Fields + +| Resend | PostHog | A site stays on Resend when | +|---|---|---| +| `from` | `from` | Never. It needs a verified sender (Step 4) | +| `to` | `to` | `to` can hold more than one address. A list with exactly one address moves as that address | +| `subject` | `subject` | Never | +| `html` | `html` | Never | +| `text` | `text` | Never | +| `react` | `html`, rendered in the app | Never. The app renders the component | +| `template` | a local template in the app's code | The template uses syntax beyond variables and fallbacks | +| `cc`, `bcc` | `cc`, `bcc` | An entry carries a name, such as `Jane `, or there are more than 10 | +| `replyTo` / `reply_to` | `replyTo` / `reply_to` | Never | +| `headers` | `headers` | A header is one PostHog sets itself (`From`, `To`, `Cc`, `Bcc`, `Reply-To`, `Subject`, `Date`, `Message-ID`, `MIME-Version`, `Sender`, `Return-Path`, `Auto-Submitted`, any `Content-*`, `X-PostHog-*`, `X-SES-*`), a value has a line break or a non-ASCII character, or there are more than 10 | +| `tags` | `tags` | A name or value has characters other than ASCII letters, digits, `_`, and `-`, a name starts with `ph_`, or there are more than 10 | +| `attachments` | `attachments` | An attachment uses `path` (a URL Resend fetches), the files can be more than 10 or more than 512 KB in total, or a file type is one mailbox providers block, such as `.exe` | +| `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | Never. The key keeps its value | +| `scheduledAt` / `scheduled_at` | none | Always | +| `topicId` / `topic_id` | none | Always | + +## Calls + +| Resend call | A site stays on Resend when | +|---|---| +| `emails.send`, `emails.create`, `Emails.send`, `POST /emails` | A field above keeps it | +| `batch.send`, `Batch.send`, `POST /emails/batch` | Always | +| SMTP through `smtp.resend.com` | Always. PostHog has no SMTP relay | +| Laravel's or Rails' `resend` mailer | Always. PostHog has no mailer driver | +| A send in a language other than JavaScript or TypeScript | Always, until the skill moves that language | + +## Code around the send + +| Code | A site stays on Resend when | +|---|---| +| `if (error.name === '...')` | The name is not one of PostHog's: `validation_error`, `missing_api_key`, `invalid_permission`, `not_found`, `concurrent_idempotent_requests`, `invalid_idempotent_request`, `rate_limit_exceeded`, `monthly_quota_exceeded`, `service_unavailable`, `application_error` | +| `emails.get(id)` and a branch on `last_event` | Always: the send and its status read stay together. PostHog's status is not `last_event` | +| `data.id` stored for a webhook or a status read | Always, when Resend webhooks or status reads use the id | + +## Content + +- `html`, `text`, and `react` content is rendered for one recipient before the send. PostHog sends it as it is. +- A `template` site needs the template's content from the Resend dashboard, because the code has only its id. PostHog's Liquid escapes HTML in a variable's value. A variable the app fills with HTML keeps the site on Resend. diff --git a/context/skills/migrate-email/references/resend/sdk-reference.md b/context/skills/migrate-email/references/resend/sdk-reference.md new file mode 100644 index 000000000..fa3cf5f02 --- /dev/null +++ b/context/skills/migrate-email/references/resend/sdk-reference.md @@ -0,0 +1,90 @@ +# Resend SDK reference + +This file says what Resend looks like in a codebase. It does not describe PostHog. `mapping.md` maps each field to PostHog. + +## Key + +The API key lives in `RESEND_API_KEY` by convention. Apps also use their own names, such as `PRIVATE_RESEND_API_KEY`: take the name the client reads. + +## Packages + +- Node.js: `resend`. +- Python: `resend` (PyPI). +- Ruby: `resend` (RubyGems), and `resend-rails`. +- PHP: `resend/resend-php`, and `resend/resend-laravel` for Laravel. +- Go: `github.com/resend/resend-go`. +- Elixir: `resend` (Hex). +- Java: `com.resend:resend-java`. +- .NET: `Resend`. +- Rust: `resend-rs`. + +These are not Resend, and alone they are not a migration: `@react-email/components`, `@react-email/render`, `react-email`, and `jsx-email` render emails, and `nodemailer` sends through any SMTP server. + +## Clients + +```js +import { Resend } from 'resend' +const resend = new Resend(process.env.RESEND_API_KEY) +``` + +```python +import resend +resend.api_key = os.environ["RESEND_API_KEY"] +``` + +Look for `new Resend(`, `from 'resend'`, `require('resend')`, `import resend`, `Resend::`, and `resend.NewClient(`. + +## Sends + +**Node.js.** `resend.emails.send(payload, options?)`, and its alias `resend.emails.create(...)`. The answer is `{ data, error }`: `data.id` is the email's id, and `error` has `name`, `message`, and `statusCode`. The SDK does not throw on API errors. + +```js +const { data, error } = await resend.emails.send({ + from: 'Example ', + to: ['jane@example.com'], + subject: 'Welcome', + html: '

Welcome

', +}, { idempotencyKey: `welcome:${user.id}` }) +``` + +**Python.** `resend.Emails.send(params)`, with the same fields in snake_case, and `options={"idempotency_key": ...}`. It raises on API errors. + +**Batch.** `resend.batch.send([...])` in Node.js and `resend.Batch.send([...])` in Python send up to 100 emails in one call. + +**HTTP.** `POST https://api.resend.com/emails` with `Authorization: Bearer `, a JSON body with the snake_case fields, and an optional `Idempotency-Key` header. `POST https://api.resend.com/emails/batch` is the batch send. Look for `api.resend.com` in `fetch`, `axios`, `got`, `requests`, `httpx`, and `curl` calls. + +**SMTP.** Resend also takes mail over SMTP at `smtp.resend.com`, with the user `resend` and the API key as the password. Look for that host in Nodemailer transports, `MAIL_HOST` or `SMTP_HOST` settings, and framework mail config. + +**Frameworks.** Laravel's `resend` mailer (`MAIL_MAILER=resend`) and Rails' `resend` delivery method send every framework mail through Resend: each mailable or mailer that sends is a site. + +## Send fields + +| Node.js field | HTTP field | Value | +|---|---|---| +| `from` | `from` | One address, with an optional name: `Name ` | +| `to` | `to` | One address, or a list of up to 50 | +| `subject` | `subject` | String | +| `html` | `html` | String | +| `text` | `text` | String. Resend derives one from `html` when it is absent | +| `react` | (none) | A React element that the Node.js SDK renders to HTML | +| `cc`, `bcc` | `cc`, `bcc` | One address or a list | +| `replyTo` | `reply_to` | One address or a list | +| `headers` | `headers` | Object of custom headers | +| `tags` | `tags` | List of `{ name, value }` | +| `attachments` | `attachments` | List of `{ filename, content, path, contentType, contentId }`. `content` is a Buffer or base64, `path` is a URL Resend fetches | +| `scheduledAt` | `scheduled_at` | A time to send later | +| `topicId` | `topic_id` | A topic the recipient can unsubscribe from | +| `template` | `template` | `{ id, variables }`: a template stored at Resend | +| `idempotencyKey` option | `Idempotency-Key` header | Up to 256 characters, kept for 24 hours | + +## Templates stored at Resend + +A send with `template: { id: 'tmpl_...', variables: { FIRST_NAME: 'Jane' } }` renders a template from the Resend dashboard. Its content is not in the code. The template reads variables as `{{{FIRST_NAME}}}`, with an optional fallback: `{{{FIRST_NAME|there}}}`. + +## Status reads + +`resend.emails.get(id)` and `GET https://api.resend.com/emails/{id}` return the email with `last_event`, such as `delivered`, `bounced`, or `complained`. Code that branches on `last_event` reads Resend's delivery state. + +## Other APIs + +`resend.contacts`, `resend.audiences`, `resend.segments`, `resend.broadcasts`, `resend.domains`, `resend.apiKeys`, `resend.webhooks`, and their HTTP routes are not transactional sends. diff --git a/context/skills/migrate/config.yaml b/context/skills/migrate/config.yaml index c56409d57..d4e2cb5a8 100644 --- a/context/skills/migrate/config.yaml +++ b/context/skills/migrate/config.yaml @@ -5,7 +5,7 @@ description: Migrate an existing analytics or feature-flag vendor to PostHog. Re tags: [migration] cli: role: command - command: migrate + parentCommand: migrate references: preamble: "**Read ONLY this file.** Do not read any other reference file until this one tells you to." shared_docs: [] diff --git a/scripts/lib/tests/migrate-email-skill.test.js b/scripts/lib/tests/migrate-email-skill.test.js new file mode 100644 index 000000000..29ca4ea6c --- /dev/null +++ b/scripts/lib/tests/migrate-email-skill.test.js @@ -0,0 +1,96 @@ +import { afterEach, describe, expect, it, vi } from 'vitest'; +import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync } from 'fs'; +import { join, relative } from 'path'; +import { tmpdir } from 'os'; + +const CONFIG_DIR = join(process.cwd(), 'context'); +const DOCS_URL = 'https://posthog.com/docs/workflows/transactional-email-api.md'; +const DOCS_PAGE = '# Transactional email API\n\nSend one email to one person from your server code.\n'; +const REFERENCE_PATH = /references\/[A-Za-z0-9_./-]+\.md/g; + +async function loadSkills() { + vi.resetModules(); + vi.stubEnv('DOCS_CACHE_TTL_MS', '0'); + vi.stubGlobal('fetch', async (url) => { + if (url !== DOCS_URL) return new Response('not found', { status: 404, statusText: 'Not Found' }); + return new Response(DOCS_PAGE, { status: 200 }); + }); + const generator = await import('../skill-generator.js'); + const skills = generator.expandSkillGroups(generator.loadSkillsConfig(CONFIG_DIR), CONFIG_DIR); + return { generator, skills }; +} + +async function buildSkill(skillId, outputDir) { + const { generator, skills } = await loadSkills(); + const skill = skills.find((candidate) => candidate.id === skillId); + expect(skill).toBeDefined(); + + await generator.generateSkill({ + skill, + version: 'test', + repoRoot: process.cwd(), + configDir: CONFIG_DIR, + outputDir, + skipPatterns: { global: [], examples: {} }, + commandmentsConfig: { commandments: {} }, + skillTemplate: skill._template, + sharedDocs: skill._sharedDocs, + }); + return join(outputDir, skillId); +} + +function markdownFiles(dir) { + return readdirSync(dir, { withFileTypes: true, recursive: true }) + .filter((entry) => entry.isFile() && entry.name.endsWith('.md')) + .map((entry) => join(entry.parentPath, entry.name)); +} + +function unresolvedReferences(skillDir) { + const missing = []; + for (const file of markdownFiles(skillDir)) { + for (const reference of readFileSync(file, 'utf8').match(REFERENCE_PATH) ?? []) { + if (!existsSync(join(skillDir, reference))) missing.push(`${relative(skillDir, file)} → ${reference}`); + } + } + return missing; +} + +describe('migrate-email skill', () => { + let outputDir; + + afterEach(() => { + vi.unstubAllGlobals(); + vi.unstubAllEnvs(); + if (outputDir) rmSync(outputDir, { recursive: true, force: true }); + }); + + it.each(['migrate-email-resend', 'migrate-statsig'])( + 'builds %s as a bundle whose every reference path resolves', + async (skillId) => { + outputDir = mkdtempSync(join(tmpdir(), 'migrate-skill-')); + + const skillDir = await buildSkill(skillId, outputDir); + + expect(readFileSync(join(skillDir, 'SKILL.md'), 'utf8')).toMatch(new RegExp(`^---\\nname: ${skillId}\\n`)); + expect(unresolvedReferences(skillDir)).toEqual([]); + }, + ); + + it('bundles the send API reference and the Resend files without the send skill', async () => { + outputDir = mkdtempSync(join(tmpdir(), 'migrate-skill-')); + + const skillDir = await buildSkill('migrate-email-resend', outputDir); + + expect(readFileSync(join(skillDir, 'references', 'transactional-email-api.md'), 'utf8')).toBe(DOCS_PAGE); + expect(existsSync(join(skillDir, 'references', 'resend', 'sdk-reference.md'))).toBe(true); + expect(markdownFiles(skillDir).map((file) => readFileSync(file, 'utf8')).join('\n')).not.toMatch(/\{\{>|\{display_name\}|\{references\}/); + }); + + it('publishes Resend and Statsig as wizard migrate subcommands', async () => { + const { skills } = await loadSkills(); + const cliOf = (id) => skills.find((skill) => skill.id === id)?._cli; + + expect(cliOf('migrate-email-resend')).toEqual({ role: 'command', parentCommand: 'migrate', command: 'resend' }); + expect(cliOf('migrate-statsig')).toEqual({ role: 'command', parentCommand: 'migrate', command: 'statsig' }); + }); +}); From 5e019aa3ba673a1980571f0ee27c3fac61695675 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 22 Oct 2026 06:46:19 +0000 Subject: [PATCH 04/70] fix(skills): keep migrate-email's summary values bare and define a site Fixture runs wrote reasons into the summary block, which the Wizard can't parse, and counted a forwarding helper as one site or as each caller. The report step now shows bare values, and a site is the place that decides a send's content and fields. Co-Authored-By: Claude Opus 5.5 --- .../migrate-email/references/3-inventory.md | 5 +++- .../migrate-email/references/7-report.md | 23 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index 1755818f0..884e90052 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -18,7 +18,10 @@ List every place the code sends email through the provider, and decide for each Read the provider's `sdk-reference.md` for the call shapes, and its `mapping.md` for the fields. -A **site** is one place in the code that calls the provider to send, such as one `emails.send(...)` call or one HTTP request to the send endpoint. A helper that wraps the call is one site, however many places call the helper. Read the callers of a helper anyway: they decide values such as how many recipients a send has. +A **site** is one place in the code that decides what a send contains: its content and its fields. Usually that is the `emails.send(...)` call or the HTTP request itself. + +- When a helper builds the send from a few parameters, such as a subject and a template name, the helper is one site, however many places call it. Read its callers anyway: they decide values such as how many recipients a send has. +- When a helper only forwards a payload that its callers build, each caller is a site, and the helper is not. For each site, read the surrounding code and record: diff --git a/context/skills/migrate-email/references/7-report.md b/context/skills/migrate-email/references/7-report.md index 0dfb9a330..6869e754e 100644 --- a/context/skills/migrate-email/references/7-report.md +++ b/context/skills/migrate-email/references/7-report.md @@ -56,18 +56,25 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ## Summary ``` -End the report with the summary block, as the last thing in the file. The Wizard reads it, so keep the keys and their order: +End the report with the summary block, as the last thing in the file. The Wizard parses it, so keep the keys, their order, and bare values: a whole number, `true`, `false`, or the provider folder name. Never add a comment or a reason to a value. The reasons are in the tables above. For example: ```yaml -from: -sites_found: -sites_rewritten: -sites_left: -dns_ready: -suppressions_ready: +from: resend +sites_found: 3 +sites_rewritten: 0 +sites_left: 1 +dns_ready: false +suppressions_ready: true ``` -This version changes no site, so `sites_rewritten` is `0`. Sites that are ready to move count in `sites_found` only. +- `from`: the provider folder name. +- `sites_found`: every row of the sites table. +- `sites_rewritten`: the sites this run changed to send with PostHog. This version changes none, so it is `0`. +- `sites_left`: the sites that stay on the provider. +- `dns_ready`: `true` when every sending domain has a verified sender. +- `suppressions_ready`: `true` when the suppression list was imported or was empty. + +Sites that are ready to move count in `sites_found` only. After the report is written, print its path: From 6e902dc5ffc67178253e4a5682de11ef4169be11 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Sat, 31 Oct 2026 09:52:37 +0000 Subject: [PATCH 05/70] fix(skills): point migrate-email at the transactional email docs and the sending skill The send-transactional-email skill is gone from this stack, so migrate-email bundles the transactional email pages and names the sending-transactional-emails skill for the general move. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/config.yaml | 3 ++- context/skills/migrate-email/description.md | 4 +++- .../references/resend/mapping.md | 2 +- scripts/lib/tests/migrate-email-skill.test.js | 19 +++++++++++++------ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/context/skills/migrate-email/config.yaml b/context/skills/migrate-email/config.yaml index 6b0b83c37..2accfcd59 100644 --- a/context/skills/migrate-email/config.yaml +++ b/context/skills/migrate-email/config.yaml @@ -10,7 +10,8 @@ cli: references: preamble: "**Read ONLY this file.** Do not read any other reference file until this one tells you to." shared_docs: - - https://posthog.com/docs/workflows/transactional-email-api.md + - https://posthog.com/docs/workflows/transactional-emails.md + - https://posthog.com/docs/workflows/transactional-emails/api.md variants: - id: resend display_name: Resend diff --git a/context/skills/migrate-email/description.md b/context/skills/migrate-email/description.md index 174a82b6a..7bb85a8d2 100644 --- a/context/skills/migrate-email/description.md +++ b/context/skills/migrate-email/description.md @@ -52,4 +52,6 @@ Outside the Wizard, skip the `[STATUS]` lines, and tell the person why you stopp {references} -`transactional-email-api.md` is the transactional email API page. It covers senders, the send forms, `posthog-node`, idempotency, and every error code. +`transactional-emails.md` is the transactional email overview. It covers how to create a transactional email and its API key, idempotency, and the error codes. `api.md` covers the send route, including content from your code, and the checks of a send. + +When the `sending-transactional-emails` skill is available, read it too. Its `moving-from-other-providers.md` moves any provider's sends to a PostHog template. This skill adds what is specific to {display_name}: it finds every send, sets up the sender next to {display_name}'s DNS records, imports {display_name}'s suppression list, and hands over the key. diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index eecb90fb0..8649ddbd8 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -1,6 +1,6 @@ # Resend to PostHog mapping -This file decides, field by field, whether PostHog can send a Resend call site. A site moves only when every field it sets moves. Otherwise it stays on Resend, and the reason names the first field or feature that keeps it there. `transactional-email-api.md` has the PostHog side in full. +This file decides, field by field, whether PostHog can send a Resend call site. A site moves only when every field it sets moves. Otherwise it stays on Resend, and the reason names the first field or feature that keeps it there. `api.md` has the PostHog side in full. ## Fields diff --git a/scripts/lib/tests/migrate-email-skill.test.js b/scripts/lib/tests/migrate-email-skill.test.js index 29ca4ea6c..8ffca7b6e 100644 --- a/scripts/lib/tests/migrate-email-skill.test.js +++ b/scripts/lib/tests/migrate-email-skill.test.js @@ -4,16 +4,18 @@ import { join, relative } from 'path'; import { tmpdir } from 'os'; const CONFIG_DIR = join(process.cwd(), 'context'); -const DOCS_URL = 'https://posthog.com/docs/workflows/transactional-email-api.md'; -const DOCS_PAGE = '# Transactional email API\n\nSend one email to one person from your server code.\n'; +const DOCS_PAGES = { + 'https://posthog.com/docs/workflows/transactional-emails.md': '# Transactional emails\n\nSend one email to one person.\n', + 'https://posthog.com/docs/workflows/transactional-emails/api.md': '# Send transactional emails with the API\n', +}; const REFERENCE_PATH = /references\/[A-Za-z0-9_./-]+\.md/g; async function loadSkills() { vi.resetModules(); vi.stubEnv('DOCS_CACHE_TTL_MS', '0'); vi.stubGlobal('fetch', async (url) => { - if (url !== DOCS_URL) return new Response('not found', { status: 404, statusText: 'Not Found' }); - return new Response(DOCS_PAGE, { status: 200 }); + if (!(url in DOCS_PAGES)) return new Response('not found', { status: 404, statusText: 'Not Found' }); + return new Response(DOCS_PAGES[url], { status: 200 }); }); const generator = await import('../skill-generator.js'); const skills = generator.expandSkillGroups(generator.loadSkillsConfig(CONFIG_DIR), CONFIG_DIR); @@ -76,12 +78,17 @@ describe('migrate-email skill', () => { }, ); - it('bundles the send API reference and the Resend files without the send skill', async () => { + it('bundles the transactional email docs and the Resend files', async () => { outputDir = mkdtempSync(join(tmpdir(), 'migrate-skill-')); const skillDir = await buildSkill('migrate-email-resend', outputDir); - expect(readFileSync(join(skillDir, 'references', 'transactional-email-api.md'), 'utf8')).toBe(DOCS_PAGE); + expect(readFileSync(join(skillDir, 'references', 'transactional-emails.md'), 'utf8')).toBe( + DOCS_PAGES['https://posthog.com/docs/workflows/transactional-emails.md'], + ); + expect(readFileSync(join(skillDir, 'references', 'api.md'), 'utf8')).toBe( + DOCS_PAGES['https://posthog.com/docs/workflows/transactional-emails/api.md'], + ); expect(existsSync(join(skillDir, 'references', 'resend', 'sdk-reference.md'))).toBe(true); expect(markdownFiles(skillDir).map((file) => readFileSync(file, 'utf8')).join('\n')).not.toMatch(/\{\{>|\{display_name\}|\{references\}/); }); From 0286e235e3c0d2ac05e102d3e3ab130e1b721513 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Sun, 1 Nov 2026 13:02:02 +0000 Subject: [PATCH 06/70] fix(skills): check migrate-email's API access with the real tools and PostHog's reply-to rules The preflight looked for two MCP tools that don't exist. It now looks for the make-transactional pair, and a missing pair records the API as not confirmed instead of stopping, because it can also mean a missing scope. The mapping now keeps a site on Resend for reply-to addresses with a name or more than 10, and lists every reserved header and the header and tag length limits. Co-Authored-By: Claude Opus 5.5 --- .../skills/migrate-email/references/2-preflight.md | 11 +++-------- .../skills/migrate-email/references/resend/mapping.md | 6 +++--- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/context/skills/migrate-email/references/2-preflight.md b/context/skills/migrate-email/references/2-preflight.md index ffd88264d..a643d9be2 100644 --- a/context/skills/migrate-email/references/2-preflight.md +++ b/context/skills/migrate-email/references/2-preflight.md @@ -18,15 +18,10 @@ Do not change any file. Check which PostHog MCP tools exist. - When there are no PostHog tools at all, the PostHog MCP is not connected or not signed in. Ask the person to connect it, and wait. -- When other PostHog tools exist but `workflows-upload-email-template` and `workflows-send-email` don't, the transactional email API is not enabled for this project. Stop and tell the person: the API is in beta, and they can ask PostHog in-app to enable it for their project. Then emit: +- When `workflows-make-email-template-transactional-prepare` and `workflows-make-email-template-transactional-execute` exist, the API is on. Record `api: on`. +- When other PostHog tools exist but that pair doesn't, either the login lacks the `hog_flow:write` scope, or transactional email is not on for the project yet. A missing tool cannot tell these apart. Tell the person both causes, record `api: not confirmed`, and continue. The report asks them to confirm it before cutover. -``` -[ABORT] transactional email api not enabled -``` - -- When both tools exist, the API is on. Record `api: on`. - -Inside the Wizard, a missing tool can mean that the login lacks its scope, so missing tools do not stop the run. Record `api: not confirmed` and continue. The report asks the person to confirm it. +Do not call a tool that changes anything to find out. ## The sending tier diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 8649ddbd8..097d84c87 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -14,9 +14,9 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `react` | `html`, rendered in the app | Never. The app renders the component | | `template` | a local template in the app's code | The template uses syntax beyond variables and fallbacks | | `cc`, `bcc` | `cc`, `bcc` | An entry carries a name, such as `Jane `, or there are more than 10 | -| `replyTo` / `reply_to` | `replyTo` / `reply_to` | Never | -| `headers` | `headers` | A header is one PostHog sets itself (`From`, `To`, `Cc`, `Bcc`, `Reply-To`, `Subject`, `Date`, `Message-ID`, `MIME-Version`, `Sender`, `Return-Path`, `Auto-Submitted`, any `Content-*`, `X-PostHog-*`, `X-SES-*`), a value has a line break or a non-ASCII character, or there are more than 10 | -| `tags` | `tags` | A name or value has characters other than ASCII letters, digits, `_`, and `-`, a name starts with `ph_`, or there are more than 10 | +| `replyTo` / `reply_to` | `replyTo` / `reply_to`, as a list | An entry carries a name, such as `Jane `, there are more than 10, or the code builds the value at run time and you cannot tell that it holds bare addresses only. A single address moves as a list of one | +| `headers` | `headers` | A header is one PostHog sets itself (`From`, `To`, `Cc`, `Bcc`, `Reply-To`, `Subject`, `Date`, `Message-ID`, `MIME-Version`, `Sender`, `Return-Path`, `Auto-Submitted`, `DKIM-Signature`, `Received`, any `Content-*`, `X-PostHog-*`, `X-SES-*`), a name is longer than 126 characters, a value is longer than 870 characters or has a line break or a non-ASCII character, or there are more than 10 | +| `tags` | `tags` | A name or value has characters other than ASCII letters, digits, `_`, and `-` or is longer than 256 characters, a name starts with `ph_`, or there are more than 10 | | `attachments` | `attachments` | An attachment uses `path` (a URL Resend fetches), the files can be more than 10 or more than 512 KB in total, or a file type is one mailbox providers block, such as `.exe` | | `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | Never. The key keeps its value | | `scheduledAt` / `scheduled_at` | none | Always | From 0920218521daeb77280e41f90bb5f0e409d853c2 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 22 Oct 2026 07:00:11 +0000 Subject: [PATCH 07/70] refactor(skills): share the posthog-node client setup as a partial Co-Authored-By: Claude Opus 5.5 --- context/shared/email-node-client.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 context/shared/email-node-client.md diff --git a/context/shared/email-node-client.md b/context/shared/email-node-client.md new file mode 100644 index 000000000..3f26ccb42 --- /dev/null +++ b/context/shared/email-node-client.md @@ -0,0 +1,7 @@ +--- +title: Configure the posthog-node client for email +--- + +- Reuse the app's existing `posthog-node` client when it has one, and add `secretKey`. Keep `enableLocalEvaluation: false` unless the key also has `feature_flag:read` and the app uses local evaluation. +- When the project token or the host is not configured yet, get the token from the PostHog MCP `projects-get` tool (`api_token`). The host is `https://us.i.posthog.com` for US Cloud and `https://eu.i.posthog.com` for EU Cloud. Ask the person which one when you can't tell. +- When `host` is a reverse proxy or a self-hosted instance, also set `appHost` to the PostHog app URL, such as `https://us.posthog.com`. posthog-node never sends the secret key to a proxy, and without `appHost` the send fails with `missing_app_host`. From 64a2397db57f938a5052a733e1c67ac83b13baae Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 22 Oct 2026 07:00:11 +0000 Subject: [PATCH 08/70] feat(skills): move Resend sends to posthog-node in migrate-email The migrate-email skill now rewrites every call site PostHog can send: hosted Resend templates become local templates, React and html/text sites send rendered content, and the client carries migratedFrom. It checks the build and one email on one person before it writes the report. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/config.yaml | 2 +- context/skills/migrate-email/description.md | 12 ++-- .../migrate-email/references/3-inventory.md | 4 ++ .../skills/migrate-email/references/6-key.md | 2 +- .../migrate-email/references/7-rewrite.md | 68 +++++++++++++++++++ .../migrate-email/references/8-verify.md | 48 +++++++++++++ .../references/{7-report.md => 9-report.md} | 30 +++++--- .../references/resend/account.md | 18 ++++- .../references/resend/mapping.md | 41 ++++++++++- .../references/resend/sdk-reference.md | 7 +- scripts/lib/tests/migrate-email-skill.test.js | 19 ++++++ 11 files changed, 227 insertions(+), 24 deletions(-) create mode 100644 context/skills/migrate-email/references/7-rewrite.md create mode 100644 context/skills/migrate-email/references/8-verify.md rename context/skills/migrate-email/references/{7-report.md => 9-report.md} (58%) diff --git a/context/skills/migrate-email/config.yaml b/context/skills/migrate-email/config.yaml index 2accfcd59..8becd4c82 100644 --- a/context/skills/migrate-email/config.yaml +++ b/context/skills/migrate-email/config.yaml @@ -2,7 +2,7 @@ type: skill template: description.md category: migrate -description: Migrate transactional email from {display_name} to PostHog. Use when asked to migrate from {display_name}, replace {display_name} with PostHog, or switch email providers. It finds every {display_name} send in the code, sets up the sender and DNS next to {display_name}'s records, imports {display_name}'s suppression list, hands over the PostHog secret key, and writes a migration report. It changes no send call site yet. +description: Migrate transactional email from {display_name} to PostHog. Use when asked to migrate from {display_name}, replace {display_name} with PostHog, or switch email providers. It finds every {display_name} send in the code, sets up the sender and DNS next to {display_name}'s records, imports {display_name}'s suppression list, moves each send PostHog can take to posthog-node, and writes a migration report that lists the sends that stay. tags: [migration, workflows] cli: role: command diff --git a/context/skills/migrate-email/description.md b/context/skills/migrate-email/description.md index 7bb85a8d2..9eaf4cf41 100644 --- a/context/skills/migrate-email/description.md +++ b/context/skills/migrate-email/description.md @@ -2,7 +2,7 @@ Use this skill to move an app's transactional email, such as welcome emails, password resets, and receipts, from {display_name} to PostHog. -This version prepares the move and changes no send call site. It finds every {display_name} send, sets up the PostHog sender and its DNS records next to {display_name}'s, imports {display_name}'s suppression list, hands over the PostHog secret key, and writes a report. Both providers can send during the cutover. +It finds every {display_name} send, sets up the PostHog sender and its DNS records next to {display_name}'s, imports {display_name}'s suppression list, and hands over the PostHog secret key. Then it moves every send PostHog can take to `posthog-node`, checks one email on one person, and writes a report. Sends PostHog can't take stay on {display_name} with a reason, so both providers send during the cutover. The transactional email API is in beta. PostHog enables it per project. @@ -17,8 +17,8 @@ Read the step files in order, one at a time. Each step names the next one. Do no The folder `references//` holds everything specific to {display_name}. The steps tell you when to read each file: - `sdk-reference.md`: how {display_name} looks in code, so you can find every send. -- `mapping.md`: how each send field maps to PostHog, and what keeps a call site on {display_name}. -- `account.md`: {display_name}'s DNS records and how to export its suppression list. +- `mapping.md`: how each send field maps to PostHog, what keeps a call site on {display_name}, and how to rewrite a site that moves. +- `account.md`: {display_name}'s DNS records, and how to get its templates and its suppression list. Everything you need is on disk. Do not fetch {display_name}'s docs. @@ -28,10 +28,10 @@ The plan file `.posthog-email-migration-plan.md` lives at the project root. Step ## Rules -- Change no send call site. This version only prepares the move. +- Change only the call sites that move, and only in Step 7. Leave every site that stays as it is. - Never touch DNS or the {display_name} account. Give the person the records and the links, and let them make the change. -- Never remove the {display_name} package, its client, or its API key. -- Never create, upload, or edit a template in PostHog. +- Never remove the {display_name} package or its API key. The report tells the person when to remove them. +- Never create, upload, or edit a template in PostHog. A moved local template uploads on its first send. - Never write a recipient's email address into a file in the repository, the plan, or the report. Count addresses instead. - Keep keys in environment variables. Never hardcode a key, and never ask the person to paste one into the chat. - Do not commit. The person reviews the diff and commits. diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index 884e90052..452109d72 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -39,6 +39,8 @@ Go through `mapping.md` field by field. A site **moves** when PostHog can send e When the code passes a value you can't read, such as a list of recipients built at run time, follow it to its callers. When you still can't tell, the site stays, and the reason says what you could not check. +A `template` site needs the template's content to be classified. Read the provider's `account.md`, and ask the person once for every template the sites send: copy from the dashboard, or read through the API. Keep the content for Step 7, and never write it into the plan. When the person can't give the content, the site stays. + ## Write the plan file Write `.posthog-email-migration-plan.md` at the project root with three sections. Never write an email address of a recipient into it. A `from` address is fine. @@ -51,6 +53,8 @@ A phase checklist, in this order. Tick `preflight` with what Step 2 recorded, an - [ ] sender - [ ] suppressions - [ ] key +- [ ] rewrite +- [ ] verify ``` A sites table, one row per site, in source tree order: diff --git a/context/skills/migrate-email/references/6-key.md b/context/skills/migrate-email/references/6-key.md index 0b4a08208..0c39a80d5 100644 --- a/context/skills/migrate-email/references/6-key.md +++ b/context/skills/migrate-email/references/6-key.md @@ -1,6 +1,6 @@ --- title: Hand over the PostHog secret key -next_step: 7-report.md +next_step: 7-rewrite.md --- # Step 6, hand over the PostHog secret key diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md new file mode 100644 index 000000000..f107996d0 --- /dev/null +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -0,0 +1,68 @@ +--- +title: Move every site that can move +next_step: 8-verify.md +--- + +# Step 7, move every site that can move + +Rewrite each site whose `moves` is `yes` in the plan to send with `posthog-node`. The provider's `mapping.md` has the rewrite of each field, call, and content form under "Rewrite". + +## Status + +``` +[STATUS] Setting up posthog-node for email +[STATUS] Moving the send call sites +``` + +## Before you change code + +- Change only the sites whose `moves` is `yes`. Never change a site that stays, and never change a line that a site that stays still needs. +- When no site moves, tick the phase in the plan with `none moved` and go to the next step. + +## Set up the client + +Install or upgrade `posthog-node` with the project's package manager, to a version that has `posthog.emails`. + +Configure one server-side client for email. Set `migratedFrom` to the provider folder name, once on the client, so PostHog knows which sends a migration moved: + +```js +import { PostHog } from 'posthog-node' + +export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { + host: process.env.POSTHOG_HOST, + secretKey: process.env.POSTHOG_PROJECT_SECRET_API_KEY, + migratedFrom: 'resend', + enableLocalEvaluation: false, +}) +``` + +{{> email-node-client}} +- A reused client gets `migratedFrom` too. +- Put a new client in its own server-only module, next to the provider's client, and import it where the sites send. +- Use the env variable names the app already uses for the PostHog token and host. Add each new name, without a value, to the env example file. + +## Find the user ID + +PostHog shows each email on the person the send names with `distinctId`. Use the ID the app already identifies people with in PostHog: + +- Find the app's identify call, such as `posthog.identify(user.id)` in posthog-js, or the `distinctId` of its `posthog-node` captures. +- At each site, pass the same ID for the recipient, such as `distinctId: user.id`. Follow the recipient back through the callers when the site only has the address. +- When the recipient is not a user of the app, such as a team inbox, or the site has no way to know the user, leave `distinctId` out and note it in the plan row. +- When the app identifies no one in PostHog, use the app's own user ID, and note it for the report. + +## Rewrite each site + +For each site that moves, in plan order: + +- Rewrite the call as the provider's `mapping.md` says, for the site's content form: `html` and `text` content, a component the app renders, or a template stored at the provider. +- Give each send a `templateKey` that names the kind of email, such as `welcome` or `password-reset`, with letters, digits, `-`, and `_` only. Two sites that send the same email share a key. A template stored at the provider keeps the key `mapping.md` gives it. +- A template stored at the provider becomes a module that exports `subject` and `html`, and `text` when it has one, in an `emails/` folder next to the server code. The site imports it and passes `templateData`. +- Install `@react-email/render` with the project's package manager when a site renders a component and the app doesn't have it. +- Keep the site's idempotency key, error branches, logging, and return value working as before. Keep the code around the send unchanged where you can. +- Never add a field that the old call didn't set, apart from `templateKey` and `distinctId`. + +When a site turns out to need something `mapping.md` keeps on the provider, undo its change, set `moves` to `no` with the reason, and go on. + +## Write down + +Tick the phase in the plan: `- [x] rewrite — sites moved`. Add a `key` column to the sites table with each moved site's `templateKey`. Under the table, note each site without a `distinctId`, each fallback that an empty string now replaces, each new dependency, and each new env variable name. diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md new file mode 100644 index 000000000..61ee2c3a7 --- /dev/null +++ b/context/skills/migrate-email/references/8-verify.md @@ -0,0 +1,48 @@ +--- +title: Check the moved sites +next_step: 9-report.md +--- + +# Step 8, check the moved sites + +Check that the app still builds, its tests still pass, and one moved email reaches one person in PostHog. When no site moved in Step 7, tick the phase with `nothing to check` and go to the next step. + +## Status + +``` +[STATUS] Checking the moved sites +[STATUS] Sending a test email +``` + +## Build and tests + +- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error in a line you changed. An error in a file you didn't change was there before: note it, and leave it. +- Run the tests that cover the files you changed. A test that mocks the provider's client for a moved site now mocks `posthog.emails.send` with the same assertions. Never delete or skip a test. +- Search the changed files for the provider's calls: a moved site has none left, and each moved site has one `posthog.emails.send`. + +## One email on one person + +The chain to prove: PostHog sends the email, records its engagement on the person, and that person's product events show next to it. + +Skip this part and record `not checked` with the reason when the API is not confirmed on, no sender is verified, or `POSTHOG_PROJECT_SECRET_API_KEY` is not set. + +1. Ask the person whether to send one test email. Say that it sends a real email, and that the first send of a local template uploads it to the PostHog project. When they say no, record `not checked: declined`. +2. Ask them to trigger one moved email in their local app while they are signed in as themselves, such as a signup or a password reset, so the email goes to an address they own. Ask them to tell you when it is sent and to open the email. +3. When the send fails, find its code in `transactional-email-api.md`, tell the person the fix, and record it. Never retry a send yourself. +4. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID over the last hour: + + ```sql + SELECT event, timestamp FROM events + WHERE distinct_id = '' AND timestamp > now() - INTERVAL 1 HOUR + ORDER BY timestamp + ``` + +5. The chain holds when the result has `$workflows_email_sent`, an engagement event such as `$workflows_email_delivered` or `$workflows_email_opened`, and at least one product event of the app. Delivery events arrive after the provider reports back: when only the send shows, wait a minute and run the query once more. + +When the MCP has no SQL tool, ask the person to open their person in PostHog and tell you which of the three they see. + +Never write the address or the distinct ID into a file. + +## Write down + +Tick the phase in the plan: `- [x] verify — typecheck: , tests: , chain: `. diff --git a/context/skills/migrate-email/references/7-report.md b/context/skills/migrate-email/references/9-report.md similarity index 58% rename from context/skills/migrate-email/references/7-report.md rename to context/skills/migrate-email/references/9-report.md index 6869e754e..08441c30b 100644 --- a/context/skills/migrate-email/references/7-report.md +++ b/context/skills/migrate-email/references/9-report.md @@ -3,7 +3,7 @@ title: Write the migration report next_step: null --- -# Step 7, write the migration report +# Step 9, write the migration report The report comes from the plan file. Invent nothing. @@ -20,14 +20,16 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ```markdown # Email migration report: to PostHog - + ## Send call sites -| File | Line | Content | Status | -|------|------|---------|--------| +| File | Line | Content | Key | Status | +|------|------|---------|-----|--------| -: ".> +", or "Stays on : ".> + + ## Other calls @@ -45,13 +47,23 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- +## Checks + + + ## Sending tier ## Before cutover -
+The moved sites send through PostHog as soon as this code is deployed. Everything in this list has to be done before that deploy. + + + +## After cutover + + ## Summary ``` @@ -61,7 +73,7 @@ End the report with the summary block, as the last thing in the file. The Wizard ```yaml from: resend sites_found: 3 -sites_rewritten: 0 +sites_rewritten: 2 sites_left: 1 dns_ready: false suppressions_ready: true @@ -69,13 +81,11 @@ suppressions_ready: true - `from`: the provider folder name. - `sites_found`: every row of the sites table. -- `sites_rewritten`: the sites this run changed to send with PostHog. This version changes none, so it is `0`. +- `sites_rewritten`: the sites this run moved to send with PostHog. - `sites_left`: the sites that stay on the provider. - `dns_ready`: `true` when every sending domain has a verified sender. - `suppressions_ready`: `true` when the suppression list was imported or was empty. -Sites that are ready to move count in `sites_found` only. - After the report is written, print its path: ``` diff --git a/context/skills/migrate-email/references/resend/account.md b/context/skills/migrate-email/references/resend/account.md index dfd42d4b5..f4c38602e 100644 --- a/context/skills/migrate-email/references/resend/account.md +++ b/context/skills/migrate-email/references/resend/account.md @@ -18,18 +18,32 @@ A domain verified at Resend carries these records. Keep all of them until the cu - PostHog's DKIM records have their own names, so they sit next to `resend._domainkey`. - Keep the one `_dmarc` record. Never add a second one. +## Full-access key + +The app's own Resend key is usually a sending-only key, and it can't read templates or the suppression list. When the person chooses the API over the dashboard, ask them to create a full-access key in Resend, store it in `RESEND_FULL_ACCESS_API_KEY` in the git-ignored env file, and delete the key in Resend after the migration. Never print the key, and never write it into another file. + +## Template content + +A site that sends a template stored at Resend needs the template's content. + +**Copy from the dashboard.** In Resend: Templates, then the template. Ask the person for its HTML, its plain text when it has one, its subject, its `from` and reply-to when they are set, and each variable's fallback. + +**Read from the API.** `GET https://api.resend.com/templates/{id or alias}` with `Authorization: Bearer $RESEND_FULL_ACCESS_API_KEY`. The answer holds `alias`, `name`, `subject`, `from`, `reply_to`, `html`, `text`, and `variables`, a list of `{ key, type, fallback_value }`. + +The content goes only into the template module the rewrite writes. Never write it into the plan or the report. + ## Suppression list Resend suppresses an address after a hard bounce or a spam complaint, and keeps addresses the team added by hand. **Export from the dashboard (preferred).** In Resend: Emails, then Suppressions, then **Download CSV**. Read the header row to find the address column and the origin column. -**Read from the API.** `GET https://api.resend.com/suppressions?limit=100` with `Authorization: Bearer $RESEND_SUPPRESSIONS_API_KEY`. +**Read from the API.** `GET https://api.resend.com/suppressions?limit=100` with `Authorization: Bearer $RESEND_FULL_ACCESS_API_KEY`. - The answer is `{ "object": "list", "has_more": , "data": [{ "id", "email", "origin", "source_id", "created_at" }] }`. - Page with `after=` until `has_more` is `false`. - Resend allows 10 requests per second per team. Wait and retry on `429`. -- A sending-only key can't read the list. Ask the person to create a full-access key, store it in `RESEND_SUPPRESSIONS_API_KEY` for the import, and delete the key in Resend afterwards. +- A sending-only key can't read the list. Use the full-access key below. **Map each entry.** diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 097d84c87..cf8bc23f6 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -12,13 +12,13 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `html` | `html` | Never | | `text` | `text` | Never | | `react` | `html`, rendered in the app | Never. The app renders the component | -| `template` | a local template in the app's code | The template uses syntax beyond variables and fallbacks | +| `template` | a local template in the app's code | Its content can't be read, it uses syntax beyond variables and fallbacks, or the app fills a variable with HTML | | `cc`, `bcc` | `cc`, `bcc` | An entry carries a name, such as `Jane `, or there are more than 10 | | `replyTo` / `reply_to` | `replyTo` / `reply_to`, as a list | An entry carries a name, such as `Jane `, there are more than 10, or the code builds the value at run time and you cannot tell that it holds bare addresses only. A single address moves as a list of one | | `headers` | `headers` | A header is one PostHog sets itself (`From`, `To`, `Cc`, `Bcc`, `Reply-To`, `Subject`, `Date`, `Message-ID`, `MIME-Version`, `Sender`, `Return-Path`, `Auto-Submitted`, `DKIM-Signature`, `Received`, any `Content-*`, `X-PostHog-*`, `X-SES-*`), a name is longer than 126 characters, a value is longer than 870 characters or has a line break or a non-ASCII character, or there are more than 10 | | `tags` | `tags` | A name or value has characters other than ASCII letters, digits, `_`, and `-` or is longer than 256 characters, a name starts with `ph_`, or there are more than 10 | | `attachments` | `attachments` | An attachment uses `path` (a URL Resend fetches), the files can be more than 10 or more than 512 KB in total, or a file type is one mailbox providers block, such as `.exe` | -| `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | Never. The key keeps its value | +| `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | The key can hold a space or a non-ASCII character, or be longer than 255 characters. Otherwise the key keeps its value and its meaning: both providers keep a key for 24 hours | | `scheduledAt` / `scheduled_at` | none | Always | | `topicId` / `topic_id` | none | Always | @@ -43,4 +43,39 @@ This file decides, field by field, whether PostHog can send a Resend call site. ## Content - `html`, `text`, and `react` content is rendered for one recipient before the send. PostHog sends it as it is. -- A `template` site needs the template's content from the Resend dashboard, because the code has only its id. PostHog's Liquid escapes HTML in a variable's value. A variable the app fills with HTML keeps the site on Resend. +- A `template` site needs the template's content, because the code has only its id. `account.md` says how to get it. +- Resend inserts a variable's value as it is. PostHog's Liquid escapes HTML in a value, so `` shows as text. A variable is HTML when the code fills it with markup or with a renderer's output. A variable the app fills with plain values, such as names, numbers, and URLs, renders the same. +- A template that holds anything other than `{{{VAR}}}` and `{{{VAR|fallback}}}` placeholders, such as a section, a loop, or a condition, stays on Resend. + +## Rewrite + +How a site that moves is written with `posthog-node`. Step 7 says when to use each part. + +**The call.** `resend.emails.send(payload, { idempotencyKey })` and `resend.emails.create(...)` become one `posthog.emails.send({ ... })`. The options object goes away: `idempotencyKey` moves into the payload. + +**The fields.** + +- `to: ['jane@example.com']` becomes `to: 'jane@example.com'`. A value that is a list with one entry becomes that entry. +- `from`, `subject`, `html`, `text`, `replyTo`, `cc`, `bcc`, `headers`, and `tags` keep their names and values. +- `attachments` keep `filename`, `content`, `contentType`, and `contentId`. +- Each send gets a `templateKey`, as Step 7 says. + +**React.** `react: ` becomes `html: await render()`, with `import { render } from '@react-email/render'`. Keep a `text` the site already passes. + +**HTTP.** A `fetch` or `axios` call to `https://api.resend.com/emails` becomes `posthog.emails.send` with the camelCase fields: `reply_to` becomes `replyTo`, and the `Idempotency-Key` header becomes `idempotencyKey`. Code that read the response status reads `error` instead. + +**Templates stored at Resend.** The template becomes a module in the app's code, in the format of the send skill's local template: a `subject` and an `html` string, and a `text` string when the template has one. + +- `{{{NAME}}}` becomes `{{ variables.NAME }}`. The name keeps its case. +- `{{{NAME|there}}}` becomes `{{ variables.NAME | default: "there" }}`. A variable with a `fallback_value` in the template's definition gets the same `default`. Escape a `"` in the fallback as `\"`. +- Liquid's `default` also replaces an empty string, which Resend inserts as it is. When the code can pass an empty string for a variable with a fallback, the email shows the fallback instead. Note it in the report. +- The site sends `templateKey`, `subject`, `html`, `text` when there is one, and `templateData` with the site's `variables` object unchanged. +- The site's own `subject`, `from`, and `replyTo` win over the template's. When the site has none, use the template's: put its `from` and `replyTo` on the send, and its subject in the module. +- The template's alias, or its name in lowercase with `-` between words, becomes the `templateKey` and the module's file name. + +**The answer.** posthog-node answers `{ data, error }` like Resend and never throws on an API error. + +- `data.id` is PostHog's message id. Code that logs it or stores it for the app's own use keeps working. +- `error.name` uses Resend's names, so `if (error.name === 'rate_limit_exceeded')` keeps working. `error.message` and `error.statusCode` keep their names. + +**The Resend client.** Keep `new Resend(...)` and its import while any site or other call still uses it. When nothing uses it, remove the import and the client, and keep the `resend` package and its key: the person removes them after the cutover. diff --git a/context/skills/migrate-email/references/resend/sdk-reference.md b/context/skills/migrate-email/references/resend/sdk-reference.md index fa3cf5f02..f88d47b29 100644 --- a/context/skills/migrate-email/references/resend/sdk-reference.md +++ b/context/skills/migrate-email/references/resend/sdk-reference.md @@ -79,7 +79,12 @@ const { data, error } = await resend.emails.send({ ## Templates stored at Resend -A send with `template: { id: 'tmpl_...', variables: { FIRST_NAME: 'Jane' } }` renders a template from the Resend dashboard. Its content is not in the code. The template reads variables as `{{{FIRST_NAME}}}`, with an optional fallback: `{{{FIRST_NAME|there}}}`. +A send with `template: { id: '...', variables: { PRODUCT: 'Laptop' } }` renders a template from the Resend dashboard. `id` is the template's id or its alias. Its content is not in the code. + +- The template reads variables as `{{{PRODUCT}}}`, with an optional fallback: `{{{PRODUCT|a laptop}}}`. A variable's definition in the template can also carry a `fallback_value`. +- A variable's type is `string` or `number`. +- The template can hold a default `from`, `subject`, and `reply_to`. A value the send passes wins over the default. +- A send with `template` passes no `html`, `text`, or `react`. ## Status reads diff --git a/scripts/lib/tests/migrate-email-skill.test.js b/scripts/lib/tests/migrate-email-skill.test.js index 8ffca7b6e..546138455 100644 --- a/scripts/lib/tests/migrate-email-skill.test.js +++ b/scripts/lib/tests/migrate-email-skill.test.js @@ -93,6 +93,25 @@ describe('migrate-email skill', () => { expect(markdownFiles(skillDir).map((file) => readFileSync(file, 'utf8')).join('\n')).not.toMatch(/\{\{>|\{display_name\}|\{references\}/); }); + it('moves the supported sites and checks them before it writes the report', async () => { + outputDir = mkdtempSync(join(tmpdir(), 'migrate-skill-')); + + const skillDir = await buildSkill('migrate-email-resend', outputDir); + const workflow = readFileSync(join(skillDir, 'SKILL.md'), 'utf8').match(/^\d+\. `references\/[^`]+`/gm); + + expect(workflow.map((step) => step.replace(/^\d+\. /, ''))).toEqual([ + '`references/1-detect.md`', + '`references/2-preflight.md`', + '`references/3-inventory.md`', + '`references/4-sender.md`', + '`references/5-suppressions.md`', + '`references/6-key.md`', + '`references/7-rewrite.md`', + '`references/8-verify.md`', + '`references/9-report.md`', + ]); + }); + it('publishes Resend and Statsig as wizard migrate subcommands', async () => { const { skills } = await loadSkills(); const cliOf = (id) => skills.find((skill) => skill.id === id)?._cli; From ad4b0c7a70cc48ab28234f49f4dd9b9e65552f3d Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 22 Oct 2026 07:07:57 +0000 Subject: [PATCH 09/70] fix(skills): keep migrate-email from splitting sends or faking the old provider in tests Fixture runs looped over or truncated a one-recipient list, and one run mocked posthog-node to rebuild a Resend request. The rewrite now narrows the helper's parameter to one address, and the verify step asserts on the fields posthog.emails.send gets. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/8-verify.md | 2 +- context/skills/migrate-email/references/resend/mapping.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 61ee2c3a7..2bd615b8f 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -17,7 +17,7 @@ Check that the app still builds, its tests still pass, and one moved email reach ## Build and tests - Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error in a line you changed. An error in a file you didn't change was there before: note it, and leave it. -- Run the tests that cover the files you changed. A test that mocks the provider's client for a moved site now mocks `posthog.emails.send` with the same assertions. Never delete or skip a test. +- Run the tests that cover the files you changed. A test that mocks the provider's client or intercepts its HTTP requests for a moved site now mocks `posthog.emails.send` and asserts on the fields it gets, with the same expected values. Never turn a PostHog send back into the provider's request shape to keep an old assertion. Never delete or skip a test. - Search the changed files for the provider's calls: a moved site has none left, and each moved site has one `posthog.emails.send`. ## One email on one person diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index cf8bc23f6..40d54826d 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -56,6 +56,7 @@ How a site that moves is written with `posthog-node`. Step 7 says when to use ea **The fields.** - `to: ['jane@example.com']` becomes `to: 'jane@example.com'`. A value that is a list with one entry becomes that entry. +- When a helper takes a list of recipients and every caller passes one address, change the parameter to one address and update the callers, so the type keeps a second address out. Never send one email per address in a loop, and never drop the addresses after the first. - `from`, `subject`, `html`, `text`, `replyTo`, `cc`, `bcc`, `headers`, and `tags` keep their names and values. - `attachments` keep `filename`, `content`, `contentType`, and `contentId`. - Each send gets a `templateKey`, as Step 7 says. From b2965cc70daf9be4a38c4dc72e3117262c694abd Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 22 Oct 2026 07:14:55 +0000 Subject: [PATCH 10/70] fix(skills): handle suppressed recipients and dynamic subjects in migrate-email A moved site now treats recipient_suppressed like a send that went out, a site-built subject becomes a module placeholder so the template hash stays stable, fallbacks use single quotes, and the report warns that idempotency keys don't cross providers. The rules and Step 7 no longer contradict the mapping. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/description.md | 2 +- context/skills/migrate-email/references/7-rewrite.md | 9 +++++---- .../skills/migrate-email/references/resend/mapping.md | 8 +++++--- scripts/lib/tests/migrate-email-skill.test.js | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/context/skills/migrate-email/description.md b/context/skills/migrate-email/description.md index 9eaf4cf41..52937c8b1 100644 --- a/context/skills/migrate-email/description.md +++ b/context/skills/migrate-email/description.md @@ -28,7 +28,7 @@ The plan file `.posthog-email-migration-plan.md` lives at the project root. Step ## Rules -- Change only the call sites that move, and only in Step 7. Leave every site that stays as it is. +- Change send code only in Step 7, and fix it only in Step 8: the sites that move, and the helpers, callers, and tests they need. Leave every site that stays as it is. - Never touch DNS or the {display_name} account. Give the person the records and the links, and let them make the change. - Never remove the {display_name} package or its API key. The report tells the person when to remove them. - Never create, upload, or edit a template in PostHog. A moved local template uploads on its first send. diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index f107996d0..1670e95c9 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -23,7 +23,7 @@ Rewrite each site whose `moves` is `yes` in the plan to send with `posthog-node` Install or upgrade `posthog-node` with the project's package manager, to a version that has `posthog.emails`. -Configure one server-side client for email. Set `migratedFrom` to the provider folder name, once on the client, so PostHog knows which sends a migration moved: +Configure one server-side client for email. Set `migratedFrom` to the provider folder name, such as `resend`, once on the client, so PostHog knows which sends a migration moved: ```js import { PostHog } from 'posthog-node' @@ -31,7 +31,7 @@ import { PostHog } from 'posthog-node' export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { host: process.env.POSTHOG_HOST, secretKey: process.env.POSTHOG_PROJECT_SECRET_API_KEY, - migratedFrom: 'resend', + migratedFrom: '', enableLocalEvaluation: false, }) ``` @@ -59,10 +59,11 @@ For each site that moves, in plan order: - A template stored at the provider becomes a module that exports `subject` and `html`, and `text` when it has one, in an `emails/` folder next to the server code. The site imports it and passes `templateData`. - Install `@react-email/render` with the project's package manager when a site renders a component and the app doesn't have it. - Keep the site's idempotency key, error branches, logging, and return value working as before. Keep the code around the send unchanged where you can. -- Never add a field that the old call didn't set, apart from `templateKey` and `distinctId`. +- `posthog.emails.send` never throws on an API error: it returns `{ data, error }`. When the old call threw on an error, or the code checked an HTTP status, check `error` so the site fails the same way. +- Never add a field that the old call didn't set, apart from `templateKey`, `distinctId`, and the template defaults `mapping.md` names. When a site turns out to need something `mapping.md` keeps on the provider, undo its change, set `moves` to `no` with the reason, and go on. ## Write down -Tick the phase in the plan: `- [x] rewrite — sites moved`. Add a `key` column to the sites table with each moved site's `templateKey`. Under the table, note each site without a `distinctId`, each fallback that an empty string now replaces, each new dependency, and each new env variable name. +Tick the phase in the plan: `- [x] rewrite — sites moved`. Add a `key` column to the sites table with each moved site's `templateKey`. Under the table, note each site without a `distinctId`, each fallback that an empty string now replaces, each site that got a branch for a suppressed recipient, each idempotency key a retry across the deploy could send twice, each new dependency, and each new env variable name. diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 40d54826d..6797511c4 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -18,7 +18,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `headers` | `headers` | A header is one PostHog sets itself (`From`, `To`, `Cc`, `Bcc`, `Reply-To`, `Subject`, `Date`, `Message-ID`, `MIME-Version`, `Sender`, `Return-Path`, `Auto-Submitted`, `DKIM-Signature`, `Received`, any `Content-*`, `X-PostHog-*`, `X-SES-*`), a name is longer than 126 characters, a value is longer than 870 characters or has a line break or a non-ASCII character, or there are more than 10 | | `tags` | `tags` | A name or value has characters other than ASCII letters, digits, `_`, and `-` or is longer than 256 characters, a name starts with `ph_`, or there are more than 10 | | `attachments` | `attachments` | An attachment uses `path` (a URL Resend fetches), the files can be more than 10 or more than 512 KB in total, or a file type is one mailbox providers block, such as `.exe` | -| `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | The key can hold a space or a non-ASCII character, or be longer than 255 characters. Otherwise the key keeps its value and its meaning: both providers keep a key for 24 hours | +| `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | The key can hold a space or a non-ASCII character, or be longer than 255 characters. Otherwise the key keeps its value, and PostHog keeps it for 24 hours as Resend does. The two providers don't share keys: a retry that runs after the deploy, of a send Resend already took, sends a second email. Note it in the report | | `scheduledAt` / `scheduled_at` | none | Always | | `topicId` / `topic_id` | none | Always | @@ -45,7 +45,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. - `html`, `text`, and `react` content is rendered for one recipient before the send. PostHog sends it as it is. - A `template` site needs the template's content, because the code has only its id. `account.md` says how to get it. - Resend inserts a variable's value as it is. PostHog's Liquid escapes HTML in a value, so `` shows as text. A variable is HTML when the code fills it with markup or with a renderer's output. A variable the app fills with plain values, such as names, numbers, and URLs, renders the same. -- A template that holds anything other than `{{{VAR}}}` and `{{{VAR|fallback}}}` placeholders, such as a section, a loop, or a condition, stays on Resend. +- A template that holds anything other than `{{{VAR}}}` and `{{{VAR|fallback}}}` placeholders, such as a section, a loop, or a condition, stays on Resend. So does a fallback that holds both `'` and `"`. ## Rewrite @@ -68,15 +68,17 @@ How a site that moves is written with `posthog-node`. Step 7 says when to use ea **Templates stored at Resend.** The template becomes a module in the app's code, in the format of the send skill's local template: a `subject` and an `html` string, and a `text` string when the template has one. - `{{{NAME}}}` becomes `{{ variables.NAME }}`. The name keeps its case. -- `{{{NAME|there}}}` becomes `{{ variables.NAME | default: "there" }}`. A variable with a `fallback_value` in the template's definition gets the same `default`. Escape a `"` in the fallback as `\"`. +- `{{{NAME|there}}}` becomes `{{ variables.NAME | default: 'there' }}`. A variable with a `fallback_value` in the template's definition gets the same `default`. Quote a fallback that holds a `'` with `"` instead. Liquid has no escape character in a quoted value. - Liquid's `default` also replaces an empty string, which Resend inserts as it is. When the code can pass an empty string for a variable with a fallback, the email shows the fallback instead. Note it in the report. - The site sends `templateKey`, `subject`, `html`, `text` when there is one, and `templateData` with the site's `variables` object unchanged. - The site's own `subject`, `from`, and `replyTo` win over the template's. When the site has none, use the template's: put its `from` and `replyTo` on the send, and its subject in the module. +- The module's subject is fixed text with placeholders. When the site builds its subject from values, such as `` `Order #${order.id}` ``, write the subject in the module as `Order #{{ variables.ORDER_ID }}` and add each value to `templateData`. Never send a subject that changes per email with `templateData`: PostHog hashes the subject with the template, so each email would upload a new version of the template. - The template's alias, or its name in lowercase with `-` between words, becomes the `templateKey` and the module's file name. **The answer.** posthog-node answers `{ data, error }` like Resend and never throws on an API error. - `data.id` is PostHog's message id. Code that logs it or stores it for the app's own use keeps working. - `error.name` uses Resend's names, so `if (error.name === 'rate_limit_exceeded')` keeps working. `error.message` and `error.statusCode` keep their names. +- Resend takes a send to a suppressed address and drops it later. PostHog refuses it with `error.code` `recipient_suppressed` (name `validation_error`), and refuses the whole send when a `cc` or `bcc` address is suppressed. When the site throws, retries, or reports a failure on any error, add `if (error?.code === 'recipient_suppressed')` before that branch and handle it the way the site handled a send that went out: log it and go on. Note each site that got this branch in the report. **The Resend client.** Keep `new Resend(...)` and its import while any site or other call still uses it. When nothing uses it, remove the import and the client, and keep the `resend` package and its key: the person removes them after the cutover. diff --git a/scripts/lib/tests/migrate-email-skill.test.js b/scripts/lib/tests/migrate-email-skill.test.js index 546138455..2dee17a33 100644 --- a/scripts/lib/tests/migrate-email-skill.test.js +++ b/scripts/lib/tests/migrate-email-skill.test.js @@ -93,7 +93,7 @@ describe('migrate-email skill', () => { expect(markdownFiles(skillDir).map((file) => readFileSync(file, 'utf8')).join('\n')).not.toMatch(/\{\{>|\{display_name\}|\{references\}/); }); - it('moves the supported sites and checks them before it writes the report', async () => { + it('runs the rewrite and verify steps between the key and the report', async () => { outputDir = mkdtempSync(join(tmpdir(), 'migrate-skill-')); const skillDir = await buildSkill('migrate-email-resend', outputDir); From f8f4feace4d6c790cac3dde9734618cb18b8ecf4 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 22 Oct 2026 07:17:02 +0000 Subject: [PATCH 11/70] fix(skills): keep a suppressed copy address from passing as a sent email Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/mapping.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 6797511c4..d9bbd837d 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -70,7 +70,7 @@ How a site that moves is written with `posthog-node`. Step 7 says when to use ea - `{{{NAME}}}` becomes `{{ variables.NAME }}`. The name keeps its case. - `{{{NAME|there}}}` becomes `{{ variables.NAME | default: 'there' }}`. A variable with a `fallback_value` in the template's definition gets the same `default`. Quote a fallback that holds a `'` with `"` instead. Liquid has no escape character in a quoted value. - Liquid's `default` also replaces an empty string, which Resend inserts as it is. When the code can pass an empty string for a variable with a fallback, the email shows the fallback instead. Note it in the report. -- The site sends `templateKey`, `subject`, `html`, `text` when there is one, and `templateData` with the site's `variables` object unchanged. +- The site sends `templateKey`, `subject`, `html`, `text` when there is one, and `templateData` with the site's `variables` object, plus the subject values below. - The site's own `subject`, `from`, and `replyTo` win over the template's. When the site has none, use the template's: put its `from` and `replyTo` on the send, and its subject in the module. - The module's subject is fixed text with placeholders. When the site builds its subject from values, such as `` `Order #${order.id}` ``, write the subject in the module as `Order #{{ variables.ORDER_ID }}` and add each value to `templateData`. Never send a subject that changes per email with `templateData`: PostHog hashes the subject with the template, so each email would upload a new version of the template. - The template's alias, or its name in lowercase with `-` between words, becomes the `templateKey` and the module's file name. @@ -79,6 +79,7 @@ How a site that moves is written with `posthog-node`. Step 7 says when to use ea - `data.id` is PostHog's message id. Code that logs it or stores it for the app's own use keeps working. - `error.name` uses Resend's names, so `if (error.name === 'rate_limit_exceeded')` keeps working. `error.message` and `error.statusCode` keep their names. -- Resend takes a send to a suppressed address and drops it later. PostHog refuses it with `error.code` `recipient_suppressed` (name `validation_error`), and refuses the whole send when a `cc` or `bcc` address is suppressed. When the site throws, retries, or reports a failure on any error, add `if (error?.code === 'recipient_suppressed')` before that branch and handle it the way the site handled a send that went out: log it and go on. Note each site that got this branch in the report. +- Resend takes a send to a suppressed address and drops it later. PostHog refuses it with `error.code` `recipient_suppressed` (name `validation_error`). When the site sets no `cc` or `bcc`, and it throws, retries, or reports a failure on any error, add `if (error?.code === 'recipient_suppressed')` before that branch and handle it the way the site handled a send that went out: log it and go on. Note each site that got this branch in the report. +- PostHog also refuses the whole send when a `cc` or `bcc` address is suppressed, where Resend still delivered to `to`. Give a site with `cc` or `bcc` no such branch: the error keeps failing the site, and the report says that a suppressed copy address now stops the email. **The Resend client.** Keep `new Resend(...)` and its import while any site or other call still uses it. When nothing uses it, remove the import and the client, and keep the `resend` package and its key: the person removes them after the cutover. From 8dcd459afc9348e0fdbe043ddd6ef7aa2b1e948f Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 22 Oct 2026 07:18:15 +0000 Subject: [PATCH 12/70] fix(skills): warn that retrying a send with a suppressed copy address uses sending cap Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/mapping.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index d9bbd837d..e942fa824 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -80,6 +80,6 @@ How a site that moves is written with `posthog-node`. Step 7 says when to use ea - `data.id` is PostHog's message id. Code that logs it or stores it for the app's own use keeps working. - `error.name` uses Resend's names, so `if (error.name === 'rate_limit_exceeded')` keeps working. `error.message` and `error.statusCode` keep their names. - Resend takes a send to a suppressed address and drops it later. PostHog refuses it with `error.code` `recipient_suppressed` (name `validation_error`). When the site sets no `cc` or `bcc`, and it throws, retries, or reports a failure on any error, add `if (error?.code === 'recipient_suppressed')` before that branch and handle it the way the site handled a send that went out: log it and go on. Note each site that got this branch in the report. -- PostHog also refuses the whole send when a `cc` or `bcc` address is suppressed, where Resend still delivered to `to`. Give a site with `cc` or `bcc` no such branch: the error keeps failing the site, and the report says that a suppressed copy address now stops the email. +- PostHog also refuses the whole send when a `cc` or `bcc` address is suppressed, where Resend still delivered to `to`. Give a site with `cc` or `bcc` no such branch: the error keeps failing the site, and the report says that a suppressed copy address now stops the email, and that a job runner that retries the site repeats the refusal, each attempt using the project's sending cap. **The Resend client.** Keep `new Resend(...)` and its import while any site or other call still uses it. When nothing uses it, remove the import and the client, and keep the `resend` package and its key: the person removes them after the cutover. From 154e8f57ffdfe3f0573582fdc2955e211c6c1d38 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Sat, 31 Oct 2026 09:52:56 +0000 Subject: [PATCH 13/70] fix(skills): leave migratedFrom off the posthog-node client in migrate-email posthog-node has no migratedFrom option. The Wizard records the migration on its setup wizard finished event instead. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 4 +--- context/skills/migrate-email/references/8-verify.md | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 1670e95c9..259e94eb7 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -23,7 +23,7 @@ Rewrite each site whose `moves` is `yes` in the plan to send with `posthog-node` Install or upgrade `posthog-node` with the project's package manager, to a version that has `posthog.emails`. -Configure one server-side client for email. Set `migratedFrom` to the provider folder name, such as `resend`, once on the client, so PostHog knows which sends a migration moved: +Configure one server-side client for email: ```js import { PostHog } from 'posthog-node' @@ -31,13 +31,11 @@ import { PostHog } from 'posthog-node' export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { host: process.env.POSTHOG_HOST, secretKey: process.env.POSTHOG_PROJECT_SECRET_API_KEY, - migratedFrom: '', enableLocalEvaluation: false, }) ``` {{> email-node-client}} -- A reused client gets `migratedFrom` too. - Put a new client in its own server-only module, next to the provider's client, and import it where the sites send. - Use the env variable names the app already uses for the PostHog token and host. Add each new name, without a value, to the env example file. diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 2bd615b8f..902a38314 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -28,7 +28,7 @@ Skip this part and record `not checked` with the reason when the API is not conf 1. Ask the person whether to send one test email. Say that it sends a real email, and that the first send of a local template uploads it to the PostHog project. When they say no, record `not checked: declined`. 2. Ask them to trigger one moved email in their local app while they are signed in as themselves, such as a signup or a password reset, so the email goes to an address they own. Ask them to tell you when it is sent and to open the email. -3. When the send fails, find its code in `transactional-email-api.md`, tell the person the fix, and record it. Never retry a send yourself. +3. When the send fails, find its code in `transactional-emails.md` or `api.md`, tell the person the fix, and record it. Never retry a send yourself. 4. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID over the last hour: ```sql From 9cd85f5eee40e774040c8327d28ac0c5363a5029 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Sun, 1 Nov 2026 13:02:16 +0000 Subject: [PATCH 14/70] fix(skills): check that posthog-node has the code form before migrate-email rewrites a site A posthog-node release with posthog.emails can still lack templateKey, local template content, or the extra send fields. The rewrite now checks the installed types for what each moving site needs, and keeps a site on Resend when the latest release lacks it. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 259e94eb7..9eed3ea1a 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -21,7 +21,13 @@ Rewrite each site whose `moves` is `yes` in the plan to send with `posthog-node` ## Set up the client -Install or upgrade `posthog-node` with the project's package manager, to a version that has `posthog.emails`. +Install or upgrade `posthog-node` to its latest release with the project's package manager. `posthog.emails` alone is not enough: early releases send only a template stored in PostHog, by `templateId`. Check the installed package's types for what the moving sites need: + +- every site: `posthog.emails.send` takes `templateKey` with `subject` and `html` or `text`; +- a template stored at the provider: `templateData` takes the local template's content; +- a site that sets `cc`, `bcc`, `replyTo`, `headers`, `tags`, or `attachments`: the send takes that field. + +When the latest release lacks one of these, change no site that needs it. Mark each such row `moves: no — posthog-node has no yet`, tell the person, and go on with the rest. When no site is left, tick the phase with `none moved` and go to the next step. Configure one server-side client for email: From 41ca66aa8bb64d6db4e1ea454ae1c0651099b327 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Sun, 1 Nov 2026 18:37:20 +0000 Subject: [PATCH 15/70] fix(skills): detect resend over smtp, stop without sends, and record partial imports in migrate-email Step 1 now admits the SMTP host and a framework mailer and needs at least one send; step 3 stops when it finds no site. A suppression import that stops partway stays unticked and lands in the report's "Before cutover" list. A template site needs its content from the person or stays on Resend. The sender setup is inlined into step 4, which keeps the existing `from` domain and records an unverified domain instead of waiting. AGENTS.md says the migrate subcommands run once the wizard runs migrate as a family. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- context/shared/email-sender-setup.md | 15 --------------- .../skills/migrate-email/references/1-detect.md | 11 +++++++---- .../migrate-email/references/3-inventory.md | 8 ++++++++ .../skills/migrate-email/references/4-sender.md | 10 +++++++++- .../migrate-email/references/5-suppressions.md | 2 +- .../skills/migrate-email/references/7-report.md | 4 ++-- .../migrate-email/references/resend/mapping.md | 2 +- 8 files changed, 29 insertions(+), 25 deletions(-) delete mode 100644 context/shared/email-sender-setup.md diff --git a/AGENTS.md b/AGENTS.md index 2d5c0779e..45bd33c7b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -89,7 +89,7 @@ longer exist — only some keep an alias. | `wizard audit session-replay` | `audit-session-replay` | | `wizard audit web-analytics` | *(wizard-native, not a skill here)* | -**Migrate subcommands**, published as `cliEntries` with `parentCommand: migrate`. Until the wizard runs `migrate` as a family, bare `wizard migrate` keeps running `migrate-statsig`: +**Migrate subcommands**, published as `cliEntries` with `parentCommand: migrate`. They run once the wizard runs `migrate` as a family. Until then, `wizard migrate` stays a flat command that runs `migrate-statsig`, and the wizard rejects a vendor after it: | Subcommand | Backing skill | |---|---| diff --git a/context/shared/email-sender-setup.md b/context/shared/email-sender-setup.md deleted file mode 100644 index bdf95e3c5..000000000 --- a/context/shared/email-sender-setup.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: Set up an email sender ---- - -- First check that the PostHog MCP has the sender tools: `integrations-email-create`, `integrations-email-verify-create`, `integrations-domain-connect-check-retrieve`, and `integrations-domain-connect-apply-url-create`. When they are missing, go to the last bullet of this step. -- When the `setting-up-an-email-domain` skill is available, follow it. It covers the details. -- Ask which domain to send from. Recommend a subdomain such as `mail.example.com`. Use the person's own domain, never a free mailbox domain such as gmail.com. -- Never create a sender for an address that already has one: creating it again marks it unverified. For an existing unverified sender, skip to its records. -- Create the sender with `integrations-email-create`, then get its DNS records with `integrations-email-verify-create`. -- PostHog never writes DNS. Call `integrations-domain-connect-check-retrieve` with the domain. When `supported` is true, give the person the URL from `integrations-domain-connect-apply-url-create`: they approve the records at their DNS host. Otherwise, give them the records that are not `success` as a table with type, name, value, and priority. -- Always include both SPF records, merged into an existing `v=spf1` record when there is one. Never add a second `_dmarc` record when the domain already has one. -- Call `integrations-email-verify-create` again after the records are published, at least a minute apart. `success` means done. `failed` means fix the records, then verify again. After about 15 minutes of `pending` with every record published, stop and tell the person that DNS is still propagating and they can ask you to check again later. -- A 403 that says the person lacks permissions in the project means a project admin must verify the sender. Do not retry. -- **When the sender tools are missing or refused**, the agent setup for sender domains is not available to this person yet. Do not try other integration tools. Ask the person to verify a sender in PostHog: Workflows, then Channels, then add an email sender on their domain and follow the DNS steps (https://posthog.com/docs/workflows/configure-channels). Wait until they confirm that the sender shows as verified, then continue. - diff --git a/context/skills/migrate-email/references/1-detect.md b/context/skills/migrate-email/references/1-detect.md index 94881bc9c..fd4a47d30 100644 --- a/context/skills/migrate-email/references/1-detect.md +++ b/context/skills/migrate-email/references/1-detect.md @@ -15,19 +15,22 @@ Discovery only. Do not change any file. ## Procedure -Read the provider's `sdk-reference.md`. It lists the provider's packages, imports, clients, and HTTP host, and the packages that look related but are not the provider. +Read the provider's `sdk-reference.md`. It lists the provider's packages, imports, clients, send calls, HTTP host, SMTP host, and framework mailers, and the packages that look related but are not the provider. The provider is in this project when at least one of these is true: - Its package is in a dependency manifest, such as `package.json`, `requirements.txt`, `pyproject.toml`, `Gemfile`, `composer.json`, or `go.mod`. - Source code imports it or creates its client. - Source code calls its HTTP host. +- Source code, mail config, or an example env file names its SMTP host or its framework mailer. -Search the source code, not only the manifest: a package without a call site is not a migration. Skip `node_modules`, build output, and lockfiles. +Search the source code, not only the manifest. Skip `node_modules`, build output, and lockfiles. + +The migration needs at least one send: a send call, a request to the send route, or mail through the SMTP host or the framework mailer. A package without a send is not a migration, and neither are calls that only read contacts, domains, or an email's status. A rendering package alone, such as `@react-email/components`, is not the provider. It only tells you how some emails are rendered. -When you find nothing, stop before any change: +When you find no send, stop before any change: ``` [ABORT] no email provider sends found @@ -35,4 +38,4 @@ When you find nothing, stop before any change: Do not widen the search to other email providers. That outcome is correct, not a failure to work around. -When you find the provider, note each file that uses it for Step 3, and continue. +When you find a send, note each file that uses the provider for Step 3, and continue. diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index 884e90052..174ffc477 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -33,12 +33,20 @@ For each site, read the surrounding code and record: Also list every other call to the provider that is not a send, such as reading an email's status, contacts, or domains. These calls stay on the provider. Note what each one does, because a site whose code reads the status back stays on the provider too. +When you find no site, stop before you write the plan file: + +``` +[ABORT] no email provider sends found +``` + ## Classify each site Go through `mapping.md` field by field. A site **moves** when PostHog can send every field it sets. A site **stays** on the provider when any one field or feature keeps it there: record that field or feature as the reason. Never plan to drop a field. When the code passes a value you can't read, such as a list of recipients built at run time, follow it to its callers. When you still can't tell, the site stays, and the reason says what you could not check. +A `template` site needs the template's content to be classified. Ask the person once for a copy of every template the sites send, from the provider's dashboard, and never write it into the plan. When the person can't give the content, the site stays, and the reason is `template content not checked`. + ## Write the plan file Write `.posthog-email-migration-plan.md` at the project root with three sections. Never write an email address of a recipient into it. A `from` address is fine. diff --git a/context/skills/migrate-email/references/4-sender.md b/context/skills/migrate-email/references/4-sender.md index 87a968c06..e5901d7d7 100644 --- a/context/skills/migrate-email/references/4-sender.md +++ b/context/skills/migrate-email/references/4-sender.md @@ -31,7 +31,15 @@ Read the provider's `account.md` first. It lists the records the provider keeps Send from the domain of the existing `from` address, so the emails keep their sender. Ask for another domain only when the person wants one. -{{> email-sender-setup}} +- First check that the PostHog MCP has the sender tools: `integrations-email-create`, `integrations-email-verify-create`, `integrations-domain-connect-check-retrieve`, and `integrations-domain-connect-apply-url-create`. When they are missing, go to the last bullet. +- When the `setting-up-an-email-domain` skill is available, read it for the details of the records. Where it differs from this step, this step wins. +- Never create a sender for an address that already has one: creating it again marks it unverified. For an existing unverified sender, skip to its records. +- Create the sender with `integrations-email-create`, then get its DNS records with `integrations-email-verify-create`. +- PostHog never writes DNS. Call `integrations-domain-connect-check-retrieve` with the domain. When `supported` is true, give the person the URL from `integrations-domain-connect-apply-url-create`: they approve the records at their DNS host. Otherwise, give them the records that are not `success` as a table with type, name, value, and priority. +- Always include both SPF records, merged into an existing `v=spf1` record when there is one. Never add a second `_dmarc` record when the domain already has one. +- Call `integrations-email-verify-create` again after the records are published, at least a minute apart. `success` means verified. `failed` means fix the records, then verify again. After about 15 minutes of `pending` with every record published, tell the person that DNS is still propagating and that they can ask you to check again later, record the domain as not verified, and continue. +- A 403 that says the person lacks permissions in the project means a project admin must verify the sender. Do not retry: record the domain as not verified, and continue. +- When the sender tools are missing or refused, do not try other integration tools. Ask the person to add a sender on the domain in PostHog: Workflows, then Channels, then add an email sender, and follow the DNS steps (https://posthog.com/docs/workflows/configure-channels). Record the domain as not verified unless they confirm it shows as verified, and continue. ## Write down diff --git a/context/skills/migrate-email/references/5-suppressions.md b/context/skills/migrate-email/references/5-suppressions.md index 02471b58b..916a21439 100644 --- a/context/skills/migrate-email/references/5-suppressions.md +++ b/context/skills/migrate-email/references/5-suppressions.md @@ -36,4 +36,4 @@ Read the provider's `account.md`. It says how to export the list, which entries ## Write down -Tick the phase in the plan file: `- [x] suppressions — / imported`. When the list is empty, write `- [x] suppressions — empty list`. When the person has no export and no key, write `- [ ] suppressions — not imported: `. +Tick the phase in the plan file only when every entry is imported: `- [x] suppressions — / imported`. When the list is empty, write `- [x] suppressions — empty list`. When the import stopped partway, write `- [ ] suppressions — / imported: `. When the person has no export and no key, write `- [ ] suppressions — not imported: `. diff --git a/context/skills/migrate-email/references/7-report.md b/context/skills/migrate-email/references/7-report.md index 6869e754e..eaa7a69ee 100644 --- a/context/skills/migrate-email/references/7-report.md +++ b/context/skills/migrate-email/references/7-report.md @@ -51,7 +51,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ## Before cutover - + ## Summary ``` @@ -72,7 +72,7 @@ suppressions_ready: true - `sites_rewritten`: the sites this run changed to send with PostHog. This version changes none, so it is `0`. - `sites_left`: the sites that stay on the provider. - `dns_ready`: `true` when every sending domain has a verified sender. -- `suppressions_ready`: `true` when the suppression list was imported or was empty. +- `suppressions_ready`: `true` when every entry of the suppression list was imported, or the list was empty. Sites that are ready to move count in `sites_found` only. diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 097d84c87..8a27a39c7 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -12,7 +12,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `html` | `html` | Never | | `text` | `text` | Never | | `react` | `html`, rendered in the app | Never. The app renders the component | -| `template` | a local template in the app's code | The template uses syntax beyond variables and fallbacks | +| `template` | a local template in the app's code | Its content can't be read, it uses syntax beyond variables and fallbacks, or the app fills a variable with HTML | | `cc`, `bcc` | `cc`, `bcc` | An entry carries a name, such as `Jane `, or there are more than 10 | | `replyTo` / `reply_to` | `replyTo` / `reply_to`, as a list | An entry carries a name, such as `Jane `, there are more than 10, or the code builds the value at run time and you cannot tell that it holds bare addresses only. A single address moves as a list of one | | `headers` | `headers` | A header is one PostHog sets itself (`From`, `To`, `Cc`, `Bcc`, `Reply-To`, `Subject`, `Date`, `Message-ID`, `MIME-Version`, `Sender`, `Return-Path`, `Auto-Submitted`, `DKIM-Signature`, `Received`, any `Content-*`, `X-PostHog-*`, `X-SES-*`), a name is longer than 126 characters, a value is longer than 870 characters or has a line break or a non-ASCII character, or there are more than 10 | From 0e526b923515d9b0ba3a765c6498d6ae3b04f2b8 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Sun, 1 Nov 2026 18:37:20 +0000 Subject: [PATCH 16/70] refactor(scripts): ship variant references through the local reference loop The selected variant's `references//` files now go through the same loop as the root reference files, so the separate copy helper is gone. The partial expander drops the indentation it gained for the sender partial, which nothing includes any more, and the bundle test drops the migrate-statsig case that guarded nothing. Co-Authored-By: Claude Opus 5.5 --- scripts/lib/skill-generator.js | 69 ++++++------------- scripts/lib/tests/migrate-email-skill.test.js | 15 ++-- scripts/lib/tests/partial-includes.test.js | 8 --- 3 files changed, 27 insertions(+), 65 deletions(-) diff --git a/scripts/lib/skill-generator.js b/scripts/lib/skill-generator.js index 35eb4697e..c5b355059 100644 --- a/scripts/lib/skill-generator.js +++ b/scripts/lib/skill-generator.js @@ -55,18 +55,16 @@ function loadYaml(configPath) { // A line that is exactly `{{> name}}` is replaced at build time with the body // of `/shared/name.md` (frontmatter stripped), so shared prose like // the MCP tool-calling grammar lives in one canonical file and every skill that -// includes it stays in sync. The directive's indentation applies to every line -// of the partial, so a partial can nest under a step. -const PARTIAL_DIRECTIVE = /^([ \t]*)\{\{>\s*([a-z0-9-]+)\s*\}\}[ \t]*$/gm; +// includes it stays in sync. +const PARTIAL_DIRECTIVE = /^[ \t]*\{\{>\s*([a-z0-9-]+)\s*\}\}[ \t]*$/gm; function expandPartials(body, configDir) { - return body.replace(PARTIAL_DIRECTIVE, (_match, indent, name) => { + return body.replace(PARTIAL_DIRECTIVE, (_match, name) => { const partialPath = path.join(configDir, 'shared', `${name}.md`); if (!fs.existsSync(partialPath)) { throw new Error(`Partial include {{> ${name}}} references missing file ${partialPath}`); } - const partial = matter(fs.readFileSync(partialPath, 'utf8')).content.trim(); - return partial.replace(/^(?=.)/gm, indent); + return matter(fs.readFileSync(partialPath, 'utf8')).content.trim(); }); } @@ -596,29 +594,12 @@ function generateFrontmatter(skill, version) { return '---\n' + yaml.dump(frontmatter) + '---\n\n'; } -/** - * Copy the markdown files of a variant's own folder, `references//`, - * into the bundle. A group keeps what differs per vendor or platform there, so - * each bundle ships only its own variant's files. Returns their listing entries. - */ -function copyVariantReferences({ sourceDir, targetDir, variantId, configDir }) { - if (!fs.existsSync(sourceDir)) return []; - - const files = fs.readdirSync(sourceDir, { withFileTypes: true }) +function markdownReferenceNames(dir, prefix) { + if (!fs.existsSync(dir)) return []; + return fs.readdirSync(dir, { withFileTypes: true }) .filter(entry => entry.isFile() && entry.name.endsWith('.md')) - .sort((a, b) => a.name.localeCompare(b.name)); - fs.mkdirSync(targetDir, { recursive: true }); - - return files.map(file => { - const parsed = matter(fs.readFileSync(path.join(sourceDir, file.name), 'utf8')); - const body = expandPartials(parsed.content, configDir).replace(/^\n+/, '').replace(/\s+$/, ''); - fs.writeFileSync(path.join(targetDir, file.name), body, 'utf8'); - const heading = body.match(/^#\s+(.+)$/m)?.[1]; - return { - filename: `${variantId}/${file.name}`, - description: parsed.data.description || heading || file.name, - }; - }); + .map(entry => path.posix.join(prefix, entry.name)) + .sort((a, b) => a.localeCompare(b)); } /** @@ -694,21 +675,22 @@ async function generateSkill({ // Group config injects a shared `preamble`; per-file `next_step` frontmatter drives continuation links. const sourceReferencesDir = path.join(configDir, 'skills', ...skill._group.split('/'), 'references'); if (fs.existsSync(sourceReferencesDir)) { - const localReferences = fs.readdirSync(sourceReferencesDir, { withFileTypes: true }) - .filter(entry => entry.isFile() && entry.name.endsWith('.md')) - .sort((a, b) => a.name.localeCompare(b.name)); + const localReferences = [ + ...markdownReferenceNames(sourceReferencesDir, ''), + ...markdownReferenceNames(path.join(sourceReferencesDir, skill._shortId), skill._shortId), + ]; const refsConfig = skill._references || {}; for (const reference of localReferences) { - const sourcePath = path.join(sourceReferencesDir, reference.name); + const sourcePath = path.join(sourceReferencesDir, reference); const parsed = matter(fs.readFileSync(sourcePath, 'utf8')); const nextFile = parsed.data.next_step; const isWorkflowStep = 'next_step' in parsed.data; let body = expandPartials(parsed.content, configDir).replace(/^\n+/, '').replace(/\s+$/, ''); const headingMatch = body.match(/^#\s+(.+)$/m); - const displayTitle = parsed.data.title || headingMatch?.[1] || reference.name; - const displayDescription = parsed.data.description || headingMatch?.[1] || reference.name; + const displayTitle = parsed.data.title || headingMatch?.[1] || reference; + const displayDescription = parsed.data.description || headingMatch?.[1] || reference; if (nextFile) { if (refsConfig.preamble && headingMatch) { @@ -726,31 +708,22 @@ async function generateSkill({ ? `---\n${yaml.dump(emittedFrontmatter, { lineWidth: -1 })}---\n\n${body}` : body; - fs.writeFileSync( - path.join(referencesDir, reference.name), - fileContent, - 'utf8' - ); + const targetPath = path.join(referencesDir, reference); + fs.mkdirSync(path.dirname(targetPath), { recursive: true }); + fs.writeFileSync(targetPath, fileContent, 'utf8'); references.push({ - filename: reference.name, + filename: reference, description: displayDescription, }); if (isWorkflowStep) { workflowSteps.push({ - filename: reference.name, + filename: reference, title: displayTitle, }); } } - - references.push(...copyVariantReferences({ - sourceDir: path.join(sourceReferencesDir, skill._shortId), - targetDir: path.join(referencesDir, skill._shortId), - variantId: skill._shortId, - configDir, - })); } // Helper to process a doc entry (string URL or {url, title} object). diff --git a/scripts/lib/tests/migrate-email-skill.test.js b/scripts/lib/tests/migrate-email-skill.test.js index 8ffca7b6e..14044d5ef 100644 --- a/scripts/lib/tests/migrate-email-skill.test.js +++ b/scripts/lib/tests/migrate-email-skill.test.js @@ -66,17 +66,14 @@ describe('migrate-email skill', () => { if (outputDir) rmSync(outputDir, { recursive: true, force: true }); }); - it.each(['migrate-email-resend', 'migrate-statsig'])( - 'builds %s as a bundle whose every reference path resolves', - async (skillId) => { - outputDir = mkdtempSync(join(tmpdir(), 'migrate-skill-')); + it('builds migrate-email-resend as a bundle whose every reference path resolves', async () => { + outputDir = mkdtempSync(join(tmpdir(), 'migrate-skill-')); - const skillDir = await buildSkill(skillId, outputDir); + const skillDir = await buildSkill('migrate-email-resend', outputDir); - expect(readFileSync(join(skillDir, 'SKILL.md'), 'utf8')).toMatch(new RegExp(`^---\\nname: ${skillId}\\n`)); - expect(unresolvedReferences(skillDir)).toEqual([]); - }, - ); + expect(readFileSync(join(skillDir, 'SKILL.md'), 'utf8')).toMatch(/^---\nname: migrate-email-resend\n/); + expect(unresolvedReferences(skillDir)).toEqual([]); + }); it('bundles the transactional email docs and the Resend files', async () => { outputDir = mkdtempSync(join(tmpdir(), 'migrate-skill-')); diff --git a/scripts/lib/tests/partial-includes.test.js b/scripts/lib/tests/partial-includes.test.js index 3741c14a3..5ebaa8e66 100644 --- a/scripts/lib/tests/partial-includes.test.js +++ b/scripts/lib/tests/partial-includes.test.js @@ -42,14 +42,6 @@ describe('expandPartials', () => { expect(out).toContain('After.'); }); - it("indents every line of the partial as far as the directive, so it nests in a step's list", () => { - writeFileSync(join(tmpDir, 'shared', 'sender.md'), '---\ntitle: Sender\n---\n\n- First bullet.\n- Second bullet.\n'); - - const out = expandPartials('STEP 3: Set up a sender.\n {{> sender}}\n\nSTEP 4: Send.', tmpDir); - - expect(out).toBe('STEP 3: Set up a sender.\n - First bullet.\n - Second bullet.\n\nSTEP 4: Send.'); - }); - it('throws when the referenced partial does not exist', () => { expect(() => expandPartials('{{> missing-partial}}', tmpDir)).toThrow(/missing-partial/); }); From 8c841cdfa7eff05a74c65c3754680e333de34808 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Sun, 1 Nov 2026 18:44:30 +0000 Subject: [PATCH 17/70] fix(skills): tie migrate-email's test send to its own events and report every behaviour change Step 8 checks that the app sends to the MCP's project, notes the start of the test, and counts only events since then whose workflow matches the send. It compares typecheck errors with a baseline step 7 takes before it changes code. A template's content waits in a temporary file for step 7 instead of in memory, an HTML fallback keeps a template on Resend, and a derived templateKey is normalized and unique. The report lists each suppressed-recipient branch, copy-address refusal, and cross-provider idempotency risk, and reminds the person to delete the full-access Resend key. The posthog-node client setup is inlined into step 7, and description.md says this skill wins over the general moving guide. Co-Authored-By: Claude Opus 5.5 --- context/shared/email-node-client.md | 7 ------- context/skills/migrate-email/description.md | 2 +- .../migrate-email/references/3-inventory.md | 2 +- .../migrate-email/references/7-rewrite.md | 9 ++++++--- .../migrate-email/references/8-verify.md | 19 ++++++++++--------- .../migrate-email/references/9-report.md | 6 +++--- .../references/resend/account.md | 6 +++--- .../references/resend/mapping.md | 6 +++--- 8 files changed, 27 insertions(+), 30 deletions(-) delete mode 100644 context/shared/email-node-client.md diff --git a/context/shared/email-node-client.md b/context/shared/email-node-client.md deleted file mode 100644 index 3f26ccb42..000000000 --- a/context/shared/email-node-client.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: Configure the posthog-node client for email ---- - -- Reuse the app's existing `posthog-node` client when it has one, and add `secretKey`. Keep `enableLocalEvaluation: false` unless the key also has `feature_flag:read` and the app uses local evaluation. -- When the project token or the host is not configured yet, get the token from the PostHog MCP `projects-get` tool (`api_token`). The host is `https://us.i.posthog.com` for US Cloud and `https://eu.i.posthog.com` for EU Cloud. Ask the person which one when you can't tell. -- When `host` is a reverse proxy or a self-hosted instance, also set `appHost` to the PostHog app URL, such as `https://us.posthog.com`. posthog-node never sends the secret key to a proxy, and without `appHost` the send fails with `missing_app_host`. diff --git a/context/skills/migrate-email/description.md b/context/skills/migrate-email/description.md index 52937c8b1..9f7b47bbe 100644 --- a/context/skills/migrate-email/description.md +++ b/context/skills/migrate-email/description.md @@ -54,4 +54,4 @@ Outside the Wizard, skip the `[STATUS]` lines, and tell the person why you stopp `transactional-emails.md` is the transactional email overview. It covers how to create a transactional email and its API key, idempotency, and the error codes. `api.md` covers the send route, including content from your code, and the checks of a send. -When the `sending-transactional-emails` skill is available, read it too. Its `moving-from-other-providers.md` moves any provider's sends to a PostHog template. This skill adds what is specific to {display_name}: it finds every send, sets up the sender next to {display_name}'s DNS records, imports {display_name}'s suppression list, and hands over the key. +When the `sending-transactional-emails` skill is available, read it for the PostHog side of a send. Its `moving-from-other-providers.md` moves sends to a template stored in PostHog. This skill moves {display_name}'s sends to `posthog-node` with the content in the app's code instead. Where the two disagree, this skill's steps win. diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index 4a27f1b2e..6d7521f26 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -45,7 +45,7 @@ Go through `mapping.md` field by field. A site **moves** when PostHog can send e When the code passes a value you can't read, such as a list of recipients built at run time, follow it to its callers. When you still can't tell, the site stays, and the reason says what you could not check. -A `template` site needs the template's content to be classified. Read the provider's `account.md`, and ask the person once for every template the sites send: copy from the dashboard, or read through the API. Keep the content for Step 7, and never write it into the plan. When the person can't give the content, the site stays, and the reason is `template content not checked`. +A `template` site needs the template's content to be classified. Read the provider's `account.md`, and ask the person once for every template the sites send: copy from the dashboard, or read through the API. Save each template's content for Step 7 in a file in the system's temporary folder, never in the repository or the plan. When the person can't give the content, the site stays, and the reason is `template content not checked`. ## Write the plan file diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 9eed3ea1a..57a037094 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -18,6 +18,7 @@ Rewrite each site whose `moves` is `yes` in the plan to send with `posthog-node` - Change only the sites whose `moves` is `yes`. Never change a site that stays, and never change a line that a site that stays still needs. - When no site moves, tick the phase in the plan with `none moved` and go to the next step. +- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck, and keep its errors: Step 8 compares with them. ## Set up the client @@ -41,7 +42,9 @@ export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { }) ``` -{{> email-node-client}} +- Reuse the app's existing `posthog-node` client when it has one, and add `secretKey`. Keep `enableLocalEvaluation: false` unless the key also has `feature_flag:read` and the app uses local evaluation. +- When the project token or the host is not configured yet, get the token from the PostHog MCP `projects-get` tool (`api_token`). The host is `https://us.i.posthog.com` for US Cloud and `https://eu.i.posthog.com` for EU Cloud. Ask the person which one when you can't tell. +- When `host` is a reverse proxy or a self-hosted instance, also set `appHost` to the PostHog app URL, such as `https://us.posthog.com`. posthog-node never sends the secret key to a proxy, and without `appHost` the send fails with `missing_app_host`. - Put a new client in its own server-only module, next to the provider's client, and import it where the sites send. - Use the env variable names the app already uses for the PostHog token and host. Add each new name, without a value, to the env example file. @@ -60,7 +63,7 @@ For each site that moves, in plan order: - Rewrite the call as the provider's `mapping.md` says, for the site's content form: `html` and `text` content, a component the app renders, or a template stored at the provider. - Give each send a `templateKey` that names the kind of email, such as `welcome` or `password-reset`, with letters, digits, `-`, and `_` only. Two sites that send the same email share a key. A template stored at the provider keeps the key `mapping.md` gives it. -- A template stored at the provider becomes a module that exports `subject` and `html`, and `text` when it has one, in an `emails/` folder next to the server code. The site imports it and passes `templateData`. +- A template stored at the provider becomes a module that exports `subject` and `html`, and `text` when it has one, in an `emails/` folder next to the server code. Write it from the file Step 3 saved, never from memory, and delete that file once the module is written. The site imports the module and passes `templateData`. - Install `@react-email/render` with the project's package manager when a site renders a component and the app doesn't have it. - Keep the site's idempotency key, error branches, logging, and return value working as before. Keep the code around the send unchanged where you can. - `posthog.emails.send` never throws on an API error: it returns `{ data, error }`. When the old call threw on an error, or the code checked an HTTP status, check `error` so the site fails the same way. @@ -70,4 +73,4 @@ When a site turns out to need something `mapping.md` keeps on the provider, undo ## Write down -Tick the phase in the plan: `- [x] rewrite — sites moved`. Add a `key` column to the sites table with each moved site's `templateKey`. Under the table, note each site without a `distinctId`, each fallback that an empty string now replaces, each site that got a branch for a suppressed recipient, each idempotency key a retry across the deploy could send twice, each new dependency, and each new env variable name. +Tick the phase in the plan: `- [x] rewrite — sites moved`. Add a `key` column to the sites table with each moved site's `templateKey`. Under the table, note each site without a `distinctId`, each fallback that an empty string now replaces, each site that got a branch for a suppressed recipient, each site with `cc` or `bcc` that a suppressed copy address now stops, each idempotency key a retry across the deploy could send twice, each new dependency, and each new env variable name. diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 902a38314..815353510 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -16,7 +16,7 @@ Check that the app still builds, its tests still pass, and one moved email reach ## Build and tests -- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error in a line you changed. An error in a file you didn't change was there before: note it, and leave it. +- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error that is not in the list Step 7 kept, in any file: the rewrite caused it. An error in that list was there before: note it, and leave it. - Run the tests that cover the files you changed. A test that mocks the provider's client or intercepts its HTTP requests for a moved site now mocks `posthog.emails.send` and asserts on the fields it gets, with the same expected values. Never turn a PostHog send back into the provider's request shape to keep an old assertion. Never delete or skip a test. - Search the changed files for the provider's calls: a moved site has none left, and each moved site has one `posthog.emails.send`. @@ -26,20 +26,21 @@ The chain to prove: PostHog sends the email, records its engagement on the perso Skip this part and record `not checked` with the reason when the API is not confirmed on, no sender is verified, or `POSTHOG_PROJECT_SECRET_API_KEY` is not set. -1. Ask the person whether to send one test email. Say that it sends a real email, and that the first send of a local template uploads it to the PostHog project. When they say no, record `not checked: declined`. -2. Ask them to trigger one moved email in their local app while they are signed in as themselves, such as a signup or a password reset, so the email goes to an address they own. Ask them to tell you when it is sent and to open the email. -3. When the send fails, find its code in `transactional-emails.md` or `api.md`, tell the person the fix, and record it. Never retry a send yourself. -4. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID over the last hour: +1. Check that the app sends to the MCP's project: compare the project token the app reads, from its env file, with `api_token` from the PostHog MCP `projects-get` tool. When they differ, record `not checked: the app uses another project`, tell the person which project the app uses, and skip the rest of this part. +2. Ask the person whether to send one test email. Say that it sends a real email, and that the first send of a local template uploads it to the PostHog project. When they say no, record `not checked: declined`. +3. Note the current time in UTC as the start of the test. Ask them to trigger one moved email in their local app while they are signed in as themselves, such as a signup or a password reset, so the email goes to an address they own. Ask them to tell you when it is sent and to open the email. +4. When the send fails, find its code in `transactional-emails.md` or `api.md`, tell the person the fix, and record it. Never retry a send yourself. +5. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID since the start of the test: ```sql - SELECT event, timestamp FROM events - WHERE distinct_id = '' AND timestamp > now() - INTERVAL 1 HOUR + SELECT event, timestamp, properties.$workflow_id AS workflow FROM events + WHERE distinct_id = '' AND timestamp >= '' ORDER BY timestamp ``` -5. The chain holds when the result has `$workflows_email_sent`, an engagement event such as `$workflows_email_delivered` or `$workflows_email_opened`, and at least one product event of the app. Delivery events arrive after the provider reports back: when only the send shows, wait a minute and run the query once more. +6. The chain holds when the result has a `$workflows_email_sent`, an engagement event such as `$workflows_email_delivered` or `$workflows_email_opened` with the same `workflow`, and at least one product event of the app. An event from before the start of the test belongs to another email. Delivery events arrive after the provider reports back: when only the send shows, wait a minute and run the query once more. -When the MCP has no SQL tool, ask the person to open their person in PostHog and tell you which of the three they see. +When the MCP has no SQL tool, ask the person to open their person in PostHog and tell you which of the three they see after the start of the test. Never write the address or the distinct ID into a file. diff --git a/context/skills/migrate-email/references/9-report.md b/context/skills/migrate-email/references/9-report.md index 6543ecfe6..5462c62b8 100644 --- a/context/skills/migrate-email/references/9-report.md +++ b/context/skills/migrate-email/references/9-report.md @@ -29,7 +29,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ", or "Stays on : ".> - + ## Other calls @@ -59,11 +59,11 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- The moved sites send through PostHog as soon as this code is deployed. Everything in this list has to be done before that deploy. - + ## After cutover - + ## Summary ``` diff --git a/context/skills/migrate-email/references/resend/account.md b/context/skills/migrate-email/references/resend/account.md index f4c38602e..93146a650 100644 --- a/context/skills/migrate-email/references/resend/account.md +++ b/context/skills/migrate-email/references/resend/account.md @@ -20,7 +20,7 @@ A domain verified at Resend carries these records. Keep all of them until the cu ## Full-access key -The app's own Resend key is usually a sending-only key, and it can't read templates or the suppression list. When the person chooses the API over the dashboard, ask them to create a full-access key in Resend, store it in `RESEND_FULL_ACCESS_API_KEY` in the git-ignored env file, and delete the key in Resend after the migration. Never print the key, and never write it into another file. +The app's own Resend key is usually a sending-only key, and it can't read templates or the suppression list. When the person chooses the API over the dashboard, ask them to create a full-access key in Resend, store it in `RESEND_FULL_ACCESS_API_KEY` in the git-ignored env file, and note in the plan that the run created it. The report tells the person to delete it. Never print the key, and never write it into another file. ## Template content @@ -30,7 +30,7 @@ A site that sends a template stored at Resend needs the template's content. **Read from the API.** `GET https://api.resend.com/templates/{id or alias}` with `Authorization: Bearer $RESEND_FULL_ACCESS_API_KEY`. The answer holds `alias`, `name`, `subject`, `from`, `reply_to`, `html`, `text`, and `variables`, a list of `{ key, type, fallback_value }`. -The content goes only into the template module the rewrite writes. Never write it into the plan or the report. +The content goes only into the temporary file Step 3 saves and the template module the rewrite writes. Never write it into the plan or the report. ## Suppression list @@ -43,7 +43,7 @@ Resend suppresses an address after a hard bounce or a spam complaint, and keeps - The answer is `{ "object": "list", "has_more": , "data": [{ "id", "email", "origin", "source_id", "created_at" }] }`. - Page with `after=` until `has_more` is `false`. - Resend allows 10 requests per second per team. Wait and retry on `429`. -- A sending-only key can't read the list. Use the full-access key below. +- A sending-only key can't read the list. Use the full-access key above. **Map each entry.** diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index e942fa824..3820a6900 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -45,7 +45,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. - `html`, `text`, and `react` content is rendered for one recipient before the send. PostHog sends it as it is. - A `template` site needs the template's content, because the code has only its id. `account.md` says how to get it. - Resend inserts a variable's value as it is. PostHog's Liquid escapes HTML in a value, so `` shows as text. A variable is HTML when the code fills it with markup or with a renderer's output. A variable the app fills with plain values, such as names, numbers, and URLs, renders the same. -- A template that holds anything other than `{{{VAR}}}` and `{{{VAR|fallback}}}` placeholders, such as a section, a loop, or a condition, stays on Resend. So does a fallback that holds both `'` and `"`. +- A template that holds anything other than `{{{VAR}}}` and `{{{VAR|fallback}}}` placeholders, such as a section, a loop, or a condition, stays on Resend. So does a fallback that holds both `'` and `"`, and a fallback that holds HTML, such as a link: Liquid escapes the fallback too, so the markup shows as text. ## Rewrite @@ -72,8 +72,8 @@ How a site that moves is written with `posthog-node`. Step 7 says when to use ea - Liquid's `default` also replaces an empty string, which Resend inserts as it is. When the code can pass an empty string for a variable with a fallback, the email shows the fallback instead. Note it in the report. - The site sends `templateKey`, `subject`, `html`, `text` when there is one, and `templateData` with the site's `variables` object, plus the subject values below. - The site's own `subject`, `from`, and `replyTo` win over the template's. When the site has none, use the template's: put its `from` and `replyTo` on the send, and its subject in the module. -- The module's subject is fixed text with placeholders. When the site builds its subject from values, such as `` `Order #${order.id}` ``, write the subject in the module as `Order #{{ variables.ORDER_ID }}` and add each value to `templateData`. Never send a subject that changes per email with `templateData`: PostHog hashes the subject with the template, so each email would upload a new version of the template. -- The template's alias, or its name in lowercase with `-` between words, becomes the `templateKey` and the module's file name. +- The module's subject is fixed text with placeholders. When the site builds its subject from values, such as `` `Order #${order.id}` ``, write the subject in the module as `Order #{{ variables.ORDER_ID }}` and add each value to `templateData`. Never send a subject that changes per email with `templateData`: posthog-node hashes a local template's subject and content, so each email would upload a new version of the template. A send without `templateData` sends rendered content and uploads nothing. +- The template's alias, or its name when it has no alias, becomes the `templateKey` and the module's file name: in lowercase, with each run of characters other than letters, digits, `-`, and `_` replaced by one `-`, and no `-` at either end. When two templates get the same key, add `-2`, `-3`, and so on to the later ones. **The answer.** posthog-node answers `{ data, error }` like Resend and never throws on an API error. From 4ad8c6e8a7b89c5d8673442af13deb03172ee968 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Sun, 1 Nov 2026 18:49:59 +0000 Subject: [PATCH 18/70] fix(skills): let migrate-email move on when DNS waits and read templates from files Step 4 records a domain as not verified, with its records or Domain Connect link, when the person can't publish them during the run. Step 3 asks the person to save each template from the dashboard to a file outside the repository and reads it, since the Wizard can't take pasted HTML. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/3-inventory.md | 2 +- context/skills/migrate-email/references/4-sender.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index 174ffc477..160f32877 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -45,7 +45,7 @@ Go through `mapping.md` field by field. A site **moves** when PostHog can send e When the code passes a value you can't read, such as a list of recipients built at run time, follow it to its callers. When you still can't tell, the site stays, and the reason says what you could not check. -A `template` site needs the template's content to be classified. Ask the person once for a copy of every template the sites send, from the provider's dashboard, and never write it into the plan. When the person can't give the content, the site stays, and the reason is `template content not checked`. +A `template` site needs the template's content to be classified. Ask the person once to copy every template the sites send from the provider's dashboard into files outside the repository, and to tell you where they saved them. Read those files, and never write the content into the plan. When the person can't give the content, the site stays, and the reason is `template content not checked`. ## Write the plan file diff --git a/context/skills/migrate-email/references/4-sender.md b/context/skills/migrate-email/references/4-sender.md index e5901d7d7..10dee3458 100644 --- a/context/skills/migrate-email/references/4-sender.md +++ b/context/skills/migrate-email/references/4-sender.md @@ -38,6 +38,7 @@ Send from the domain of the existing `from` address, so the emails keep their se - PostHog never writes DNS. Call `integrations-domain-connect-check-retrieve` with the domain. When `supported` is true, give the person the URL from `integrations-domain-connect-apply-url-create`: they approve the records at their DNS host. Otherwise, give them the records that are not `success` as a table with type, name, value, and priority. - Always include both SPF records, merged into an existing `v=spf1` record when there is one. Never add a second `_dmarc` record when the domain already has one. - Call `integrations-email-verify-create` again after the records are published, at least a minute apart. `success` means verified. `failed` means fix the records, then verify again. After about 15 minutes of `pending` with every record published, tell the person that DNS is still propagating and that they can ask you to check again later, record the domain as not verified, and continue. +- When the person can't publish the records during this run, such as when another team owns DNS, record the domain as not verified with its records or its Domain Connect link, and continue. - A 403 that says the person lacks permissions in the project means a project admin must verify the sender. Do not retry: record the domain as not verified, and continue. - When the sender tools are missing or refused, do not try other integration tools. Ask the person to add a sender on the domain in PostHog: Workflows, then Channels, then add an email sender, and follow the DNS steps (https://posthog.com/docs/workflows/configure-channels). Record the domain as not verified unless they confirm it shows as verified, and continue. From 8452a8265f8601b8eb53b425bf187b997abefbf8 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Sun, 1 Nov 2026 18:53:20 +0000 Subject: [PATCH 19/70] fix(skills): pin migrate-email's test start to the database clock and keep template files traceable Step 8 takes the start of the test from `execute-sql` and compares Unix timestamps, so the project's timezone can't shift the window. The plan lists each saved template file, step 7 reads the module from it, and step 9 deletes every listed file. A derived templateKey falls back to the template id when the name normalizes to nothing and stays unique across the run. Step 8 may fix other posthog-node code the upgrade breaks, and the report lists those files. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/description.md | 2 +- context/skills/migrate-email/references/3-inventory.md | 2 +- context/skills/migrate-email/references/7-rewrite.md | 2 +- context/skills/migrate-email/references/8-verify.md | 8 ++++---- context/skills/migrate-email/references/9-report.md | 4 ++-- context/skills/migrate-email/references/resend/mapping.md | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/context/skills/migrate-email/description.md b/context/skills/migrate-email/description.md index 9f7b47bbe..745723a67 100644 --- a/context/skills/migrate-email/description.md +++ b/context/skills/migrate-email/description.md @@ -28,7 +28,7 @@ The plan file `.posthog-email-migration-plan.md` lives at the project root. Step ## Rules -- Change send code only in Step 7, and fix it only in Step 8: the sites that move, and the helpers, callers, and tests they need. Leave every site that stays as it is. +- Change send code only in Step 7, and fix it only in Step 8: the sites that move, the helpers, callers, and tests they need, and other `posthog-node` code that the upgrade breaks. Leave every site that stays as it is. - Never touch DNS or the {display_name} account. Give the person the records and the links, and let them make the change. - Never remove the {display_name} package or its API key. The report tells the person when to remove them. - Never create, upload, or edit a template in PostHog. A moved local template uploads on its first send. diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index 03d30f39e..4d00be176 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -45,7 +45,7 @@ Go through `mapping.md` field by field. A site **moves** when PostHog can send e When the code passes a value you can't read, such as a list of recipients built at run time, follow it to its callers. When you still can't tell, the site stays, and the reason says what you could not check. -A `template` site needs the template's content to be classified. Read the provider's `account.md`, and ask the person once for every template the sites send: copies from the dashboard that they save in files outside the repository and tell you where, or a read through the API. Save each template's content for Step 7 in a file in the system's temporary folder, never in the repository or the plan. When the person can't give the content, the site stays, and the reason is `template content not checked`. +A `template` site needs the template's content to be classified. Read the provider's `account.md`, and ask the person once for every template the sites send: copies from the dashboard that they save in files outside the repository and tell you where, or a read through the API. Save each template's content in a file in the system's temporary folder, never in the repository or the plan, and list each file's path with its site under the sites table. When the person can't give the content, the site stays, and the reason is `template content not checked`. ## Write the plan file diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 57a037094..aa98de9dd 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -63,7 +63,7 @@ For each site that moves, in plan order: - Rewrite the call as the provider's `mapping.md` says, for the site's content form: `html` and `text` content, a component the app renders, or a template stored at the provider. - Give each send a `templateKey` that names the kind of email, such as `welcome` or `password-reset`, with letters, digits, `-`, and `_` only. Two sites that send the same email share a key. A template stored at the provider keeps the key `mapping.md` gives it. -- A template stored at the provider becomes a module that exports `subject` and `html`, and `text` when it has one, in an `emails/` folder next to the server code. Write it from the file Step 3 saved, never from memory, and delete that file once the module is written. The site imports the module and passes `templateData`. +- A template stored at the provider becomes a module that exports `subject` and `html`, and `text` when it has one, in an `emails/` folder next to the server code. Write it from the file the plan lists for the site, never from memory. The site imports the module and passes `templateData`. - Install `@react-email/render` with the project's package manager when a site renders a component and the app doesn't have it. - Keep the site's idempotency key, error branches, logging, and return value working as before. Keep the code around the send unchanged where you can. - `posthog.emails.send` never throws on an API error: it returns `{ data, error }`. When the old call threw on an error, or the code checked an HTTP status, check `error` so the site fails the same way. diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 815353510..5e473f92f 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -16,7 +16,7 @@ Check that the app still builds, its tests still pass, and one moved email reach ## Build and tests -- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error that is not in the list Step 7 kept, in any file: the rewrite caused it. An error in that list was there before: note it, and leave it. +- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error that is not in the list Step 7 kept, in any file: the rewrite or the posthog-node upgrade caused it. Note each file you fix outside the moved sites for the report. An error in that list was there before: note it, and leave it. - Run the tests that cover the files you changed. A test that mocks the provider's client or intercepts its HTTP requests for a moved site now mocks `posthog.emails.send` and asserts on the fields it gets, with the same expected values. Never turn a PostHog send back into the provider's request shape to keep an old assertion. Never delete or skip a test. - Search the changed files for the provider's calls: a moved site has none left, and each moved site has one `posthog.emails.send`. @@ -28,19 +28,19 @@ Skip this part and record `not checked` with the reason when the API is not conf 1. Check that the app sends to the MCP's project: compare the project token the app reads, from its env file, with `api_token` from the PostHog MCP `projects-get` tool. When they differ, record `not checked: the app uses another project`, tell the person which project the app uses, and skip the rest of this part. 2. Ask the person whether to send one test email. Say that it sends a real email, and that the first send of a local template uploads it to the PostHog project. When they say no, record `not checked: declined`. -3. Note the current time in UTC as the start of the test. Ask them to trigger one moved email in their local app while they are signed in as themselves, such as a signup or a password reset, so the email goes to an address they own. Ask them to tell you when it is sent and to open the email. +3. Run `SELECT toUnixTimestamp(now())` through the PostHog MCP `execute-sql` tool, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app while they are signed in as themselves, such as a signup or a password reset, so the email goes to an address they own. Ask them to tell you when it is sent and to open the email. 4. When the send fails, find its code in `transactional-emails.md` or `api.md`, tell the person the fix, and record it. Never retry a send yourself. 5. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID since the start of the test: ```sql SELECT event, timestamp, properties.$workflow_id AS workflow FROM events - WHERE distinct_id = '' AND timestamp >= '' + WHERE distinct_id = '' AND toUnixTimestamp(timestamp) >= ORDER BY timestamp ``` 6. The chain holds when the result has a `$workflows_email_sent`, an engagement event such as `$workflows_email_delivered` or `$workflows_email_opened` with the same `workflow`, and at least one product event of the app. An event from before the start of the test belongs to another email. Delivery events arrive after the provider reports back: when only the send shows, wait a minute and run the query once more. -When the MCP has no SQL tool, ask the person to open their person in PostHog and tell you which of the three they see after the start of the test. +When the MCP has no SQL tool, ask the person to open their person in PostHog and tell you which of the three they see since they triggered the test email. Never write the address or the distinct ID into a file. diff --git a/context/skills/migrate-email/references/9-report.md b/context/skills/migrate-email/references/9-report.md index 5462c62b8..649265c70 100644 --- a/context/skills/migrate-email/references/9-report.md +++ b/context/skills/migrate-email/references/9-report.md @@ -15,7 +15,7 @@ The report comes from the plan file. Invent nothing. ## Write the report -Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email--report.md` at the project root, where `` is the name of the provider folder under `references/`. Use the structure below, then delete the plan file. Never write a recipient's email address into the report. +Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email--report.md` at the project root, where `` is the name of the provider folder under `references/`. Use the structure below. Then delete every template file the plan lists, and the plan file. Never write a recipient's email address into the report. ```markdown # Email migration report: to PostHog @@ -49,7 +49,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ## Checks - + ## Sending tier diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 3820a6900..26d8e2f31 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -73,7 +73,7 @@ How a site that moves is written with `posthog-node`. Step 7 says when to use ea - The site sends `templateKey`, `subject`, `html`, `text` when there is one, and `templateData` with the site's `variables` object, plus the subject values below. - The site's own `subject`, `from`, and `replyTo` win over the template's. When the site has none, use the template's: put its `from` and `replyTo` on the send, and its subject in the module. - The module's subject is fixed text with placeholders. When the site builds its subject from values, such as `` `Order #${order.id}` ``, write the subject in the module as `Order #{{ variables.ORDER_ID }}` and add each value to `templateData`. Never send a subject that changes per email with `templateData`: posthog-node hashes a local template's subject and content, so each email would upload a new version of the template. A send without `templateData` sends rendered content and uploads nothing. -- The template's alias, or its name when it has no alias, becomes the `templateKey` and the module's file name: in lowercase, with each run of characters other than letters, digits, `-`, and `_` replaced by one `-`, and no `-` at either end. When two templates get the same key, add `-2`, `-3`, and so on to the later ones. +- The template's alias, or its name when it has no alias, becomes the `templateKey` and the module's file name: in lowercase, with each run of characters other than letters, digits, `-`, and `_` replaced by one `-`, and no `-` at either end. When that leaves nothing, use the template's id the same way. When the key is already taken by another email of this run, add `-2`, `-3`, and so on. **The answer.** posthog-node answers `{ data, error }` like Resend and never throws on an API error. From 53a190cde2beecc9d3e57d3ea7d36f6bf1ea0859 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Sun, 1 Nov 2026 18:57:23 +0000 Subject: [PATCH 20/70] fix(skills): keep migrate-email's test clock uncached and report dependency upgrades The clock query carries a fresh random literal so a cached answer can't widen the test window. Step 3 may write the template files it saves, the dashboard copy includes the template's alias or name for its key, and a major dependency upgrade lands in the report's "Before cutover" list. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/3-inventory.md | 2 +- context/skills/migrate-email/references/7-rewrite.md | 2 +- context/skills/migrate-email/references/8-verify.md | 2 +- context/skills/migrate-email/references/9-report.md | 2 +- context/skills/migrate-email/references/resend/account.md | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index 4d00be176..58a3f528a 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -5,7 +5,7 @@ next_step: 4-sender.md # Step 3, list and classify every send -List every place the code sends email through the provider, and decide for each one whether PostHog can send it. Change no source file. The only file you write is the plan file. +List every place the code sends email through the provider, and decide for each one whether PostHog can send it. Change no source file. The only files you write are the plan file and the template files below. ## Status diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index aa98de9dd..bedada723 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -73,4 +73,4 @@ When a site turns out to need something `mapping.md` keeps on the provider, undo ## Write down -Tick the phase in the plan: `- [x] rewrite — sites moved`. Add a `key` column to the sites table with each moved site's `templateKey`. Under the table, note each site without a `distinctId`, each fallback that an empty string now replaces, each site that got a branch for a suppressed recipient, each site with `cc` or `bcc` that a suppressed copy address now stops, each idempotency key a retry across the deploy could send twice, each new dependency, and each new env variable name. +Tick the phase in the plan: `- [x] rewrite — sites moved`. Add a `key` column to the sites table with each moved site's `templateKey`. Under the table, note each site without a `distinctId`, each fallback that an empty string now replaces, each site that got a branch for a suppressed recipient, each site with `cc` or `bcc` that a suppressed copy address now stops, each idempotency key a retry across the deploy could send twice, each new dependency, each upgraded one with its old and new version, and each new env variable name. diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 5e473f92f..1eacd6213 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -28,7 +28,7 @@ Skip this part and record `not checked` with the reason when the API is not conf 1. Check that the app sends to the MCP's project: compare the project token the app reads, from its env file, with `api_token` from the PostHog MCP `projects-get` tool. When they differ, record `not checked: the app uses another project`, tell the person which project the app uses, and skip the rest of this part. 2. Ask the person whether to send one test email. Say that it sends a real email, and that the first send of a local template uploads it to the PostHog project. When they say no, record `not checked: declined`. -3. Run `SELECT toUnixTimestamp(now())` through the PostHog MCP `execute-sql` tool, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app while they are signed in as themselves, such as a signup or a password reset, so the email goes to an address they own. Ask them to tell you when it is sent and to open the email. +3. Run `SELECT toUnixTimestamp(now()), ''` through the PostHog MCP `execute-sql` tool, so the answer can't come from a cached run, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app while they are signed in as themselves, such as a signup or a password reset, so the email goes to an address they own. Ask them to tell you when it is sent and to open the email. 4. When the send fails, find its code in `transactional-emails.md` or `api.md`, tell the person the fix, and record it. Never retry a send yourself. 5. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID since the start of the test: diff --git a/context/skills/migrate-email/references/9-report.md b/context/skills/migrate-email/references/9-report.md index 649265c70..c943df576 100644 --- a/context/skills/migrate-email/references/9-report.md +++ b/context/skills/migrate-email/references/9-report.md @@ -59,7 +59,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- The moved sites send through PostHog as soon as this code is deployed. Everything in this list has to be done before that deploy. - + ## After cutover diff --git a/context/skills/migrate-email/references/resend/account.md b/context/skills/migrate-email/references/resend/account.md index 93146a650..5241f7831 100644 --- a/context/skills/migrate-email/references/resend/account.md +++ b/context/skills/migrate-email/references/resend/account.md @@ -26,7 +26,7 @@ The app's own Resend key is usually a sending-only key, and it can't read templa A site that sends a template stored at Resend needs the template's content. -**Copy from the dashboard.** In Resend: Templates, then the template. Ask the person for its HTML, its plain text when it has one, its subject, its `from` and reply-to when they are set, and each variable's fallback. +**Copy from the dashboard.** In Resend: Templates, then the template. Ask the person for its alias or name, its HTML, its plain text when it has one, its subject, its `from` and reply-to when they are set, and each variable's fallback. **Read from the API.** `GET https://api.resend.com/templates/{id or alias}` with `Authorization: Bearer $RESEND_FULL_ACCESS_API_KEY`. The answer holds `alias`, `name`, `subject`, `from`, `reply_to`, `html`, `text`, and `variables`, a list of `{ key, type, fallback_value }`. From 50b5f27f18ca54047bd71adca497025b9c1f335c Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Sun, 1 Nov 2026 18:58:28 +0000 Subject: [PATCH 21/70] fix(skills): keep migrate-email's chain query uncached on its rerun Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/8-verify.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 1eacd6213..17f9ad725 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -30,10 +30,10 @@ Skip this part and record `not checked` with the reason when the API is not conf 2. Ask the person whether to send one test email. Say that it sends a real email, and that the first send of a local template uploads it to the PostHog project. When they say no, record `not checked: declined`. 3. Run `SELECT toUnixTimestamp(now()), ''` through the PostHog MCP `execute-sql` tool, so the answer can't come from a cached run, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app while they are signed in as themselves, such as a signup or a password reset, so the email goes to an address they own. Ask them to tell you when it is sent and to open the email. 4. When the send fails, find its code in `transactional-emails.md` or `api.md`, tell the person the fix, and record it. Never retry a send yourself. -5. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID since the start of the test: +5. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID since the start of the test, with a new random string each time you run it: ```sql - SELECT event, timestamp, properties.$workflow_id AS workflow FROM events + SELECT event, timestamp, properties.$workflow_id AS workflow, '' AS run FROM events WHERE distinct_id = '' AND toUnixTimestamp(timestamp) >= ORDER BY timestamp ``` From 8f77354c203d8e7e4efcd377d3a0725872dc5fd1 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Mon, 2 Nov 2026 15:02:22 +0000 Subject: [PATCH 22/70] fix(skills): keep cc, bcc, headers, tags and attachments sites on Resend, and move templates only to PostHog The first PostHog release sends a template made in PostHog by template id, or rendered html and text. A Resend template site moves only once the person makes the template in PostHog, or stays on Resend for now. Co-Authored-By: Claude Opus 5.5 --- .../skills/migrate-email/references/3-inventory.md | 2 +- .../skills/migrate-email/references/7-report.md | 2 +- .../migrate-email/references/resend/mapping.md | 14 ++++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index 160f32877..2def92d75 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -45,7 +45,7 @@ Go through `mapping.md` field by field. A site **moves** when PostHog can send e When the code passes a value you can't read, such as a list of recipients built at run time, follow it to its callers. When you still can't tell, the site stays, and the reason says what you could not check. -A `template` site needs the template's content to be classified. Ask the person once to copy every template the sites send from the provider's dashboard into files outside the repository, and to tell you where they saved them. Read those files, and never write the content into the plan. When the person can't give the content, the site stays, and the reason is `template content not checked`. +A `template` site moves only to a template made in PostHog, and the person makes that template. Ask the person once, for every template the sites send, whether to move it to PostHog or keep it on the provider for now. A template they keep stays, and the reason is `kept on for now`. For each template they move, ask them to copy it from the provider's dashboard into a file outside the repository, and to tell you where they saved it. Read those files to classify the site, and never write the content into the plan. When the person can't give the content, the site stays, and the reason is `template content not checked`. ## Write the plan file diff --git a/context/skills/migrate-email/references/7-report.md b/context/skills/migrate-email/references/7-report.md index eaa7a69ee..e7f4c39ce 100644 --- a/context/skills/migrate-email/references/7-report.md +++ b/context/skills/migrate-email/references/7-report.md @@ -51,7 +51,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ## Before cutover - + ## Summary ``` diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 8a27a39c7..0630178d0 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -12,12 +12,12 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `html` | `html` | Never | | `text` | `text` | Never | | `react` | `html`, rendered in the app | Never. The app renders the component | -| `template` | a local template in the app's code | Its content can't be read, it uses syntax beyond variables and fallbacks, or the app fills a variable with HTML | -| `cc`, `bcc` | `cc`, `bcc` | An entry carries a name, such as `Jane `, or there are more than 10 | +| `template` | a template made in PostHog, sent by its `templateId` with `templateData` | The person keeps it on Resend for now, its content can't be read, it uses syntax beyond variables and fallbacks, the app fills a variable with HTML, or the site sets `from`, `replyTo`, or `subject` next to it | +| `cc`, `bcc` | none | Always | | `replyTo` / `reply_to` | `replyTo` / `reply_to`, as a list | An entry carries a name, such as `Jane `, there are more than 10, or the code builds the value at run time and you cannot tell that it holds bare addresses only. A single address moves as a list of one | -| `headers` | `headers` | A header is one PostHog sets itself (`From`, `To`, `Cc`, `Bcc`, `Reply-To`, `Subject`, `Date`, `Message-ID`, `MIME-Version`, `Sender`, `Return-Path`, `Auto-Submitted`, `DKIM-Signature`, `Received`, any `Content-*`, `X-PostHog-*`, `X-SES-*`), a name is longer than 126 characters, a value is longer than 870 characters or has a line break or a non-ASCII character, or there are more than 10 | -| `tags` | `tags` | A name or value has characters other than ASCII letters, digits, `_`, and `-` or is longer than 256 characters, a name starts with `ph_`, or there are more than 10 | -| `attachments` | `attachments` | An attachment uses `path` (a URL Resend fetches), the files can be more than 10 or more than 512 KB in total, or a file type is one mailbox providers block, such as `.exe` | +| `headers` | none | Always | +| `tags` | none | Always | +| `attachments` | none | Always | | `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | Never. The key keeps its value | | `scheduledAt` / `scheduled_at` | none | Always | | `topicId` / `topic_id` | none | Always | @@ -43,4 +43,6 @@ This file decides, field by field, whether PostHog can send a Resend call site. ## Content - `html`, `text`, and `react` content is rendered for one recipient before the send. PostHog sends it as it is. -- A `template` site needs the template's content from the Resend dashboard, because the code has only its id. PostHog's Liquid escapes HTML in a variable's value. A variable the app fills with HTML keeps the site on Resend. +- A `template` site moves only to a template made in PostHog. This skill never makes one: the person makes it from the Resend template, makes it transactional, and gives you its template ID. Until then the site stays on Resend. +- The check needs the template's content from the Resend dashboard, because the code has only its id. In the PostHog template, `{{{NAME}}}` becomes `{{ variables.NAME }}`, and `{{{NAME|there}}}` becomes `{{ variables.NAME | default: 'there' }}`. PostHog's Liquid escapes HTML in a variable's value, so a variable the app fills with HTML keeps the site on Resend. +- The PostHog template carries its own sender, reply-to address, and subject. A site that sets `from`, `replyTo`, or `subject` next to `template` stays on Resend. From b9d785e82a5fdfb7aa1aaee7f13835d037fe2c51 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Mon, 2 Nov 2026 15:05:32 +0000 Subject: [PATCH 23/70] Drop local templates and parked fields from the cutover steps Under the scope cut, a moved template site sends a template made in PostHog by templateId with templateData. Rendered sends keep templateKey, subject, html and text. No local-template module, no upload on first send, and no cc, bcc, headers, tags or attachments. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/description.md | 4 ++-- .../migrate-email/references/7-rewrite.md | 17 ++++++++--------- .../skills/migrate-email/references/8-verify.md | 2 +- .../migrate-email/references/resend/account.md | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/context/skills/migrate-email/description.md b/context/skills/migrate-email/description.md index 745723a67..b36e4c43a 100644 --- a/context/skills/migrate-email/description.md +++ b/context/skills/migrate-email/description.md @@ -31,7 +31,7 @@ The plan file `.posthog-email-migration-plan.md` lives at the project root. Step - Change send code only in Step 7, and fix it only in Step 8: the sites that move, the helpers, callers, and tests they need, and other `posthog-node` code that the upgrade breaks. Leave every site that stays as it is. - Never touch DNS or the {display_name} account. Give the person the records and the links, and let them make the change. - Never remove the {display_name} package or its API key. The report tells the person when to remove them. -- Never create, upload, or edit a template in PostHog. A moved local template uploads on its first send. +- Never create, upload, or edit a template in PostHog. The person makes each template that moves to PostHog. - Never write a recipient's email address into a file in the repository, the plan, or the report. Count addresses instead. - Keep keys in environment variables. Never hardcode a key, and never ask the person to paste one into the chat. - Do not commit. The person reviews the diff and commits. @@ -54,4 +54,4 @@ Outside the Wizard, skip the `[STATUS]` lines, and tell the person why you stopp `transactional-emails.md` is the transactional email overview. It covers how to create a transactional email and its API key, idempotency, and the error codes. `api.md` covers the send route, including content from your code, and the checks of a send. -When the `sending-transactional-emails` skill is available, read it for the PostHog side of a send. Its `moving-from-other-providers.md` moves sends to a template stored in PostHog. This skill moves {display_name}'s sends to `posthog-node` with the content in the app's code instead. Where the two disagree, this skill's steps win. +When the `sending-transactional-emails` skill is available, read it for the PostHog side of a send. Its `moving-from-other-providers.md` moves sends to a template stored in PostHog. This skill moves {display_name}'s sends to `posthog-node`, with the content in the app's code, or to a template the person makes in PostHog. Where the two disagree, this skill's steps win. diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index bedada723..3e7444ab1 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -22,11 +22,10 @@ Rewrite each site whose `moves` is `yes` in the plan to send with `posthog-node` ## Set up the client -Install or upgrade `posthog-node` to its latest release with the project's package manager. `posthog.emails` alone is not enough: early releases send only a template stored in PostHog, by `templateId`. Check the installed package's types for what the moving sites need: +Install or upgrade `posthog-node` to its latest release with the project's package manager. `posthog.emails` alone is not enough: early releases send only a template made in PostHog, by `templateId`. Check the installed package's types for what the moving sites need: -- every site: `posthog.emails.send` takes `templateKey` with `subject` and `html` or `text`; -- a template stored at the provider: `templateData` takes the local template's content; -- a site that sets `cc`, `bcc`, `replyTo`, `headers`, `tags`, or `attachments`: the send takes that field. +- a site with `html`, `text`, or a component: `posthog.emails.send` takes `templateKey` with `subject` and `html` or `text`; +- a site that sets `replyTo`: the send takes `replyTo`. When the latest release lacks one of these, change no site that needs it. Mark each such row `moves: no — posthog-node has no yet`, tell the person, and go on with the rest. When no site is left, tick the phase with `none moved` and go to the next step. @@ -61,16 +60,16 @@ PostHog shows each email on the person the send names with `distinctId`. Use the For each site that moves, in plan order: -- Rewrite the call as the provider's `mapping.md` says, for the site's content form: `html` and `text` content, a component the app renders, or a template stored at the provider. -- Give each send a `templateKey` that names the kind of email, such as `welcome` or `password-reset`, with letters, digits, `-`, and `_` only. Two sites that send the same email share a key. A template stored at the provider keeps the key `mapping.md` gives it. -- A template stored at the provider becomes a module that exports `subject` and `html`, and `text` when it has one, in an `emails/` folder next to the server code. Write it from the file the plan lists for the site, never from memory. The site imports the module and passes `templateData`. +- Rewrite the call as the provider's `mapping.md` says, for the site's content form: `html` and `text` content, a component the app renders, or a template made in PostHog. +- Give each send with rendered content a `templateKey` that names the kind of email, such as `welcome` or `password-reset`, with letters, digits, `-`, and `_` only. Two sites that send the same email share a key. +- A site that moves to a template made in PostHog sends the template ID the person gave in Step 3, never one you guess. - Install `@react-email/render` with the project's package manager when a site renders a component and the app doesn't have it. - Keep the site's idempotency key, error branches, logging, and return value working as before. Keep the code around the send unchanged where you can. - `posthog.emails.send` never throws on an API error: it returns `{ data, error }`. When the old call threw on an error, or the code checked an HTTP status, check `error` so the site fails the same way. -- Never add a field that the old call didn't set, apart from `templateKey`, `distinctId`, and the template defaults `mapping.md` names. +- Never add a field that the old call didn't set, apart from `templateKey`, `templateId`, and `distinctId`. `templateData` takes the place of the provider's template variables. When a site turns out to need something `mapping.md` keeps on the provider, undo its change, set `moves` to `no` with the reason, and go on. ## Write down -Tick the phase in the plan: `- [x] rewrite — sites moved`. Add a `key` column to the sites table with each moved site's `templateKey`. Under the table, note each site without a `distinctId`, each fallback that an empty string now replaces, each site that got a branch for a suppressed recipient, each site with `cc` or `bcc` that a suppressed copy address now stops, each idempotency key a retry across the deploy could send twice, each new dependency, each upgraded one with its old and new version, and each new env variable name. +Tick the phase in the plan: `- [x] rewrite — sites moved`. Add a `key` column to the sites table with each moved site's `templateKey`, or its `templateId` for a template made in PostHog. Under the table, note each site without a `distinctId`, each fallback that an empty string now replaces, each site that got a branch for a suppressed recipient, each idempotency key a retry across the deploy could send twice, each new dependency, each upgraded one with its old and new version, and each new env variable name. diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 17f9ad725..36fa7e6dd 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -27,7 +27,7 @@ The chain to prove: PostHog sends the email, records its engagement on the perso Skip this part and record `not checked` with the reason when the API is not confirmed on, no sender is verified, or `POSTHOG_PROJECT_SECRET_API_KEY` is not set. 1. Check that the app sends to the MCP's project: compare the project token the app reads, from its env file, with `api_token` from the PostHog MCP `projects-get` tool. When they differ, record `not checked: the app uses another project`, tell the person which project the app uses, and skip the rest of this part. -2. Ask the person whether to send one test email. Say that it sends a real email, and that the first send of a local template uploads it to the PostHog project. When they say no, record `not checked: declined`. +2. Ask the person whether to send one test email. Say that it sends a real email. When they say no, record `not checked: declined`. 3. Run `SELECT toUnixTimestamp(now()), ''` through the PostHog MCP `execute-sql` tool, so the answer can't come from a cached run, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app while they are signed in as themselves, such as a signup or a password reset, so the email goes to an address they own. Ask them to tell you when it is sent and to open the email. 4. When the send fails, find its code in `transactional-emails.md` or `api.md`, tell the person the fix, and record it. Never retry a send yourself. 5. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID since the start of the test, with a new random string each time you run it: diff --git a/context/skills/migrate-email/references/resend/account.md b/context/skills/migrate-email/references/resend/account.md index 5241f7831..c3922cdb6 100644 --- a/context/skills/migrate-email/references/resend/account.md +++ b/context/skills/migrate-email/references/resend/account.md @@ -24,13 +24,13 @@ The app's own Resend key is usually a sending-only key, and it can't read templa ## Template content -A site that sends a template stored at Resend needs the template's content. +A site whose template the person moves to PostHog needs the template's content, to check it before they make the PostHog template. **Copy from the dashboard.** In Resend: Templates, then the template. Ask the person for its alias or name, its HTML, its plain text when it has one, its subject, its `from` and reply-to when they are set, and each variable's fallback. **Read from the API.** `GET https://api.resend.com/templates/{id or alias}` with `Authorization: Bearer $RESEND_FULL_ACCESS_API_KEY`. The answer holds `alias`, `name`, `subject`, `from`, `reply_to`, `html`, `text`, and `variables`, a list of `{ key, type, fallback_value }`. -The content goes only into the temporary file Step 3 saves and the template module the rewrite writes. Never write it into the plan or the report. +The content goes only into the temporary file Step 3 saves. Never write it into the plan or the report. ## Suppression list From 5edeb92e44ae895988144f6a37d734c06589c7e7 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Mon, 2 Nov 2026 15:51:07 +0000 Subject: [PATCH 24/70] feat(migrate-email): set migratedFrom on the posthog-node client posthog-node's migratedFrom client option sends the provider a send moved from with every email request. Step 7 now sets it, and the Resend mapping names its value. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 4 +++- context/skills/migrate-email/references/resend/mapping.md | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 3e7444ab1..0169fb194 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -38,10 +38,12 @@ export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { host: process.env.POSTHOG_HOST, secretKey: process.env.POSTHOG_PROJECT_SECRET_API_KEY, enableLocalEvaluation: false, + migratedFrom: '', }) ``` -- Reuse the app's existing `posthog-node` client when it has one, and add `secretKey`. Keep `enableLocalEvaluation: false` unless the key also has `feature_flag:read` and the app uses local evaluation. +- Set `migratedFrom` to the value that the provider's `mapping.md` names under "The PostHog client". posthog-node sends it with every email request, so PostHog knows that the sends moved from that provider. +- Reuse the app's existing `posthog-node` client when it has one, and add `secretKey` and `migratedFrom`. Keep `enableLocalEvaluation: false` unless the key also has `feature_flag:read` and the app uses local evaluation. - When the project token or the host is not configured yet, get the token from the PostHog MCP `projects-get` tool (`api_token`). The host is `https://us.i.posthog.com` for US Cloud and `https://eu.i.posthog.com` for EU Cloud. Ask the person which one when you can't tell. - When `host` is a reverse proxy or a self-hosted instance, also set `appHost` to the PostHog app URL, such as `https://us.posthog.com`. posthog-node never sends the secret key to a proxy, and without `appHost` the send fails with `missing_app_host`. - Put a new client in its own server-only module, next to the provider's client, and import it where the sites send. diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 24a9341e8..59edca2ed 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -55,6 +55,8 @@ This file decides, field by field, whether PostHog can send a Resend call site. How a site that moves is written with `posthog-node`. Step 7 says when to use each part. +**The PostHog client.** Set `migratedFrom: 'resend'` on the `posthog-node` client that Step 7 configures. + **The call.** `resend.emails.send(payload, { idempotencyKey })` and `resend.emails.create(...)` become one `posthog.emails.send({ ... })`. The options object goes away: `idempotencyKey` moves into the payload. **The fields.** From 64cf8efd22d4cb2f2d4ec160a76e9301e515ba1a Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:03:00 +0000 Subject: [PATCH 25/70] fix(migrate-email): ask for the PostHog template ID before a template site moves Review round 1 on #451: - Step 3 asks for the template ID once the person made the template in PostHog. A template without one stays: PostHog template not made yet. - Step 7 checks that the client takes migratedFrom, and undoes the posthog-node install when no site is left to move. - Template files from an API read are deleted once their site is classified, and the full-access Resend key right after Step 5. - Step 8 reads only the token's line of the env file, and picks a signed-in flow for the test email. - replyTo moves as one address or a list. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/3-inventory.md | 4 +++- context/skills/migrate-email/references/5-suppressions.md | 2 ++ context/skills/migrate-email/references/7-rewrite.md | 5 +++-- context/skills/migrate-email/references/8-verify.md | 4 ++-- context/skills/migrate-email/references/9-report.md | 6 +++--- context/skills/migrate-email/references/resend/account.md | 2 +- context/skills/migrate-email/references/resend/mapping.md | 2 +- 7 files changed, 15 insertions(+), 10 deletions(-) diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index cb9f12f2f..bc243b7fd 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -47,7 +47,9 @@ When the code passes a value you can't read, such as a list of recipients built A `template` site moves only to a template made in PostHog, and the person makes that template. Ask the person once, for every template the sites send, whether to move it to PostHog or keep it on the provider for now. A template they keep stays, and the reason is `kept on for now`. -A template they move needs its content to be classified. Read the provider's `account.md`, and ask the person once for every template they move: copies from the dashboard that they save in files outside the repository and tell you where, or a read through the API. Save each template's content in a file in the system's temporary folder, never in the repository or the plan, and list each file's path with its site under the sites table. When the person can't give the content, the site stays, and the reason is `template content not checked`. +A template they move needs its content to be classified. Read the provider's `account.md`, and ask the person once for every template they move: copies from the dashboard that they save in files outside the repository and tell you where, or a read through the API. Read the person's copies where they saved them. Write an API answer to a file in the system's temporary folder, never in the repository or the plan, and delete that file as soon as its site is classified. When the person can't give the content, the site stays, and the reason is `template content not checked`. + +A template whose content passes the checks moves only once the person has made it in PostHog. Ask them once, for every such template, to make it in PostHog from the provider's template, make it transactional, and give you its template ID. Tell them how its placeholders change, as `mapping.md` says under "Content". Record each template ID with its site under the sites table. A template without an ID stays, and the reason is `PostHog template not made yet`. ## Write the plan file diff --git a/context/skills/migrate-email/references/5-suppressions.md b/context/skills/migrate-email/references/5-suppressions.md index 916a21439..5f6559b9c 100644 --- a/context/skills/migrate-email/references/5-suppressions.md +++ b/context/skills/migrate-email/references/5-suppressions.md @@ -37,3 +37,5 @@ Read the provider's `account.md`. It says how to export the list, which entries ## Write down Tick the phase in the plan file only when every entry is imported: `- [x] suppressions — / imported`. When the list is empty, write `- [x] suppressions — empty list`. When the import stopped partway, write `- [ ] suppressions — / imported: `. When the person has no export and no key, write `- [ ] suppressions — not imported: `. + +When the plan says the run created a full-access provider key, ask the person now to delete it at the provider and remove its variable from the env file, as `account.md` says. Note in the plan whether they did. diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 0169fb194..0bd2c3674 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -25,9 +25,10 @@ Rewrite each site whose `moves` is `yes` in the plan to send with `posthog-node` Install or upgrade `posthog-node` to its latest release with the project's package manager. `posthog.emails` alone is not enough: early releases send only a template made in PostHog, by `templateId`. Check the installed package's types for what the moving sites need: - a site with `html`, `text`, or a component: `posthog.emails.send` takes `templateKey` with `subject` and `html` or `text`; -- a site that sets `replyTo`: the send takes `replyTo`. +- a site that sets `replyTo`: the send takes `replyTo`; +- the client: the client options take `migratedFrom`. -When the latest release lacks one of these, change no site that needs it. Mark each such row `moves: no — posthog-node has no yet`, tell the person, and go on with the rest. When no site is left, tick the phase with `none moved` and go to the next step. +When the latest release lacks one of these, change no site that needs it. Mark each such row `moves: no — posthog-node has no yet`, tell the person, and go on with the rest. When the client options lack `migratedFrom`, leave it out of the client. When no site is left, undo the install or upgrade of `posthog-node`, tick the phase with `none moved`, and go to the next step. Configure one server-side client for email: diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 36fa7e6dd..6779afb76 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -26,9 +26,9 @@ The chain to prove: PostHog sends the email, records its engagement on the perso Skip this part and record `not checked` with the reason when the API is not confirmed on, no sender is verified, or `POSTHOG_PROJECT_SECRET_API_KEY` is not set. -1. Check that the app sends to the MCP's project: compare the project token the app reads, from its env file, with `api_token` from the PostHog MCP `projects-get` tool. When they differ, record `not checked: the app uses another project`, tell the person which project the app uses, and skip the rest of this part. +1. Check that the app sends to the MCP's project: compare the project token the app reads with `api_token` from the PostHog MCP `projects-get` tool. Read only the token's line of the env file, by searching for the token variable's name: the file also holds secret keys, so never open all of it. When they differ, record `not checked: the app uses another project`, tell the person which project the app uses, and skip the rest of this part. 2. Ask the person whether to send one test email. Say that it sends a real email. When they say no, record `not checked: declined`. -3. Run `SELECT toUnixTimestamp(now()), ''` through the PostHog MCP `execute-sql` tool, so the answer can't come from a cached run, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app while they are signed in as themselves, such as a signup or a password reset, so the email goes to an address they own. Ask them to tell you when it is sent and to open the email. +3. Run `SELECT toUnixTimestamp(now()), ''` through the PostHog MCP `execute-sql` tool, so the answer can't come from a cached run, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app that sends it to an address they own while they are signed in as themselves, such as a signup. A flow that runs signed out, such as a password reset, sends product events on another distinct ID. Ask them to tell you when it is sent and to open the email. 4. When the send fails, find its code in `transactional-emails.md` or `api.md`, tell the person the fix, and record it. Never retry a send yourself. 5. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID since the start of the test, with a new random string each time you run it: diff --git a/context/skills/migrate-email/references/9-report.md b/context/skills/migrate-email/references/9-report.md index 407921979..12e291a89 100644 --- a/context/skills/migrate-email/references/9-report.md +++ b/context/skills/migrate-email/references/9-report.md @@ -15,7 +15,7 @@ The report comes from the plan file. Invent nothing. ## Write the report -Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email--report.md` at the project root, where `` is the name of the provider folder under `references/`. Use the structure below. Then delete every template file the plan lists, and the plan file. Never write a recipient's email address into the report. +Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email--report.md` at the project root, where `` is the name of the provider folder under `references/`. Use the structure below. Then delete the plan file. Never write a recipient's email address into the report. ```markdown # Email migration report: to PostHog @@ -59,11 +59,11 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- The moved sites send through PostHog as soon as this code is deployed. Everything in this list has to be done before that deploy. - + ## After cutover - + ## Summary ``` diff --git a/context/skills/migrate-email/references/resend/account.md b/context/skills/migrate-email/references/resend/account.md index c3922cdb6..66b1f929d 100644 --- a/context/skills/migrate-email/references/resend/account.md +++ b/context/skills/migrate-email/references/resend/account.md @@ -20,7 +20,7 @@ A domain verified at Resend carries these records. Keep all of them until the cu ## Full-access key -The app's own Resend key is usually a sending-only key, and it can't read templates or the suppression list. When the person chooses the API over the dashboard, ask them to create a full-access key in Resend, store it in `RESEND_FULL_ACCESS_API_KEY` in the git-ignored env file, and note in the plan that the run created it. The report tells the person to delete it. Never print the key, and never write it into another file. +The app's own Resend key is usually a sending-only key, and it can't read templates or the suppression list. When the person chooses the API over the dashboard, ask them to create a full-access key in Resend, store it in `RESEND_FULL_ACCESS_API_KEY` in the git-ignored env file, and note in the plan that the run created it. Its last use is the suppression import in Step 5. At the end of Step 5, ask the person to delete the key in Resend and remove its variable from the env file, and note in the plan whether they did. The report reminds them when they didn't. Never print the key, and never write it into another file. ## Template content diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 59edca2ed..e93ba0ec7 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -14,7 +14,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `react` | `html`, rendered in the app | Never. The app renders the component | | `template` | a template made in PostHog, sent by its `templateId` with `templateData` | The person keeps it on Resend for now, its content can't be read, it uses syntax beyond variables and fallbacks, the app fills a variable with HTML, or the site sets `from`, `replyTo`, or `subject` next to it | | `cc`, `bcc` | none | Always | -| `replyTo` / `reply_to` | `replyTo` / `reply_to`, as a list | An entry carries a name, such as `Jane `, there are more than 10, or the code builds the value at run time and you cannot tell that it holds bare addresses only. A single address moves as a list of one | +| `replyTo` / `reply_to` | `replyTo`, one address or a list | An entry carries a name, such as `Jane `, there are more than 10, or the code builds the value at run time and you cannot tell that it holds bare addresses only | | `headers` | none | Always | | `tags` | none | Always | | `attachments` | none | Always | From 85f60962c4cdb1bbe24efb6462c5335bceb1b290 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:08:02 +0000 Subject: [PATCH 26/70] fix(migrate-email): check each PostHog template and its sender before cutover Review round 2 on #451: - Step 3 asks for the address a PostHog template sends from and writes it in the site's from column, so Step 4 sets up a sender for its domain. - The report asks the person to send a test of each PostHog template and check that it is transactional, has a verified sender and fills its variables. - Step 5 asks to delete the full-access key on every way out of the step, and after a partial import only once the person won't repeat it. - Step 8 allows a signed-out flow: the person signs in as the recipient afterwards, so product events show on the same distinct ID. - migratedFrom is set only when the client options take it. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/3-inventory.md | 2 +- context/skills/migrate-email/references/5-suppressions.md | 6 ++++-- context/skills/migrate-email/references/7-rewrite.md | 4 ++-- context/skills/migrate-email/references/8-verify.md | 2 +- context/skills/migrate-email/references/9-report.md | 2 +- context/skills/migrate-email/references/resend/account.md | 2 +- context/skills/migrate-email/references/resend/mapping.md | 2 +- 7 files changed, 11 insertions(+), 9 deletions(-) diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index bc243b7fd..7d21b665b 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -49,7 +49,7 @@ A `template` site moves only to a template made in PostHog, and the person makes A template they move needs its content to be classified. Read the provider's `account.md`, and ask the person once for every template they move: copies from the dashboard that they save in files outside the repository and tell you where, or a read through the API. Read the person's copies where they saved them. Write an API answer to a file in the system's temporary folder, never in the repository or the plan, and delete that file as soon as its site is classified. When the person can't give the content, the site stays, and the reason is `template content not checked`. -A template whose content passes the checks moves only once the person has made it in PostHog. Ask them once, for every such template, to make it in PostHog from the provider's template, make it transactional, and give you its template ID. Tell them how its placeholders change, as `mapping.md` says under "Content". Record each template ID with its site under the sites table. A template without an ID stays, and the reason is `PostHog template not made yet`. +A template whose content passes the checks moves only once the person has made it in PostHog. Ask them once, for every such template, to make it in PostHog from the provider's template, make it transactional, and give you its template ID and the address it sends from, usually the provider template's sender. Tell them how its placeholders change, as `mapping.md` says under "Content". Record each template ID with its site under the sites table, and write the address in the site's `from` column, so Step 4 sets up a sender for its domain. A template without an ID stays, and the reason is `PostHog template not made yet`. ## Write the plan file diff --git a/context/skills/migrate-email/references/5-suppressions.md b/context/skills/migrate-email/references/5-suppressions.md index 5f6559b9c..b04becbb7 100644 --- a/context/skills/migrate-email/references/5-suppressions.md +++ b/context/skills/migrate-email/references/5-suppressions.md @@ -17,7 +17,7 @@ The provider keeps a suppression list: addresses that hard-bounced or marked an Look for the PostHog MCP tool `email-suppressions-add`, and read its schema with `info`. -When it is missing, the import is not available to this person yet. Do not try other tools, and do not use the opt-out tools: opt-outs are marketing preferences, and transactional email ignores them. Tick the phase as `- [ ] suppressions — not imported: no import tool`, and continue to the next step. The report tells the person to add the addresses in PostHog (Workflows, then Messaging, then Suppression list) before cutover. +When it is missing, the import is not available to this person yet. Do not try other tools, and do not use the opt-out tools: opt-outs are marketing preferences, and transactional email ignores them. Tick the phase as `- [ ] suppressions — not imported: no import tool`, ask about the full-access key as the last section says, and continue to the next step. The report tells the person to add the addresses in PostHog (Workflows, then Messaging, then Suppression list) before cutover. ## Get the list @@ -38,4 +38,6 @@ Read the provider's `account.md`. It says how to export the list, which entries Tick the phase in the plan file only when every entry is imported: `- [x] suppressions — / imported`. When the list is empty, write `- [x] suppressions — empty list`. When the import stopped partway, write `- [ ] suppressions — / imported: `. When the person has no export and no key, write `- [ ] suppressions — not imported: `. -When the plan says the run created a full-access provider key, ask the person now to delete it at the provider and remove its variable from the env file, as `account.md` says. Note in the plan whether they did. +## The full-access key + +Every way out of this step ends here. When the plan says the run created a full-access provider key, ask the person now to delete it at the provider and remove its variable from the env file, as `account.md` says. When the import stopped partway, ask only once the person decides not to repeat it. Note in the plan whether they did. diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 0bd2c3674..e07c02fb1 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -43,8 +43,8 @@ export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { }) ``` -- Set `migratedFrom` to the value that the provider's `mapping.md` names under "The PostHog client". posthog-node sends it with every email request, so PostHog knows that the sends moved from that provider. -- Reuse the app's existing `posthog-node` client when it has one, and add `secretKey` and `migratedFrom`. Keep `enableLocalEvaluation: false` unless the key also has `feature_flag:read` and the app uses local evaluation. +- When the client options take `migratedFrom`, set it to the value that the provider's `mapping.md` names under "The PostHog client". posthog-node sends it with every email request, so PostHog knows that the sends moved from that provider. +- Reuse the app's existing `posthog-node` client when it has one, and add `secretKey`, and `migratedFrom` when the client options take it. Keep `enableLocalEvaluation: false` unless the key also has `feature_flag:read` and the app uses local evaluation. - When the project token or the host is not configured yet, get the token from the PostHog MCP `projects-get` tool (`api_token`). The host is `https://us.i.posthog.com` for US Cloud and `https://eu.i.posthog.com` for EU Cloud. Ask the person which one when you can't tell. - When `host` is a reverse proxy or a self-hosted instance, also set `appHost` to the PostHog app URL, such as `https://us.posthog.com`. posthog-node never sends the secret key to a proxy, and without `appHost` the send fails with `missing_app_host`. - Put a new client in its own server-only module, next to the provider's client, and import it where the sites send. diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 6779afb76..3bd221056 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -28,7 +28,7 @@ Skip this part and record `not checked` with the reason when the API is not conf 1. Check that the app sends to the MCP's project: compare the project token the app reads with `api_token` from the PostHog MCP `projects-get` tool. Read only the token's line of the env file, by searching for the token variable's name: the file also holds secret keys, so never open all of it. When they differ, record `not checked: the app uses another project`, tell the person which project the app uses, and skip the rest of this part. 2. Ask the person whether to send one test email. Say that it sends a real email. When they say no, record `not checked: declined`. -3. Run `SELECT toUnixTimestamp(now()), ''` through the PostHog MCP `execute-sql` tool, so the answer can't come from a cached run, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app that sends it to an address they own while they are signed in as themselves, such as a signup. A flow that runs signed out, such as a password reset, sends product events on another distinct ID. Ask them to tell you when it is sent and to open the email. +3. Run `SELECT toUnixTimestamp(now()), ''` through the PostHog MCP `execute-sql` tool, so the answer can't come from a cached run, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app that sends it to an address they own, such as a signup or a password reset. Ask them to open the email, then to sign in as the user it went to and use the app for a moment, so that the app's product events show on the same distinct ID. Ask them to tell you when they are done. 4. When the send fails, find its code in `transactional-emails.md` or `api.md`, tell the person the fix, and record it. Never retry a send yourself. 5. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID since the start of the test, with a new random string each time you run it: diff --git a/context/skills/migrate-email/references/9-report.md b/context/skills/migrate-email/references/9-report.md index 12e291a89..4562e9f1a 100644 --- a/context/skills/migrate-email/references/9-report.md +++ b/context/skills/migrate-email/references/9-report.md @@ -59,7 +59,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- The moved sites send through PostHog as soon as this code is deployed. Everything in this list has to be done before that deploy. - + ## After cutover diff --git a/context/skills/migrate-email/references/resend/account.md b/context/skills/migrate-email/references/resend/account.md index 66b1f929d..22e6461c9 100644 --- a/context/skills/migrate-email/references/resend/account.md +++ b/context/skills/migrate-email/references/resend/account.md @@ -20,7 +20,7 @@ A domain verified at Resend carries these records. Keep all of them until the cu ## Full-access key -The app's own Resend key is usually a sending-only key, and it can't read templates or the suppression list. When the person chooses the API over the dashboard, ask them to create a full-access key in Resend, store it in `RESEND_FULL_ACCESS_API_KEY` in the git-ignored env file, and note in the plan that the run created it. Its last use is the suppression import in Step 5. At the end of Step 5, ask the person to delete the key in Resend and remove its variable from the env file, and note in the plan whether they did. The report reminds them when they didn't. Never print the key, and never write it into another file. +The app's own Resend key is usually a sending-only key, and it can't read templates or the suppression list. When the person chooses the API over the dashboard, ask them to create a full-access key in Resend, store it in `RESEND_FULL_ACCESS_API_KEY` in the git-ignored env file, and note in the plan that the run created it. Its last use is the suppression import in Step 5. At the end of Step 5, on every way out of it, ask the person to delete the key in Resend and remove its variable from the env file, and note in the plan whether they did. The report reminds them when they didn't. Never print the key, and never write it into another file. ## Template content diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index e93ba0ec7..4e2f7993d 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -55,7 +55,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. How a site that moves is written with `posthog-node`. Step 7 says when to use each part. -**The PostHog client.** Set `migratedFrom: 'resend'` on the `posthog-node` client that Step 7 configures. +**The PostHog client.** Set `migratedFrom: 'resend'` on the `posthog-node` client that Step 7 configures, when its client options take it. **The call.** `resend.emails.send(payload, { idempotencyKey })` and `resend.emails.create(...)` become one `posthog.emails.send({ ... })`. The options object goes away: `idempotencyKey` moves into the payload. From a759ff460e5d556f7a27910add5b26171051f432 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:14:51 +0000 Subject: [PATCH 27/70] fix(migrate-email): ask about a repeat import and test a send that names a person Review round 3 on #451: - Step 5 asks once whether to repeat an import that stopped partway, and asks about the full-access key after that answer or the repeat. - Step 8's test email comes from a moved site that passes distinctId; without one, the chain is recorded as not checked. - The client example marks migratedFrom as conditional. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/5-suppressions.md | 4 ++-- context/skills/migrate-email/references/7-rewrite.md | 2 +- context/skills/migrate-email/references/8-verify.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/context/skills/migrate-email/references/5-suppressions.md b/context/skills/migrate-email/references/5-suppressions.md index b04becbb7..48c55e11b 100644 --- a/context/skills/migrate-email/references/5-suppressions.md +++ b/context/skills/migrate-email/references/5-suppressions.md @@ -32,7 +32,7 @@ Read the provider's `account.md`. It says how to export the list, which entries - Send the entries to `email-suppressions-add` in batches of the size its schema allows. Give each entry the source and the reason `account.md` names. - Repeating an import is safe: an address already on the list stays on it. - Never print the addresses, and never write them into the plan or the report. Count them. -- When a call fails, read its error and fix the call. When it fails again, stop the import and record how many entries you imported. +- When a call fails, read its error and fix the call. When it fails again, stop the import, record how many entries you imported, and ask the person once whether to repeat it now. Repeat it when they say yes. ## Write down @@ -40,4 +40,4 @@ Tick the phase in the plan file only when every entry is imported: `- [x] suppre ## The full-access key -Every way out of this step ends here. When the plan says the run created a full-access provider key, ask the person now to delete it at the provider and remove its variable from the env file, as `account.md` says. When the import stopped partway, ask only once the person decides not to repeat it. Note in the plan whether they did. +Every way out of this step ends here. When the plan says the run created a full-access provider key, ask the person now to delete it at the provider and remove its variable from the env file, as `account.md` says. After a partial import, ask once the person said no to a repeat, or the repeat ended. Note in the plan whether they did. diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index e07c02fb1..eefe42ebe 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -39,7 +39,7 @@ export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { host: process.env.POSTHOG_HOST, secretKey: process.env.POSTHOG_PROJECT_SECRET_API_KEY, enableLocalEvaluation: false, - migratedFrom: '', + migratedFrom: '', // only when the client options take it }) ``` diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 3bd221056..1b29050e9 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -28,7 +28,7 @@ Skip this part and record `not checked` with the reason when the API is not conf 1. Check that the app sends to the MCP's project: compare the project token the app reads with `api_token` from the PostHog MCP `projects-get` tool. Read only the token's line of the env file, by searching for the token variable's name: the file also holds secret keys, so never open all of it. When they differ, record `not checked: the app uses another project`, tell the person which project the app uses, and skip the rest of this part. 2. Ask the person whether to send one test email. Say that it sends a real email. When they say no, record `not checked: declined`. -3. Run `SELECT toUnixTimestamp(now()), ''` through the PostHog MCP `execute-sql` tool, so the answer can't come from a cached run, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app that sends it to an address they own, such as a signup or a password reset. Ask them to open the email, then to sign in as the user it went to and use the app for a moment, so that the app's product events show on the same distinct ID. Ask them to tell you when they are done. +3. Run `SELECT toUnixTimestamp(now()), ''` through the PostHog MCP `execute-sql` tool, so the answer can't come from a cached run, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app that sends it to an address they own, from a site that passes `distinctId`, such as a signup or a password reset. When no moved site passes `distinctId`, record `not checked: no moved site names a person`, and skip the rest of this part. Ask them to open the email, then to sign in as the user it went to and use the app for a moment, so that the app's product events show on the same distinct ID. Ask them to tell you when they are done. 4. When the send fails, find its code in `transactional-emails.md` or `api.md`, tell the person the fix, and record it. Never retry a send yourself. 5. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID since the start of the test, with a new random string each time you run it: From 5c8a34b8b86a5d521ad389f83c37a82d2266fdad Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:26:55 +0000 Subject: [PATCH 28/70] fix(migrate-email): ask for the PostHog template ID and sender before a template site moves Review round 1 on #450: - Step 3 checks a template site's other fields before it asks about the template, and asks for the PostHog template ID and the address it sends from. A template without an ID stays: PostHog template not made yet. The address goes in the from column, so Step 4 sets up its domain. - mapping.md quotes a fallback that holds ' with ", carries a definition-level fallback_value, notes that default replaces an empty string, and keeps a fallback with both quotes or HTML on Resend. - The report asks the person to test each PostHog template before cutover. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/3-inventory.md | 4 +++- context/skills/migrate-email/references/7-report.md | 2 +- context/skills/migrate-email/references/resend/mapping.md | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index 2def92d75..8ad9ba5ec 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -45,7 +45,9 @@ Go through `mapping.md` field by field. A site **moves** when PostHog can send e When the code passes a value you can't read, such as a list of recipients built at run time, follow it to its callers. When you still can't tell, the site stays, and the reason says what you could not check. -A `template` site moves only to a template made in PostHog, and the person makes that template. Ask the person once, for every template the sites send, whether to move it to PostHog or keep it on the provider for now. A template they keep stays, and the reason is `kept on for now`. For each template they move, ask them to copy it from the provider's dashboard into a file outside the repository, and to tell you where they saved it. Read those files to classify the site, and never write the content into the plan. When the person can't give the content, the site stays, and the reason is `template content not checked`. +A `template` site moves only to a template made in PostHog, and the person makes that template. Check the site's other fields first: a site that another field keeps on the provider stays with that reason, and needs no question about its template. Ask the person once, for every other template the sites send, whether to move it to PostHog or keep it on the provider for now. A template they keep stays, and the reason is `kept on for now`. For each template they move, ask them to copy it from the provider's dashboard into a file outside the repository, and to tell you where they saved it. Read those files to classify the site, and never write the content into the plan. When the person can't give the content, the site stays, and the reason is `template content not checked`. + +A template whose content passes the checks moves only once the person has made it in PostHog. Ask them once, for every such template, to make it in PostHog from the provider's template, make it transactional, and give you its template ID and the address it sends from, usually the provider template's sender. Tell them how its placeholders change, as `mapping.md` says under "Content". Record each template ID with its site under the sites table, and write the address in the site's `from` column, so Step 4 sets up a sender for its domain. A template without an ID stays, and the reason is `PostHog template not made yet`. ## Write the plan file diff --git a/context/skills/migrate-email/references/7-report.md b/context/skills/migrate-email/references/7-report.md index e7f4c39ce..8a321c0f0 100644 --- a/context/skills/migrate-email/references/7-report.md +++ b/context/skills/migrate-email/references/7-report.md @@ -51,7 +51,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ## Before cutover - + ## Summary ``` diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 0630178d0..31be4fd5e 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -44,5 +44,9 @@ This file decides, field by field, whether PostHog can send a Resend call site. - `html`, `text`, and `react` content is rendered for one recipient before the send. PostHog sends it as it is. - A `template` site moves only to a template made in PostHog. This skill never makes one: the person makes it from the Resend template, makes it transactional, and gives you its template ID. Until then the site stays on Resend. -- The check needs the template's content from the Resend dashboard, because the code has only its id. In the PostHog template, `{{{NAME}}}` becomes `{{ variables.NAME }}`, and `{{{NAME|there}}}` becomes `{{ variables.NAME | default: 'there' }}`. PostHog's Liquid escapes HTML in a variable's value, so a variable the app fills with HTML keeps the site on Resend. +- The check needs the template's content from the Resend dashboard, because the code has only its id. +- In the PostHog template, `{{{NAME}}}` becomes `{{ variables.NAME }}`, and the name keeps its case. `{{{NAME|there}}}` becomes `{{ variables.NAME | default: 'there' }}`, and a variable with a `fallback_value` in the template's definition gets the same `default`. Quote a fallback that holds a `'` with `"` instead. Liquid has no escape character in a quoted value. +- Liquid's `default` also replaces an empty string, which Resend inserts as it is. When the code can pass an empty string for a variable with a fallback, the email shows the fallback instead. Note it in the report. +- Resend inserts a variable's value as it is. PostHog's Liquid escapes HTML in a value, so `` shows as text. A variable is HTML when the code fills it with markup or with a renderer's output, and such a variable keeps the site on Resend. A variable the app fills with plain values, such as names, numbers, and URLs, renders the same. +- A template that holds anything other than `{{{VAR}}}` and `{{{VAR|fallback}}}` placeholders, such as a section, a loop, or a condition, stays on Resend. So does a fallback that holds both `'` and `"`, and a fallback that holds HTML, such as a link: Liquid escapes the fallback too, so the markup shows as text. - The PostHog template carries its own sender, reply-to address, and subject. A site that sets `from`, `replyTo`, or `subject` next to `template` stays on Resend. From efa493348628cc8f01b1afc53b3e02d6f0f25141 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:39:13 +0000 Subject: [PATCH 29/70] fix(skills): read Dirent.path when parentPath is missing in the migrate-email test Node 20.11, the oldest release engines allows, has no Dirent.parentPath, so the bundle tests threw before their assertions. Use the same parentPath ?? path fallback as build-phases.js. Co-Authored-By: Claude Opus 5.5 --- scripts/lib/tests/migrate-email-skill.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lib/tests/migrate-email-skill.test.js b/scripts/lib/tests/migrate-email-skill.test.js index 14044d5ef..67217f510 100644 --- a/scripts/lib/tests/migrate-email-skill.test.js +++ b/scripts/lib/tests/migrate-email-skill.test.js @@ -44,7 +44,7 @@ async function buildSkill(skillId, outputDir) { function markdownFiles(dir) { return readdirSync(dir, { withFileTypes: true, recursive: true }) .filter((entry) => entry.isFile() && entry.name.endsWith('.md')) - .map((entry) => join(entry.parentPath, entry.name)); + .map((entry) => join(entry.parentPath ?? entry.path, entry.name)); } function unresolvedReferences(skillDir) { From 2c368531a9a0718218f90b2c76933a3101968317 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:39:22 +0000 Subject: [PATCH 30/70] fix(migrate-email): match account.md's template-content rule to Step 3 account.md said template content goes only into a temporary file, while Step 3 reads the person's dashboard copies where they saved them. Only an API answer goes into the temporary file now. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/account.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/resend/account.md b/context/skills/migrate-email/references/resend/account.md index 22e6461c9..920c5a8d4 100644 --- a/context/skills/migrate-email/references/resend/account.md +++ b/context/skills/migrate-email/references/resend/account.md @@ -30,7 +30,7 @@ A site whose template the person moves to PostHog needs the template's content, **Read from the API.** `GET https://api.resend.com/templates/{id or alias}` with `Authorization: Bearer $RESEND_FULL_ACCESS_API_KEY`. The answer holds `alias`, `name`, `subject`, `from`, `reply_to`, `html`, `text`, and `variables`, a list of `{ key, type, fallback_value }`. -The content goes only into the temporary file Step 3 saves. Never write it into the plan or the report. +Read the person's copies where they saved them. An API answer goes only into the temporary file Step 3 writes, which Step 3 deletes once the site is classified. Never write the content into the plan or the report. ## Suppression list From 8dcf6e74a3d41ad5ecce98ab6da44bfe1c47e406 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:49:02 +0000 Subject: [PATCH 31/70] fix(migrate-email): keep a site on Resend when its idempotency key doesn't fit PostHog's PostHog takes an idempotency key of 1 to 255 printable ASCII characters without spaces. A site whose key can hold a space or a non-ASCII character, or run longer, stays on Resend. The report names each key a retry across the deploy could send twice, since the providers don't share keys. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-report.md | 2 +- context/skills/migrate-email/references/resend/mapping.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/7-report.md b/context/skills/migrate-email/references/7-report.md index 8a321c0f0..fc974a0c9 100644 --- a/context/skills/migrate-email/references/7-report.md +++ b/context/skills/migrate-email/references/7-report.md @@ -51,7 +51,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ## Before cutover - + ## Summary ``` diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 31be4fd5e..a3d12a58e 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -18,7 +18,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `headers` | none | Always | | `tags` | none | Always | | `attachments` | none | Always | -| `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | Never. The key keeps its value | +| `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | The key can hold a space or a non-ASCII character, or be longer than 255 characters. Otherwise the key keeps its value, and PostHog keeps it for 24 hours as Resend does. The two providers don't share keys: a retry that runs after the deploy, of a send Resend already took, sends a second email. Note it in the report | | `scheduledAt` / `scheduled_at` | none | Always | | `topicId` / `topic_id` | none | Always | From 07dbf3a6d437e002f66801ef7a973514a96e870c Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:49:17 +0000 Subject: [PATCH 32/70] fix(migrate-email): name PostHog's idempotency key rule exactly Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/mapping.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index a3d12a58e..d72d5ed3a 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -18,7 +18,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `headers` | none | Always | | `tags` | none | Always | | `attachments` | none | Always | -| `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | The key can hold a space or a non-ASCII character, or be longer than 255 characters. Otherwise the key keeps its value, and PostHog keeps it for 24 hours as Resend does. The two providers don't share keys: a retry that runs after the deploy, of a send Resend already took, sends a second email. Note it in the report | +| `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | The key can hold anything but visible ASCII characters, such as a space, or be longer than 255 characters. PostHog takes 1 to 255 visible ASCII characters. Otherwise the key keeps its value, and PostHog keeps it for 24 hours as Resend does. The two providers don't share keys: a retry that runs after the deploy, of a send Resend already took, sends a second email. Note it in the report | | `scheduledAt` / `scheduled_at` | none | Always | | `topicId` / `topic_id` | none | Always | From 21f683e38f1d2986e6d7ebec9bd960ebdf35c258 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:49:52 +0000 Subject: [PATCH 33/70] fix(migrate-email): end Step 8's email check when the person declines the test email Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/8-verify.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 1b29050e9..c0efde366 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -27,7 +27,7 @@ The chain to prove: PostHog sends the email, records its engagement on the perso Skip this part and record `not checked` with the reason when the API is not confirmed on, no sender is verified, or `POSTHOG_PROJECT_SECRET_API_KEY` is not set. 1. Check that the app sends to the MCP's project: compare the project token the app reads with `api_token` from the PostHog MCP `projects-get` tool. Read only the token's line of the env file, by searching for the token variable's name: the file also holds secret keys, so never open all of it. When they differ, record `not checked: the app uses another project`, tell the person which project the app uses, and skip the rest of this part. -2. Ask the person whether to send one test email. Say that it sends a real email. When they say no, record `not checked: declined`. +2. Ask the person whether to send one test email. Say that it sends a real email. When they say no, record `not checked: declined`, and skip the rest of this part. 3. Run `SELECT toUnixTimestamp(now()), ''` through the PostHog MCP `execute-sql` tool, so the answer can't come from a cached run, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app that sends it to an address they own, from a site that passes `distinctId`, such as a signup or a password reset. When no moved site passes `distinctId`, record `not checked: no moved site names a person`, and skip the rest of this part. Ask them to open the email, then to sign in as the user it went to and use the app for a moment, so that the app's product events show on the same distinct ID. Ask them to tell you when they are done. 4. When the send fails, find its code in `transactional-emails.md` or `api.md`, tell the person the fix, and record it. Never retry a send yourself. 5. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID since the start of the test, with a new random string each time you run it: From d1578595a5c728361869f3d7b27c3096eacfe778 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:31:31 +0000 Subject: [PATCH 34/70] docs(migrate-email): say where a send without distinctId lands Rename "Find the user ID" to "Link emails to your users", name the identify() ID, say that without distinctId PostHog records the email on a separate person keyed by the address, and add invites and signup checks to the cases that leave it out. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index eefe42ebe..795cf7031 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -50,13 +50,14 @@ export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { - Put a new client in its own server-only module, next to the provider's client, and import it where the sites send. - Use the env variable names the app already uses for the PostHog token and host. Add each new name, without a value, to the env example file. -## Find the user ID +## Link emails to your users -PostHog shows each email on the person the send names with `distinctId`. Use the ID the app already identifies people with in PostHog: +PostHog records each send, and its sent, opened and clicked events when engagement events are on, against the person the send names with `distinctId`. Pass the ID the app already passes to `identify()`: - Find the app's identify call, such as `posthog.identify(user.id)` in posthog-js, or the `distinctId` of its `posthog-node` captures. - At each site, pass the same ID for the recipient, such as `distinctId: user.id`. Follow the recipient back through the callers when the site only has the address. -- When the recipient is not a user of the app, such as a team inbox, or the site has no way to know the user, leave `distinctId` out and note it in the plan row. +- Without `distinctId`, PostHog records the email against a person whose distinct ID is the recipient's address. Unless the app identifies people by their address, that is a separate person from the user. +- When the recipient isn't a user yet, such as an invite or a check during signup, isn't a user at all, such as a team inbox, or the site has no way to know the user, leave `distinctId` out and note it in the plan row. - When the app identifies no one in PostHog, use the app's own user ID, and note it for the report. ## Rewrite each site From 5dcdd2180bfd06f5a5daadbbceda8e1296b6da30 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:35:35 +0000 Subject: [PATCH 35/70] docs(migrate-email): test Step 8 on a site that passes distinctId Step 7 now leaves distinctId off an address check before the account exists, so Step 8 picks its test site from the plan rows that pass one. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 2 +- context/skills/migrate-email/references/8-verify.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 795cf7031..08484a90d 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -57,7 +57,7 @@ PostHog records each send, and its sent, opened and clicked events when engageme - Find the app's identify call, such as `posthog.identify(user.id)` in posthog-js, or the `distinctId` of its `posthog-node` captures. - At each site, pass the same ID for the recipient, such as `distinctId: user.id`. Follow the recipient back through the callers when the site only has the address. - Without `distinctId`, PostHog records the email against a person whose distinct ID is the recipient's address. Unless the app identifies people by their address, that is a separate person from the user. -- When the recipient isn't a user yet, such as an invite or a check during signup, isn't a user at all, such as a team inbox, or the site has no way to know the user, leave `distinctId` out and note it in the plan row. +- When the recipient isn't a user yet, such as an invite or an address check before the account exists, isn't a user at all, such as a team inbox, or the site has no way to know the user, leave `distinctId` out and note it in the plan row. - When the app identifies no one in PostHog, use the app's own user ID, and note it for the report. ## Rewrite each site diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index c0efde366..75f522ee6 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -28,7 +28,7 @@ Skip this part and record `not checked` with the reason when the API is not conf 1. Check that the app sends to the MCP's project: compare the project token the app reads with `api_token` from the PostHog MCP `projects-get` tool. Read only the token's line of the env file, by searching for the token variable's name: the file also holds secret keys, so never open all of it. When they differ, record `not checked: the app uses another project`, tell the person which project the app uses, and skip the rest of this part. 2. Ask the person whether to send one test email. Say that it sends a real email. When they say no, record `not checked: declined`, and skip the rest of this part. -3. Run `SELECT toUnixTimestamp(now()), ''` through the PostHog MCP `execute-sql` tool, so the answer can't come from a cached run, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app that sends it to an address they own, from a site that passes `distinctId`, such as a signup or a password reset. When no moved site passes `distinctId`, record `not checked: no moved site names a person`, and skip the rest of this part. Ask them to open the email, then to sign in as the user it went to and use the app for a moment, so that the app's product events show on the same distinct ID. Ask them to tell you when they are done. +3. Run `SELECT toUnixTimestamp(now()), ''` through the PostHog MCP `execute-sql` tool, so the answer can't come from a cached run, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app that sends it to an address they own, from a site whose plan row shows it passes `distinctId`, such as a password reset or a welcome email after signup. When no moved site passes `distinctId`, record `not checked: no moved site names a person`, and skip the rest of this part. Ask them to open the email, then to sign in as the user it went to and use the app for a moment, so that the app's product events show on the same distinct ID. Ask them to tell you when they are done. 4. When the send fails, find its code in `transactional-emails.md` or `api.md`, tell the person the fix, and record it. Never retry a send yourself. 5. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID since the start of the test, with a new random string each time you run it: From 4fc8d4157732e95db26d6a735bb815cbcacab394 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Wed, 4 Nov 2026 08:24:06 +0000 Subject: [PATCH 36/70] docs(migrate-email): say why cc, bcc and attachments stay on Resend The rows said only "Always", so an agent made up a reason, such as posthog-node not taking attachments. They now say this skill doesn't move them yet. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/mapping.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index dbf94e6a5..963c60203 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -13,11 +13,11 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `text` | `text` | Never | | `react` | `html`, rendered in the app | Never. The app renders the component | | `template` | a template made in PostHog, sent by its `templateId` with `templateData` | The person keeps it on Resend for now, its content can't be read, it uses syntax beyond variables and fallbacks, the app fills a variable with HTML, or the site sets `from`, `replyTo`, or `subject` next to it | -| `cc`, `bcc` | none | Always | +| `cc`, `bcc` | none | Always. This skill doesn't move them yet, so keep the site on Resend | | `replyTo` / `reply_to` | `replyTo`, one address or a list | An entry carries a name, such as `Jane `, there are more than 10, or the code builds the value at run time and you cannot tell that it holds bare addresses only | | `headers` | none | Always | | `tags` | none | Always | -| `attachments` | none | Always | +| `attachments` | none | Always. This skill doesn't move them yet, so keep the site on Resend | | `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | The key can hold anything but visible ASCII characters, such as a space, or be longer than 255 characters. PostHog takes 1 to 255 visible ASCII characters. Otherwise the key keeps its value, and PostHog keeps it for 24 hours as Resend does. The two providers don't share keys: a retry that runs after the deploy, of a send Resend already took, sends a second email. Note it in the report | | `scheduledAt` / `scheduled_at` | none | Always | | `topicId` / `topic_id` | none | Always | From 96646597bcb64d9c4df7bcc9da09dc9914799548 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Wed, 4 Nov 2026 08:25:30 +0000 Subject: [PATCH 37/70] docs(migrate-email): name the real reason a field stays on Resend Step 9's report tells the person what would let a site move, from the row's reason. cc, bcc, attachments, headers and tags now say PostHog's send doesn't take them yet, not that this skill doesn't move them. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/mapping.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 963c60203..fcd95389b 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -13,11 +13,11 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `text` | `text` | Never | | `react` | `html`, rendered in the app | Never. The app renders the component | | `template` | a template made in PostHog, sent by its `templateId` with `templateData` | The person keeps it on Resend for now, its content can't be read, it uses syntax beyond variables and fallbacks, the app fills a variable with HTML, or the site sets `from`, `replyTo`, or `subject` next to it | -| `cc`, `bcc` | none | Always. This skill doesn't move them yet, so keep the site on Resend | +| `cc`, `bcc` | none | Always. PostHog's send doesn't take it yet | | `replyTo` / `reply_to` | `replyTo`, one address or a list | An entry carries a name, such as `Jane `, there are more than 10, or the code builds the value at run time and you cannot tell that it holds bare addresses only | -| `headers` | none | Always | -| `tags` | none | Always | -| `attachments` | none | Always. This skill doesn't move them yet, so keep the site on Resend | +| `headers` | none | Always. PostHog's send doesn't take it yet | +| `tags` | none | Always. PostHog's send doesn't take it yet | +| `attachments` | none | Always. PostHog's send doesn't take it yet | | `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | The key can hold anything but visible ASCII characters, such as a space, or be longer than 255 characters. PostHog takes 1 to 255 visible ASCII characters. Otherwise the key keeps its value, and PostHog keeps it for 24 hours as Resend does. The two providers don't share keys: a retry that runs after the deploy, of a send Resend already took, sends a second email. Note it in the report | | `scheduledAt` / `scheduled_at` | none | Always | | `topicId` / `topic_id` | none | Always | From 4e5a6728cb5ad9208c0fa609fa306e3679aa89cb Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Wed, 4 Nov 2026 08:26:35 +0000 Subject: [PATCH 38/70] docs(migrate-email): give scheduled sends and topics a reason too Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/mapping.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index fcd95389b..98c856aaf 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -19,8 +19,8 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `tags` | none | Always. PostHog's send doesn't take it yet | | `attachments` | none | Always. PostHog's send doesn't take it yet | | `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | The key can hold anything but visible ASCII characters, such as a space, or be longer than 255 characters. PostHog takes 1 to 255 visible ASCII characters. Otherwise the key keeps its value, and PostHog keeps it for 24 hours as Resend does. The two providers don't share keys: a retry that runs after the deploy, of a send Resend already took, sends a second email. Note it in the report | -| `scheduledAt` / `scheduled_at` | none | Always | -| `topicId` / `topic_id` | none | Always | +| `scheduledAt` / `scheduled_at` | none | Always. PostHog's send doesn't take it yet | +| `topicId` / `topic_id` | none | Always. PostHog's send doesn't take it yet | ## Calls From 8d88206613708da974fa19a267f8c10b151292ec Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Wed, 4 Nov 2026 08:48:20 +0000 Subject: [PATCH 39/70] fix(migrate-email): keep a site on Resend when its key length is unbounded A key built from a URL or caller text could read as either "can be longer than 255 characters" or not. Such a key now counts as one that can, so the site stays on Resend and the report names the value to bound. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/mapping.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 98c856aaf..82c8aa421 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -18,7 +18,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `headers` | none | Always. PostHog's send doesn't take it yet | | `tags` | none | Always. PostHog's send doesn't take it yet | | `attachments` | none | Always. PostHog's send doesn't take it yet | -| `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | The key can hold anything but visible ASCII characters, such as a space, or be longer than 255 characters. PostHog takes 1 to 255 visible ASCII characters. Otherwise the key keeps its value, and PostHog keeps it for 24 hours as Resend does. The two providers don't share keys: a retry that runs after the deploy, of a send Resend already took, sends a second email. Note it in the report | +| `idempotencyKey` / `Idempotency-Key` | `idempotencyKey` / `Idempotency-Key` | The key can hold anything but visible ASCII characters, such as a space, or be longer than 255 characters. PostHog takes 1 to 255 visible ASCII characters. A key built from a value whose length or characters the code doesn't bound, such as a URL or text from a caller, counts as one that can. The report names that value, so the person can bound the key, such as by hashing that part, and move the site. Otherwise the key keeps its value, and PostHog keeps it for 24 hours as Resend does. The two providers don't share keys: a retry that runs after the deploy, of a send Resend already took, sends a second email. Note it in the report | | `scheduledAt` / `scheduled_at` | none | Always. PostHog's send doesn't take it yet | | `topicId` / `topic_id` | none | Always. PostHog's send doesn't take it yet | From 5863a997198f52c9f98df1209e7b49383e404ce9 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Wed, 4 Nov 2026 09:45:28 +0000 Subject: [PATCH 40/70] fix(migrate-email): quote Resend fallbacks with single quotes only A double-quoted Liquid fallback inside the template's JSON body raises TokenizationError. Every fallback is quoted with ', and a fallback that holds a ' keeps the site on Resend, since Liquid has no escape character. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/mapping.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 82c8aa421..7067e4ff7 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -45,10 +45,10 @@ This file decides, field by field, whether PostHog can send a Resend call site. - `html`, `text`, and `react` content is rendered for one recipient before the send. PostHog sends it as it is. - A `template` site moves only to a template made in PostHog. This skill never makes one: the person makes it from the Resend template, makes it transactional, and gives you its template ID. Until then the site stays on Resend. - The check needs the template's content, because the code has only its id. `account.md` says how to get it. -- In the PostHog template, `{{{NAME}}}` becomes `{{ variables.NAME }}`, and the name keeps its case. `{{{NAME|there}}}` becomes `{{ variables.NAME | default: 'there' }}`, and a variable with a `fallback_value` in the template's definition gets the same `default`. Quote a fallback that holds a `'` with `"` instead. Liquid has no escape character in a quoted value. +- In the PostHog template, `{{{NAME}}}` becomes `{{ variables.NAME }}`, and the name keeps its case. `{{{NAME|there}}}` becomes `{{ variables.NAME | default: 'there' }}`, and a variable with a `fallback_value` in the template's definition gets the same `default`. Quote every fallback with `'`: a `"` inside the template's JSON body raises `TokenizationError`. Liquid has no escape character in a quoted value, so a fallback that holds a `'` keeps the site on Resend. - Liquid's `default` also replaces an empty string, which Resend inserts as it is. When the code can pass an empty string for a variable with a fallback, the email shows the fallback instead. Note it in the report. - Resend inserts a variable's value as it is. PostHog's Liquid escapes HTML in a value, so `` shows as text. A variable is HTML when the code fills it with markup or with a renderer's output, and such a variable keeps the site on Resend. A variable the app fills with plain values, such as names, numbers, and URLs, renders the same. -- A template that holds anything other than `{{{VAR}}}` and `{{{VAR|fallback}}}` placeholders, such as a section, a loop, or a condition, stays on Resend. So does a fallback that holds both `'` and `"`, and a fallback that holds HTML, such as a link: Liquid escapes the fallback too, so the markup shows as text. +- A template that holds anything other than `{{{VAR}}}` and `{{{VAR|fallback}}}` placeholders, such as a section, a loop, or a condition, stays on Resend. So does a fallback that holds a `'`, and a fallback that holds HTML, such as a link: Liquid escapes the fallback too, so the markup shows as text. - The PostHog template carries its own sender, reply-to address, and subject. A site that sets `from`, `replyTo`, or `subject` next to `template` stays on Resend. ## Rewrite From eed16c6772e4db80fad3c0fbb34190e894955439 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:17:13 +0000 Subject: [PATCH 41/70] fix(migrate-email): record the PostHog key as set only after a check finds it Step 6 ticked the key phase as set when the person said they would add the key themselves. The step now checks the env file with a count-only grep (or a successful set_env_values in the Wizard). A promise to add it later, or a refusal, records the key as not set, and the report lists it before cutover. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/6-key.md | 8 +++++++- context/skills/migrate-email/references/9-report.md | 2 +- scripts/lib/tests/migrate-email-skill.test.js | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/6-key.md b/context/skills/migrate-email/references/6-key.md index 0c39a80d5..f0f9947ad 100644 --- a/context/skills/migrate-email/references/6-key.md +++ b/context/skills/migrate-email/references/6-key.md @@ -21,6 +21,12 @@ PostHog's send needs a project secret API key on the server. The provider's key - Add the variable name, without a value, to the project's env example file when it has one. - Never hardcode the key, never commit it, and never ask the person to paste it into the chat. +## Check that the key is set + +The key is set only when the env file holds it. Inside the Wizard, it is set once `set_env_values` succeeds. Otherwise, once the person says they added it, check the file with a command that prints a count and never the key, such as `grep -cE '^(export +)?POSTHOG_PROJECT_SECRET_API_KEY=.?phs_' .env`. A count of `0` means the key is not set. + +A person who says they will add the key later has not set it, and neither has one who declines. Don't wait for them: record the key as not set, and go on. + ## Every other place the provider key lives The provider's `sdk-reference.md` names its key's environment variable. Search the whole repository for that name, including CI workflows, deploy and hosting config, Docker and compose files, env example files, and docs. Skip `node_modules` and build output. @@ -29,4 +35,4 @@ List each place with its file and line. Each one needs `POSTHOG_PROJECT_SECRET_A ## Write down -Tick the phase in the plan file: `- [x] key — POSTHOG_PROJECT_SECRET_API_KEY set in `, or `- [ ] key — not set: `. Under the phase list, add the places of the provider key. +Tick the phase in the plan file only when the check above found the key: `- [x] key — POSTHOG_PROJECT_SECRET_API_KEY set in `. Otherwise write `- [ ] key — not set: `, such as `the person adds it to .env`. Under the phase list, add the places of the provider key. diff --git a/context/skills/migrate-email/references/9-report.md b/context/skills/migrate-email/references/9-report.md index 4562e9f1a..51023397c 100644 --- a/context/skills/migrate-email/references/9-report.md +++ b/context/skills/migrate-email/references/9-report.md @@ -59,7 +59,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- The moved sites send through PostHog as soon as this code is deployed. Everything in this list has to be done before that deploy. - + ## After cutover diff --git a/scripts/lib/tests/migrate-email-skill.test.js b/scripts/lib/tests/migrate-email-skill.test.js index ff7b5bf48..06b875cbb 100644 --- a/scripts/lib/tests/migrate-email-skill.test.js +++ b/scripts/lib/tests/migrate-email-skill.test.js @@ -109,6 +109,14 @@ describe('migrate-email skill', () => { ]); }); + it('ticks the key phase only after a check finds the key, never on a promise to add it', () => { + const keyStep = readFileSync(join(CONFIG_DIR, 'skills', 'migrate-email', 'references', '6-key.md'), 'utf8'); + + expect(keyStep).toMatch(/grep -cE '\^\(export \+\)\?POSTHOG_PROJECT_SECRET_API_KEY=\.\?phs_'/); + expect(keyStep).toMatch(/A person who says they will add the key later has not set it/); + expect(keyStep).toMatch(/`- \[ \] key — not set: `/); + }); + it('publishes Resend and Statsig as wizard migrate subcommands', async () => { const { skills } = await loadSkills(); const cliOf = (id) => skills.find((skill) => skill.id === id)?._cli; From 2d919365bdd9806dc4009e5b17894aaaf0ec6cb3 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:19:24 +0000 Subject: [PATCH 42/70] fix(migrate-email): accept spaces around = in the key check dotenv loads a key with leading whitespace or spaces around =, so the count-only grep accepts them too. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/6-key.md | 2 +- scripts/lib/tests/migrate-email-skill.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/6-key.md b/context/skills/migrate-email/references/6-key.md index f0f9947ad..ddc0c9c00 100644 --- a/context/skills/migrate-email/references/6-key.md +++ b/context/skills/migrate-email/references/6-key.md @@ -23,7 +23,7 @@ PostHog's send needs a project secret API key on the server. The provider's key ## Check that the key is set -The key is set only when the env file holds it. Inside the Wizard, it is set once `set_env_values` succeeds. Otherwise, once the person says they added it, check the file with a command that prints a count and never the key, such as `grep -cE '^(export +)?POSTHOG_PROJECT_SECRET_API_KEY=.?phs_' .env`. A count of `0` means the key is not set. +The key is set only when the env file holds it. Inside the Wizard, it is set once `set_env_values` succeeds. Otherwise, once the person says they added it, check the file with a command that prints a count and never the key, such as `grep -cE '^\s*(export\s+)?POSTHOG_PROJECT_SECRET_API_KEY\s*=\s*.?phs_' .env`. A count of `0` means the key is not set. A person who says they will add the key later has not set it, and neither has one who declines. Don't wait for them: record the key as not set, and go on. diff --git a/scripts/lib/tests/migrate-email-skill.test.js b/scripts/lib/tests/migrate-email-skill.test.js index 06b875cbb..b9f9d847b 100644 --- a/scripts/lib/tests/migrate-email-skill.test.js +++ b/scripts/lib/tests/migrate-email-skill.test.js @@ -112,7 +112,7 @@ describe('migrate-email skill', () => { it('ticks the key phase only after a check finds the key, never on a promise to add it', () => { const keyStep = readFileSync(join(CONFIG_DIR, 'skills', 'migrate-email', 'references', '6-key.md'), 'utf8'); - expect(keyStep).toMatch(/grep -cE '\^\(export \+\)\?POSTHOG_PROJECT_SECRET_API_KEY=\.\?phs_'/); + expect(keyStep).toContain("grep -cE '^\\s*(export\\s+)?POSTHOG_PROJECT_SECRET_API_KEY\\s*=\\s*.?phs_'"); expect(keyStep).toMatch(/A person who says they will add the key later has not set it/); expect(keyStep).toMatch(/`- \[ \] key — not set: `/); }); From 074130e5f77fbdbd14ee680154263ce2d2bca152 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:41:14 +0000 Subject: [PATCH 43/70] fix(migrate-email): check the last assignment of the PostHog key The count-only grep counted a key that an env loader reads as empty: a value that is only a comment (= #phs_x), and a key overridden by a later empty line. The check now reads only the last line that sets the variable and needs its value to start with phs_, still printing only a count. The test runs the documented command against fixture env files in place of matching its wording. Co-Authored-By: Claude Opus 5.5 --- .../skills/migrate-email/references/6-key.md | 8 +++- scripts/lib/tests/migrate-email-skill.test.js | 47 +++++++++++++++++-- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/context/skills/migrate-email/references/6-key.md b/context/skills/migrate-email/references/6-key.md index ddc0c9c00..5834ae278 100644 --- a/context/skills/migrate-email/references/6-key.md +++ b/context/skills/migrate-email/references/6-key.md @@ -23,7 +23,13 @@ PostHog's send needs a project secret API key on the server. The provider's key ## Check that the key is set -The key is set only when the env file holds it. Inside the Wizard, it is set once `set_env_values` succeeds. Otherwise, once the person says they added it, check the file with a command that prints a count and never the key, such as `grep -cE '^\s*(export\s+)?POSTHOG_PROJECT_SECRET_API_KEY\s*=\s*.?phs_' .env`. A count of `0` means the key is not set. +The key is set only when the env file holds it. Inside the Wizard, it is set once `set_env_values` succeeds. Otherwise, once the person says they added it, check the file with a command that prints a count and never the key. It reads the last line that sets the variable, as the app's env loader does, and checks that the value starts with `phs_`: + +```bash +grep -E '^[[:space:]]*(export[[:space:]]+)?POSTHOG_PROJECT_SECRET_API_KEY[[:space:]]*=' .env | tail -n 1 | grep -cE '^[^=]*=[[:space:]]*[^#[:space:]]?phs_' +``` + +Use the env file the key went into in place of `.env`. A count of `0` means the key is not set. A person who says they will add the key later has not set it, and neither has one who declines. Don't wait for them: record the key as not set, and go on. diff --git a/scripts/lib/tests/migrate-email-skill.test.js b/scripts/lib/tests/migrate-email-skill.test.js index b9f9d847b..11dec9ab9 100644 --- a/scripts/lib/tests/migrate-email-skill.test.js +++ b/scripts/lib/tests/migrate-email-skill.test.js @@ -1,5 +1,6 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; -import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync } from 'fs'; +import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs'; +import { spawnSync } from 'child_process'; import { join, relative } from 'path'; import { tmpdir } from 'os'; @@ -109,12 +110,48 @@ describe('migrate-email skill', () => { ]); }); - it('ticks the key phase only after a check finds the key, never on a promise to add it', () => { + describe('the key check in step 6', () => { const keyStep = readFileSync(join(CONFIG_DIR, 'skills', 'migrate-email', 'references', '6-key.md'), 'utf8'); + const command = keyStep.match(/```bash\n(grep .+)\n```/)?.[1]; + let envDir; + + afterEach(() => { + if (envDir) rmSync(envDir, { recursive: true, force: true }); + envDir = undefined; + }); + + function check(envFile) { + envDir = mkdtempSync(join(tmpdir(), 'migrate-key-')); + writeFileSync(join(envDir, '.env'), envFile); + return spawnSync('bash', ['-c', command], { cwd: envDir, encoding: 'utf8' }); + } - expect(keyStep).toContain("grep -cE '^\\s*(export\\s+)?POSTHOG_PROJECT_SECRET_API_KEY\\s*=\\s*.?phs_'"); - expect(keyStep).toMatch(/A person who says they will add the key later has not set it/); - expect(keyStep).toMatch(/`- \[ \] key — not set: `/); + it.each([ + ['a plain key', 'POSTHOG_PROJECT_SECRET_API_KEY=phs_abc\n', '1'], + ['an exported, spaced and double-quoted key', ' export POSTHOG_PROJECT_SECRET_API_KEY = "phs_abc"\n', '1'], + ['a single-quoted key', "POSTHOG_PROJECT_SECRET_API_KEY='phs_abc'\n", '1'], + ['a key after an empty line for it', 'POSTHOG_PROJECT_SECRET_API_KEY=\nPOSTHOG_PROJECT_SECRET_API_KEY=phs_abc\n', '1'], + ['no line for the key', 'RESEND_API_KEY=re_abc\n', '0'], + ['an empty key', 'POSTHOG_PROJECT_SECRET_API_KEY=\n', '0'], + ['an empty quoted key', 'POSTHOG_PROJECT_SECRET_API_KEY=""\n', '0'], + ['a commented-out line', '# POSTHOG_PROJECT_SECRET_API_KEY=phs_abc\n', '0'], + ['a value that is only a comment', 'POSTHOG_PROJECT_SECRET_API_KEY= #phs_abc\n', '0'], + ['a key overridden by a later empty line', 'POSTHOG_PROJECT_SECRET_API_KEY=phs_abc\nPOSTHOG_PROJECT_SECRET_API_KEY=\n', '0'], + ['another variable ending in the name', 'OTHER_POSTHOG_PROJECT_SECRET_API_KEY=phs_abc\n', '0'], + ])('finds the key in %s only when it is set, and never prints it', (_name, envFile, count) => { + const result = check(envFile); + + expect(result.stdout.trim()).toBe(count); + expect(result.stdout).not.toContain('phs_'); + expect(result.stderr).toBe(''); + }); + + it('ticks the phase only when the check found the key', () => { + expect(command).toBeDefined(); + expect(keyStep).toMatch(/A person who says they will add the key later has not set it/); + expect(keyStep).toMatch(/Tick the phase in the plan file only when the check above found the key/); + expect(keyStep).toMatch(/`- \[ \] key — not set: `/); + }); }); it('publishes Resend and Statsig as wizard migrate subcommands', async () => { From 5c9224593d631e1dc7e138c18f2977881c9a9ec1 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 5 Nov 2026 07:44:49 +0000 Subject: [PATCH 44/70] docs(migrate-email): ask for the transactional_email:write scope Code sends now need transactional_email:write. A key with hog_flow:write keeps working through the legacy scope fallback. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/6-key.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/6-key.md b/context/skills/migrate-email/references/6-key.md index 0b4a08208..c49eed2e7 100644 --- a/context/skills/migrate-email/references/6-key.md +++ b/context/skills/migrate-email/references/6-key.md @@ -15,7 +15,7 @@ PostHog's send needs a project secret API key on the server. The provider's key ## The PostHog key -- Ask the person to create a project secret API key (it starts with `phs_`) with the `hog_flow:write` scope in their PostHog project settings. +- Ask the person to create a project secret API key (it starts with `phs_`) with the `transactional_email:write` scope in their PostHog project settings. A key that already has `hog_flow:write` works too. - The key goes into `POSTHOG_PROJECT_SECRET_API_KEY`, in the env file the app loads its provider key from, such as `.env` or `.env.local`. Check that git ignores that file. When it doesn't, ask the person where the key goes. - Ask the person to add the key to that file themselves. Inside the Wizard, ask for it and store it as the "Inside the PostHog Wizard" section of `SKILL.md` says. - Add the variable name, without a value, to the project's env example file when it has one. From 254dbb9fba905fbb690253eb42f1941d0d8dab8b Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 5 Nov 2026 08:09:32 +0000 Subject: [PATCH 45/70] fix(migrate-email): name the transactional email scope in the preflight The make-transactional tools move to transactional_email:write, and a login with hog_flow:write still works. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/2-preflight.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/2-preflight.md b/context/skills/migrate-email/references/2-preflight.md index a643d9be2..e6ee87ee5 100644 --- a/context/skills/migrate-email/references/2-preflight.md +++ b/context/skills/migrate-email/references/2-preflight.md @@ -19,7 +19,7 @@ Check which PostHog MCP tools exist. - When there are no PostHog tools at all, the PostHog MCP is not connected or not signed in. Ask the person to connect it, and wait. - When `workflows-make-email-template-transactional-prepare` and `workflows-make-email-template-transactional-execute` exist, the API is on. Record `api: on`. -- When other PostHog tools exist but that pair doesn't, either the login lacks the `hog_flow:write` scope, or transactional email is not on for the project yet. A missing tool cannot tell these apart. Tell the person both causes, record `api: not confirmed`, and continue. The report asks them to confirm it before cutover. +- When other PostHog tools exist but that pair doesn't, either the login lacks the `transactional_email:write` scope (a login with `hog_flow:write` works too), or transactional email is not on for the project yet. A missing tool cannot tell these apart. Tell the person both causes, record `api: not confirmed`, and continue. The report asks them to confirm it before cutover. Do not call a tool that changes anything to find out. From 4ce6c2d8471841c65800b91201b838ac975e0567 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:31:10 +0000 Subject: [PATCH 46/70] docs(migrate-email): record engagement events only when engagement capture is on Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 08484a90d..4744baafd 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -52,7 +52,7 @@ export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { ## Link emails to your users -PostHog records each send, and its sent, opened and clicked events when engagement events are on, against the person the send names with `distinctId`. Pass the ID the app already passes to `identify()`: +PostHog records each send, and its sent, opened and clicked events when engagement capture is on, against the person the send names with `distinctId`. Pass the ID the app already passes to `identify()`: - Find the app's identify call, such as `posthog.identify(user.id)` in posthog-js, or the `distinctId` of its `posthog-node` captures. - At each site, pass the same ID for the recipient, such as `distinctId: user.id`. Follow the recipient back through the callers when the site only has the address. From 0192a3d0f657c137bbbdcf9884ce8923ffa3a2bb Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 07:16:03 +0000 Subject: [PATCH 47/70] fix(migrate-email): keep an app's PostHog key, and a Resend HTTP call's deadline A reused posthog-node client that already sets secretKey or personalApiKey keeps it, and the sends get their own client: posthog-node uses secretKey for local flag evaluation and remote config too, and prefers it over personalApiKey, so the email key would replace the app's key. A Resend HTTP call with its own timeout keeps it through emailRequestTimeoutMs, with maxRetries: 0 on the send, so a send never runs past the site's deadline. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 2 +- context/skills/migrate-email/references/resend/mapping.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 4744baafd..2578abee4 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -44,7 +44,7 @@ export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { ``` - When the client options take `migratedFrom`, set it to the value that the provider's `mapping.md` names under "The PostHog client". posthog-node sends it with every email request, so PostHog knows that the sends moved from that provider. -- Reuse the app's existing `posthog-node` client when it has one, and add `secretKey`, and `migratedFrom` when the client options take it. Keep `enableLocalEvaluation: false` unless the key also has `feature_flag:read` and the app uses local evaluation. +- Reuse the app's existing `posthog-node` client when it sets neither `secretKey` nor `personalApiKey`: add `secretKey`, `enableLocalEvaluation: false`, and `migratedFrom` when the client options take it. A client that sets either key keeps it as it is: posthog-node also uses `secretKey` for local flag evaluation and remote config, and prefers it over `personalApiKey`, so the email key would replace the app's key. The sends get their own client instead, as above, and the plan notes it. - When the project token or the host is not configured yet, get the token from the PostHog MCP `projects-get` tool (`api_token`). The host is `https://us.i.posthog.com` for US Cloud and `https://eu.i.posthog.com` for EU Cloud. Ask the person which one when you can't tell. - When `host` is a reverse proxy or a self-hosted instance, also set `appHost` to the PostHog app URL, such as `https://us.posthog.com`. posthog-node never sends the secret key to a proxy, and without `appHost` the send fails with `missing_app_host`. - Put a new client in its own server-only module, next to the provider's client, and import it where the sites send. diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 7067e4ff7..c6ec57b7f 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -68,7 +68,7 @@ How a site that moves is written with `posthog-node`. Step 7 says when to use ea **React.** `react: ` becomes `html: await render()`, with `import { render } from '@react-email/render'`. Keep a `text` the site already passes. -**HTTP.** A `fetch` or `axios` call to `https://api.resend.com/emails` becomes `posthog.emails.send` with the camelCase fields: `reply_to` becomes `replyTo`, and the `Idempotency-Key` header becomes `idempotencyKey`. Code that read the response status reads `error` instead. +**HTTP.** A `fetch` or `axios` call to `https://api.resend.com/emails` becomes `posthog.emails.send` with the camelCase fields: `reply_to` becomes `replyTo`, and the `Idempotency-Key` header becomes `idempotencyKey`. Code that read the response status reads `error` instead. A request with its own deadline, such as `signal: AbortSignal.timeout(5000)` or axios `timeout: 5000`, keeps it: set `emailRequestTimeoutMs` to that value on the client the sends use, and pass `maxRetries: 0` on the send, since the request never retried. posthog-node otherwise waits up to 15 seconds and retries twice, which can run past the site's deadline. When sites use different deadlines, set the shortest, and note the sites whose deadline it shortens. **Templates made in PostHog.** The site sends `templateId` with the template ID the person gave, and `templateData` with the site's `variables` object. It sends no `templateKey`, `subject`, `html`, `text`, `from`, or `replyTo`: the template holds them. From 5c996dee46206e2110f606a9f142250c4b054ea1 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 07:19:10 +0000 Subject: [PATCH 48/70] fix(migrate-email): keep email off a disabled client, and pass numeric IDs as strings A client that can be disabled answers every send with client_disabled while it is, so a reused analytics client would stop emails where the old provider still sent them: the sends get their own client. distinctId takes a string, so a numeric user ID is passed as String(user.id), the same string posthog-js identifies. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 2578abee4..cbfe39da9 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -44,7 +44,7 @@ export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { ``` - When the client options take `migratedFrom`, set it to the value that the provider's `mapping.md` names under "The PostHog client". posthog-node sends it with every email request, so PostHog knows that the sends moved from that provider. -- Reuse the app's existing `posthog-node` client when it sets neither `secretKey` nor `personalApiKey`: add `secretKey`, `enableLocalEvaluation: false`, and `migratedFrom` when the client options take it. A client that sets either key keeps it as it is: posthog-node also uses `secretKey` for local flag evaluation and remote config, and prefers it over `personalApiKey`, so the email key would replace the app's key. The sends get their own client instead, as above, and the plan notes it. +- Reuse the app's existing `posthog-node` client when it sets neither `secretKey` nor `personalApiKey` and is never disabled: add `secretKey`, `enableLocalEvaluation: false`, and `migratedFrom` when the client options take it. A client that sets either key keeps it as it is: posthog-node also uses `secretKey` for local flag evaluation and remote config, and prefers it over `personalApiKey`, so the email key would replace the app's key. A client that can be disabled, such as `disabled: process.env.NODE_ENV !== 'production'`, answers every send with `client_disabled` while it is, so emails would stop where the old provider still sent them. In both cases the sends get their own client instead, as above, and the plan notes it. - When the project token or the host is not configured yet, get the token from the PostHog MCP `projects-get` tool (`api_token`). The host is `https://us.i.posthog.com` for US Cloud and `https://eu.i.posthog.com` for EU Cloud. Ask the person which one when you can't tell. - When `host` is a reverse proxy or a self-hosted instance, also set `appHost` to the PostHog app URL, such as `https://us.posthog.com`. posthog-node never sends the secret key to a proxy, and without `appHost` the send fails with `missing_app_host`. - Put a new client in its own server-only module, next to the provider's client, and import it where the sites send. @@ -55,7 +55,7 @@ export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { PostHog records each send, and its sent, opened and clicked events when engagement capture is on, against the person the send names with `distinctId`. Pass the ID the app already passes to `identify()`: - Find the app's identify call, such as `posthog.identify(user.id)` in posthog-js, or the `distinctId` of its `posthog-node` captures. -- At each site, pass the same ID for the recipient, such as `distinctId: user.id`. Follow the recipient back through the callers when the site only has the address. +- At each site, pass the same ID for the recipient, such as `distinctId: user.id`. `distinctId` takes a string, and posthog-js turns a number into its string, so a numeric ID becomes `distinctId: String(user.id)`. Follow the recipient back through the callers when the site only has the address. - Without `distinctId`, PostHog records the email against a person whose distinct ID is the recipient's address. Unless the app identifies people by their address, that is a separate person from the user. - When the recipient isn't a user yet, such as an invite or an address check before the account exists, isn't a user at all, such as a team inbox, or the site has no way to know the user, leave `distinctId` out and note it in the plan row. - When the app identifies no one in PostHog, use the app's own user ID, and note it for the report. From 487262bc3c73dda2b8b5d01d3ff7977eae0e274e Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 11:02:06 +0000 Subject: [PATCH 49/70] fix(skills): close the migrate-email preparation gaps the QA swarm found - Step 6 ticks the key only when a check finds it in the env file, and the report lists a key that is not set. - Step 3 asks for a template to be made transactional only once a verified sender covers its address, since PostHog refuses it before. - Step 2 and the report name sends with content from the code, which PostHog enables apart from template sends. - The report asks for a last suppression import right before cutover, since the provider keeps adding entries. - A template site that sets `reply_to` stays on Resend, as `replyTo` does. - The CLI test reads the entries the Wizard gets from the menu. Co-Authored-By: Claude Opus 5.5 --- .../migrate-email/references/2-preflight.md | 2 + .../migrate-email/references/3-inventory.md | 2 +- .../references/5-suppressions.md | 1 + .../skills/migrate-email/references/6-key.md | 14 ++- .../migrate-email/references/7-report.md | 2 +- .../references/resend/mapping.md | 4 +- scripts/lib/tests/migrate-email-skill.test.js | 87 +++++++++++++++++-- 7 files changed, 101 insertions(+), 11 deletions(-) diff --git a/context/skills/migrate-email/references/2-preflight.md b/context/skills/migrate-email/references/2-preflight.md index e6ee87ee5..129d17bae 100644 --- a/context/skills/migrate-email/references/2-preflight.md +++ b/context/skills/migrate-email/references/2-preflight.md @@ -23,6 +23,8 @@ Check which PostHog MCP tools exist. Do not call a tool that changes anything to find out. +Those tools confirm sends by template. PostHog enables sends with content from the code separately, and no tool shows it. The report asks the person to confirm it before cutover when a site that moves sends its content from the code. + ## The sending tier PostHog gives each project a sending allowance: how many emails it sends per hour and per day. A new project starts on a low tier, and the tier grows with low bounce and complaint rates. Emails above the allowance are not dropped, they are sent later. So a cutover with more mail than the tier allows delays email, such as password resets. diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index 8ad9ba5ec..a39070527 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -47,7 +47,7 @@ When the code passes a value you can't read, such as a list of recipients built A `template` site moves only to a template made in PostHog, and the person makes that template. Check the site's other fields first: a site that another field keeps on the provider stays with that reason, and needs no question about its template. Ask the person once, for every other template the sites send, whether to move it to PostHog or keep it on the provider for now. A template they keep stays, and the reason is `kept on for now`. For each template they move, ask them to copy it from the provider's dashboard into a file outside the repository, and to tell you where they saved it. Read those files to classify the site, and never write the content into the plan. When the person can't give the content, the site stays, and the reason is `template content not checked`. -A template whose content passes the checks moves only once the person has made it in PostHog. Ask them once, for every such template, to make it in PostHog from the provider's template, make it transactional, and give you its template ID and the address it sends from, usually the provider template's sender. Tell them how its placeholders change, as `mapping.md` says under "Content". Record each template ID with its site under the sites table, and write the address in the site's `from` column, so Step 4 sets up a sender for its domain. A template without an ID stays, and the reason is `PostHog template not made yet`. +A template whose content passes the checks moves only once the person has made it in PostHog. Ask them once, for every such template, to make it in PostHog from the provider's template and give you its template ID and the address it sends from, usually the provider template's sender. PostHog makes a template transactional only once a verified sender covers its address: ask them to make it transactional now when the project has one, and otherwise once Step 4 verifies the sender. The report lists it before cutover either way. Tell them how its placeholders change, as `mapping.md` says under "Content". Record each template ID with its site under the sites table, and write the address in the site's `from` column, so Step 4 sets up a sender for its domain. A template without an ID stays, and the reason is `PostHog template not made yet`. ## Write the plan file diff --git a/context/skills/migrate-email/references/5-suppressions.md b/context/skills/migrate-email/references/5-suppressions.md index 916a21439..eb723bf2a 100644 --- a/context/skills/migrate-email/references/5-suppressions.md +++ b/context/skills/migrate-email/references/5-suppressions.md @@ -31,6 +31,7 @@ Read the provider's `account.md`. It says how to export the list, which entries - Send the entries to `email-suppressions-add` in batches of the size its schema allows. Give each entry the source and the reason `account.md` names. - Repeating an import is safe: an address already on the list stays on it. +- The provider keeps adding to its list while it sends, so the report asks the person for one last import right before cutover. - Never print the addresses, and never write them into the plan or the report. Count them. - When a call fails, read its error and fix the call. When it fails again, stop the import and record how many entries you imported. diff --git a/context/skills/migrate-email/references/6-key.md b/context/skills/migrate-email/references/6-key.md index c49eed2e7..6d5a59f28 100644 --- a/context/skills/migrate-email/references/6-key.md +++ b/context/skills/migrate-email/references/6-key.md @@ -21,6 +21,18 @@ PostHog's send needs a project secret API key on the server. The provider's key - Add the variable name, without a value, to the project's env example file when it has one. - Never hardcode the key, never commit it, and never ask the person to paste it into the chat. +## Check that the key is set + +The key is set only when the env file holds it. Inside the Wizard, it is set once `set_env_values` succeeds. Otherwise, once the person says they added it, check the file with a command that prints a count and never the key. It reads the last line that sets the variable, as the app's env loader does, and checks that the value starts with `phs_`: + +```bash +grep -E '^[[:space:]]*(export[[:space:]]+)?POSTHOG_PROJECT_SECRET_API_KEY[[:space:]]*=' .env | tail -n 1 | grep -cE '^[^=]*=[[:space:]]*[^#[:space:]]?phs_' +``` + +Use the env file the key went into in place of `.env`. A count of `0` means the key is not set. + +A person who says they will add the key later has not set it, and neither has one who declines. Don't wait for them: record the key as not set, and go on. + ## Every other place the provider key lives The provider's `sdk-reference.md` names its key's environment variable. Search the whole repository for that name, including CI workflows, deploy and hosting config, Docker and compose files, env example files, and docs. Skip `node_modules` and build output. @@ -29,4 +41,4 @@ List each place with its file and line. Each one needs `POSTHOG_PROJECT_SECRET_A ## Write down -Tick the phase in the plan file: `- [x] key — POSTHOG_PROJECT_SECRET_API_KEY set in `, or `- [ ] key — not set: `. Under the phase list, add the places of the provider key. +Tick the phase in the plan file only when the check above found the key: `- [x] key — POSTHOG_PROJECT_SECRET_API_KEY set in `. Otherwise write `- [ ] key — not set: `, such as `the person adds it to .env`. Under the phase list, add the places of the provider key. diff --git a/context/skills/migrate-email/references/7-report.md b/context/skills/migrate-email/references/7-report.md index fc974a0c9..6795e92df 100644 --- a/context/skills/migrate-email/references/7-report.md +++ b/context/skills/migrate-email/references/7-report.md @@ -51,7 +51,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ## Before cutover - + ## Summary ``` diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index d72d5ed3a..63b6fe064 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -12,7 +12,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `html` | `html` | Never | | `text` | `text` | Never | | `react` | `html`, rendered in the app | Never. The app renders the component | -| `template` | a template made in PostHog, sent by its `templateId` with `templateData` | The person keeps it on Resend for now, its content can't be read, it uses syntax beyond variables and fallbacks, the app fills a variable with HTML, or the site sets `from`, `replyTo`, or `subject` next to it | +| `template` | a template made in PostHog, sent by its `templateId` with `templateData` | The person keeps it on Resend for now, its content can't be read, it uses syntax beyond variables and fallbacks, the app fills a variable with HTML, or the site sets `from`, `replyTo` / `reply_to`, or `subject` next to it | | `cc`, `bcc` | none | Always | | `replyTo` / `reply_to` | `replyTo` / `reply_to`, as a list | An entry carries a name, such as `Jane `, there are more than 10, or the code builds the value at run time and you cannot tell that it holds bare addresses only. A single address moves as a list of one | | `headers` | none | Always | @@ -49,4 +49,4 @@ This file decides, field by field, whether PostHog can send a Resend call site. - Liquid's `default` also replaces an empty string, which Resend inserts as it is. When the code can pass an empty string for a variable with a fallback, the email shows the fallback instead. Note it in the report. - Resend inserts a variable's value as it is. PostHog's Liquid escapes HTML in a value, so `` shows as text. A variable is HTML when the code fills it with markup or with a renderer's output, and such a variable keeps the site on Resend. A variable the app fills with plain values, such as names, numbers, and URLs, renders the same. - A template that holds anything other than `{{{VAR}}}` and `{{{VAR|fallback}}}` placeholders, such as a section, a loop, or a condition, stays on Resend. So does a fallback that holds both `'` and `"`, and a fallback that holds HTML, such as a link: Liquid escapes the fallback too, so the markup shows as text. -- The PostHog template carries its own sender, reply-to address, and subject. A site that sets `from`, `replyTo`, or `subject` next to `template` stays on Resend. +- The PostHog template carries its own sender, reply-to address, and subject. A site that sets `from`, `replyTo` / `reply_to`, or `subject` next to `template` stays on Resend. diff --git a/scripts/lib/tests/migrate-email-skill.test.js b/scripts/lib/tests/migrate-email-skill.test.js index 67217f510..0d6c353fb 100644 --- a/scripts/lib/tests/migrate-email-skill.test.js +++ b/scripts/lib/tests/migrate-email-skill.test.js @@ -1,7 +1,9 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; -import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync } from 'fs'; +import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs'; +import { spawnSync } from 'child_process'; import { join, relative } from 'path'; import { tmpdir } from 'os'; +import { generateCliEntries } from '../build-phases.js'; const CONFIG_DIR = join(process.cwd(), 'context'); const DOCS_PAGES = { @@ -9,6 +11,7 @@ const DOCS_PAGES = { 'https://posthog.com/docs/workflows/transactional-emails/api.md': '# Send transactional emails with the API\n', }; const REFERENCE_PATH = /references\/[A-Za-z0-9_./-]+\.md/g; +const read = (file) => readFileSync(join(CONFIG_DIR, 'skills', 'migrate-email', 'references', file), 'utf8'); async function loadSkills() { vi.resetModules(); @@ -90,11 +93,83 @@ describe('migrate-email skill', () => { expect(markdownFiles(skillDir).map((file) => readFileSync(file, 'utf8')).join('\n')).not.toMatch(/\{\{>|\{display_name\}|\{references\}/); }); - it('publishes Resend and Statsig as wizard migrate subcommands', async () => { - const { skills } = await loadSkills(); - const cliOf = (id) => skills.find((skill) => skill.id === id)?._cli; + describe('the key check in step 6', () => { + const keyStep = readFileSync(join(CONFIG_DIR, 'skills', 'migrate-email', 'references', '6-key.md'), 'utf8'); + const command = keyStep.match(/```bash\n(grep .+)\n```/)?.[1]; + let envDir; - expect(cliOf('migrate-email-resend')).toEqual({ role: 'command', parentCommand: 'migrate', command: 'resend' }); - expect(cliOf('migrate-statsig')).toEqual({ role: 'command', parentCommand: 'migrate', command: 'statsig' }); + afterEach(() => { + if (envDir) rmSync(envDir, { recursive: true, force: true }); + envDir = undefined; + }); + + function check(envFile) { + envDir = mkdtempSync(join(tmpdir(), 'migrate-key-')); + writeFileSync(join(envDir, '.env'), envFile); + return spawnSync('bash', ['-c', command], { cwd: envDir, encoding: 'utf8' }); + } + + it.each([ + ['a plain key', 'POSTHOG_PROJECT_SECRET_API_KEY=phs_abc\n', '1'], + ['an exported, spaced and double-quoted key', ' export POSTHOG_PROJECT_SECRET_API_KEY = "phs_abc"\n', '1'], + ['a single-quoted key', "POSTHOG_PROJECT_SECRET_API_KEY='phs_abc'\n", '1'], + ['a key after an empty line for it', 'POSTHOG_PROJECT_SECRET_API_KEY=\nPOSTHOG_PROJECT_SECRET_API_KEY=phs_abc\n', '1'], + ['no line for the key', 'RESEND_API_KEY=re_abc\n', '0'], + ['an empty key', 'POSTHOG_PROJECT_SECRET_API_KEY=\n', '0'], + ['an empty quoted key', 'POSTHOG_PROJECT_SECRET_API_KEY=""\n', '0'], + ['a commented-out line', '# POSTHOG_PROJECT_SECRET_API_KEY=phs_abc\n', '0'], + ['a value that is only a comment', 'POSTHOG_PROJECT_SECRET_API_KEY= #phs_abc\n', '0'], + ['a key overridden by a later empty line', 'POSTHOG_PROJECT_SECRET_API_KEY=phs_abc\nPOSTHOG_PROJECT_SECRET_API_KEY=\n', '0'], + ['another variable ending in the name', 'OTHER_POSTHOG_PROJECT_SECRET_API_KEY=phs_abc\n', '0'], + ])('finds the key in %s only when it is set, and never prints it', (_name, envFile, count) => { + expect(command).toBeDefined(); + const result = check(envFile); + + expect(result.stdout.trim()).toBe(count); + expect(result.stdout).not.toContain('phs_'); + expect(result.stderr).toBe(''); + }); + + it('ticks the phase only when the check found the key, and the report asks for a key that is not set', () => { + expect(keyStep).toMatch(/A person who says they will add the key later has not set it/); + expect(keyStep).toMatch(/Tick the phase in the plan file only when the check above found the key/); + expect(keyStep).toMatch(/`- \[ \] key — not set: `/); + expect(read('7-report.md')).toMatch(/`POSTHOG_PROJECT_SECRET_API_KEY` in the env file when the plan says it is not set/); + }); + }); + + describe('what the run cannot finish before cutover', () => { + it('asks for a last suppression import right before cutover, since the provider keeps adding entries', () => { + expect(read('5-suppressions.md')).toMatch(/The provider keeps adding to its list while it sends/); + expect(read('7-report.md')).toMatch(/import the entries the provider added to its suppression list since the export, right before cutover/); + }); + + it('lets a template made in PostHog become transactional only once its sender is verified', () => { + const inventory = read('3-inventory.md'); + + expect(inventory).toMatch(/PostHog makes a template transactional only once a verified sender covers its address/); + expect(inventory).not.toMatch(/make it in PostHog from the provider's template, make it transactional, and give you/); + }); + + it('has the person confirm sends with content from the code, which the template tools do not show', () => { + expect(read('2-preflight.md')).toMatch(/PostHog enables sends with content from the code separately/); + expect(read('7-report.md')).toMatch(/sends with content from the code \(`html`, `text`, or `react`\) when a site that moves has them \(confirm with PostHog/); + }); + }); + + it('keeps a template site on Resend when it sets a reply-to, in either spelling', () => { + const mapping = read('resend/mapping.md'); + + expect(mapping).toMatch(/the site sets `from`, `replyTo` \/ `reply_to`, or `subject` next to it \|/); + expect(mapping).toMatch(/A site that sets `from`, `replyTo` \/ `reply_to`, or `subject` next to `template` stays on Resend/); + }); + + it('publishes Resend and Statsig as wizard migrate subcommands in the menu the Wizard reads', async () => { + const { generator, skills } = await loadSkills(); + const entries = generateCliEntries({ allSkills: skills.map(generator.serializeSkill) }); + const entryOf = (skillId) => entries.find((entry) => entry.skillId === skillId); + + expect(entryOf('migrate-email-resend')).toMatchObject({ role: 'command', parentCommand: 'migrate', command: 'resend' }); + expect(entryOf('migrate-statsig')).toMatchObject({ role: 'command', parentCommand: 'migrate', command: 'statsig' }); }); }); From 00b9aa37ef94c69a09d6ec4b845ebe25d377f498 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 11:36:18 +0000 Subject: [PATCH 50/70] fix(skills): tighten the migrate-email key check and template rules - Step 6's check accepts only a quote before `phs_`, so a placeholder such as `` or a value like `xphs_...` no longer counts as a set key. - `mapping.md` matches Step 3: the person makes a template transactional only once a verified sender covers its address. - A template made in PostHog for an email with a login code or reset link is marked sensitive, and the report checks it before cutover. - Drop the tests that only matched skill sentences; the key check keeps its tests against real env files. Co-Authored-By: Claude Opus 5.5 --- .../migrate-email/references/3-inventory.md | 2 +- .../skills/migrate-email/references/6-key.md | 4 +- .../migrate-email/references/7-report.md | 2 +- .../references/resend/mapping.md | 3 +- scripts/lib/tests/migrate-email-skill.test.js | 37 ++----------------- 5 files changed, 9 insertions(+), 39 deletions(-) diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index a39070527..fdbac1813 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -47,7 +47,7 @@ When the code passes a value you can't read, such as a list of recipients built A `template` site moves only to a template made in PostHog, and the person makes that template. Check the site's other fields first: a site that another field keeps on the provider stays with that reason, and needs no question about its template. Ask the person once, for every other template the sites send, whether to move it to PostHog or keep it on the provider for now. A template they keep stays, and the reason is `kept on for now`. For each template they move, ask them to copy it from the provider's dashboard into a file outside the repository, and to tell you where they saved it. Read those files to classify the site, and never write the content into the plan. When the person can't give the content, the site stays, and the reason is `template content not checked`. -A template whose content passes the checks moves only once the person has made it in PostHog. Ask them once, for every such template, to make it in PostHog from the provider's template and give you its template ID and the address it sends from, usually the provider template's sender. PostHog makes a template transactional only once a verified sender covers its address: ask them to make it transactional now when the project has one, and otherwise once Step 4 verifies the sender. The report lists it before cutover either way. Tell them how its placeholders change, as `mapping.md` says under "Content". Record each template ID with its site under the sites table, and write the address in the site's `from` column, so Step 4 sets up a sender for its domain. A template without an ID stays, and the reason is `PostHog template not made yet`. +A template whose content passes the checks moves only once the person has made it in PostHog. Ask them once, for every such template, to make it in PostHog from the provider's template and give you its template ID and the address it sends from, usually the provider template's sender. PostHog makes a template transactional only once a verified sender covers its address: ask them to make it transactional now when the project has one, and otherwise once Step 4 verifies the sender. When the email carries a login code, a reset link, or another secret, ask them to mark the template sensitive, as `mapping.md` says. The report lists both before cutover either way. Tell them how its placeholders change, as `mapping.md` says under "Content". Record each template ID with its site under the sites table, and write the address in the site's `from` column, so Step 4 sets up a sender for its domain. A template without an ID stays, and the reason is `PostHog template not made yet`. ## Write the plan file diff --git a/context/skills/migrate-email/references/6-key.md b/context/skills/migrate-email/references/6-key.md index 6d5a59f28..2366c5ba0 100644 --- a/context/skills/migrate-email/references/6-key.md +++ b/context/skills/migrate-email/references/6-key.md @@ -23,10 +23,10 @@ PostHog's send needs a project secret API key on the server. The provider's key ## Check that the key is set -The key is set only when the env file holds it. Inside the Wizard, it is set once `set_env_values` succeeds. Otherwise, once the person says they added it, check the file with a command that prints a count and never the key. It reads the last line that sets the variable, as the app's env loader does, and checks that the value starts with `phs_`: +The key is set only when the env file holds it. Inside the Wizard, it is set once `set_env_values` succeeds. Otherwise, once the person says they added it, check the file with a command that prints a count and never the key. It reads the last line that sets the variable, as the app's env loader does, and checks that the value, after an optional quote, starts with `phs_`: ```bash -grep -E '^[[:space:]]*(export[[:space:]]+)?POSTHOG_PROJECT_SECRET_API_KEY[[:space:]]*=' .env | tail -n 1 | grep -cE '^[^=]*=[[:space:]]*[^#[:space:]]?phs_' +grep -E '^[[:space:]]*(export[[:space:]]+)?POSTHOG_PROJECT_SECRET_API_KEY[[:space:]]*=' .env | tail -n 1 | grep -cE "^[^=]*=[[:space:]]*[\"']?phs_" ``` Use the env file the key went into in place of `.env`. A count of `0` means the key is not set. diff --git a/context/skills/migrate-email/references/7-report.md b/context/skills/migrate-email/references/7-report.md index 6795e92df..5745c2496 100644 --- a/context/skills/migrate-email/references/7-report.md +++ b/context/skills/migrate-email/references/7-report.md @@ -51,7 +51,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ## Before cutover - + ## Summary ``` diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 63b6fe064..3fbf09e79 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -43,7 +43,8 @@ This file decides, field by field, whether PostHog can send a Resend call site. ## Content - `html`, `text`, and `react` content is rendered for one recipient before the send. PostHog sends it as it is. -- A `template` site moves only to a template made in PostHog. This skill never makes one: the person makes it from the Resend template, makes it transactional, and gives you its template ID. Until then the site stays on Resend. +- A `template` site moves only to a template made in PostHog. This skill never makes one: the person makes it from the Resend template and gives you its template ID, and makes it transactional once a verified sender covers its address, as Step 3 says. Until they give the ID, the site stays on Resend. +- An email that carries a login code, a reset link, or another secret needs its PostHog template marked sensitive: PostHog then keeps no copy of each sent email's body or filled-in subject, and a clicked link keeps only the site's address. Templates are not sensitive by default. - The check needs the template's content from the Resend dashboard, because the code has only its id. - In the PostHog template, `{{{NAME}}}` becomes `{{ variables.NAME }}`, and the name keeps its case. `{{{NAME|there}}}` becomes `{{ variables.NAME | default: 'there' }}`, and a variable with a `fallback_value` in the template's definition gets the same `default`. Quote a fallback that holds a `'` with `"` instead. Liquid has no escape character in a quoted value. - Liquid's `default` also replaces an empty string, which Resend inserts as it is. When the code can pass an empty string for a variable with a fallback, the email shows the fallback instead. Note it in the report. diff --git a/scripts/lib/tests/migrate-email-skill.test.js b/scripts/lib/tests/migrate-email-skill.test.js index 0d6c353fb..e55985fdd 100644 --- a/scripts/lib/tests/migrate-email-skill.test.js +++ b/scripts/lib/tests/migrate-email-skill.test.js @@ -11,7 +11,6 @@ const DOCS_PAGES = { 'https://posthog.com/docs/workflows/transactional-emails/api.md': '# Send transactional emails with the API\n', }; const REFERENCE_PATH = /references\/[A-Za-z0-9_./-]+\.md/g; -const read = (file) => readFileSync(join(CONFIG_DIR, 'skills', 'migrate-email', 'references', file), 'utf8'); async function loadSkills() { vi.resetModules(); @@ -121,6 +120,9 @@ describe('migrate-email skill', () => { ['a value that is only a comment', 'POSTHOG_PROJECT_SECRET_API_KEY= #phs_abc\n', '0'], ['a key overridden by a later empty line', 'POSTHOG_PROJECT_SECRET_API_KEY=phs_abc\nPOSTHOG_PROJECT_SECRET_API_KEY=\n', '0'], ['another variable ending in the name', 'OTHER_POSTHOG_PROJECT_SECRET_API_KEY=phs_abc\n', '0'], + ['a placeholder in angle brackets', 'POSTHOG_PROJECT_SECRET_API_KEY=\n', '0'], + ['a value with another prefix', 'POSTHOG_PROJECT_SECRET_API_KEY=xphs_abc\n', '0'], + ['a value that starts with =', 'POSTHOG_PROJECT_SECRET_API_KEY==phs_abc\n', '0'], ])('finds the key in %s only when it is set, and never prints it', (_name, envFile, count) => { expect(command).toBeDefined(); const result = check(envFile); @@ -129,39 +131,6 @@ describe('migrate-email skill', () => { expect(result.stdout).not.toContain('phs_'); expect(result.stderr).toBe(''); }); - - it('ticks the phase only when the check found the key, and the report asks for a key that is not set', () => { - expect(keyStep).toMatch(/A person who says they will add the key later has not set it/); - expect(keyStep).toMatch(/Tick the phase in the plan file only when the check above found the key/); - expect(keyStep).toMatch(/`- \[ \] key — not set: `/); - expect(read('7-report.md')).toMatch(/`POSTHOG_PROJECT_SECRET_API_KEY` in the env file when the plan says it is not set/); - }); - }); - - describe('what the run cannot finish before cutover', () => { - it('asks for a last suppression import right before cutover, since the provider keeps adding entries', () => { - expect(read('5-suppressions.md')).toMatch(/The provider keeps adding to its list while it sends/); - expect(read('7-report.md')).toMatch(/import the entries the provider added to its suppression list since the export, right before cutover/); - }); - - it('lets a template made in PostHog become transactional only once its sender is verified', () => { - const inventory = read('3-inventory.md'); - - expect(inventory).toMatch(/PostHog makes a template transactional only once a verified sender covers its address/); - expect(inventory).not.toMatch(/make it in PostHog from the provider's template, make it transactional, and give you/); - }); - - it('has the person confirm sends with content from the code, which the template tools do not show', () => { - expect(read('2-preflight.md')).toMatch(/PostHog enables sends with content from the code separately/); - expect(read('7-report.md')).toMatch(/sends with content from the code \(`html`, `text`, or `react`\) when a site that moves has them \(confirm with PostHog/); - }); - }); - - it('keeps a template site on Resend when it sets a reply-to, in either spelling', () => { - const mapping = read('resend/mapping.md'); - - expect(mapping).toMatch(/the site sets `from`, `replyTo` \/ `reply_to`, or `subject` next to it \|/); - expect(mapping).toMatch(/A site that sets `from`, `replyTo` \/ `reply_to`, or `subject` next to `template` stays on Resend/); }); it('publishes Resend and Statsig as wizard migrate subcommands in the menu the Wizard reads', async () => { From 708f7f182e808c0f5ac1bb3b3ec1f1aa61898d1e Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 11:41:05 +0000 Subject: [PATCH 51/70] fix(migrate-email): keep each site's own HTTP deadline A moved HTTP send with its own deadline set the shortest deadline on one shared client, which shortened other sites' deadlines. Give each distinct deadline its own client instead, so no site gets a deadline it didn't have. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 1 + context/skills/migrate-email/references/resend/mapping.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index cbfe39da9..7f0622372 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -48,6 +48,7 @@ export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { - When the project token or the host is not configured yet, get the token from the PostHog MCP `projects-get` tool (`api_token`). The host is `https://us.i.posthog.com` for US Cloud and `https://eu.i.posthog.com` for EU Cloud. Ask the person which one when you can't tell. - When `host` is a reverse proxy or a self-hosted instance, also set `appHost` to the PostHog app URL, such as `https://us.posthog.com`. posthog-node never sends the secret key to a proxy, and without `appHost` the send fails with `missing_app_host`. - Put a new client in its own server-only module, next to the provider's client, and import it where the sites send. +- A site whose request had its own deadline keeps it: the provider's `mapping.md` says how, under "HTTP". Each distinct deadline gets its own client like the one above, with that timeout, in the same module. - Use the env variable names the app already uses for the PostHog token and host. Add each new name, without a value, to the env example file. ## Link emails to your users diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 88a66bc0b..c1582b9f0 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -69,7 +69,7 @@ How a site that moves is written with `posthog-node`. Step 7 says when to use ea **React.** `react: ` becomes `html: await render()`, with `import { render } from '@react-email/render'`. Keep a `text` the site already passes. -**HTTP.** A `fetch` or `axios` call to `https://api.resend.com/emails` becomes `posthog.emails.send` with the camelCase fields: `reply_to` becomes `replyTo`, and the `Idempotency-Key` header becomes `idempotencyKey`. Code that read the response status reads `error` instead. A request with its own deadline, such as `signal: AbortSignal.timeout(5000)` or axios `timeout: 5000`, keeps it: set `emailRequestTimeoutMs` to that value on the client the sends use, and pass `maxRetries: 0` on the send, since the request never retried. posthog-node otherwise waits up to 15 seconds and retries twice, which can run past the site's deadline. When sites use different deadlines, set the shortest, and note the sites whose deadline it shortens. +**HTTP.** A `fetch` or `axios` call to `https://api.resend.com/emails` becomes `posthog.emails.send` with the camelCase fields: `reply_to` becomes `replyTo`, and the `Idempotency-Key` header becomes `idempotencyKey`. Code that read the response status reads `error` instead. A request with its own deadline, such as `signal: AbortSignal.timeout(5000)` or axios `timeout: 5000`, keeps it: set `emailRequestTimeoutMs` to that value on the client the sends use, and pass `maxRetries: 0` on the send, since the request never retried. posthog-node otherwise waits up to 15 seconds and retries twice, which can run past the site's deadline. The timeout belongs to the client, so each distinct deadline gets its own client, set up as Step 7 says with that `emailRequestTimeoutMs`, and its sites send through it. Sites without a deadline keep the shared client. Never give a site a deadline it didn't have. **Templates made in PostHog.** The site sends `templateId` with the template ID the person gave, and `templateData` with the site's `variables` object. It sends no `templateKey`, `subject`, `html`, `text`, `from`, or `replyTo`: the template holds them. From 56158d100c2924b3953f798764c18e248efdd4eb Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 11:42:06 +0000 Subject: [PATCH 52/70] fix(migrate-email): keep marketing sends on the provider PostHog's transactional send ignores marketing opt-outs and is only for emails a person needs. A newsletter whose fields all move passed the field check and showed as ready to move. Check what a site sends first, and keep marketing or unclear sends on the provider. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/3-inventory.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index fdbac1813..87086bacf 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -41,7 +41,9 @@ When you find no site, stop before you write the plan file: ## Classify each site -Go through `mapping.md` field by field. A site **moves** when PostHog can send every field it sets. A site **stays** on the provider when any one field or feature keeps it there: record that field or feature as the reason. Never plan to drop a field. +Check what each site sends first. PostHog's transactional send ignores marketing opt-outs, so it is only for an email that a person needs, such as a password reset, a receipt, or an invite. A site that sends marketing, such as a newsletter, a promotion, or a product announcement, stays, and the reason is `marketing email`. When neither the code nor the template's name tells you, ask the person once for every such site. A site they call marketing, or don't answer for, stays with that reason. + +Then go through `mapping.md` field by field. A site **moves** when PostHog can send every field it sets. A site **stays** on the provider when any one field or feature keeps it there: record that field or feature as the reason. Never plan to drop a field. When the code passes a value you can't read, such as a list of recipients built at run time, follow it to its callers. When you still can't tell, the site stays, and the reason says what you could not check. From 04e7c8424c083bdedef022e4821daf659ffdd7a9 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 11:44:08 +0000 Subject: [PATCH 53/70] fix(migrate-email): read the provider's report notes without the import tool Step 5 read the provider's account.md only after the import tool check, so without the tool, the facts account.md adds for the report never reached the plan. Read it first on every path, through a "For the report" section, and carry those facts into the report. A manual import also happens right before cutover. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/5-suppressions.md | 8 ++++++-- context/skills/migrate-email/references/7-report.md | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/context/skills/migrate-email/references/5-suppressions.md b/context/skills/migrate-email/references/5-suppressions.md index eb723bf2a..5dfeb60d9 100644 --- a/context/skills/migrate-email/references/5-suppressions.md +++ b/context/skills/migrate-email/references/5-suppressions.md @@ -13,15 +13,19 @@ The provider keeps a suppression list: addresses that hard-bounced or marked an [STATUS] Importing the suppression list ``` +## Read the provider's notes + +Read the provider's `account.md` first, whether or not the import runs. Its "For the report" section, when it has one, names facts the report carries, such as a count of entries the import leaves out. Find each one as the section says, and write it under the phase in the plan file. Never write an address. + ## Check the import tool Look for the PostHog MCP tool `email-suppressions-add`, and read its schema with `info`. -When it is missing, the import is not available to this person yet. Do not try other tools, and do not use the opt-out tools: opt-outs are marketing preferences, and transactional email ignores them. Tick the phase as `- [ ] suppressions — not imported: no import tool`, and continue to the next step. The report tells the person to add the addresses in PostHog (Workflows, then Messaging, then Suppression list) before cutover. +When it is missing, the import is not available to this person yet. Do not try other tools, and do not use the opt-out tools: opt-outs are marketing preferences, and transactional email ignores them. Tick the phase as `- [ ] suppressions — not imported: no import tool`, and continue to the next step. The report tells the person to add the addresses in PostHog (Workflows, then Messaging, then Suppression list) right before cutover, so the list holds the entries the provider adds until then. ## Get the list -Read the provider's `account.md`. It says how to export the list, which entries to take, and how each entry maps to PostHog. +The provider's `account.md` says how to export the list, which entries to take, and how each entry maps to PostHog. - Prefer the export the person downloads from the provider's dashboard. Ask them where they saved the file. - Read the list from the provider's API only when the person gives you a key that can read it, through an environment variable that `account.md` names. The app's own sending key usually can't. diff --git a/context/skills/migrate-email/references/7-report.md b/context/skills/migrate-email/references/7-report.md index 5745c2496..47a273617 100644 --- a/context/skills/migrate-email/references/7-report.md +++ b/context/skills/migrate-email/references/7-report.md @@ -39,7 +39,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ## Suppression list - + ## PostHog secret key From 0186ee205ed737758e458a99c3d061fe29d4a7d5 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 12:09:12 +0000 Subject: [PATCH 54/70] fix(migrate-email): answer the round 1 review of the rewrite and verify steps - Step 8 keeps each test at its boundary: an HTTP test intercepts PostHog's send with the real posthog-node client. - Email always gets its own posthog-node client; changing the app's client would change how its flags evaluate. - A request with a signal the code aborts stays on Resend. - Step 7 allows the fields mapping.md adds, such as maxRetries: 0. - Step 8 matches the moved site's send by template and its engagement by send, not by workflow. - The plan records the full-access key and the baseline typecheck errors; posthog-node is upgraded only when it lacks a capability. - The step test walks the built continuation chain. Co-Authored-By: Claude Opus 5.5 --- .../migrate-email/references/3-inventory.md | 2 ++ .../migrate-email/references/7-rewrite.md | 12 +++---- .../migrate-email/references/8-verify.md | 8 ++--- .../references/resend/account.md | 2 +- .../references/resend/mapping.md | 1 + scripts/lib/tests/migrate-email-skill.test.js | 31 +++++++++++-------- 6 files changed, 32 insertions(+), 24 deletions(-) diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index b25551cae..07e3f8e15 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -69,6 +69,8 @@ A phase checklist, in this order. Tick `preflight` with what Step 2 recorded, an - [ ] verify ``` +When the run created a full-access provider key, as `account.md` says, add a line under the checklist: `full-access key — created: `. Step 5 adds whether the person deleted it. + A sites table, one row per site, in source tree order: ``` diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 7f0622372..a93dca4d7 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -18,11 +18,11 @@ Rewrite each site whose `moves` is `yes` in the plan to send with `posthog-node` - Change only the sites whose `moves` is `yes`. Never change a site that stays, and never change a line that a site that stays still needs. - When no site moves, tick the phase in the plan with `none moved` and go to the next step. -- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck, and keep its errors: Step 8 compares with them. +- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck, and write each error's file and line under the rewrite phase in the plan: Step 8 compares with them. ## Set up the client -Install or upgrade `posthog-node` to its latest release with the project's package manager. `posthog.emails` alone is not enough: early releases send only a template made in PostHog, by `templateId`. Check the installed package's types for what the moving sites need: +Install `posthog-node` with the project's package manager when the app doesn't have it. `posthog.emails` alone is not enough: early releases send only a template made in PostHog, by `templateId`. Check the installed package's types for what the moving sites need, and upgrade it to its latest release only when they lack one of these: - a site with `html`, `text`, or a component: `posthog.emails.send` takes `templateKey` with `subject` and `html` or `text`; - a site that sets `replyTo`: the send takes `replyTo`; @@ -30,7 +30,7 @@ Install or upgrade `posthog-node` to its latest release with the project's packa When the latest release lacks one of these, change no site that needs it. Mark each such row `moves: no — posthog-node has no yet`, tell the person, and go on with the rest. When the client options lack `migratedFrom`, leave it out of the client. When no site is left, undo the install or upgrade of `posthog-node`, tick the phase with `none moved`, and go to the next step. -Configure one server-side client for email: +Configure a server-side client of its own for email, also when the app already has a `posthog-node` client: ```js import { PostHog } from 'posthog-node' @@ -44,10 +44,10 @@ export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { ``` - When the client options take `migratedFrom`, set it to the value that the provider's `mapping.md` names under "The PostHog client". posthog-node sends it with every email request, so PostHog knows that the sends moved from that provider. -- Reuse the app's existing `posthog-node` client when it sets neither `secretKey` nor `personalApiKey` and is never disabled: add `secretKey`, `enableLocalEvaluation: false`, and `migratedFrom` when the client options take it. A client that sets either key keeps it as it is: posthog-node also uses `secretKey` for local flag evaluation and remote config, and prefers it over `personalApiKey`, so the email key would replace the app's key. A client that can be disabled, such as `disabled: process.env.NODE_ENV !== 'production'`, answers every send with `client_disabled` while it is, so emails would stop where the old provider still sent them. In both cases the sends get their own client instead, as above, and the plan notes it. +- Never change the app's own `posthog-node` client for email. posthog-node also uses `secretKey` for its flags and remote config, so the email key, or `enableLocalEvaluation: false`, would change how the app's flags evaluate, and a client the app disables answers every send with `client_disabled`. - When the project token or the host is not configured yet, get the token from the PostHog MCP `projects-get` tool (`api_token`). The host is `https://us.i.posthog.com` for US Cloud and `https://eu.i.posthog.com` for EU Cloud. Ask the person which one when you can't tell. - When `host` is a reverse proxy or a self-hosted instance, also set `appHost` to the PostHog app URL, such as `https://us.posthog.com`. posthog-node never sends the secret key to a proxy, and without `appHost` the send fails with `missing_app_host`. -- Put a new client in its own server-only module, next to the provider's client, and import it where the sites send. +- Put the client in its own server-only module, next to the provider's client, and import it where the sites send. - A site whose request had its own deadline keeps it: the provider's `mapping.md` says how, under "HTTP". Each distinct deadline gets its own client like the one above, with that timeout, in the same module. - Use the env variable names the app already uses for the PostHog token and host. Add each new name, without a value, to the env example file. @@ -71,7 +71,7 @@ For each site that moves, in plan order: - Install `@react-email/render` with the project's package manager when a site renders a component and the app doesn't have it. - Keep the site's idempotency key, error branches, logging, and return value working as before. Keep the code around the send unchanged where you can. - `posthog.emails.send` never throws on an API error: it returns `{ data, error }`. When the old call threw on an error, or the code checked an HTTP status, check `error` so the site fails the same way. -- Never add a field that the old call didn't set, apart from `templateKey`, `templateId`, and `distinctId`. `templateData` takes the place of the provider's template variables. +- Never add a field that the old call didn't set, apart from `templateKey`, `templateId`, `distinctId`, and a field the provider's `mapping.md` says to add, such as `maxRetries: 0` on a request that kept its own deadline. `templateData` takes the place of the provider's template variables. When a site turns out to need something `mapping.md` keeps on the provider, undo its change, set `moves` to `no` with the reason, and go on. diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 75f522ee6..1ba25b625 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -16,8 +16,8 @@ Check that the app still builds, its tests still pass, and one moved email reach ## Build and tests -- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error that is not in the list Step 7 kept, in any file: the rewrite or the posthog-node upgrade caused it. Note each file you fix outside the moved sites for the report. An error in that list was there before: note it, and leave it. -- Run the tests that cover the files you changed. A test that mocks the provider's client or intercepts its HTTP requests for a moved site now mocks `posthog.emails.send` and asserts on the fields it gets, with the same expected values. Never turn a PostHog send back into the provider's request shape to keep an old assertion. Never delete or skip a test. +- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error that is not in the list Step 7 wrote into the plan, in any file: the rewrite or the posthog-node upgrade caused it. Note each file you fix outside the moved sites for the report. An error in that list was there before: note it, and leave it. +- Run the tests that cover the files you changed. Keep each test at the boundary it had. A test that intercepts the provider's HTTP requests for a moved site now intercepts PostHog's send request, as `api.md` describes it, with the real `posthog-node` client, and asserts on the request PostHog gets and on what the app does, with the same expected values. A test that mocks the provider's client now mocks `posthog.emails.send` and asserts on the fields it gets. Never turn a PostHog send back into the provider's request shape to keep an old assertion. Never delete or skip a test. - Search the changed files for the provider's calls: a moved site has none left, and each moved site has one `posthog.emails.send`. ## One email on one person @@ -33,12 +33,12 @@ Skip this part and record `not checked` with the reason when the API is not conf 5. Find the person's distinct ID: the value the moved site passed as `distinctId`. Run a SQL query through the PostHog MCP `execute-sql` tool for that distinct ID since the start of the test, with a new random string each time you run it: ```sql - SELECT event, timestamp, properties.$workflow_id AS workflow, '' AS run FROM events + SELECT event, timestamp, properties.$workflow_invocation_id AS send, properties.$email_template_key AS template_key, properties.$email_template_id AS template_id, '' AS run FROM events WHERE distinct_id = '' AND toUnixTimestamp(timestamp) >= ORDER BY timestamp ``` -6. The chain holds when the result has a `$workflows_email_sent`, an engagement event such as `$workflows_email_delivered` or `$workflows_email_opened` with the same `workflow`, and at least one product event of the app. An event from before the start of the test belongs to another email. Delivery events arrive after the provider reports back: when only the send shows, wait a minute and run the query once more. +6. The chain holds when the result has a `$workflows_email_sent` whose `template_key` or `template_id` is the moved site's, an engagement event such as `$workflows_email_delivered` or `$workflows_email_opened` with the same `send`, and at least one product event of the app. A send of another email to the same person proves nothing about this one. An event from before the start of the test belongs to another email. Delivery events arrive after the provider reports back: when only the send shows, wait a minute and run the query once more. When the MCP has no SQL tool, ask the person to open their person in PostHog and tell you which of the three they see since they triggered the test email. diff --git a/context/skills/migrate-email/references/resend/account.md b/context/skills/migrate-email/references/resend/account.md index 920c5a8d4..dfee44c48 100644 --- a/context/skills/migrate-email/references/resend/account.md +++ b/context/skills/migrate-email/references/resend/account.md @@ -20,7 +20,7 @@ A domain verified at Resend carries these records. Keep all of them until the cu ## Full-access key -The app's own Resend key is usually a sending-only key, and it can't read templates or the suppression list. When the person chooses the API over the dashboard, ask them to create a full-access key in Resend, store it in `RESEND_FULL_ACCESS_API_KEY` in the git-ignored env file, and note in the plan that the run created it. Its last use is the suppression import in Step 5. At the end of Step 5, on every way out of it, ask the person to delete the key in Resend and remove its variable from the env file, and note in the plan whether they did. The report reminds them when they didn't. Never print the key, and never write it into another file. +The app's own Resend key is usually a sending-only key, and it can't read templates or the suppression list. When the person chooses the API over the dashboard, ask them to create a full-access key in Resend, store it in `RESEND_FULL_ACCESS_API_KEY` in the git-ignored env file, and write it into the plan as Step 3's plan layout says. Its last use is the suppression import in Step 5. At the end of Step 5, on every way out of it, ask the person to delete the key in Resend and remove its variable from the env file, and note in the plan whether they did. The report reminds them when they didn't. Never print the key, and never write it into another file. ## Template content diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index c1582b9f0..34b1fb479 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -39,6 +39,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `if (error.name === '...')` | The name is not one of PostHog's: `validation_error`, `missing_api_key`, `invalid_permission`, `not_found`, `concurrent_idempotent_requests`, `invalid_idempotent_request`, `rate_limit_exceeded`, `monthly_quota_exceeded`, `service_unavailable`, `application_error` | | `emails.get(id)` and a branch on `last_event` | Always: the send and its status read stay together. PostHog's status is not `last_event` | | `data.id` stored for a webhook or a status read | Always, when Resend webhooks or status reads use the id | +| A `fetch` or axios request with a `signal` the code can abort, such as one a caller passes in or an `AbortController` it aborts | Always: `posthog.emails.send` takes no signal, so an email the old code cancelled would go out. A fixed `AbortSignal.timeout(...)` is a deadline, and moves as "HTTP" below says | ## Content diff --git a/scripts/lib/tests/migrate-email-skill.test.js b/scripts/lib/tests/migrate-email-skill.test.js index 045f16ed7..9685afc90 100644 --- a/scripts/lib/tests/migrate-email-skill.test.js +++ b/scripts/lib/tests/migrate-email-skill.test.js @@ -92,22 +92,27 @@ describe('migrate-email skill', () => { expect(markdownFiles(skillDir).map((file) => readFileSync(file, 'utf8')).join('\n')).not.toMatch(/\{\{>|\{display_name\}|\{references\}/); }); - it('runs the rewrite and verify steps between the key and the report', async () => { + it('chains the steps from detection through rewrite and verify to the report', async () => { outputDir = mkdtempSync(join(tmpdir(), 'migrate-skill-')); const skillDir = await buildSkill('migrate-email-resend', outputDir); - const workflow = readFileSync(join(skillDir, 'SKILL.md'), 'utf8').match(/^\d+\. `references\/[^`]+`/gm); - - expect(workflow.map((step) => step.replace(/^\d+\. /, ''))).toEqual([ - '`references/1-detect.md`', - '`references/2-preflight.md`', - '`references/3-inventory.md`', - '`references/4-sender.md`', - '`references/5-suppressions.md`', - '`references/6-key.md`', - '`references/7-rewrite.md`', - '`references/8-verify.md`', - '`references/9-report.md`', + const visited = []; + for (let step = '1-detect.md'; step && visited.length < 20; ) { + visited.push(step); + const text = readFileSync(join(skillDir, 'references', step), 'utf8'); + step = text.match(/\*\*Upon completion, continue with:\*\* \[[^\]]+\]\(([^)]+)\)/)?.[1]; + } + + expect(visited).toEqual([ + '1-detect.md', + '2-preflight.md', + '3-inventory.md', + '4-sender.md', + '5-suppressions.md', + '6-key.md', + '7-rewrite.md', + '8-verify.md', + '9-report.md', ]); }); From 30f387358eef7ff984140c77cdeaa5f29b4ab2c0 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 12:14:52 +0000 Subject: [PATCH 55/70] fix(migrate-email): match baseline typecheck errors without their line The rewrite adds lines above an old error, so a file-and-line match made Step 8 fix errors that were there before. Record and match each error by file, code, and message. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 2 +- context/skills/migrate-email/references/8-verify.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index a93dca4d7..1816d2ebe 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -18,7 +18,7 @@ Rewrite each site whose `moves` is `yes` in the plan to send with `posthog-node` - Change only the sites whose `moves` is `yes`. Never change a site that stays, and never change a line that a site that stays still needs. - When no site moves, tick the phase in the plan with `none moved` and go to the next step. -- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck, and write each error's file and line under the rewrite phase in the plan: Step 8 compares with them. +- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck, and write each error's file, code, and message, such as `TS2345` and its text, under the rewrite phase in the plan: Step 8 compares with them. Leave out the line: the rewrite moves it. ## Set up the client diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 1ba25b625..33de4e42c 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -16,7 +16,7 @@ Check that the app still builds, its tests still pass, and one moved email reach ## Build and tests -- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error that is not in the list Step 7 wrote into the plan, in any file: the rewrite or the posthog-node upgrade caused it. Note each file you fix outside the moved sites for the report. An error in that list was there before: note it, and leave it. +- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error whose file, code, and message are not in the list Step 7 wrote into the plan, in any file: the rewrite or the posthog-node upgrade caused it. Note each file you fix outside the moved sites for the report. An error in that list was there before: note it, and leave it. - Run the tests that cover the files you changed. Keep each test at the boundary it had. A test that intercepts the provider's HTTP requests for a moved site now intercepts PostHog's send request, as `api.md` describes it, with the real `posthog-node` client, and asserts on the request PostHog gets and on what the app does, with the same expected values. A test that mocks the provider's client now mocks `posthog.emails.send` and asserts on the fields it gets. Never turn a PostHog send back into the provider's request shape to keep an old assertion. Never delete or skip a test. - Search the changed files for the provider's calls: a moved site has none left, and each moved site has one `posthog.emails.send`. From dc18f5dfafbfae8c309e4c7f7c54776c8c5f43e0 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 12:16:14 +0000 Subject: [PATCH 56/70] fix(migrate-email): count each baseline typecheck error An error that was there before could hide a new copy of itself. Record how many times each error shows, and fix the extra ones in lines the rewrite changed. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 2 +- context/skills/migrate-email/references/8-verify.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 1816d2ebe..9a4708c97 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -18,7 +18,7 @@ Rewrite each site whose `moves` is `yes` in the plan to send with `posthog-node` - Change only the sites whose `moves` is `yes`. Never change a site that stays, and never change a line that a site that stays still needs. - When no site moves, tick the phase in the plan with `none moved` and go to the next step. -- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck, and write each error's file, code, and message, such as `TS2345` and its text, under the rewrite phase in the plan: Step 8 compares with them. Leave out the line: the rewrite moves it. +- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck, and write each error's file, code, and message, such as `TS2345` and its text, with how many times it shows, under the rewrite phase in the plan: Step 8 compares with them. Leave out the line: the rewrite moves it. ## Set up the client diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 33de4e42c..f0afec8cb 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -16,7 +16,7 @@ Check that the app still builds, its tests still pass, and one moved email reach ## Build and tests -- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error whose file, code, and message are not in the list Step 7 wrote into the plan, in any file: the rewrite or the posthog-node upgrade caused it. Note each file you fix outside the moved sites for the report. An error in that list was there before: note it, and leave it. +- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error whose file, code, and message are not in the list Step 7 wrote into the plan, in any file: the rewrite or the posthog-node upgrade caused it. When an error in the list now shows more times than the list says, the extra ones are new too: fix the ones in lines the rewrite changed. Note each file you fix outside the moved sites for the report. An error in that list was there before: note it, and leave it. - Run the tests that cover the files you changed. Keep each test at the boundary it had. A test that intercepts the provider's HTTP requests for a moved site now intercepts PostHog's send request, as `api.md` describes it, with the real `posthog-node` client, and asserts on the request PostHog gets and on what the app does, with the same expected values. A test that mocks the provider's client now mocks `posthog.emails.send` and asserts on the fields it gets. Never turn a PostHog send back into the provider's request shape to keep an old assertion. Never delete or skip a test. - Search the changed files for the provider's calls: a moved site has none left, and each moved site has one `posthog.emails.send`. From a2994e96cdcd99b26cacab2029bf01d0baa26a9c Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 12:21:55 +0000 Subject: [PATCH 57/70] fix(migrate-email): keep a named recipient on Resend PostHog's send takes one bare address in to, and refuses an entry with a name, such as Jane . A one-entry list with a name passed the field check. Keep it on Resend, as reply-to already does. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/mapping.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 3fbf09e79..b529247ca 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -7,7 +7,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. | Resend | PostHog | A site stays on Resend when | |---|---|---| | `from` | `from` | Never. It needs a verified sender (Step 4) | -| `to` | `to` | `to` can hold more than one address. A list with exactly one address moves as that address | +| `to` | `to`, one bare address | `to` can hold more than one address, its entry carries a name, such as `Jane `, or the code builds it at run time and you cannot tell that it holds a bare address only. A list with exactly one bare address moves as that address | | `subject` | `subject` | Never | | `html` | `html` | Never | | `text` | `text` | Never | From 497d0179df59481d21abf74a72383a849e23a02f Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 12:29:30 +0000 Subject: [PATCH 58/70] fix(migrate-email): keep a site on Resend when it needs a suppressed send's id PostHog refuses a send to a suppressed address with no data.id, where Resend accepted it and returned one. A helper that returns or stores the id would get null on the success path, so such a site stays unless its callers already handle a send without an id. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/mapping.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 4b09cc1c7..65694b585 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -78,6 +78,6 @@ How a site that moves is written with `posthog-node`. Step 7 says when to use ea - `data.id` is PostHog's message id. Code that logs it or stores it for the app's own use keeps working. - `error.name` uses Resend's names, so `if (error.name === 'rate_limit_exceeded')` keeps working. `error.message` and `error.statusCode` keep their names. -- Resend takes a send to a suppressed address and drops it later. PostHog refuses it with `error.code` `recipient_suppressed` (name `validation_error`). When the site throws, retries, or reports a failure on any error, add `if (error?.code === 'recipient_suppressed')` before that branch and handle it the way the site handled a send that went out: log it and go on. Note each site that got this branch in the report. +- Resend takes a send to a suppressed address and drops it later. PostHog refuses it with `error.code` `recipient_suppressed` (name `validation_error`). When the site throws, retries, or reports a failure on any error, add `if (error?.code === 'recipient_suppressed')` before that branch and handle it the way the site handled a send that went out: log it and go on. A suppressed send has no `data.id`: when the code after the send uses the id for more than a log line, such as returning it to its callers or storing it, the site stays, and the reason is `uses the message id of a suppressed send`, unless its callers already handle a send without an id. Note each site that got this branch in the report. **The Resend client.** Keep `new Resend(...)` and its import while any site or other call still uses it. When nothing uses it, remove the import and the client, and keep the `resend` package and its key: the person removes them after the cutover. From 69edcdd1fa266934c985d6c4121e04f989e89995 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 12:40:56 +0000 Subject: [PATCH 59/70] fix(migrate-email): keep a Resend SDK send with an abortable signal on Resend Resend's SDK takes a signal in the options of emails.send and passes it to fetch. Dropping the options object would send an email the old code cancelled, so the signal rule now covers SDK sends as well as fetch and axios requests. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/mapping.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 65694b585..88d64e43c 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -39,7 +39,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. | `if (error.name === '...')` | The name is not one of PostHog's: `validation_error`, `missing_api_key`, `invalid_permission`, `not_found`, `concurrent_idempotent_requests`, `invalid_idempotent_request`, `rate_limit_exceeded`, `monthly_quota_exceeded`, `service_unavailable`, `application_error` | | `emails.get(id)` and a branch on `last_event` | Always: the send and its status read stay together. PostHog's status is not `last_event` | | `data.id` stored for a webhook or a status read | Always, when Resend webhooks or status reads use the id | -| A `fetch` or axios request with a `signal` the code can abort, such as one a caller passes in or an `AbortController` it aborts | Always: `posthog.emails.send` takes no signal, so an email the old code cancelled would go out. A fixed `AbortSignal.timeout(...)` is a deadline, and moves as "HTTP" below says | +| A `signal` the code can abort, such as one a caller passes in or an `AbortController` it aborts, on a `fetch` or axios request or in the options of `resend.emails.send(payload, { signal })`, which the SDK passes to its request | Always: `posthog.emails.send` takes no signal, so an email the old code cancelled would go out. A fixed `AbortSignal.timeout(...)` is a deadline, and moves as "HTTP" below says, in an SDK send too | ## Content @@ -59,7 +59,7 @@ How a site that moves is written with `posthog-node`. Step 7 says when to use ea **The PostHog client.** Set `migratedFrom: 'resend'` on the `posthog-node` client that Step 7 configures, when its client options take it. -**The call.** `resend.emails.send(payload, { idempotencyKey })` and `resend.emails.create(...)` become one `posthog.emails.send({ ... })`. The options object goes away: `idempotencyKey` moves into the payload. +**The call.** `resend.emails.send(payload, { idempotencyKey })` and `resend.emails.create(...)` become one `posthog.emails.send({ ... })`. The options object goes away: `idempotencyKey` moves into the payload. A `signal` in it is code around the send, as the table above says. **The fields.** From a66e15b6fc1a4e57821b96d2ebe5ea4b913c7232 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 15:44:24 +0000 Subject: [PATCH 60/70] fix(migrate-email): upgrade mocked send tests to the HTTP boundary A test that mocked the provider's client now runs the real posthog-node client and intercepts PostHog's send request, asserting on that request and on what the app does. It uses the suite's interception tool, asks before adding one, and keeps the mock only when the person declines, which the report lists. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/8-verify.md | 5 ++++- context/skills/migrate-email/references/9-report.md | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index f0afec8cb..afbcc10d3 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -17,7 +17,10 @@ Check that the app still builds, its tests still pass, and one moved email reach ## Build and tests - Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error whose file, code, and message are not in the list Step 7 wrote into the plan, in any file: the rewrite or the posthog-node upgrade caused it. When an error in the list now shows more times than the list says, the extra ones are new too: fix the ones in lines the rewrite changed. Note each file you fix outside the moved sites for the report. An error in that list was there before: note it, and leave it. -- Run the tests that cover the files you changed. Keep each test at the boundary it had. A test that intercepts the provider's HTTP requests for a moved site now intercepts PostHog's send request, as `api.md` describes it, with the real `posthog-node` client, and asserts on the request PostHog gets and on what the app does, with the same expected values. A test that mocks the provider's client now mocks `posthog.emails.send` and asserts on the fields it gets. Never turn a PostHog send back into the provider's request shape to keep an old assertion. Never delete or skip a test. +- Run the tests that cover the files you changed. Never delete or skip a test, and never turn a PostHog send back into the provider's request shape to keep an old assertion. + - A test of a moved site runs the real `posthog-node` client and intercepts PostHog's send request at the HTTP boundary, as `api.md` describes the request. It asserts on the request PostHog gets and on what the app does, with the same expected values the old test had. A test that intercepted the provider's HTTP requests now intercepts PostHog's. A test that mocked the provider's client, such as `jest.mock('resend')`, drops that mock and becomes such a test too. A test that mocks the app's own email module stays as it is. + - The test sets the env variables Step 7's email client reads: any project token and secret key, and the PostHog host the app uses, such as `https://us.i.posthog.com`. Without them the send fails before it makes a request. It intercepts the app host the client sends to, such as `https://us.posthog.com` for that host. A test that answers with a 429 or a 503 answers each of the client's two retries too, which wait about one second, then two. + - Intercept with the tool the test suite already uses for HTTP. posthog-node sends with the global `fetch`, which `msw`, `nock` 14 or later, and undici's `MockAgent` intercept; `nock` before 14 doesn't see `fetch`. When the suite has no such tool, ask the person before adding one as a dev dependency. When they decline, a test that mocked the provider's client mocks `posthog.emails.send` instead and asserts on the fields it gets: note it in the plan row and for the report. - Search the changed files for the provider's calls: a moved site has none left, and each moved site has one `posthog.emails.send`. ## One email on one person diff --git a/context/skills/migrate-email/references/9-report.md b/context/skills/migrate-email/references/9-report.md index 3246553f7..a8d6afb87 100644 --- a/context/skills/migrate-email/references/9-report.md +++ b/context/skills/migrate-email/references/9-report.md @@ -49,7 +49,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ## Checks - + ## Sending tier From 18ab3510a0b5cb457fab6a6b3d6079d8078bbc2d Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 15:47:39 +0000 Subject: [PATCH 61/70] fix(migrate-email): fake fetch instead of keeping a send mock posthog-node sends with the global fetch, so a test suite without an HTTP interception tool replaces globalThis.fetch with a fake for the test. No dependency is added, and no test stays on a mock of the send. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/8-verify.md | 2 +- context/skills/migrate-email/references/9-report.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index afbcc10d3..2cdf80786 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -20,7 +20,7 @@ Check that the app still builds, its tests still pass, and one moved email reach - Run the tests that cover the files you changed. Never delete or skip a test, and never turn a PostHog send back into the provider's request shape to keep an old assertion. - A test of a moved site runs the real `posthog-node` client and intercepts PostHog's send request at the HTTP boundary, as `api.md` describes the request. It asserts on the request PostHog gets and on what the app does, with the same expected values the old test had. A test that intercepted the provider's HTTP requests now intercepts PostHog's. A test that mocked the provider's client, such as `jest.mock('resend')`, drops that mock and becomes such a test too. A test that mocks the app's own email module stays as it is. - The test sets the env variables Step 7's email client reads: any project token and secret key, and the PostHog host the app uses, such as `https://us.i.posthog.com`. Without them the send fails before it makes a request. It intercepts the app host the client sends to, such as `https://us.posthog.com` for that host. A test that answers with a 429 or a 503 answers each of the client's two retries too, which wait about one second, then two. - - Intercept with the tool the test suite already uses for HTTP. posthog-node sends with the global `fetch`, which `msw`, `nock` 14 or later, and undici's `MockAgent` intercept; `nock` before 14 doesn't see `fetch`. When the suite has no such tool, ask the person before adding one as a dev dependency. When they decline, a test that mocked the provider's client mocks `posthog.emails.send` instead and asserts on the fields it gets: note it in the plan row and for the report. + - Intercept with the tool the test suite already uses for HTTP. posthog-node sends with the global `fetch`, which `msw`, `nock` 14 or later, and undici's `MockAgent` intercept; `nock` before 14 doesn't see `fetch`. When the suite has none of them, the test replaces `globalThis.fetch` with a fake that records the request and answers it, and puts the real one back after, so no dependency is added. - Search the changed files for the provider's calls: a moved site has none left, and each moved site has one `posthog.emails.send`. ## One email on one person diff --git a/context/skills/migrate-email/references/9-report.md b/context/skills/migrate-email/references/9-report.md index a8d6afb87..3246553f7 100644 --- a/context/skills/migrate-email/references/9-report.md +++ b/context/skills/migrate-email/references/9-report.md @@ -49,7 +49,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ## Checks - + ## Sending tier From cff58f516b33b2fe5eb3c0a5d2704f874f7c3d85 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 16:39:43 +0000 Subject: [PATCH 62/70] fix(migrate-email): route a network failure the way Resend's code did Resend answers a network failure as application_error with a null statusCode, and posthog-node as network_error named service_unavailable. A branch on application_error now also takes network_error, and a branch on service_unavailable skips it, so a network failure takes the path the old code gave it. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/mapping.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index 88d64e43c..adcbf31e1 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -77,7 +77,8 @@ How a site that moves is written with `posthog-node`. Step 7 says when to use ea **The answer.** posthog-node answers `{ data, error }` like Resend and never throws on an API error. - `data.id` is PostHog's message id. Code that logs it or stores it for the app's own use keeps working. -- `error.name` uses Resend's names, so `if (error.name === 'rate_limit_exceeded')` keeps working. `error.message` and `error.statusCode` keep their names. +- `error.name` uses Resend's names for the API's answers, so `if (error.name === 'rate_limit_exceeded')` keeps working. `error.message` and `error.statusCode` keep their names. +- A network failure is the exception. Resend answers it as an `error` with the name `application_error` and a `statusCode` of `null`. posthog-node answers it, once its retries are spent, with the code `network_error`, the name `service_unavailable`, and no `statusCode`. So a branch on `error.name === 'application_error'` also takes `error.code === 'network_error'`, and a branch on `error.name === 'service_unavailable'`, which took only Resend's `503` answers, also checks `error.code !== 'network_error'`, wherever it stands: a network failure then takes the path the old code gave it. A check of `error.statusCode === null` becomes `error.statusCode == null`, which a local argument error matches too, as Resend's `null` did. - Resend takes a send to a suppressed address and drops it later. PostHog refuses it with `error.code` `recipient_suppressed` (name `validation_error`). When the site throws, retries, or reports a failure on any error, add `if (error?.code === 'recipient_suppressed')` before that branch and handle it the way the site handled a send that went out: log it and go on. A suppressed send has no `data.id`: when the code after the send uses the id for more than a log line, such as returning it to its callers or storing it, the site stays, and the reason is `uses the message id of a suppressed send`, unless its callers already handle a send without an id. Note each site that got this branch in the report. **The Resend client.** Keep `new Resend(...)` and its import while any site or other call still uses it. When nothing uses it, remove the import and the client, and keep the `resend` package and its key: the person removes them after the cutover. From 2df1f2616658365304dc7102e30512cb4e2450f1 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Thu, 12 Nov 2026 18:49:43 +0000 Subject: [PATCH 63/70] fix(migrate-email): read the project token with project-get projects-get lists the organization's projects without their API token; project-get, called without an ID, is the one tool that returns the active project and its api_token. Step 7's token lookup and Step 8's project check now name it. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 2 +- context/skills/migrate-email/references/8-verify.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 9a4708c97..e7794be2e 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -45,7 +45,7 @@ export const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { - When the client options take `migratedFrom`, set it to the value that the provider's `mapping.md` names under "The PostHog client". posthog-node sends it with every email request, so PostHog knows that the sends moved from that provider. - Never change the app's own `posthog-node` client for email. posthog-node also uses `secretKey` for its flags and remote config, so the email key, or `enableLocalEvaluation: false`, would change how the app's flags evaluate, and a client the app disables answers every send with `client_disabled`. -- When the project token or the host is not configured yet, get the token from the PostHog MCP `projects-get` tool (`api_token`). The host is `https://us.i.posthog.com` for US Cloud and `https://eu.i.posthog.com` for EU Cloud. Ask the person which one when you can't tell. +- When the project token or the host is not configured yet, get the token from the PostHog MCP `project-get` tool, called without an ID (`api_token`). The host is `https://us.i.posthog.com` for US Cloud and `https://eu.i.posthog.com` for EU Cloud. Ask the person which one when you can't tell. - When `host` is a reverse proxy or a self-hosted instance, also set `appHost` to the PostHog app URL, such as `https://us.posthog.com`. posthog-node never sends the secret key to a proxy, and without `appHost` the send fails with `missing_app_host`. - Put the client in its own server-only module, next to the provider's client, and import it where the sites send. - A site whose request had its own deadline keeps it: the provider's `mapping.md` says how, under "HTTP". Each distinct deadline gets its own client like the one above, with that timeout, in the same module. diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 2cdf80786..61cb155ba 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -29,7 +29,7 @@ The chain to prove: PostHog sends the email, records its engagement on the perso Skip this part and record `not checked` with the reason when the API is not confirmed on, no sender is verified, or `POSTHOG_PROJECT_SECRET_API_KEY` is not set. -1. Check that the app sends to the MCP's project: compare the project token the app reads with `api_token` from the PostHog MCP `projects-get` tool. Read only the token's line of the env file, by searching for the token variable's name: the file also holds secret keys, so never open all of it. When they differ, record `not checked: the app uses another project`, tell the person which project the app uses, and skip the rest of this part. +1. Check that the app sends to the MCP's project: compare the project token the app reads with `api_token` from the PostHog MCP `project-get` tool, called without an ID. Read only the token's line of the env file, by searching for the token variable's name: the file also holds secret keys, so never open all of it. When they differ, record `not checked: the app uses another project`, tell the person which project the app uses, and skip the rest of this part. 2. Ask the person whether to send one test email. Say that it sends a real email. When they say no, record `not checked: declined`, and skip the rest of this part. 3. Run `SELECT toUnixTimestamp(now()), ''` through the PostHog MCP `execute-sql` tool, so the answer can't come from a cached run, and keep the number as the start of the test; skip this when the MCP has no SQL tool. Ask them to trigger one moved email in their local app that sends it to an address they own, from a site whose plan row shows it passes `distinctId`, such as a password reset or a welcome email after signup. When no moved site passes `distinctId`, record `not checked: no moved site names a person`, and skip the rest of this part. Ask them to open the email, then to sign in as the user it went to and use the app for a moment, so that the app's product events show on the same distinct ID. Ask them to tell you when they are done. 4. When the send fails, find its code in `transactional-emails.md` or `api.md`, tell the person the fix, and record it. Never retry a send yourself. From 5e0607f3a41e6fa0652e4d22c14a7bb47417c89b Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Fri, 13 Nov 2026 04:45:59 +0000 Subject: [PATCH 64/70] fix(migrate-email): keep sites a Resend webhook handler acts on, and state the SDK limit for sites without a deadline Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/3-inventory.md | 4 +++- context/skills/migrate-email/references/resend/mapping.md | 6 +++++- .../skills/migrate-email/references/resend/sdk-reference.md | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index 07e3f8e15..0cd23e93e 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -33,6 +33,8 @@ For each site, read the surrounding code and record: Also list every other call to the provider that is not a send, such as reading an email's status, contacts, or domains. These calls stay on the provider. Note what each one does, because a site whose code reads the status back stays on the provider too. +When `sdk-reference.md` has a "Webhooks" section, also list each webhook handler: a route of the app that receives the provider's delivery events. Note the events it handles, what it does with them, and how it finds the send an event belongs to, such as by the provider's message id, by a value the send set, or by the recipient's address. `mapping.md` says under "Webhooks" which sites a handler keeps on the provider. + When you find no site, stop before you write the plan file: ``` @@ -79,4 +81,4 @@ A sites table, one row per site, in source tree order: `moves` is `yes` or `no`. `reason` is empty when the site moves. -A list of the other provider calls, each with its file, line, and what it does. +A list of the other provider calls, each with its file, line, and what it does, and a list of the webhook handlers, each with its file, line, the events it handles, and how it finds the send. diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index adcbf31e1..3e6d0ef7b 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -53,6 +53,10 @@ This file decides, field by field, whether PostHog can send a Resend call site. - A template that holds anything other than `{{{VAR}}}` and `{{{VAR|fallback}}}` placeholders, such as a section, a loop, or a condition, stays on Resend. So does a fallback that holds a `'`, and a fallback that holds HTML, such as a link: Liquid escapes the fallback too, so the markup shows as text. - The PostHog template carries its own sender, reply-to address, and subject. A site that sets `from`, `replyTo` / `reply_to`, or `subject` next to `template` stays on Resend. +## Webhooks + +Resend stops sending email events for a site that moves, and PostHog's events carry no Resend `email_id` and no `tags`. A site whose emails a webhook handler acts on stays, however the handler finds the send an event belongs to: by `email_id`, by a tag, or by anything else, such as the recipient's address. The reason is `its events feed a webhook handler`. When you can't tell which sites' emails a handler acts on, such as one that finds the send by the recipient's address, every site whose emails can reach it stays. The handler itself keeps working for the sites that stay. Never change it. + ## Rewrite How a site that moves is written with `posthog-node`. Step 7 says when to use each part. @@ -70,7 +74,7 @@ How a site that moves is written with `posthog-node`. Step 7 says when to use ea **React.** `react: ` becomes `html: await render()`, with `import { render } from '@react-email/render'`. Keep a `text` the site already passes. -**HTTP.** A `fetch` or `axios` call to `https://api.resend.com/emails` becomes `posthog.emails.send` with the camelCase fields: `reply_to` becomes `replyTo`, and the `Idempotency-Key` header becomes `idempotencyKey`. Code that read the response status reads `error` instead. A request with its own deadline, such as `signal: AbortSignal.timeout(5000)` or axios `timeout: 5000`, keeps it: set `emailRequestTimeoutMs` to that value on the client the sends use, and pass `maxRetries: 0` on the send, since the request never retried. posthog-node otherwise waits up to 15 seconds and retries twice, which can run past the site's deadline. The timeout belongs to the client, so each distinct deadline gets its own client, set up as Step 7 says with that `emailRequestTimeoutMs`, and its sites send through it. Sites without a deadline keep the shared client. Never give a site a deadline it didn't have. +**HTTP.** A `fetch` or `axios` call to `https://api.resend.com/emails` becomes `posthog.emails.send` with the camelCase fields: `reply_to` becomes `replyTo`, and the `Idempotency-Key` header becomes `idempotencyKey`. Code that read the response status reads `error` instead. A request with its own deadline, such as `signal: AbortSignal.timeout(5000)` or axios `timeout: 5000`, keeps it: set `emailRequestTimeoutMs` to that value on the client the sends use, and pass `maxRetries: 0` on the send, since the request never retried. posthog-node otherwise waits up to 15 seconds and retries twice, which can run past the site's deadline. The timeout belongs to the client, so each distinct deadline gets its own client, set up as Step 7 says with that `emailRequestTimeoutMs`, and its sites send through it. Sites without a deadline keep the shared client, and with it the SDK's limit: up to 15 seconds per request and two retries with the same idempotency key, so a retry never sends twice, and a send slower than 15 seconds on every try now ends in `network_error` where it used to wait. Never give a site a deadline it didn't have. **Templates made in PostHog.** The site sends `templateId` with the template ID the person gave, and `templateData` with the site's `variables` object. It sends no `templateKey`, `subject`, `html`, `text`, `from`, or `replyTo`: the template holds them. diff --git a/context/skills/migrate-email/references/resend/sdk-reference.md b/context/skills/migrate-email/references/resend/sdk-reference.md index f88d47b29..cb0b72b63 100644 --- a/context/skills/migrate-email/references/resend/sdk-reference.md +++ b/context/skills/migrate-email/references/resend/sdk-reference.md @@ -86,6 +86,12 @@ A send with `template: { id: '...', variables: { PRODUCT: 'Laptop' } }` renders - The template can hold a default `from`, `subject`, and `reply_to`. A value the send passes wins over the default. - A send with `template` passes no `html`, `text`, or `react`. +## Webhooks + +Resend posts each event to an endpoint of the app, signed through Svix. An event has `type`, `created_at`, and `data`, which holds the send's `email_id`, `from`, `to`, `subject`, and `tags`. An email event's `type` is such as `email.sent`, `email.delivered`, `email.delivery_delayed`, `email.bounced`, `email.complained`, `email.opened`, or `email.clicked`. Resend also sends events on contacts and domains. + +Look for routes that read `email_id` or an `email.` event type, `resend.webhooks.verify`, `Webhook` from `svix`, and the `svix-id`, `svix-timestamp`, and `svix-signature` headers. + ## Status reads `resend.emails.get(id)` and `GET https://api.resend.com/emails/{id}` return the email with `last_event`, such as `delivered`, `bounced`, or `complained`. Code that branches on `last_event` reads Resend's delivery state. From eeed7cb8d3058e401050e4b7f01898752f4aef8b Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Fri, 13 Nov 2026 04:54:35 +0000 Subject: [PATCH 65/70] fix(migrate-email): check every error in a rewritten line against its old version Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/8-verify.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 61cb155ba..f377a452d 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -16,7 +16,7 @@ Check that the app still builds, its tests still pass, and one moved email reach ## Build and tests -- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error whose file, code, and message are not in the list Step 7 wrote into the plan, in any file: the rewrite or the posthog-node upgrade caused it. When an error in the list now shows more times than the list says, the extra ones are new too: fix the ones in lines the rewrite changed. Note each file you fix outside the moved sites for the report. An error in that list was there before: note it, and leave it. +- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error whose file, code, and message are not in the list Step 7 wrote into the plan, in any file: the rewrite or the posthog-node upgrade caused it. When an error in the list now shows more times than the list says, the extra ones are new too: fix the ones in lines the rewrite changed. The count can hide a new error, since the rewrite can remove one error and add one just like it, so check every error in a line the rewrite changed, even one the list has: compare the line with its old version in `git diff`, and fix the error unless the old line had it too, such as in a value the rewrite carried over as it was. Note each file you fix outside the moved sites for the report. An error in that list was there before: note it, and leave it. - Run the tests that cover the files you changed. Never delete or skip a test, and never turn a PostHog send back into the provider's request shape to keep an old assertion. - A test of a moved site runs the real `posthog-node` client and intercepts PostHog's send request at the HTTP boundary, as `api.md` describes the request. It asserts on the request PostHog gets and on what the app does, with the same expected values the old test had. A test that intercepted the provider's HTTP requests now intercepts PostHog's. A test that mocked the provider's client, such as `jest.mock('resend')`, drops that mock and becomes such a test too. A test that mocks the app's own email module stays as it is. - The test sets the env variables Step 7's email client reads: any project token and secret key, and the PostHog host the app uses, such as `https://us.i.posthog.com`. Without them the send fails before it makes a request. It intercepts the app host the client sends to, such as `https://us.posthog.com` for that host. A test that answers with a 429 or a 503 answers each of the client's two retries too, which wait about one second, then two. From 77b680b16d708a962410f88d68ed0f37528c52e7 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Fri, 13 Nov 2026 05:07:14 +0000 Subject: [PATCH 66/70] fix(migrate-email): give Step 8 one rule for which typecheck errors are new Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/8-verify.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index f377a452d..0844064af 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -16,7 +16,7 @@ Check that the app still builds, its tests still pass, and one moved email reach ## Build and tests -- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error whose file, code, and message are not in the list Step 7 wrote into the plan, in any file: the rewrite or the posthog-node upgrade caused it. When an error in the list now shows more times than the list says, the extra ones are new too: fix the ones in lines the rewrite changed. The count can hide a new error, since the rewrite can remove one error and add one just like it, so check every error in a line the rewrite changed, even one the list has: compare the line with its old version in `git diff`, and fix the error unless the old line had it too, such as in a value the rewrite carried over as it was. Note each file you fix outside the moved sites for the report. An error in that list was there before: note it, and leave it. +- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error whose file, code, and message are not in the list Step 7 wrote into the plan, in any file: the rewrite or the posthog-node upgrade caused it. An error in a line the rewrite changed is new too, even when the list has it, unless the line's old version in `git diff` had it, such as in a value the rewrite carried over as it was: fix it. When an error in the list still shows more times than the list says, and the changed lines don't explain the extra ones, look for them in the unchanged lines that use what the rewrite changed, such as the send's result, its error, or the client, and fix them there. Note each file you fix outside the moved sites for the report. Every other error in the list was there before: note it, and leave it. - Run the tests that cover the files you changed. Never delete or skip a test, and never turn a PostHog send back into the provider's request shape to keep an old assertion. - A test of a moved site runs the real `posthog-node` client and intercepts PostHog's send request at the HTTP boundary, as `api.md` describes the request. It asserts on the request PostHog gets and on what the app does, with the same expected values the old test had. A test that intercepted the provider's HTTP requests now intercepts PostHog's. A test that mocked the provider's client, such as `jest.mock('resend')`, drops that mock and becomes such a test too. A test that mocks the app's own email module stays as it is. - The test sets the env variables Step 7's email client reads: any project token and secret key, and the PostHog host the app uses, such as `https://us.i.posthog.com`. Without them the send fails before it makes a request. It intercepts the app host the client sends to, such as `https://us.posthog.com` for that host. A test that answers with a 429 or a 503 answers each of the client's two retries too, which wait about one second, then two. From 1d851554192c112f991d802ac9ddc73cdf7266af Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Fri, 13 Nov 2026 05:33:52 +0000 Subject: [PATCH 67/70] fix(migrate-email): tie the kept Resend error names to posthog-node, HTTP sites included Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/resend/mapping.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/resend/mapping.md b/context/skills/migrate-email/references/resend/mapping.md index b529247ca..7dbd35876 100644 --- a/context/skills/migrate-email/references/resend/mapping.md +++ b/context/skills/migrate-email/references/resend/mapping.md @@ -36,7 +36,7 @@ This file decides, field by field, whether PostHog can send a Resend call site. | Code | A site stays on Resend when | |---|---| -| `if (error.name === '...')` | The name is not one of PostHog's: `validation_error`, `missing_api_key`, `invalid_permission`, `not_found`, `concurrent_idempotent_requests`, `invalid_idempotent_request`, `rate_limit_exceeded`, `monthly_quota_exceeded`, `service_unavailable`, `application_error` | +| `if (error.name === '...')` | The name is not one of posthog-node's, which every site that moves sends through, an HTTP site too: PostHog's HTTP API answers with `type` and `code`, and only posthog-node gives these names: `validation_error`, `missing_api_key`, `invalid_permission`, `not_found`, `concurrent_idempotent_requests`, `invalid_idempotent_request`, `rate_limit_exceeded`, `monthly_quota_exceeded`, `service_unavailable`, `application_error` | | `emails.get(id)` and a branch on `last_event` | Always: the send and its status read stay together. PostHog's status is not `last_event` | | `data.id` stored for a webhook or a status read | Always, when Resend webhooks or status reads use the id | From 19b1b90a061960ab7f98172a9c455bf116ab02f6 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Fri, 13 Nov 2026 05:51:31 +0000 Subject: [PATCH 68/70] fix(migrate-email): mark secret emails sensitive, check template keys, and ask before adding an open pixel Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/3-inventory.md | 8 ++++++++ context/skills/migrate-email/references/7-rewrite.md | 5 +++-- context/skills/migrate-email/references/9-report.md | 2 +- context/skills/migrate-email/references/resend/account.md | 4 ++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/context/skills/migrate-email/references/3-inventory.md b/context/skills/migrate-email/references/3-inventory.md index 0cd23e93e..85f2e7c2f 100644 --- a/context/skills/migrate-email/references/3-inventory.md +++ b/context/skills/migrate-email/references/3-inventory.md @@ -55,6 +55,14 @@ A template they move needs its content to be classified. Read the provider's `ac A template whose content passes the checks moves only once the person has made it in PostHog. Ask them once, for every such template, to make it in PostHog from the provider's template and give you its template ID and the address it sends from, usually the provider template's sender. PostHog makes a template transactional only once a verified sender covers its address: ask them to make it transactional now when the project has one, and otherwise once Step 4 verifies the sender. When the email carries a login code, a reset link, or another secret, ask them to mark the template sensitive, as `mapping.md` says. The report lists both before cutover either way. Tell them how its placeholders change, as `mapping.md` says under "Content". Record each template ID with its site under the sites table, and write the address in the site's `from` column, so Step 4 sets up a sender for its domain. A template without an ID stays, and the reason is `PostHog template not made yet`. +### Opens the provider didn't track + +PostHog adds its open pixel to every email it sends, in the code form and from a template made in PostHog alike. Check this for each site that nothing else keeps on the provider, as the provider's `account.md` says: whether the provider tracked the opens of its emails, with an open pixel in each one. + +- When a site's emails had no open pixel, because the provider never tracks opens, or open tracking was off or never set up, ask the person once, for all such sites together, whether PostHog may add its open pixel to emails that never had one. Yes: those sites move, and the report says that PostHog now counts their opens. No, or no answer: they stay, and the reason is `open tracking off`. +- When nobody can tell whether the provider tracked a site's opens, the site stays, and the reason is `open tracking not checked`. +- For each site that moves with the person's yes, write `open pixel added: the person agreed` in its note under the sites table, so the report names it. + ## Write the plan file Write `.posthog-email-migration-plan.md` at the project root with three sections. Never write an email address of a recipient into it. A `from` address is fine. diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index e7794be2e..9d11b5cea 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -66,12 +66,13 @@ PostHog records each send, and its sent, opened and clicked events when engageme For each site that moves, in plan order: - Rewrite the call as the provider's `mapping.md` says, for the site's content form: `html` and `text` content, a component the app renders, or a template made in PostHog. -- Give each send with rendered content a `templateKey` that names the kind of email, such as `welcome` or `password-reset`, with letters, digits, `-`, and `_` only. Two sites that send the same email share a key. +- Give each send with rendered content a `templateKey` that names the kind of email, such as `welcome` or `password-reset`, with letters, digits, `-`, and `_` only. Two sites that send the same email share a key. A send whose key a template saved in PostHog already has goes out through that template's settings, and fails when that template isn't transactional. The PostHog MCP doesn't list template keys, so ask the person once, for all the keys together, whether a template in the project already has any of them, and give each such send another key. +- An email that carries a login code, a reset link, or another secret gets `sensitive: true`. Without it, a send whose key matches a template saved in PostHog takes that template's setting, which is off by default, and PostHog then sends the email's links through its click tracking and puts its subject on engagement events. - A site that moves to a template made in PostHog sends the template ID the person gave in Step 3, never one you guess. - Install `@react-email/render` with the project's package manager when a site renders a component and the app doesn't have it. - Keep the site's idempotency key, error branches, logging, and return value working as before. Keep the code around the send unchanged where you can. - `posthog.emails.send` never throws on an API error: it returns `{ data, error }`. When the old call threw on an error, or the code checked an HTTP status, check `error` so the site fails the same way. -- Never add a field that the old call didn't set, apart from `templateKey`, `templateId`, `distinctId`, and a field the provider's `mapping.md` says to add, such as `maxRetries: 0` on a request that kept its own deadline. `templateData` takes the place of the provider's template variables. +- Never add a field that the old call didn't set, apart from `templateKey`, `templateId`, `distinctId`, `sensitive: true` on an email that carries a secret, and a field the provider's `mapping.md` says to add, such as `maxRetries: 0` on a request that kept its own deadline. `templateData` takes the place of the provider's template variables. When a site turns out to need something `mapping.md` keeps on the provider, undo its change, set `moves` to `no` with the reason, and go on. diff --git a/context/skills/migrate-email/references/9-report.md b/context/skills/migrate-email/references/9-report.md index 3246553f7..47bb4a7a4 100644 --- a/context/skills/migrate-email/references/9-report.md +++ b/context/skills/migrate-email/references/9-report.md @@ -29,7 +29,7 @@ Read `.posthog-email-migration-plan.md`. Write `posthog-migrate-email- ", or "Stays on : ".> - + ## Other calls diff --git a/context/skills/migrate-email/references/resend/account.md b/context/skills/migrate-email/references/resend/account.md index dfee44c48..92eca841b 100644 --- a/context/skills/migrate-email/references/resend/account.md +++ b/context/skills/migrate-email/references/resend/account.md @@ -32,6 +32,10 @@ A site whose template the person moves to PostHog needs the template's content, Read the person's copies where they saved them. An API answer goes only into the temporary file Step 3 writes, which Step 3 deletes once the site is classified. Never write the content into the plan or the report. +## Open tracking + +Resend tracks opens per sending domain, only when open tracking is on for it: Domains, then the domain, then Configuration. Ask the person once, for each sending domain of the sites that move, whether open tracking is on. Off means the site's emails had no open pixel, and no answer means nobody knows whether they had one, as Step 3 says under "Opens the provider didn't track". + ## Suppression list Resend suppresses an address after a hard bounce or a spam complaint, and keeps addresses the team added by hand. From fdea2d3d8d024ea51156e0d8fdf23992b85bf142 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Fri, 13 Nov 2026 05:56:24 +0000 Subject: [PATCH 69/70] fix(migrate-email): send sensitive only with rendered content, and only when posthog-node takes it Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 9d11b5cea..18ae87cf4 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -26,6 +26,7 @@ Install `posthog-node` with the project's package manager when the app doesn't h - a site with `html`, `text`, or a component: `posthog.emails.send` takes `templateKey` with `subject` and `html` or `text`; - a site that sets `replyTo`: the send takes `replyTo`; +- a site with rendered content whose email carries a login code, a reset link, or another secret: the send takes `sensitive`; - the client: the client options take `migratedFrom`. When the latest release lacks one of these, change no site that needs it. Mark each such row `moves: no — posthog-node has no yet`, tell the person, and go on with the rest. When the client options lack `migratedFrom`, leave it out of the client. When no site is left, undo the install or upgrade of `posthog-node`, tick the phase with `none moved`, and go to the next step. @@ -67,12 +68,12 @@ For each site that moves, in plan order: - Rewrite the call as the provider's `mapping.md` says, for the site's content form: `html` and `text` content, a component the app renders, or a template made in PostHog. - Give each send with rendered content a `templateKey` that names the kind of email, such as `welcome` or `password-reset`, with letters, digits, `-`, and `_` only. Two sites that send the same email share a key. A send whose key a template saved in PostHog already has goes out through that template's settings, and fails when that template isn't transactional. The PostHog MCP doesn't list template keys, so ask the person once, for all the keys together, whether a template in the project already has any of them, and give each such send another key. -- An email that carries a login code, a reset link, or another secret gets `sensitive: true`. Without it, a send whose key matches a template saved in PostHog takes that template's setting, which is off by default, and PostHog then sends the email's links through its click tracking and puts its subject on engagement events. +- A send with rendered content whose email carries a login code, a reset link, or another secret gets `sensitive: true`. Without it, a send whose key matches a template saved in PostHog takes that template's setting, which is off by default, and PostHog then sends the email's links through its click tracking and puts its subject on engagement events. A send by `templateId` takes no `sensitive`: PostHog refuses it, and the template made in PostHog holds that setting, as Step 3 asks. - A site that moves to a template made in PostHog sends the template ID the person gave in Step 3, never one you guess. - Install `@react-email/render` with the project's package manager when a site renders a component and the app doesn't have it. - Keep the site's idempotency key, error branches, logging, and return value working as before. Keep the code around the send unchanged where you can. - `posthog.emails.send` never throws on an API error: it returns `{ data, error }`. When the old call threw on an error, or the code checked an HTTP status, check `error` so the site fails the same way. -- Never add a field that the old call didn't set, apart from `templateKey`, `templateId`, `distinctId`, `sensitive: true` on an email that carries a secret, and a field the provider's `mapping.md` says to add, such as `maxRetries: 0` on a request that kept its own deadline. `templateData` takes the place of the provider's template variables. +- Never add a field that the old call didn't set, apart from `templateKey`, `templateId`, `distinctId`, `sensitive: true` on a send with rendered content that carries a secret, and a field the provider's `mapping.md` says to add, such as `maxRetries: 0` on a request that kept its own deadline. `templateData` takes the place of the provider's template variables. When a site turns out to need something `mapping.md` keeps on the provider, undo its change, set `moves` to `no` with the reason, and go on. From 2fe843053f90d4479e96f8e485794efdc0e8acb6 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" <755327+Silthus@users.noreply.github.com> Date: Fri, 13 Nov 2026 06:37:09 +0000 Subject: [PATCH 70/70] fix(migrate-email): check the app's Node version and count removed errors Step 7 now checks the Node.js version the app runs against the engines of the posthog-node release it installs, and keeps every site on Resend when that release doesn't support it: an older Node lacks crypto.randomUUID(), which the send uses for its idempotency key. Step 8 counts a listed error against the list's number less the copies the changed lines no longer have, so an identical error the rewrite adds in an unchanged line is found even when it replaces one it removed. Co-Authored-By: Claude Opus 5.5 --- context/skills/migrate-email/references/7-rewrite.md | 2 ++ context/skills/migrate-email/references/8-verify.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/context/skills/migrate-email/references/7-rewrite.md b/context/skills/migrate-email/references/7-rewrite.md index 18ae87cf4..924ead987 100644 --- a/context/skills/migrate-email/references/7-rewrite.md +++ b/context/skills/migrate-email/references/7-rewrite.md @@ -29,6 +29,8 @@ Install `posthog-node` with the project's package manager when the app doesn't h - a site with rendered content whose email carries a login code, a reset link, or another secret: the send takes `sensitive`; - the client: the client options take `migratedFrom`. +Before you install or upgrade `posthog-node`, check that the app runs on a Node.js version the release you install supports: compare the `engines` field the registry lists for it with the version the app runs in production, from its `engines`, `.nvmrc`, `.node-version`, Dockerfile base image, or hosting config. When you can't tell that version, ask the person. When the release doesn't support it, change no site: an older Node lacks what the client needs, such as `crypto.randomUUID()`, and every send fails. Mark each moving row `moves: no — the app runs Node , which posthog-node doesn't support`, tell the person, tick the phase with `none moved`, and go to the next step. + When the latest release lacks one of these, change no site that needs it. Mark each such row `moves: no — posthog-node has no yet`, tell the person, and go on with the rest. When the client options lack `migratedFrom`, leave it out of the client. When no site is left, undo the install or upgrade of `posthog-node`, tick the phase with `none moved`, and go to the next step. Configure a server-side client of its own for email, also when the app already has a `posthog-node` client: diff --git a/context/skills/migrate-email/references/8-verify.md b/context/skills/migrate-email/references/8-verify.md index 0844064af..aa53a9fe1 100644 --- a/context/skills/migrate-email/references/8-verify.md +++ b/context/skills/migrate-email/references/8-verify.md @@ -16,7 +16,7 @@ Check that the app still builds, its tests still pass, and one moved email reach ## Build and tests -- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error whose file, code, and message are not in the list Step 7 wrote into the plan, in any file: the rewrite or the posthog-node upgrade caused it. An error in a line the rewrite changed is new too, even when the list has it, unless the line's old version in `git diff` had it, such as in a value the rewrite carried over as it was: fix it. When an error in the list still shows more times than the list says, and the changed lines don't explain the extra ones, look for them in the unchanged lines that use what the rewrite changed, such as the send's result, its error, or the client, and fix them there. Note each file you fix outside the moved sites for the report. Every other error in the list was there before: note it, and leave it. +- Run the project's typecheck, such as its `typecheck` script or `tsc --noEmit`, or its build when it has no typecheck. Fix each error whose file, code, and message are not in the list Step 7 wrote into the plan, in any file: the rewrite or the posthog-node upgrade caused it. An error in a line the rewrite changed is new too, even when the list has it, unless the line's old version in `git diff` had it, such as in a value the rewrite carried over as it was: fix it. For each error in the list, take the number of times the list says, less the copies that changed lines had in their old version and no longer have. When the error still shows more times than that, and the changed lines don't explain the extra ones, look for them in the unchanged lines that use what the rewrite changed, such as the send's result, its error, or the client, and fix them there. Note each file you fix outside the moved sites for the report. Every other error in the list was there before: note it, and leave it. - Run the tests that cover the files you changed. Never delete or skip a test, and never turn a PostHog send back into the provider's request shape to keep an old assertion. - A test of a moved site runs the real `posthog-node` client and intercepts PostHog's send request at the HTTP boundary, as `api.md` describes the request. It asserts on the request PostHog gets and on what the app does, with the same expected values the old test had. A test that intercepted the provider's HTTP requests now intercepts PostHog's. A test that mocked the provider's client, such as `jest.mock('resend')`, drops that mock and becomes such a test too. A test that mocks the app's own email module stays as it is. - The test sets the env variables Step 7's email client reads: any project token and secret key, and the PostHog host the app uses, such as `https://us.i.posthog.com`. Without them the send fails before it makes a request. It intercepts the app host the client sends to, such as `https://us.posthog.com` for that host. A test that answers with a 429 or a 503 answers each of the client's two retries too, which wait about one second, then two.