Fill the shared core template's per-platform slots for this platform. The template is authored once in POSIX shell; a ``shell = "powershell"`` platform gets the same composed body translated to strict PowerShell (see ``_core_to_powershell``), so the two variants cannot drift apart.
(platform: Platform)
| 566 | |
| 567 | |
| 568 | def _render_core(platform: Platform) -> str: |
| 569 | """Fill the shared core template's per-platform slots for this platform. |
| 570 | |
| 571 | The template is authored once in POSIX shell; a ``shell = "powershell"`` |
| 572 | platform gets the same composed body translated to strict PowerShell (see |
| 573 | ``_core_to_powershell``), so the two variants cannot drift apart. |
| 574 | """ |
| 575 | template = _read_fragment(f"core/{platform.core}.md") |
| 576 | |
| 577 | if platform.dispatch is None: |
| 578 | raise ValueError(f"split platform '{platform.key}' is missing a dispatch variant") |
| 579 | |
| 580 | install = _read_fragment(f"shell/{platform.shell}.md").rstrip("\n") |
| 581 | interp_guard = _read_fragment(f"shell/interpreter-guard-{platform.shell}.md").rstrip("\n") |
| 582 | dispatch = _read_fragment(f"dispatch/{platform.dispatch}.md").rstrip("\n") |
| 583 | query_stub = _read_fragment(_QUERY_STUB).rstrip("\n") |
| 584 | writer_agent, writer_agent_arg = _WRITER_AGENT.get(platform.dispatch, _DEFAULT_WRITER_AGENT) |
| 585 | |
| 586 | if platform.extra_sections: |
| 587 | extra = "".join( |
| 588 | _read_fragment(f"extra/{name}.md").rstrip("\n") + "\n\n" |
| 589 | for name in platform.extra_sections |
| 590 | ) |
| 591 | else: |
| 592 | extra = "" |
| 593 | |
| 594 | body = ( |
| 595 | template.replace("@@FRONTMATTER@@", _render_frontmatter(platform)) |
| 596 | .replace("@@INSTALL@@", install) |
| 597 | .replace("@@INTERP_GUARD@@", interp_guard) |
| 598 | .replace("@@DISPATCH@@", dispatch) |
| 599 | .replace("@@WRITER_AGENT@@", writer_agent) |
| 600 | .replace("@@WRITER_AGENT_ARG@@", writer_agent_arg) |
| 601 | .replace("@@QUERY_STUB@@", query_stub) |
| 602 | .replace("@@HOOKS_TARGET@@", platform.hooks_target) |
| 603 | .replace("@@EXTRA@@", extra) |
| 604 | ) |
| 605 | if "@@" in body: |
| 606 | leftover = sorted(set(re.findall(r"@@\w+@@", body))) |
| 607 | raise ValueError(f"unfilled core slots for '{platform.key}': {leftover}") |
| 608 | if platform.shell == "powershell": |
| 609 | body = _core_to_powershell(body) |
| 610 | return _normalise(body) |
| 611 | |
| 612 | |
| 613 | def _render_agents_md_hooks(platform: Platform) -> str: |
no test coverage detected