Repository navigation
feat(transactional-email): add a command that sets up the first email send - #1507
Conversation
… send `npx @posthog/wizard transactional-email` runs the context-mill skill omnibus-send-transactional-email: the setup agent checks for a verified sender, writes the project secret API key to the env file, and adds the first send with posthog-node or the HTTP API. The intro spell book of a plain run lists it, and the skill's two [ABORT] reasons end the run with a next step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eanup Import `ProgramConfig` from `@programs/program-contract`, where the services refactor moved it, and take the outro's `exit` step from the skill cleanup in the flow trace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A run of a migrate-email-<provider> skill sets migrated_from, so the setup wizard finished event names the provider. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…migration The tag stayed on the process after the skill changed, so a later skill's events still said the run migrated from the email provider. Every skill change now sets or clears it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both abort cases carry the transactional emails docs link, so the error outro of a matched abort shows where to go next. The test reads the cases through the program's run config, so dropping them from the config fails it. The program sets its binding explicitly, and the added comments go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The program names Pi, the linear sequence and its model, so a change to the default binding no longer moves it off the sequence its abort cases need. The abort test drops a check the type already makes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🧙 Wizard CIRun the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands: Test all apps:
Test all apps in a directory:
Test an individual app:
Show more apps
Test against a Context Mill branch:
Add Results will be posted here when complete. |
The program ran omnibus-send-transactional-email, which no menu publishes. Run sending-transactional-emails, the PostHog/posthog skill that PostHog/context-mill now publishes, and ask for what it sets up: a transactional template in PostHog and its template ID in the report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The setup prompt asked the agent for a transactional template. The sending-transactional-emails skill now keeps the email in the app's code by default and uses a PostHog template only when the person picks it, so the prompt and README say the same. The report names where the email's content lives and its template key or ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he skill The prompt restated the skill's choice between code and a PostHog template. It now lists only what to set up, so the skill alone owns that choice and its default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The skill sends with PostHog's SDK for the backend's language, eight in all, not only Node.js and Python. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ail-program # Conflicts: # src/cli/index.ts # src/programs/program-runner/__tests__/program-registry.test.ts # src/programs/program-runner/program-registry.ts # src/programs/tsconfig.json # src/tui/__tests__/__snapshots__/flow-traces.test.ts.snap
There was a problem hiding this comment.
PostHog Review · Standard · reviewed 04b7915: 1 Must fix.
See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.
A program with abort cases tells its skill to emit '[ABORT] <reason>'. The Pi harness only stopped on the gateway's [posthog:abort], so such a run went on to the success outro. It now ends on the reason, as the Anthropic path does, and the linear sequence shows the matching case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Capture setup wizard finished at a fake posthog-node client instead of reading a mocked setTag. Drop the tests that asserted a mocked runner's arguments and re-ran the abort regexes over the config. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A reply that mentions the marker mid-line no longer ends the run, and each text block is read on its own line, so a block after the [ABORT] line can't run into its reason. Tests pin both, and that a program without abort cases keeps its nudge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After login, every error outro but a security stop went to "The Wizard's a little busy". An agent that stops on [ABORT] made a decision, so its outro, such as "No server code found", now shows with its body and docs link. Found on a live walk of transactional-email. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
✅ Security review complete — No findings above the confidence threshold, in 7 min. Add the |
The command a person types is now `email`: `npx @posthog/wizard@latest email`. The program id, its analytics label and its report file keep the `transactional-email` name, the same way `errors` runs error-tracking. The old word never shipped, so it keeps no alias. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t an unmatched [ABORT] From the final read: the command test now starts the CLI with `email` and checks the transactional email program reaches the TUI, instead of reading the command object. The Pi test's fake finishes its task once Pi asks it to carry on, so the run succeeds only when Pi continues. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The email command (#1507) sets up the first send from code, which is what the question offers. The yes screen now leads with it and keeps the Workflows link as the other way in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sarahxsanders
left a comment
There was a problem hiding this comment.
Two follow-up findings from the local review.
| policyAbort(reply); | ||
| if (remarkTurn || abortReason || !config.abortCases?.length) return; | ||
| const lines = reply.split(/\r?\n/); | ||
| const at = lines.findIndex((text) => /^[\s`*_>]*\[ABORT\]/.test(text)); |
There was a problem hiding this comment.
Pi treats a quoted [ABORT] example as an actual abort, even when the reply says setup succeeded. Skip markers inside blockquotes and fenced code blocks, and add a regression test for the quoted example.
|
|
||
| setSkillId(skillId: string | null): void { | ||
| this.set('skillId', skillId); | ||
| analytics.setTag( |
There was a problem hiding this comment.
setSkillId now parses email migration skill names to derive migrated_from. Derive the provider where the email migration skill is resolved and pass it through as an analytics tag.
Moved from Silthus#1.
Problem
A team that has never sent email from code has no guided way to start with PostHog. Wizard can add PostHog to a project, but the setup agent has no path to send a transactional email, such as a welcome email after signup.
With this PR,
npx @posthog/wizard@latest emailchecks for a verified sender, writes the email in the app's code (or as a PostHog template, when the person picks that), writes the project secret API key to the env file, and adds the first send to the app's server code. A plain run that finds PostHog already installed lists the command in its intro spell book.Part of Silthus/posthog#544.
Merge order
Done up to the last step:
workflows-email-from-codeis at 100%.Warning
🟡 Merge risk: medium · one-way door once a Wizard release publishes the
emailcommand name, a public command that changes people's apps and sends email[ABORT]line, as the Anthropic binding does:audit,migration,revenue-analytics,warehouse-source,warehouse-destination,self-driving,mcp-analytics,web-analytics-doctoranderror-tracking-upload-source-maps. Today Pi ignores that line, and such a run carries on to a nudge, then the success outro or open tasks. Prod shape: every linear Pi abort of these programs in 30 days was a user cancel, and the Anthropic binding of the same programs has not ended a run on a matched[ABORT]since September, so few runs should move. The failure path is a run that prints an[ABORT]line by mistake and now ends on the error outro. A reply to the closing remark question never ends a run.[ABORT]now shows its own outro (message, body, docs link) instead of "The Wizard's a little busy" handoff, on every program and harness. A security stop already did. The run still ends with exit code 1 and analyticserror. Prod shape: in 30 days the only busy handoff after a program's[ABORT]was this PR's own walk; every other busy handoff keeps its screen. The same routing also moves two uncovered rows that never reach an agent: a stop before the run, such as "AI processing approval declined.", and the unsupported-platform stop oferror-tracking,feature-flagsandreplay-vision. They now show their own outro, which names the manual setup docs, instead of the busy handoff, still with exit code 1. Residual incident: cosmetic, a wrong message on a stop that already happened.latestpoints to, so this PR merges on its own.email, and no other command has that name. The program id, analytics label and report file keeptransactional-email. Thecommandanalytics tag is the word typed, so it readsemail; only this PR's proof runs ever senttransactional-email. PostHog/posthog#137730 changes the in-app command block, which is behind its flag, and merges after the Wizard release.queuedwith its message ID and readdeliveredagainst today's send API. The agent run that wrote that code ran on7c9de7e4(2026-11-16): an Express app gets its email code and the key in.envthroughset_env_values, and a frontend-only app ends on "No server code found" before any question. In prod shape, many Wizard runs with a known framework have no server code and take that outro.mainsince7c9de7e4touches none of this PR's files, and the skill package it downloads is byte-identical, but the walk's credentials were revoked, so neither ran again. Residual incident: the same as the uncovered rows below.wizard_ask. Residual incident: the run stops or waits on the person, or the first send answers an error, visible in the run and its report. The key is written only to the app's env file, and a send goes only to an address the person gives after a yes: no row sends silently.[ABORT] transactional email api not enabledoutro reaches no US project today.migrated_fromis a new property on the events of a run whose skill ID ismigrate-email-<provider>,setup wizard finishedincluded. Other runs send the same events as before.[ABORT]handling.Tier: critical (c, f: a Wizard release publishes the command name)
Impact
Moves weekly orgs outside PostHog's own org that send email from code, on the Code-sending orgs by client insight: the Wizard's runs show up as their own client after a release. It rolls up to Workflows revenue through billed
workflows_emails.Changes
transactional-email(src/programs/transactional-email/), built withcreateSkillProgram. It names its binding: Pi, the linear sequence, GPT-5.6 Sol at medium thinking, the same as the default today.email(nativeCommandFactory,src/cli/commands/email.ts), registered inrunCli. It runs thetransactional-emailprogram, the same wayerrorsrunserror-tracking.email Send your first transactional email from code.https://posthog.com/docs/workflows/transactional-emails.[ABORT]handling (src/agent/runner/harness/pi/index.ts,287887f4,226aad62,904543aa): on a program with abort cases, a reply line that starts with[ABORT]ends the linear Pi run with its reason, with no nudge, and the linear sequence shows the matching outro. A reply that only mentions the marker mid-line keeps running, and a reason on the line after a bare marker still counts. The gateway refusal marker keeps its own path and itsgateway_policysource. A reply to the closing remark question is ignored.src/tui/mint-failure.ts,60445c76): an error outro withPHW_AGENT_ABORTor a matched case'sPHW_DETECT_UNSUPPORTED_PLATFORMis a decision, like a security stop, so the TUI shows it instead of the busy handoff.integrations-*sender tools and theworkflows-*email tools. The skill's Wizard section treats a missing tool as inconclusive, sends the person to the PostHog UI to verify a sender, and takes only a send's404as "API not enabled".sending-transactional-emails. Its prompt asks for a verified sender, the email, the project secret API key, and the first send. The skill owns where the email lives: in the app's code by default, or a PostHog template when the person picks that.migrated_fromonsetup wizard finished(src/services/session/session-store.ts): when a run's skill ID ismigrate-email-<provider>, such asmigrate-email-resend, the session sets the analytics tagmigrated_fromto the provider. Every event after the run picks its skill carries it. A later skill, or none, clears it. No new event.The skill's Wizard section is in PostHog/context-mill#456. A test there checks that the built skill emits only the two
[ABORT]reasons this program matches.This revision (2026-11-16,
7c9de7e4):04b79150mergesmain(thesupportcommand landed next to this one),287887f4makes Pi end on a program's[ABORT],b09af2e4replaces tests that read the program's config with tests through the harness and the analytics client, and226aad62and904543aatake only a line that starts with the marker, from round 2 and the final read,60445c76shows an agent's abort on its outro, from the live walk, and7c9de7e4makes the abort tests assert the run's outcome instead of prompt counts.ad984585(2026-11-17) is a signed merge ofmainthat touches none of this PR's files. It brings the orchestrator's repackaged step skills behindwizard-agent-dag-skills, optionalreplacesandframeworkReferencesfields on skill-menu entries, a login fix for a user with no reachable project, andretryTransientwithout its abort-during-backoff handling. Typecheck passes, and the full suite passes except onecli.test.tscase that timed out under load and passes alone. The first send through the code the Wizard wrote was replayed at this head against today's send API: it answeredqueuedwith its message ID and readdelivered.This revision (2026-11-18,
a999ab6e): renames the command a person types fromtransactional-emailtoemail, as Michael asked on the merge card. Only the command word changes:src/cli/commands/email.ts, the program'scommand, and the README. The program id, analytics label, report file and the skill stay the same. The old word never shipped, so it keeps no alias. In the built CLI,wizard email --helpshows the command and the root help listsemail Send your first transactional email from code. Typecheck and lint pass. The full suite passes except six cases that timed out at 5 s under disk load; all of them pass rerun alone with a longer timeout.30ea23c6, from the final read: the command test now starts the CLI withemailand checks that the transactional email program reaches the TUI, and the Pi test of a program without abort cases now succeeds only when Pi carries on past the[ABORT]line. Both fail when the behavior they cover is removed.Test plan
[ABORT](src/agent/runner/harness/pi/__tests__/structured-run.test.ts): a linear Pi run with an open task whose reply holds the line[ABORT] no server code foundreturns an abort with that reason. So does the reason in its own text block, or on the line after a bare[ABORT]. A mid-line mention, or the same line in the remark reply, leaves the run a success. A program without abort cases runs on and returns its open-tasks failure. Each fails without the code it guards.migrated_from(src/services/session/__tests__/migrated-from.test.ts): the test fakesposthog-nodeand reads thesetup wizard finishedevent the analytics client sends. Amigrate-email-resendrun carriesmigrated_from: resend. Amigrate-statsigrun, and a run that moves on frommigrate-email-resendtomigrate-statsigor to no skill, carry none.src/tui/__tests__/router.test.ts): after login, an error outro withPHW_AGENT_ABORTorPHW_DETECT_UNSUPPORTED_PLATFORMresolves to the outro, then the exit once dismissed. Both fail on904543aa.intro-menu.test.ts): the list ends with thetransactional-emailprogram, and the row fits 80 columns.cli.test.ts,program-registry.test.ts):wizard emailstarts the transactional email program in the TUI, and the spell book shows its path asemail.program-registry.test.tspins the linear Pi binding. The flow-traces snapshot records intro, health check, auth, run, and outro for the program.Proofs:
7c9de7e4, Wizard TUI host walks in project 2 through the CI gateway, skill served by the dev server of PostHog/context-mill#456 atb58090a2; no key value in any output):posthog-nodewith aTODOfor a welcome email at signup.src/emails/welcome.jsandsrc/posthog.js, and a send at signup throughposthog.emails.sendwithsecretKey, the template keywelcome, the idempotency keywelcome:<user id>and the user's distinct ID.posthog.emails.getanswereddelivered10 s later, and "Welcome to Notes" is in the PR author's inbox.904543aathis run showed "The Wizard's a little busy";60445c76fixed that.f95c37b1also covered the template path.[ABORT]was this PR's walk; about a third of Wizard runs with a known framework have no server code; most projects have no email sender, no engagement events and no transactional template yet; both API flags are at 100% in US.migrated_fromis one added string property on existing events, which ingestion stores as is.agent abortedwith a matched reason on Pi, by program.Decisions
workflows-email-from-codereaches 100% and the skill is releasedwizard emailrunssending-transactional-emailsfrom PostHog/posthog, published to the menu by PostHog/context-mill#456migrated_fromon the existingsetup wizard finishedevent, from the skill ID, set inSessionStore.setSkillId[ABORT]gap here or in its own PR[ABORT]handling to programs with abort cases[ABORT], in the Pi harness; the shared parser stays as the Anthropic harness uses it. Rejected: changing the shared parserposthog-nodefakeFollow-ups:
linear.tswould let this program drop its per-case links.Involvement: no grilling rounds, no prototypes. Fork reviews: GPT-6.1 Sol rounds and a two-family QA swarm (9 lenses). On
04b79150: ReviewHog and a fleet proof panel (GPT-6.1 Sol correctness, risk, design, systems, sweep, anti-overengineering; Opus 5.5 fresh eyes). It found the Pi[ABORT]gap and tests that read config; both fixed in287887f4andb09af2e4. Round 2 on the fixes (GPT-6.1 Sol correctness, risk, systems; Opus 5.5 fresh eyes): three minor findings and one test rewrite, fixed in226aad62. Two GPT-6.1 Sol final reads: one high finding, fixed in904543aa, then none.LLM context
Written by Claude Code, Claude Opus 5.5 (
claude-opus-5-5), as a build lane of a planning map. Reviews: GPT-6.1 Sol (high) and Claude Opus 5.5 (high) in fleet proof panels, plus ReviewHog.🤖 Generated with Claude Code
How did you test this code?
30ea23c(reused froma999ab6)30ea23c(reused from7c9de7e)04b7915toa999ab630ea23cNot checked: The Wizard agent walk at this head (carried from 2026-11-16, decision d-1d7ac768)
Gaps: judge: The judge's model is out of quota at 30ea23c. At every earlier head the judge failed only on the agent run carried from 16 Nov, which Michael accepted at ad98458. This head renames the CLI word to email and strengthens two tests; the program, its prompt and its skill are unchanged, accepted by a standing rule
Full receipt (PostHog team): https://artifacts.posthog.com/a/d2lamIVrZVkABguvak1qqR