Skip to content

The agent that grows with you

fix(onboarding): option clicks keep their label; a layout in words goes through set_theme

alt-glitch88f8e115f99d
diff --git a/agent/onboarding_flow.py b/agent/onboarding_flow.py
index d3a7ebd4345..b6c8ce722f3 100644
--- a/agent/onboarding_flow.py
+++ b/agent/onboarding_flow.py
@@ -247,8 +247,12 @@ def _is_names(value: Any) -> bool:
def valid_answer(beat: str, answer: Mapping[str, Any], facts: Facts, picks: Mapping[str, Any]) -> bool:
- """A card answer carries only its beat's pick keys, with ids from the card's own options."""
+ """A card answer carries only its beat's pick keys, with ids from the card's own options. ``label``
+ is the text the card showed, kept for the transcript and never recorded."""
spec = BEAT_BY_ID[beat]
+ if not isinstance(answer.get("label", ""), str):
+ return False
+ answer = {key: value for key, value in answer.items() if key != "label"}
if not answer or not set(answer) <= set(spec.picks):
return False
if spec.values is not None:
@@ -282,8 +286,16 @@ def _timed_out(record: dict, event: TimedOut, facts: Facts, now: float) -> Step:
return Step(record, {"beat": event.beat, "timed_out": True}, "timed_out")
+# Beats a general tool applies; their result settles the beat, so a value given in words would only
+# record a pick that never reaches the screen.
+APPLIED_BY = {"theme": "set_theme", "layout": "set_theme"}
+
+
def _recorded(record: dict, event: Recorded, facts: Facts, now: float) -> Step:
beat = BEAT_BY_ID[event.beat]
+ if tool := APPLIED_BY.get(event.beat):
+ return Step(record, {"error": f"Apply the {event.beat} with {tool}; its result settles this beat.",
+ "next": _next_field(record)})
accepted = beat.values(facts, record["picks"]) if beat.values else None
if accepted is not None and event.value not in accepted:
return Step(record, {"error": f"value for {event.beat} must be one of: {', '.join(accepted)}.",
diff --git a/agent/onboarding_text.py b/agent/onboarding_text.py
index a335f98e434..92ce55ab747 100644
--- a/agent/onboarding_text.py
+++ b/agent/onboarding_text.py
@@ -104,7 +104,7 @@ _LOOK_AROUND = (
_TYPED_ANSWER = {
"name": 'setup_beat(beat="name", value="<their name>")',
"theme": _SET_THEME.replace('"accent":"Ultraviolet"', '"accent":"<colour>"'),
- "layout": 'setup_beat(beat="layout", value="sidebar-left" or "terminal-deck")',
+ "layout": 'tool_call {"calls":[{"name":"set_theme","arguments":{"layout":"sidebar-left" or "terminal-deck"}}]}',
"connectors": 'setup_beat(beat="connectors", value="continue") for "done" or "continue", skip=true for "skip"',
"plugins": 'setup_beat(beat="plugins", value="continue") for "done" or "continue", skip=true for "skip"',
"tour": 'setup_beat(beat="tour", value="quick", "full" or "skip"), bucketing their words into one of the three',
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.ts
index 051eff3e8f0..d2292a3d438 100644
--- a/apps/shared/src/gateway-contract.generated.ts
+++ b/apps/shared/src/gateway-contract.generated.ts
@@ -4603,12 +4603,15 @@ export interface SetupConnectorsAnswer {
}
export interface SetupPluginsAnswer {
installed: string[]
+ label?: string | null
}
export interface SetupTourAnswer {
tour: string
+ label?: string | null
}
export interface SetupBuildAnswer {
build: string
+ label?: string | null
}
/** ``tui_gateway/server.py::_approval_request_payload`` — the command is redacted server-side. */
export interface ApprovalRequestParams {
diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.json
index 5024228e8e2..8174177075d 100644
--- a/apps/shared/src/gateway-contract.openrpc.json
+++ b/apps/shared/src/gateway-contract.openrpc.json
@@ -33625,6 +33625,18 @@
"build": {
"title": "Build",
"type": "string"
+ },
+ "label": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Label"
}
},
"required": [
@@ -33925,6 +33937,18 @@
},
"title": "Installed",
"type": "array"
+ },
+ "label": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Label"
}
},
"required": [
@@ -34357,6 +34381,18 @@
"tour": {
"title": "Tour",
"type": "string"
+ },
+ "label": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Label"
}
},
"required": [
diff --git a/tests/agent/test_onboarding_flow.py b/tests/agent/test_onboarding_flow.py
index a6ea7d20c12..18ada3e5146 100644
--- a/tests/agent/test_onboarding_flow.py
+++ b/tests/agent/test_onboarding_flow.py
@@ -280,6 +280,24 @@ def test_a_card_answer_outside_the_cards_options_is_refused_and_the_beat_stays_o
assert "error" in apply(new_record(facts), Answered(beat, answer), facts, now=1.0).result
+def test_a_click_carries_the_option_label_for_the_transcript_and_only_the_id_is_recorded():
+ facts = MACHINES["mac"]
+ record = run(facts, Shown("tour", "call_t"))[-1].record
+ step = apply(record, Answered("tour", {"tour": "quick", "label": "Quick look"}), facts, now=2.0)
+
+ assert step.result["answer"] == {"tour": "quick", "label": "Quick look"} and step.reminder == "tour_quick"
+ assert step.record["picks"]["tour"] == "quick" and "label" not in step.record["picks"]
+ assert "error" in apply(record, Answered("tour", {"tour": "quick", "label": 3}), facts, now=2.0).result
+
+
+def test_a_layout_or_theme_given_in_words_is_applied_by_set_theme_not_recorded():
+ facts = MACHINES["mac"]
+ for beat, value in [("layout", "terminal-deck"), ("theme", "Ultraviolet")]:
+ step = apply(new_record(facts), Recorded(beat, value), facts, now=1.0)
+ assert "set_theme" in step.result["error"] and step.record["beats"][beat] == PENDING
+ assert '"name":"set_theme"' in reminder("said", new_record(facts), facts, "layout")
+
+
def test_no_turn_note_once_every_card_is_settled():
facts = MACHINES["linux"]
steps = run(facts, *answer_all(facts)[:-1])
diff --git a/tui_gateway/contracts/server_requests.py b/tui_gateway/contracts/server_requests.py
index 13e14dd6a78..ee94796de9d 100644
--- a/tui_gateway/contracts/server_requests.py
+++ b/tui_gateway/contracts/server_requests.py
@@ -161,14 +161,17 @@ class SetupConnectorsAnswer(Result):
class SetupPluginsAnswer(Result):
installed: list[str]
+ label: str | None = None # what the card showed, for the transcript; never recorded
class SetupTourAnswer(Result):
tour: str
+ label: str | None = None
class SetupBuildAnswer(Result):
build: str
+ label: str | None = None
class SetupBeatResult(Result):