Skip to content

The agent that grows with you

fix(onboarding): typed setup_beat cards and answers; no note after the last card

alt-glitch7801375572eb
diff --git a/agent/onboarding_flow.py b/agent/onboarding_flow.py
index a9edb9af435..781e92e6fdf 100644
--- a/agent/onboarding_flow.py
+++ b/agent/onboarding_flow.py
@@ -242,8 +242,31 @@ def _shown(record: dict, event: Shown, facts: Facts, now: float) -> Step:
return Step(record, {})
+def _is_names(value: Any) -> bool:
+ return isinstance(value, list) and all(isinstance(item, str) for item in value)
+
+
+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."""
+ spec = BEAT_BY_ID[beat]
+ if not answer or not set(answer) <= set(spec.picks):
+ return False
+ if spec.values is not None:
+ return answer.get(spec.value) in spec.values(facts, picks)
+ if beat == "name":
+ return isinstance(answer.get("name"), str) and bool(answer["name"].strip())
+ if beat == "theme":
+ return all(value is None or isinstance(value, str) for value in answer.values())
+ if beat == "plugins":
+ return _is_names(answer.get("installed")) and set(answer["installed"]) <= set(facts.plugins)
+ return "connected" in answer and all(_is_names(value) for value in answer.values())
+
+
def _answered(record: dict, event: Answered, facts: Facts, now: float) -> Step:
record["waiting"] = None
+ if not valid_answer(event.beat, event.answer, facts, record["picks"]):
+ return Step(record, {"beat": event.beat, "error": "The card sent an answer this beat does not accept. "
+ f'Bring it back with setup_beat(beat="{event.beat}").'})
_settle(record, event.beat, event.answer)
return Step(record, {"beat": event.beat, "answer": dict(event.answer), "next": _next_field(record)},
BEAT_BY_ID[event.beat].after(record["picks"]))
diff --git a/agent/onboarding_text.py b/agent/onboarding_text.py
index 1b82e275e89..2fdac371c79 100644
--- a/agent/onboarding_text.py
+++ b/agent/onboarding_text.py
@@ -199,8 +199,8 @@ def _tour(preset: str):
'setup_beat(beat="next"): the build card waits under the tour. Never bring the tour up again.')
-def _waiting_beat(record) -> str:
- return (record.get("waiting") or {}).get("beat") or next_beat(record) or "build"
+def _waiting_beat(record) -> str | None:
+ return (record.get("waiting") or {}).get("beat") or next_beat(record)
_REMINDERS = {
@@ -239,15 +239,17 @@ def reminder(key: str, record: Mapping[str, Any], facts: Facts, beat: str | None
if not key:
return ""
if key in ("said", "timed_out"):
- return (_said if key == "said" else _timed_out)(record, facts, beat or _waiting_beat(record))
+ return (_said if key == "said" else _timed_out)(record, facts, beat or _waiting_beat(record) or "build")
if key.startswith("build_"):
return build_guidance(key.removeprefix("build_"), facts)
return _REMINDERS[key](record, facts)
def turn_note(record: Mapping[str, Any]) -> str:
- """The note on a user turn while no card waits: which card is closed and how to bring it back."""
- beat = _waiting_beat(record)
+ """The note on a user turn while no card waits: which card is closed and how to bring it back.
+ Empty once every card is settled: the build is under way and nothing is left to reopen."""
+ if (beat := _waiting_beat(record)) is None:
+ return ""
return (f"[System note: Onboarding continues; the {beat} card is closed. Answer their message first, then bring "
f'the card back in one line with setup_beat(beat="{beat}").]')
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.ts
index 2a9c3cef16e..051eff3e8f0 100644
--- a/apps/shared/src/gateway-contract.generated.ts
+++ b/apps/shared/src/gateway-contract.generated.ts
@@ -4555,19 +4555,61 @@ export interface SetupChooseResult {
label?: string | string[] | null
said?: string | null
}
-/** ``card`` is the beat's data (``agent/onboarding_flow.py::BEATS``): name ``{suggested?}`` (the OS account's name, card-only), theme ``{picker}``, layout and tour ``{options}``, connectors ``{suggested}`` (slugs), plugins ``{plugins}`` (catalog names), build ``{options}``. */
+/** ``card`` is the beat's data (``agent/onboarding_flow.py::BEATS``): name, theme, connectors and plugins have their own shape; layout, tour and build carry ``options``. */
export interface SetupBeatRequestParams {
session_id: string
beat: SetupBeat
question?: string | null
- card: Record<string, unknown>
+ card: SetupNameCard | SetupThemeCard | SetupOptionsCard | SetupConnectorsCard | SetupPluginsCard
}
export type SetupBeat = 'name' | 'theme' | 'layout' | 'connectors' | 'plugins' | 'tour' | 'build'
-/** ``answer`` holds the beat's picks (name ``{name}``, theme ``{accent, mode?}``, layout ``{layout}``, connectors ``{connected, newly_connected}``, plugins ``{installed}``, tour ``{tour}``, build ``{build}``); ``said`` is composer text typed while the card waited. A response with neither, or none within 300 s, closes the card unanswered. */
+export interface SetupNameCard {
+ suggested?: string | null
+}
+export interface SetupThemeCard {
+ picker: string
+}
+export interface SetupOptionsCard {
+ options: SetupOption[]
+}
+export interface SetupOption {
+ id: string
+ label: string
+}
+export interface SetupConnectorsCard {
+ suggested: string[]
+}
+export interface SetupPluginsCard {
+ plugins: string[]
+}
+/** ``answer`` holds the shown beat's picks; ids must be one of the card's options (the backend rejects any other answer). ``said`` is composer text typed while the card waited. A response with neither, or none within 300 s, closes the card unanswered. */
export interface SetupBeatResult {
- answer?: Record<string, unknown> | null
+ answer?: SetupNameAnswer | SetupThemeAnswer | SetupLayoutAnswer | SetupConnectorsAnswer | SetupPluginsAnswer | SetupTourAnswer | SetupBuildAnswer | null
said?: string | null
}
+export interface SetupNameAnswer {
+ name: string
+}
+export interface SetupThemeAnswer {
+ accent?: string | null
+ mode?: string | null
+}
+export interface SetupLayoutAnswer {
+ layout: string
+}
+export interface SetupConnectorsAnswer {
+ connected: string[]
+ newly_connected?: string[]
+}
+export interface SetupPluginsAnswer {
+ installed: string[]
+}
+export interface SetupTourAnswer {
+ tour: string
+}
+export interface SetupBuildAnswer {
+ build: string
+}
/** ``tui_gateway/server.py::_approval_request_payload`` — the command is redacted server-side. */
export interface ApprovalRequestParams {
session_id: string
diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.json
index b3afb49a3ed..5024228e8e2 100644
--- a/apps/shared/src/gateway-contract.openrpc.json
+++ b/apps/shared/src/gateway-contract.openrpc.json
@@ -33519,7 +33519,7 @@
},
"SetupBeatRequestParams": {
"additionalProperties": false,
- "description": "``card`` is the beat's data (``agent/onboarding_flow.py::BEATS``): name ``{suggested?}`` (the OS\naccount's name, card-only), theme ``{picker}``, layout and tour ``{options}``, connectors\n``{suggested}`` (slugs), plugins ``{plugins}`` (catalog names), build ``{options}``.",
+ "description": "``card`` is the beat's data (``agent/onboarding_flow.py::BEATS``): name, theme, connectors and\nplugins have their own shape; layout, tour and build carry ``options``.",
"properties": {
"session_id": {
"title": "Session Id",
@@ -33541,9 +33541,24 @@
"title": "Question"
},
"card": {
- "additionalProperties": true,
- "title": "Card",
- "type": "object"
+ "anyOf": [
+ {
+ "$ref": "#/components/schemas/SetupNameCard"
+ },
+ {
+ "$ref": "#/components/schemas/SetupThemeCard"
+ },
+ {
+ "$ref": "#/components/schemas/SetupOptionsCard"
+ },
+ {
+ "$ref": "#/components/schemas/SetupConnectorsCard"
+ },
+ {
+ "$ref": "#/components/schemas/SetupPluginsCard"
+ }
+ ],
+ "title": "Card"
}
},
"required": [
@@ -33556,13 +33571,30 @@
},
"SetupBeatResult": {
"additionalProperties": false,
- "description": "``answer`` holds the beat's picks (name ``{name}``, theme ``{accent, mode?}``, layout ``{layout}``,\nconnectors ``{connected, newly_connected}``, plugins ``{installed}``, tour ``{tour}``, build\n``{build}``); ``said`` is composer text typed while the card waited. A response with neither, or\nnone within 300 s, closes the card unanswered.",
+ "description": "``answer`` holds the shown beat's picks; ids must be one of the card's options (the backend\nrejects any other answer). ``said`` is composer text typed while the card waited. A response\nwith neither, or none within 300 s, closes the card unanswered.",
"properties": {
"answer": {
"anyOf": [
{
- "additionalProperties": true,
- "type": "object"
+ "$ref": "#/components/schemas/SetupNameAnswer"
+ },
+ {
+ "$ref": "#/components/schemas/SetupThemeAnswer"
+ },
+ {
+ "$ref": "#/components/schemas/SetupLayoutAnswer"
+ },
+ {
+ "$ref": "#/components/schemas/SetupConnectorsAnswer"
+ },
+ {
+ "$ref": "#/components/schemas/SetupPluginsAnswer"
+ },
+ {
+ "$ref": "#/components/schemas/SetupTourAnswer"
+ },
+ {
+ "$ref": "#/components/schemas/SetupBuildAnswer"
},
{
"type": "null"
@@ -33587,6 +33619,20 @@
"title": "SetupBeatResult",
"type": "object"
},
+ "SetupBuildAnswer": {
+ "additionalProperties": false,
+ "properties": {
+ "build": {
+ "title": "Build",
+ "type": "string"
+ }
+ },
+ "required": [
+ "build"
+ ],
+ "title": "SetupBuildAnswer",
+ "type": "object"
+ },
"SetupChooseKind": {
"enum": [
"question",
@@ -33746,6 +33792,164 @@
"title": "SetupChooseResult",
"type": "object"
},
+ "SetupConnectorsAnswer": {
+ "additionalProperties": false,
+ "properties": {
+ "connected": {
+ "items": {
+ "type": "string"
+ },
+ "title": "Connected",
+ "type": "array"
+ },
+ "newly_connected": {
+ "items": {
+ "type": "string"
+ },
+ "title": "Newly Connected",
+ "type": "array"
+ }
+ },
+ "required": [
+ "connected"
+ ],
+ "title": "SetupConnectorsAnswer",
+ "type": "object"
+ },
+ "SetupConnectorsCard": {
+ "additionalProperties": false,
+ "properties": {
+ "suggested": {
+ "items": {
+ "type": "string"
+ },
+ "title": "Suggested",
+ "type": "array"
+ }
+ },
+ "required": [
+ "suggested"
+ ],
+ "title": "SetupConnectorsCard",
+ "type": "object"
+ },
+ "SetupLayoutAnswer": {
+ "additionalProperties": false,
+ "properties": {
+ "layout": {
+ "title": "Layout",
+ "type": "string"
+ }
+ },
+ "required": [
+ "layout"
+ ],
+ "title": "SetupLayoutAnswer",
+ "type": "object"
+ },
+ "SetupNameAnswer": {
+ "additionalProperties": false,
+ "properties": {
+ "name": {
+ "title": "Name",
+ "type": "string"
+ }
+ },
+ "required": [
+ "name"
+ ],
+ "title": "SetupNameAnswer",
+ "type": "object"
+ },
+ "SetupNameCard": {
+ "additionalProperties": false,
+ "properties": {
+ "suggested": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Suggested"
+ }
+ },
+ "title": "SetupNameCard",
+ "type": "object"
+ },
+ "SetupOption": {
+ "additionalProperties": false,
+ "properties": {
+ "id": {
+ "title": "Id",
+ "type": "string"
+ },
+ "label": {
+ "title": "Label",
+ "type": "string"
+ }
+ },
+ "required": [
+ "id",
+ "label"
+ ],
+ "title": "SetupOption",
+ "type": "object"
+ },
+ "SetupOptionsCard": {
+ "additionalProperties": false,
+ "properties": {
+ "options": {
+ "items": {
+ "$ref": "#/components/schemas/SetupOption"
+ },
+ "title": "Options",
+ "type": "array"
+ }
+ },
+ "required": [
+ "options"
+ ],
+ "title": "SetupOptionsCard",
+ "type": "object"
+ },
+ "SetupPluginsAnswer": {
+ "additionalProperties": false,
+ "properties": {
+ "installed": {
+ "items": {
+ "type": "string"
+ },
+ "title": "Installed",
+ "type": "array"
+ }
+ },
+ "required": [
+ "installed"
+ ],
+ "title": "SetupPluginsAnswer",
+ "type": "object"
+ },
+ "SetupPluginsCard": {
+ "additionalProperties": false,
+ "properties": {
+ "plugins": {
+ "items": {
+ "type": "string"
+ },
+ "title": "Plugins",
+ "type": "array"
+ }
+ },
+ "required": [
+ "plugins"
+ ],
+ "title": "SetupPluginsCard",
+ "type": "object"
+ },
"SetupReadyPayload": {
"additionalProperties": true,
"description": "``hermes_cli/free_tier_bootstrap.py::SetupRecord.as_payload``.",
@@ -34102,6 +34306,65 @@
"title": "SetupStatusResult",
"type": "object"
},
+ "SetupThemeAnswer": {
+ "additionalProperties": false,
+ "properties": {
+ "accent": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Accent"
+ },
+ "mode": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Mode"
+ }
+ },
+ "title": "SetupThemeAnswer",
+ "type": "object"
+ },
+ "SetupThemeCard": {
+ "additionalProperties": false,
+ "properties": {
+ "picker": {
+ "title": "Picker",
+ "type": "string"
+ }
+ },
+ "required": [
+ "picker"
+ ],
+ "title": "SetupThemeCard",
+ "type": "object"
+ },
+ "SetupTourAnswer": {
+ "additionalProperties": false,
+ "properties": {
+ "tour": {
+ "title": "Tour",
+ "type": "string"
+ }
+ },
+ "required": [
+ "tour"
+ ],
+ "title": "SetupTourAnswer",
+ "type": "object"
+ },
"SharedMetricsConsentResult": {
"additionalProperties": false,
"description": "The focused profile's ``telemetry.shared_metrics`` opt-ins. ``send`` is never true while\n``enabled`` is false; ``decided`` = either key is written in config.yaml (the shipped defaults\nare not an answer) and it is not a ``reask``: an \"off\" from before the type-ahead fix, offered\nonce more with the reason.",
diff --git a/tests/agent/test_onboarding_flow.py b/tests/agent/test_onboarding_flow.py
index d752f45ff42..98fa9870e12 100644
--- a/tests/agent/test_onboarding_flow.py
+++ b/tests/agent/test_onboarding_flow.py
@@ -41,10 +41,11 @@ def answer_all(facts: Facts) -> list:
"""The happy path for a machine: every beat it gets, shown and answered on its card."""
answers = {"name": {"name": "Sid"}, "theme": {"accent": "Ultraviolet"}, "layout": {"layout": "terminal-deck"},
"connectors": {"connected": ["slack"], "newly_connected": ["slack"]},
- "plugins": {"installed": ["blender"]}, "tour": {"tour": "quick"}, "build": {"build": "week"}}
+ "plugins": {"installed": list(facts.plugins[:1])}, "tour": {"tour": "quick"}}
record, events = new_record(facts), []
while (beat := next_beat(record)) is not None:
- for event in (Shown(beat, f"call_{beat}"), Answered(beat, answers[beat])):
+ answer = answers.get(beat) or {"build": build_options(facts, record["picks"])[0]["id"]}
+ for event in (Shown(beat, f"call_{beat}"), Answered(beat, answer)):
events.append(event)
record = apply(record, event, facts).record
return [*events, Done()]
@@ -258,3 +259,22 @@ def test_quiet_spell_after_the_build_card_completes_the_run():
ended = expire(record, now=record["updated_at"] + flow.QUIET_COMPLETE_S)
assert ended["phase"] == flow.COMPLETE and ended["ended_by"] == "timeout"
assert expire(new_record(facts), now=10**9)["phase"] == flow.ONBOARDING
+
+
+def test_a_card_answer_outside_the_cards_options_is_refused_and_the_beat_stays_open():
+ facts = MACHINES["mac"]
+ record = run(facts, Shown("build", "call_b"))[-1].record
+ step = apply(record, Answered("build", {"build": "games"}), facts, now=2.0)
+
+ assert "error" in step.result and step.record["beats"]["build"] == SHOWN
+ assert step.record["picks"]["build"] is None and step.record["waiting"] is None
+ for beat, answer in [("name", {"name": " "}), ("layout", {"layout": "x"}), ("theme", {"accent": 3}),
+ ("plugins", {"installed": ["nvidia-app"]}), ("connectors", {"installed": ["blender"]})]:
+ assert "error" in apply(new_record(facts), Answered(beat, answer), facts, now=1.0).result
+
+
+def test_no_turn_note_once_every_card_is_settled():
+ facts = MACHINES["linux"]
+ steps = run(facts, *answer_all(facts)[:-1])
+
+ assert next_beat(steps[-1].record) is None and turn_note(steps[-1].record) == ""
diff --git a/tui_gateway/contracts/server_requests.py b/tui_gateway/contracts/server_requests.py
index 37d5907c1c8..13e14dd6a78 100644
--- a/tui_gateway/contracts/server_requests.py
+++ b/tui_gateway/contracts/server_requests.py
@@ -107,23 +107,77 @@ class SetupBeat(WireEnum):
build = "build"
+class SetupOption(Params):
+ id: str
+ label: str
+
+
+class SetupNameCard(Params):
+ suggested: str | None = None # the OS account's name: shown on the card, never sent to the model
+
+
+class SetupThemeCard(Params):
+ picker: str
+
+
+class SetupOptionsCard(Params):
+ options: list[SetupOption]
+
+
+class SetupConnectorsCard(Params):
+ suggested: list[str]
+
+
+class SetupPluginsCard(Params):
+ plugins: list[str]
+
+
class SetupBeatRequestParams(ServerRequestParams):
- """``card`` is the beat's data (``agent/onboarding_flow.py::BEATS``): name ``{suggested?}`` (the OS
- account's name, card-only), theme ``{picker}``, layout and tour ``{options}``, connectors
- ``{suggested}`` (slugs), plugins ``{plugins}`` (catalog names), build ``{options}``."""
+ """``card`` is the beat's data (``agent/onboarding_flow.py::BEATS``): name, theme, connectors and
+ plugins have their own shape; layout, tour and build carry ``options``."""
beat: SetupBeat
question: str | None = None
- card: dict[str, JsonValue]
+ card: SetupNameCard | SetupThemeCard | SetupOptionsCard | SetupConnectorsCard | SetupPluginsCard
+
+
+class SetupNameAnswer(Result):
+ name: str
+
+
+class SetupThemeAnswer(Result):
+ accent: str | None = None
+ mode: str | None = None
+
+
+class SetupLayoutAnswer(Result):
+ layout: str
+
+
+class SetupConnectorsAnswer(Result):
+ connected: list[str]
+ newly_connected: list[str] = Field(default_factory=list)
+
+
+class SetupPluginsAnswer(Result):
+ installed: list[str]
+
+
+class SetupTourAnswer(Result):
+ tour: str
+
+
+class SetupBuildAnswer(Result):
+ build: str
class SetupBeatResult(Result):
- """``answer`` holds the beat's picks (name ``{name}``, theme ``{accent, mode?}``, layout ``{layout}``,
- connectors ``{connected, newly_connected}``, plugins ``{installed}``, tour ``{tour}``, build
- ``{build}``); ``said`` is composer text typed while the card waited. A response with neither, or
- none within 300 s, closes the card unanswered."""
+ """``answer`` holds the shown beat's picks; ids must be one of the card's options (the backend
+ rejects any other answer). ``said`` is composer text typed while the card waited. A response
+ with neither, or none within 300 s, closes the card unanswered."""
- answer: dict[str, JsonValue] | None = None
+ answer: (SetupNameAnswer | SetupThemeAnswer | SetupLayoutAnswer | SetupConnectorsAnswer | SetupPluginsAnswer
+ | SetupTourAnswer | SetupBuildAnswer | None) = None
said: str | None = None