SWI-11363 feat(server): capture customer TwiML for standalone BXML generation#18
Merged
Conversation
Add opt-in ADAPTER_CAPTURE_DIR: when set, the live adapter persists each customer TwiML response verbatim (content-addressed, deduped) as it proxies a call. Feeding that dir to `npm run generate` turns the paths a test call actually exercised into standalone BXML. This closes the previously documented-but-unimplemented SDK path: apps that build TwiML at runtime have no static markup to transpile, so generate could only flag them for manual capture. The adapter now produces the capture files generate ingests. Filenames derive from a content hash, never request input, matching the existing filesystem-addressing guardrail.
- Write captures private-by-default (dir 0700, file 0600); raw TwiML can carry tokenized callback URLs. - Store TwiML verbatim (drop appended newline) so file content matches the hashed bytes and the stated contract. - Document the deliberate synchronous-I/O tradeoff (opt-in, test-volume, local disk; serial writes keep dedup race-free). - Tests: assert verbatim content + private modes; add a regression test proving a failed capture still serves the call.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
joshraub-bw
approved these changes
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Adds an opt-in
ADAPTER_CAPTURE_DIR. When set, the live adapter persists each customer TwiML response verbatim as it proxies a call. Pointnpm run generateat that dir afterward and you get standalone BXML for exactly the paths a test call exercised.This closes a documented-but-unimplemented gap: apps that build TwiML at runtime via the Twilio SDK have no static markup to transpile, so
generatecould only flag them for manual capture. The adapter now produces the capture filesgenerateingests — no new plumbing, just a tap at the one point infetchAndTranslatewhere the raw customer TwiML already lives (URLs verbatim, pre-rewrite).Design notes
scripts/capture-server.mjs).0700, file0600; raw TwiML can carry tokenized callback URLs.generate.capture.ts.ADAPTER_CAPTURE_DIRis set. Capture failures are logged and never fail the live call.Caveat (kept honest in docs)
Capture only covers paths a test call actually exercises — branches you never dial won't appear. There's no completeness check; drive every flow you care about or port the rest by hand.
Testing
generateCLI over the dir, confirmed standalone BXML with URLs preserved verbatim.Review
Codex reviewed the diff: confirmed path construction is traversal-safe and the capture point is correct. Its permissions, verbatim, and missing-failure-test findings are folded in; the sync-I/O note was a deliberate keep.