hole-nested.ts 981 B

1234567891011121314151617181920
  1. // A hole inside a fill: the inner one is open and keyed by its own name like any hole (no outer
  2. // prefix, so ids do not grow with depth); its phase carries `fill=<outer id>` because the outer
  3. // fill wrote it, and it stands in the outer hole's phase, which claims the body's first ask.
  4. // No marker anywhere: the phase vocabulary comes from the holes alone.
  5. interface Survey {
  6. slowest: string;
  7. }
  8. interface Plan {
  9. groups: string[][];
  10. }
  11. interface Order {
  12. first: string;
  13. }
  14. const survey = await agent("勘察员").ask<Survey>("列出最慢的测试文件");
  15. const plan = await hole<Plan>("决定分组", `最慢的是 ${survey.slowest}`, async () => {
  16. const draft = await agent("分组员").ask<Plan>(`先按模块分组 ${survey.slowest}`);
  17. const order = await hole<Order>("决定顺序", `${draft.groups.length} 组,哪组先跑`);
  18. return { groups: [[order.first], ...draft.groups] };
  19. });
  20. return agent("执行者").ask<string>(`按 ${plan.groups.length} 组执行`);