reentrant-then-composition.ts 588 B

12345678910
  1. // Positive guard (already holds): a callback passed to unknown `.then` whose body calls
  2. // another unknown `.then` with a further callback (reentrant HOF composition). The inner
  3. // editor ask receives the outer draft via captured-parameter placeholder resolution.
  4. // Expected: source -> ask#1 (writer), ask#1 -> ask#2 (editor, INEXACT via the unknown-call
  5. // keystone widening), ask#2 -> sink.
  6. const draft = agent("writer").ask<string>("draft");
  7. const out = await draft.then((text) =>
  8. Promise.resolve(text).then((inner) => agent("editor").ask<string>(`edit ${inner}`)),
  9. );
  10. return out;