Skip to content

Commit dc145b3

Browse files
authored
Merge pull request #8547 from loopx-project/codex/guided-start-preview-rpc-20261111
2 parents cb5a49d + 04996fd commit dc145b3

7 files changed

Lines changed: 296 additions & 205 deletions

File tree

‎loopx/bootstrap_command_pack.py‎

Lines changed: 3 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,18 @@
1414
ISSUE_FIX_GOAL_CANDIDATE_DISCOVERY_COMMAND_TEMPLATE,
1515
build_issue_fix_goal_command_templates,
1616
)
17-
from .control_plane.effect_program import effect_program_from_ordered_steps
1817
from .control_plane.goals.orphaned_goal_state import (
1918
ORPHANED_GOAL_STATE_CONNECTION,
2019
absent_goal_connection,
2120
fence_command_pack,
2221
fenced_standalone_message,
2322
guided_fence,
24-
render_guided_lines,
2523
)
2624
from .control_plane.goals.start_contract import (
2725
build_goal_start_contract,
2826
build_goal_start_prompt,
2927
)
3028
from .control_plane.goals.start_goal_todo_delta import (
31-
append_todo_delta_render_line,
3229
existing_runnable_agent_frontier,
3330
todo_authoring_steps,
3431
)
@@ -41,6 +38,9 @@
4138
scheduler_command_binding_for_agent_type,
4239
)
4340
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+
)
4444
from .project_alias import resolve_canonical_project_alias
4545
from .project_prompt import (
4646
DEFAULT_HANDOFF_ADAPTER_KIND,
@@ -1762,175 +1762,6 @@ def rerun_start_goal(selected_agent_id: str) -> str:
17621762
return payload
17631763

17641764

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-
19341765
def render_loopx_bootstrap_command_pack_message(payload: dict[str, Any]) -> str:
19351766
connection = payload.get("project_connection")
19361767
connection = connection if isinstance(connection, dict) else {}

‎loopx/control_plane/effect_program.py‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -802,19 +802,20 @@ def effect_program_from_ordered_steps(
802802
ordered_steps: Sequence[Mapping[str, Any]],
803803
*,
804804
execution_mode: str | None = None,
805+
include_raw: bool = True,
805806
) -> EffectProgram:
806-
"""Map existing `guided_transaction.ordered_steps` onto an effect program."""
807-
808-
payload = effect_runtime_result(
809-
"effect.program_from_ordered_steps",
810-
{
811-
"ordered_steps": [
812-
dict(step) if isinstance(step, Mapping) else step
813-
for step in ordered_steps
814-
],
815-
"execution_mode": execution_mode,
816-
},
817-
)
807+
"""Map ordered steps onto an effect program, including source fields by default."""
808+
809+
params: dict[str, object] = {
810+
"ordered_steps": [
811+
dict(step) if isinstance(step, Mapping) else step
812+
for step in ordered_steps
813+
],
814+
"execution_mode": execution_mode,
815+
}
816+
if not include_raw:
817+
params["include_raw"] = False
818+
payload = effect_runtime_result("effect.program_from_ordered_steps", params)
818819
if not isinstance(payload, Mapping) or not isinstance(payload.get("steps"), list):
819820
raise RuntimeError("TypeScript Effect Program shape mismatch")
820821
steps = tuple(

‎loopx/control_plane/effect_program.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ function requireFailureKind(value: unknown): SettlementFailureKind {
298298
export function effectProgramFromOrderedSteps(
299299
orderedSteps: unknown,
300300
executionMode: unknown = null,
301+
includeRaw = true,
301302
): EffectProgram {
302303
const steps: EffectStep[] = [];
303304
if (Array.isArray(orderedSteps)) {
@@ -317,7 +318,7 @@ export function effectProgramFromOrderedSteps(
317318
kind: nullableTruthyString(step.kind),
318319
command: nullableTruthyString(commandValue),
319320
purpose: nullableTruthyString(step.purpose),
320-
raw: { ...step },
321+
raw: includeRaw ? { ...step } : {},
321322
});
322323
}
323324
}

‎loopx/control_plane/effect_runtime_handlers.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import { EffectRuntimeRequestError } from "./effect_runtime_errors.ts";
2929
import {
3030
optionalNonEmptyString as optionalString,
31+
requireBoolean,
3132
requireJsonObject as requiredObject,
3233
requireNonEmptyString as requiredString,
3334
requireStringLiteral,
@@ -485,6 +486,9 @@ export function createEffectRuntimeHandlers(
485486
(params) => effectProgramFromOrderedSteps(
486487
Array.isArray(params.ordered_steps) ? params.ordered_steps : [],
487488
typeof params.execution_mode === "string" ? params.execution_mode : null,
489+
Object.hasOwn(params, "include_raw")
490+
? requireBoolean(params.include_raw, "include_raw")
491+
: true,
488492
),
489493
],
490494
[

0 commit comments

Comments
 (0)