(body_steps: list, body_prev: Optional[int])
| 425 | |
| 426 | # ---------- Recursive body-step parser ---------- |
| 427 | def parse_body_steps(body_steps: list, body_prev: Optional[int]) -> tuple: |
| 428 | bf: Optional[int] = None |
| 429 | extra_tails: list[int] = [] |
| 430 | |
| 431 | def link_to(new_id: int) -> None: |
| 432 | nonlocal extra_tails |
| 433 | add_seq(body_prev, new_id) |
| 434 | if extra_tails: |
| 435 | for tail_id in list(dict.fromkeys(extra_tails)): |
| 436 | add_seq(tail_id, new_id) |
| 437 | extra_tails = [] |
| 438 | |
| 439 | for bs in body_steps: |
| 440 | bk = list(bs.keys())[0] |
| 441 | bd = bs[bk] |
| 442 | |
| 443 | if bk in ("step", "task", "synthesize", "discover"): |
| 444 | bid = alloc_id() |
| 445 | bname = bd.get("name", f"{bk}_{bid}") |
| 446 | binstr = bd.get("instruction", "") |
| 447 | bsave = bd.get("save_as", None) |
| 448 | # `discover` also reads from a `from` expression in the old YAML |
| 449 | # form; include its template vars for backward compatibility. |
| 450 | extra = bd.get("from", "") if bk == "discover" else "" |
| 451 | breads = build_reads( |
| 452 | sorted(set(extract_template_vars(binstr) + extract_template_vars(extra))) |
| 453 | ) |
| 454 | bwrites: list[TypedVar] = [] |
| 455 | if bsave: |
| 456 | bwt = determine_write_type(yaml_key_to_step_type(bk)) |
| 457 | bwrites.append(TypedVar(bsave, bwt)) |
| 458 | type_ctx[bsave] = bwt |
| 459 | nodes.append(NodeIR( |
| 460 | id=bid, name=bname, step_type=yaml_key_to_step_type(bk), |
| 461 | reads=breads, writes=bwrites, |
| 462 | instruction=binstr if binstr else None, |
| 463 | )) |
| 464 | link_to(bid) |
| 465 | if bf is None: bf = bid |
| 466 | body_prev = bid |
| 467 | |
| 468 | elif bk == "set_variable": |
| 469 | bid = alloc_id() |
| 470 | bvar = bd["name"] |
| 471 | raw_val = bd.get("value", "") |
| 472 | bval = str(raw_val) |
| 473 | breads = build_reads(extract_template_vars(bval)) |
| 474 | bwt = _infer_set_variable_type(raw_val, type_ctx) |
| 475 | bwrites = [TypedVar(bvar, bwt)] |
| 476 | type_ctx[bvar] = bwt |
| 477 | nodes.append(NodeIR( |
| 478 | id=bid, name=f"set_{bvar}", step_type="setVariable", |
| 479 | reads=breads, writes=bwrites, |
| 480 | )) |
| 481 | link_to(bid) |
| 482 | if bf is None: bf = bid |
| 483 | body_prev = bid |
| 484 |
no test coverage detected