|
14 | 14 | ISSUE_FIX_GOAL_CANDIDATE_DISCOVERY_COMMAND_TEMPLATE, |
15 | 15 | build_issue_fix_goal_command_templates, |
16 | 16 | ) |
17 | | -from .control_plane.effect_program import effect_program_from_ordered_steps |
18 | 17 | from .control_plane.goals.orphaned_goal_state import ( |
19 | 18 | ORPHANED_GOAL_STATE_CONNECTION, |
20 | 19 | absent_goal_connection, |
21 | 20 | fence_command_pack, |
22 | 21 | fenced_standalone_message, |
23 | 22 | guided_fence, |
24 | | - render_guided_lines, |
25 | 23 | ) |
26 | 24 | from .control_plane.goals.start_contract import ( |
27 | 25 | build_goal_start_contract, |
28 | 26 | build_goal_start_prompt, |
29 | 27 | ) |
30 | 28 | from .control_plane.goals.start_goal_todo_delta import ( |
31 | | - append_todo_delta_render_line, |
32 | 29 | existing_runnable_agent_frontier, |
33 | 30 | todo_authoring_steps, |
34 | 31 | ) |
|
41 | 38 | scheduler_command_binding_for_agent_type, |
42 | 39 | ) |
43 | 40 | from .history import load_registry |
| 41 | +from .presentation.renderers.start_goal_markdown import ( |
| 42 | + render_start_goal_guided_markdown as render_start_goal_guided_markdown, |
| 43 | +) |
44 | 44 | from .project_alias import resolve_canonical_project_alias |
45 | 45 | from .project_prompt import ( |
46 | 46 | DEFAULT_HANDOFF_ADAPTER_KIND, |
@@ -1762,175 +1762,6 @@ def rerun_start_goal(selected_agent_id: str) -> str: |
1762 | 1762 | return payload |
1763 | 1763 |
|
1764 | 1764 |
|
1765 | | -def render_start_goal_guided_markdown(payload: dict[str, Any]) -> str: |
1766 | | - def command_summary(value: Any) -> str: |
1767 | | - parts = str(value or "").split() |
1768 | | - return " ".join(parts[:3]) + (" ..." if len(parts) > 3 else "") |
1769 | | - |
1770 | | - def actionable_shell_command(value: Any) -> str: |
1771 | | - lines = [ |
1772 | | - line.removesuffix("\\").strip() |
1773 | | - for line in str(value or "").splitlines() |
1774 | | - if line.strip() |
1775 | | - ] |
1776 | | - if len(lines) > 1 and lines[0].startswith("cd "): |
1777 | | - return f"{lines[0]} && {' '.join(lines[1:])}" |
1778 | | - return " ".join(lines) |
1779 | | - |
1780 | | - transaction = payload.get("guided_transaction") |
1781 | | - transaction = transaction if isinstance(transaction, dict) else {} |
1782 | | - command_pack = payload.get("command_pack") |
1783 | | - command_pack = command_pack if isinstance(command_pack, dict) else {} |
1784 | | - commands = command_pack.get("commands") |
1785 | | - commands = commands if isinstance(commands, dict) else {} |
1786 | | - selected_route = transaction.get("selected_capability_route") |
1787 | | - selected_route = selected_route if isinstance(selected_route, dict) else {} |
1788 | | - ordered_steps = transaction.get("ordered_steps") |
1789 | | - ordered_steps = ordered_steps if isinstance(ordered_steps, list) else [] |
1790 | | - program = effect_program_from_ordered_steps(ordered_steps) |
1791 | | - step_lines: list[str] = [] |
1792 | | - for index, step in enumerate(program.steps, start=1): |
1793 | | - raw_step = step.raw |
1794 | | - command = ( |
1795 | | - step.command |
1796 | | - or raw_step.get("command_source") |
1797 | | - or raw_step.get("prompt") |
1798 | | - ) |
1799 | | - if step.kind == "capability_guard": |
1800 | | - entry_key = str(selected_route.get("entry_command_key") or "") |
1801 | | - admission_key = str(selected_route.get("admission_command_key") or "") |
1802 | | - entry_command = commands.get(entry_key) |
1803 | | - admission_command = commands.get(admission_key) |
1804 | | - discovery_command = raw_step.get("candidate_discovery_command_template") |
1805 | | - authority = ( |
1806 | | - "open public issue; source clues are evidence only" |
1807 | | - if raw_step.get("candidate_authority") == "public_open_tracker_issue" |
1808 | | - else raw_step.get("candidate_authority") |
1809 | | - ) |
1810 | | - step_lines.extend( |
1811 | | - [ |
1812 | | - f"{index}. `{step.step_id}` ({step.kind})", |
1813 | | - f" - authority: {authority}", |
1814 | | - ] |
1815 | | - ) |
1816 | | - if discovery_command: |
1817 | | - step_lines.append( |
1818 | | - f" - discover: `{str(discovery_command).splitlines()[0]}`" |
1819 | | - ) |
1820 | | - preflight = raw_step.get("candidate_preflight") |
1821 | | - if isinstance(preflight, dict): |
1822 | | - required_evidence = " + ".join( |
1823 | | - str(field) |
1824 | | - for field in preflight.get("required_evidence_fields") or [] |
1825 | | - ) |
1826 | | - step_lines.append( |
1827 | | - " - preflight: refresh " |
1828 | | - f"{raw_step.get('authority_refresh_required')}; " |
1829 | | - f"provide {required_evidence}; " |
1830 | | - f"{preflight.get('decision_rule')}" |
1831 | | - ) |
1832 | | - step_lines.extend( |
1833 | | - [ |
1834 | | - f" - qualify: `{command_summary(entry_command)}`", |
1835 | | - f" - proceed: `{command_summary(admission_command)}`", |
1836 | | - ] |
1837 | | - ) |
1838 | | - continue |
1839 | | - step_label = f"{index}. `{step.step_id}` ({step.kind}): " |
1840 | | - step_lines.append(step_label + str(step.purpose)) |
1841 | | - append_todo_delta_render_line(raw_step, step_lines) |
1842 | | - if command: |
1843 | | - rendered_command = ( |
1844 | | - actionable_shell_command(command) |
1845 | | - if step.step_id == "connect_if_needed" |
1846 | | - else str(command).splitlines()[0] |
1847 | | - ) |
1848 | | - step_lines.append(f" - `{rendered_command}`") |
1849 | | - preserve = transaction.get("preserve_todos_policy") |
1850 | | - preserve = preserve if isinstance(preserve, dict) else {} |
1851 | | - identity_gate = transaction.get("identity_selection_gate") |
1852 | | - identity_gate = identity_gate if isinstance(identity_gate, dict) else {} |
1853 | | - identity_gate_lines = "" |
1854 | | - if identity_gate: |
1855 | | - fresh_registration = identity_gate.get("fresh_agent_registration") |
1856 | | - fresh_lines = [] |
1857 | | - if isinstance(fresh_registration, dict): |
1858 | | - fresh_lines = [ |
1859 | | - "- **default: register a fresh agent**", |
1860 | | - f" - preview: `{fresh_registration.get('preview_command')}`", |
1861 | | - f" - apply: `{fresh_registration.get('execute_command')}`", |
1862 | | - ( |
1863 | | - " - rerun: " |
1864 | | - f"`{fresh_registration.get('rerun_start_goal_command')}`" |
1865 | | - ), |
1866 | | - ] |
1867 | | - choices = [ |
1868 | | - f"- explicit takeover `{choice.get('agent_id')}`: " |
1869 | | - f"`{choice.get('rerun_start_goal_command')}`" |
1870 | | - for choice in identity_gate.get("choices") or [] |
1871 | | - if isinstance(choice, dict) |
1872 | | - ] |
1873 | | - identity_gate_lines = ( |
1874 | | - "\n## Agent Identity Gate\n\n" |
1875 | | - f"{identity_gate.get('reason')}\n\n" |
1876 | | - + "\n".join([*fresh_lines, *choices]) |
1877 | | - + "\n" |
1878 | | - ) |
1879 | | - goal_gate = transaction.get("goal_selection_gate") |
1880 | | - goal_gate = goal_gate if isinstance(goal_gate, dict) else {} |
1881 | | - goal_gate_lines = "" |
1882 | | - if goal_gate: |
1883 | | - choices = [ |
1884 | | - f"- `{choice.get('goal_id')}` status=`{choice.get('status')}`: " |
1885 | | - f"`{choice.get('rerun_command')}`" |
1886 | | - for choice in goal_gate.get("choices") or [] |
1887 | | - if isinstance(choice, dict) |
1888 | | - ] |
1889 | | - goal_gate_lines = ( |
1890 | | - "\n## Goal Selection Gate\n\n" |
1891 | | - f"{goal_gate.get('reason')}\n\n" |
1892 | | - + "\n".join(choices) |
1893 | | - + "\n" |
1894 | | - ) |
1895 | | - orphan_gate_lines = render_guided_lines(transaction) |
1896 | | - host_gate = transaction.get("host_surface_selection_gate") |
1897 | | - host_gate = host_gate if isinstance(host_gate, dict) else {} |
1898 | | - host_gate_lines = "" |
1899 | | - if host_gate: |
1900 | | - choices = [ |
1901 | | - f"- `{choice.get('host_surface')}`: {choice.get('description')} " |
1902 | | - f"\n `{choice.get('rerun_command')}`" |
1903 | | - for choice in host_gate.get("choices") or [] |
1904 | | - if isinstance(choice, dict) |
1905 | | - ] |
1906 | | - host_gate_lines = ( |
1907 | | - "\n## Host Surface Gate\n\n" |
1908 | | - f"{host_gate.get('reason')}\n\n" |
1909 | | - + "\n".join(choices) |
1910 | | - + "\n" |
1911 | | - ) |
1912 | | - return f"""# Guided Start Goal |
1913 | | -
|
1914 | | -- project: `{payload.get("project")}` |
1915 | | -- goal_id: `{payload.get("goal_id")}` |
1916 | | -- goal_text: `{payload.get("goal_text")}` |
1917 | | -
|
1918 | | -Preview only; follow ordered commands to mutate. |
1919 | | -
|
1920 | | -## Ordered Transaction |
1921 | | -
|
1922 | | -{chr(10).join(step_lines)} |
1923 | | -{host_gate_lines} |
1924 | | -{goal_gate_lines} |
1925 | | -{orphan_gate_lines} |
1926 | | -{identity_gate_lines} |
1927 | | -
|
1928 | | -## Todo Preservation |
1929 | | -
|
1930 | | -- bootstrap: `{preserve.get("force_bootstrap_default")}`; reconnect: {preserve.get("before_destructive_reconnect")}; scope change: {preserve.get("preferred_scope_change")} |
1931 | | -""" |
1932 | | - |
1933 | | - |
1934 | 1765 | def render_loopx_bootstrap_command_pack_message(payload: dict[str, Any]) -> str: |
1935 | 1766 | connection = payload.get("project_connection") |
1936 | 1767 | connection = connection if isinstance(connection, dict) else {} |
|
0 commit comments