Skip to content

SWI-11363 feat(server): capture customer TwiML for standalone BXML generation#18

Merged
kshahbw merged 2 commits into
mainfrom
adapter/live-capture
Jul 22, 2026
Merged

SWI-11363 feat(server): capture customer TwiML for standalone BXML generation#18
kshahbw merged 2 commits into
mainfrom
adapter/live-capture

Conversation

@kshahbw

@kshahbw kshahbw commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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. Point npm run generate at 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 generate could only flag them for manual capture. The adapter now produces the capture files generate ingests — no new plumbing, just a tap at the one point in fetchAndTranslate where the raw customer TwiML already lives (URLs verbatim, pre-rewrite).

Design notes

  • Content-addressed filenames (sha256 slice), never request input — identical responses dedupe to one file, and untrusted input never participates in filesystem addressing (same guardrail as scripts/capture-server.mjs).
  • Private by default — dir 0700, file 0600; raw TwiML can carry tokenized callback URLs.
  • Verbatim — stored exactly as received, so captures feed straight into generate.
  • Synchronous I/O is deliberate — opt-in, test-call-volume eval on local disk; serial writes keep the dedup check race-free. Documented in capture.ts.
  • Off by default — no behavior change unless ADAPTER_CAPTURE_DIR is 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

  • 10 new tests (unit + server integration): verbatim content, private modes, dedup, correct artifact (raw TwiML not translated BXML, URLs un-rewritten), and a regression test proving a failed capture still serves the call.
  • Full suite: 303 pass; typecheck clean.
  • End-to-end verified: captured TwiML via the adapter, ran the real generate CLI 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.

kshahbw added 2 commits July 17, 2026 12:01
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.
@kshahbw
kshahbw requested review from a team as code owners July 17, 2026 19:19
@bwappsec

bwappsec commented Jul 17, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@kshahbw kshahbw changed the title feat(server): capture customer TwiML for standalone BXML generation SWI-11363 feat(server): capture customer TwiML for standalone BXML generation Jul 20, 2026
@kshahbw
kshahbw merged commit 54186a5 into main Jul 22, 2026
6 checks passed
@kshahbw
kshahbw deleted the adapter/live-capture branch July 22, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants