interpolated-actor-name.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Actor names the script INTERPOLATES: `agent()` gets a template literal, so the
  2. // literal test in `actorName` misses and the lane would read "Anonymous Agent" even
  3. // though the script plainly said something. The analysis extracts the template's static
  4. // affixes instead — see docs/analysis.md, "Labels and names".
  5. //
  6. // Every receiver here is INLINE on purpose. `actorName` falls back to the binding name
  7. // when the call initializes a `const`, which is a real name and must keep winning; only
  8. // an inline receiver leaves the pattern as the sole thing available. Inline is also the
  9. // one shape `askLabel` answers "ask" for (a receiver that is neither literal nor
  10. // identifier), so each step pins `label-head=`/`label-tail=` alongside the lane's.
  11. //
  12. // All five outcomes in one fixture, in lane order:
  13. // actor#1 head only `研究员${i + 1}` -> head="研究员"
  14. // actor#2 tail only `${role}-worker` -> tail="-worker"
  15. // actor#3 head and tail `a${x}b` -> head="a", tail="b"
  16. // actor#4 middle dropped `pre${x}mid${y}post` -> head="pre", tail="post"
  17. // actor#5 affix trims away ` ${x}` -> no pattern at all
  18. // actor#6 punctuation only `${x}-` -> no pattern (`…-` is worse
  19. // than the anonymous fallback)
  20. const role = "night";
  21. const x = 1;
  22. const y = 2;
  23. const drafts = await Promise.all(
  24. [1, 2, 3].map((i) => agent(`研究员${i + 1}`).ask<string>(`draft section ${i}`)),
  25. );
  26. const a = await agent(`${role}-worker`).ask<string>(`take the night shift: ${drafts.join()}`);
  27. const b = await agent(`a${x}b`).ask<string>(`wrap ${a}`);
  28. const c = await agent(`pre${x}mid${y}post`).ask<string>(`extend ${b}`);
  29. const d = await agent(` ${x}`).ask<string>(`review ${c}`);
  30. const e = await agent(`${x}-`).ask<string>(`sign off on ${d}`);
  31. return e;