holes.ts 1.1 KB

123456789101112131415161718192021222324
  1. // Holes lower to `__host.hole(siteId, name, prompt ?? void 0, (__src) => eval(__src), body?)`
  2. // (execution-engine.md, "lowering" rows for hole): the evaluator is emitted AT THE SITE so its
  3. // direct eval runs in the hole's lexical scope; a filled hole passes its lowered body as the
  4. // fifth argument and the same body comes back as text in `holeBodies`. Body sites carry the
  5. // hole's own `hole#<hash>/` prefix; the outer ids are the ones a script without the body has.
  6. interface Survey {
  7. slowest: string;
  8. }
  9. interface Plan {
  10. groups: string[][];
  11. }
  12. interface Verdict {
  13. pass: boolean;
  14. }
  15. const survey = await agent("勘察员").ask<Survey>("列出最慢的测试文件");
  16. const plan = await hole<Plan>("决定分组", `最慢的是 ${survey.slowest}`, async () => {
  17. phase("分组");
  18. const draft = await agent("分组员").ask<Plan>(`按模块分组 ${survey.slowest}`);
  19. report({ groups: draft.groups.length });
  20. return draft;
  21. });
  22. const order = await hole<string>("决定顺序");
  23. const done = await agent("执行者").ask<string>(`按 ${plan.groups.length} 组执行,先跑 ${order}`);
  24. return await hole<Verdict>("评判", `执行结果:${done}`);