The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(onboarding): onboarding.start / onboarding.skip and the gateway wiring
alt-glitch1589fec62c51
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.tsindex fcd856a2446..f55fcbb473c 100644--- a/apps/shared/src/gateway-contract.generated.ts+++ b/apps/shared/src/gateway-contract.generated.ts@@ -2202,16 +2202,37 @@ export interface OnboardingStateResult {profile?: string | null}export type OnboardingIntro = 'unseen' | 'seen'-/** ``run``: the questionnaire opens on this launch (root config ``onboarding.run``, else a fresh install). ``eligible``: the free tier is on for this backend (``anon_auth.guest_enabled``). */+/** ``run``: onboarding opens on this launch (root config ``onboarding.run``, else a fresh install). ``eligible``: the free tier is on for this backend (``anon_auth.guest_enabled``). ``session_id``: the stored id of the onboarding chat still in progress, so a relaunch reopens it. */export interface OnboardingRunStateResult {run: booleaneligible: boolean+ session_id?: string | null}/** ``mark_profile_offered`` also latches ``onboarding.seen.profile_build_offered`` in the root config, so the first chat after the questionnaire gets the plain intro instead of the profile offer. */export interface OnboardingSetRunParams {run: booleanmark_profile_offered?: boolean}+/** ``rerun``: start a new onboarding chat even when one is in progress (Settings, Run onboarding again). ``facts_source``: whether the backend runs on the user's own computer. ``locale``: the desktop's UI language, preferred over the backend OS locale. */+export interface OnboardingStartParams {+ rerun?: boolean+ facts_source?: OnboardingFactsSource+ locale?: string | null+}+export type OnboardingFactsSource = 'local' | 'remote'+/** ``session_id`` is the runtime id the client attaches to; ``resumed`` is true when an onboarding chat already in progress was reopened instead of a new one started. */+export interface OnboardingStartResult {+ session_id: string+ stored_session_id: string+ resumed: boolean+}+export interface OnboardingSkipParams {+ session_id: string+ profile?: string | null+}+export interface OnboardingSkipResult {+ skipped: boolean+}export interface OnboardingResetSetupProfileResult {name: stringpath: string@@ -4534,6 +4555,19 @@ export interface SetupChooseResult {label?: string | string[] | nullsaid?: 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}``. */+export interface SetupBeatRequestParams {+ session_id: string+ beat: SetupBeat+ question?: string | null+ card: Record<string, unknown>+}+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 SetupBeatResult {+ answer?: Record<string, unknown> | null+ said?: string | null+}/** ``tui_gateway/server.py::_approval_request_payload`` — the command is redacted server-side. */export interface ApprovalRequestParams {session_id: string@@ -5306,7 +5340,11 @@ export interface RpcMethods {'onboarding.reset_setup_profile': { params: Params; result: OnboardingResetSetupProfileResult }/** Write onboarding.run in the root profile's config.yaml; answers the new state. */'onboarding.set_run': { params: OnboardingSetRunParams; result: OnboardingRunStateResult }- /** Whether the desktop first-run questionnaire is due; reads the root profile's config. */+ /** Skip setup: end the session's onboarding run and close the card that waits. */+ 'onboarding.skip': { params: OnboardingSkipParams; result: OnboardingSkipResult }+ /** Open the onboarding chat in the default profile: create it, write its run record and play the opening. */+ 'onboarding.start': { params: OnboardingStartParams; result: OnboardingStartResult }+ /** Whether desktop first-run onboarding is due, and the chat in progress; reads the root profile's config. */'onboarding.state': { params: Params; result: OnboardingRunStateResult }/** Spill a large paste to a file and hand back the inline placeholder. */'paste.collapse': { params: PasteCollapseParams; result: PasteCollapseResult }@@ -5713,6 +5751,8 @@ export const RPC_METHODS = ['onboarding.record_failed_start','onboarding.reset_setup_profile','onboarding.set_run',+ 'onboarding.skip',+ 'onboarding.start','onboarding.state','paste.collapse','pdf.attach',@@ -5872,6 +5912,8 @@ export interface ServerRequestMap {'preview.read': { params: ReadRangeRequestParams; result: ValueResult }/** Masked value for a named env var (skills / setup flows). */secret: { params: SecretRequestParams; result: ValueResult }+ /** The onboarding chat's card for one beat; blocks setup_beat until answered (300 s). */+ setup_beat: { params: SetupBeatRequestParams; result: SetupBeatResult }setup_choose: { params: SetupChooseRequestParams; result: SetupChooseResult }/** Masked sudo password for the terminal tool. */sudo: { params: SudoRequestParams; result: ValueResult }@@ -5896,6 +5938,7 @@ export const SERVER_REQUEST_METHODS = ['preview.act','preview.read','secret',+ 'setup_beat','setup_choose','sudo','terminal.read',diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.jsonindex a584973b45e..29b2dac8348 100644--- a/apps/shared/src/gateway-contract.openrpc.json+++ b/apps/shared/src/gateway-contract.openrpc.json@@ -2130,9 +2130,45 @@}}},+ {+ "name": "onboarding.skip",+ "summary": "Skip setup: end the session's onboarding run and close the card that waits.",+ "params": [+ {+ "name": "params",+ "schema": {+ "$ref": "#/components/schemas/OnboardingSkipParams"+ }+ }+ ],+ "result": {+ "name": "result",+ "schema": {+ "$ref": "#/components/schemas/OnboardingSkipResult"+ }+ }+ },+ {+ "name": "onboarding.start",+ "summary": "Open the onboarding chat in the default profile: create it, write its run record and play the opening.",+ "params": [+ {+ "name": "params",+ "schema": {+ "$ref": "#/components/schemas/OnboardingStartParams"+ }+ }+ ],+ "result": {+ "name": "result",+ "schema": {+ "$ref": "#/components/schemas/OnboardingStartResult"+ }+ }+ },{"name": "onboarding.state",- "summary": "Whether the desktop first-run questionnaire is due; reads the root profile's config.",+ "summary": "Whether desktop first-run onboarding is due, and the chat in progress; reads the root profile's config.","params": [{"name": "params",@@ -20448,6 +20484,14 @@"title": "OnboardingEnsureSetupSessionResult","type": "object"},+ "OnboardingFactsSource": {+ "enum": [+ "local",+ "remote"+ ],+ "title": "OnboardingFactsSource",+ "type": "string"+ },"OnboardingIntro": {"enum": ["unseen",@@ -20482,7 +20526,7 @@},"OnboardingRunStateResult": {"additionalProperties": false,- "description": "``run``: the questionnaire opens on this launch (root config ``onboarding.run``, else a fresh\ninstall). ``eligible``: the free tier is on for this backend (``anon_auth.guest_enabled``).",+ "description": "``run``: onboarding opens on this launch (root config ``onboarding.run``, else a fresh\ninstall). ``eligible``: the free tier is on for this backend (``anon_auth.guest_enabled``).\n``session_id``: the stored id of the onboarding chat still in progress, so a relaunch reopens it.","properties": {"run": {"title": "Run",@@ -20491,6 +20535,18 @@"eligible": {"title": "Eligible","type": "boolean"+ },+ "session_id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Session Id"}},"required": [@@ -20520,6 +20576,100 @@"title": "OnboardingSetRunParams","type": "object"},+ "OnboardingSkipParams": {+ "additionalProperties": false,+ "properties": {+ "session_id": {+ "title": "Session Id",+ "type": "string"+ },+ "profile": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Profile"+ }+ },+ "required": [+ "session_id"+ ],+ "title": "OnboardingSkipParams",+ "type": "object"+ },+ "OnboardingSkipResult": {+ "additionalProperties": false,+ "properties": {+ "skipped": {+ "title": "Skipped",+ "type": "boolean"+ }+ },+ "required": [+ "skipped"+ ],+ "title": "OnboardingSkipResult",+ "type": "object"+ },+ "OnboardingStartParams": {+ "additionalProperties": false,+ "description": "``rerun``: start a new onboarding chat even when one is in progress (Settings, Run onboarding\nagain). ``facts_source``: whether the backend runs on the user's own computer. ``locale``: the\ndesktop's UI language, preferred over the backend OS locale.",+ "properties": {+ "rerun": {+ "default": false,+ "title": "Rerun",+ "type": "boolean"+ },+ "facts_source": {+ "$ref": "#/components/schemas/OnboardingFactsSource",+ "default": "local"+ },+ "locale": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Locale"+ }+ },+ "title": "OnboardingStartParams",+ "type": "object"+ },+ "OnboardingStartResult": {+ "additionalProperties": false,+ "description": "``session_id`` is the runtime id the client attaches to; ``resumed`` is true when an onboarding\nchat already in progress was reopened instead of a new one started.",+ "properties": {+ "session_id": {+ "title": "Session Id",+ "type": "string"+ },+ "stored_session_id": {+ "title": "Stored Session Id",+ "type": "string"+ },+ "resumed": {+ "title": "Resumed",+ "type": "boolean"+ }+ },+ "required": [+ "session_id",+ "stored_session_id",+ "resumed"+ ],+ "title": "OnboardingStartResult",+ "type": "object"+ },"OnboardingStateResult": {"additionalProperties": false,"properties": {@@ -33354,6 +33504,89 @@"title": "SessionWorkspaceMoveResult","type": "object"},+ "SetupBeat": {+ "enum": [+ "name",+ "theme",+ "layout",+ "connectors",+ "plugins",+ "tour",+ "build"+ ],+ "title": "SetupBeat",+ "type": "string"+ },+ "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}``.",+ "properties": {+ "session_id": {+ "title": "Session Id",+ "type": "string"+ },+ "beat": {+ "$ref": "#/components/schemas/SetupBeat"+ },+ "question": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Question"+ },+ "card": {+ "additionalProperties": true,+ "title": "Card",+ "type": "object"+ }+ },+ "required": [+ "session_id",+ "beat",+ "card"+ ],+ "title": "SetupBeatRequestParams",+ "type": "object"+ },+ "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.",+ "properties": {+ "answer": {+ "anyOf": [+ {+ "additionalProperties": true,+ "type": "object"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Answer"+ },+ "said": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Said"+ }+ },+ "title": "SetupBeatResult",+ "type": "object"+ },"SetupChooseKind": {"enum": ["question",@@ -40712,6 +40945,24 @@}}},+ {+ "name": "setup_beat",+ "summary": "The onboarding chat's card for one beat; blocks setup_beat until answered (300 s).",+ "params": [+ {+ "name": "params",+ "schema": {+ "$ref": "#/components/schemas/SetupBeatRequestParams"+ }+ }+ ],+ "result": {+ "name": "result",+ "schema": {+ "$ref": "#/components/schemas/SetupBeatResult"+ }+ }+ },{"name": "setup_choose","summary": "",diff --git a/tests/tui_gateway/test_onboarding_run_rpc.py b/tests/tui_gateway/test_onboarding_run_rpc.pyindex 65d98071cfc..a3a7f8efb29 100644--- a/tests/tui_gateway/test_onboarding_run_rpc.py+++ b/tests/tui_gateway/test_onboarding_run_rpc.py@@ -1,5 +1,5 @@"""``onboarding.state`` / ``onboarding.set_run`` read and write the ROOT profile's config.yaml, even-from a pooled backend launched under a named profile, and answer ``{run, eligible}``."""+from a pooled backend launched under a named profile, and answer ``{run, eligible, session_id}``."""from __future__ import annotations@@ -35,7 +35,7 @@ def _onboarding(home: Path) -> dict:def test_state_answers_run_and_eligible(launched_under_work, monkeypatch):# The user's own "work" profile is install history, so an unset flag is not due.- assert _call("onboarding.state")["result"] == {"run": False, "eligible": True}+ assert _call("onboarding.state")["result"] == {"run": False, "eligible": True, "session_id": None}monkeypatch.delenv("HERMES_GUEST_ONBOARDING")assert _call("onboarding.state")["result"]["eligible"] is False@@ -44,7 +44,7 @@ def test_state_answers_run_and_eligible(launched_under_work, monkeypatch):def test_set_run_writes_the_root_config(launched_under_work):root, work = launched_under_work- assert _call("onboarding.set_run", {"run": True})["result"] == {"run": True, "eligible": True}+ assert _call("onboarding.set_run", {"run": True})["result"] == {"run": True, "eligible": True, "session_id": None}assert _onboarding(root)["run"] is Trueassert "run" not in _onboarding(work)assert _call("onboarding.state")["result"]["run"] is Truediff --git a/tui_gateway/agent_callbacks.py b/tui_gateway/agent_callbacks.pyindex eb2ca5e3dee..5bf5d475196 100644--- a/tui_gateway/agent_callbacks.py+++ b/tui_gateway/agent_callbacks.py@@ -181,7 +181,8 @@ def _agent_cbs(sid: str) -> dict:"connection_callback": lambda payload: _emit("connection.request", sid, dict(payload)) and None,# tour (desktop GUI): renderer drives driver.js and answers the ``tour`` request."tour_callback": lambda payload: _tour_request(sid, payload),- "setup_choose_callback": lambda payload: _setup_choose_request(sid, payload)}+ "setup_choose_callback": lambda payload: _setup_choose_request(sid, payload),+ "setup_beat_callback": lambda payload: _setup_beat_request(sid, payload)}# Interim assistant commentary (text alongside tool calls), gated on display.interim_assistant_# messages; _run_prompt_submit overwrites it per turn and clears it so a stale closure can't fire.diff --git a/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py b/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.pyindex 049fe4e26cf..871fe3d4790 100644--- a/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py+++ b/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py@@ -399,15 +399,17 @@ method("onboarding.mark_seen", params=Params, result=OnboardingStateResult)class OnboardingRunStateResult(Result):- """``run``: the questionnaire opens on this launch (root config ``onboarding.run``, else a fresh- install). ``eligible``: the free tier is on for this backend (``anon_auth.guest_enabled``)."""+ """``run``: onboarding opens on this launch (root config ``onboarding.run``, else a fresh+ install). ``eligible``: the free tier is on for this backend (``anon_auth.guest_enabled``).+ ``session_id``: the stored id of the onboarding chat still in progress, so a relaunch reopens it."""run: booleligible: bool+ session_id: str | None = Nonemethod("onboarding.state", params=Params, result=OnboardingRunStateResult,- doc="Whether the desktop first-run questionnaire is due; reads the root profile's config.")+ doc="Whether desktop first-run onboarding is due, and the chat in progress; reads the root profile's config.")class OnboardingSetRunParams(Params):@@ -422,6 +424,46 @@ method("onboarding.set_run", params=OnboardingSetRunParams, result=OnboardingRundoc="Write onboarding.run in the root profile's config.yaml; answers the new state.")+class OnboardingFactsSource(WireEnum):+ local = "local"+ remote = "remote"+++class OnboardingStartParams(Params):+ """``rerun``: start a new onboarding chat even when one is in progress (Settings, Run onboarding+ again). ``facts_source``: whether the backend runs on the user's own computer. ``locale``: the+ desktop's UI language, preferred over the backend OS locale."""++ rerun: bool = False+ facts_source: OnboardingFactsSource = OnboardingFactsSource.local+ locale: str | None = None+++class OnboardingStartResult(Result):+ """``session_id`` is the runtime id the client attaches to; ``resumed`` is true when an onboarding+ chat already in progress was reopened instead of a new one started."""++ session_id: str+ stored_session_id: str+ resumed: bool+++method("onboarding.start", params=OnboardingStartParams, result=OnboardingStartResult,+ doc="Open the onboarding chat in the default profile: create it, write its run record and play the opening.")+++class OnboardingSkipParams(SessionParams):+ pass+++class OnboardingSkipResult(Result):+ skipped: bool+++method("onboarding.skip", params=OnboardingSkipParams, result=OnboardingSkipResult,+ doc="Skip setup: end the session's onboarding run and close the card that waits.")++class OnboardingResetSetupProfileResult(Result):name: strpath: strdiff --git a/tui_gateway/contracts/server_requests.py b/tui_gateway/contracts/server_requests.pyindex e02f87978cd..37d5907c1c8 100644--- a/tui_gateway/contracts/server_requests.py+++ b/tui_gateway/contracts/server_requests.py@@ -94,6 +94,43 @@ class SetupChooseResult(Result):server_request("setup_choose", params=SetupChooseRequestParams, result=SetupChooseResult)+# ── setup_beat (first-run onboarding) ─────────────────────────────────────────────────────────+++class SetupBeat(WireEnum):+ name = "name"+ theme = "theme"+ layout = "layout"+ connectors = "connectors"+ plugins = "plugins"+ tour = "tour"+ build = "build"+++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}``."""++ beat: SetupBeat+ question: str | None = None+ card: dict[str, JsonValue]+++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: dict[str, JsonValue] | None = None+ said: str | None = None+++server_request("setup_beat", params=SetupBeatRequestParams, result=SetupBeatResult,+ doc="The onboarding chat's card for one beat; blocks setup_beat until answered (300 s).")++# ── approval ──────────────────────────────────────────────────────────────────────────────────diff --git a/tui_gateway/methods_onboarding.py b/tui_gateway/methods_onboarding.pyindex fd50445c967..eb380390a54 100644--- a/tui_gateway/methods_onboarding.py+++ b/tui_gateway/methods_onboarding.py@@ -71,7 +71,135 @@ def _(rid, params: dict) -> dict:def _run_state() -> dict:from hermes_cli.anon_auth import guest_enabledfrom hermes_cli.onboarding_run import should_run- return {"run": should_run(), "eligible": guest_enabled()}+ return {"run": should_run(), "eligible": guest_enabled(), "session_id": _active_onboarding_session()}+++# ── first-run onboarding: one chat in the default profile, driven by setup_beat ───────────────++# Onboarding always runs in the default profile, whichever profile this backend was launched under.+_ONBOARDING_PROFILE = {"profile": "default"}+# Two windows pressing start at once must not both find no run and open two onboarding chats.+_onboarding_start_lock = threading.Lock()+++def _active_onboarding_session() -> str | None:+ from agent.onboarding_record import active_session_id+ with _profile_db(_ONBOARDING_PROFILE, writer=True) as db:+ return None if db is None else active_session_id(db)+++@method("onboarding.start")+def _(rid, params: dict) -> dict:+ from agent.onboarding_facts import read_facts+ from agent.onboarding_record import active_session_id, start+ from agent.onboarding_text import CHAT_TITLE, opening_prompt+ facts = None+ try:+ with _onboarding_start_lock, _profile_db(_ONBOARDING_PROFILE, writer=True) as db:+ if db is None:+ return _db_unavailable_error(rid, code=5000)+ stored = None if params.get("rerun") else active_session_id(db)+ if stored is None:+ facts = read_facts(facts_source=params.get("facts_source") or "local", locale=params.get("locale"))+ stored = db.create_session(new_session_id(), "desktop")+ db.set_session_title(stored, db.get_next_title_in_lineage(CHAT_TITLE))+ # The record exists before the agent is built, so the build folds the onboarding toolset in.+ start(db, stored, facts)+ except Exception as e:+ logger.exception("onboarding.start failed")+ return _err(rid, 5078, str(e))+ resumed = _methods["session.resume"](rid, {**_ONBOARDING_PROFILE, "session_id": stored, "source": "desktop"})+ if "error" in resumed:+ return resumed+ sid = resumed["result"]["session_id"]+ if facts is not None:+ # The opening rules ride a hidden user turn; its prelude plays the greeting and the name card.+ submitted = _methods["prompt.submit"](+ rid, {"session_id": sid, "text": opening_prompt(facts), "display_kind": "hidden"})+ if "error" in submitted:+ return submitted+ return _ok(rid, {"session_id": sid, "stored_session_id": stored, "resumed": facts is None})+++@method("onboarding.skip")+def _(rid, params: dict) -> dict:+ from agent.onboarding_flow import SkipAll+ from agent.onboarding_record import advance, load+ session, err = _sess_nowait(params, rid)+ if err:+ return err+ agent = session.get("agent")+ stored = getattr(agent, "session_id", None) or session["session_key"]+ with _session_db(session) as db:+ if load(db, stored) is None:+ return _ok(rid, {"skipped": False})+ step = advance(db, stored, SkipAll())+ from tui_gateway import server_requests+ # The card that waits returns to setup_beat, which reads the skipped record.+ server_requests.cancel(params["session_id"], "resolved", method="setup_beat")+ return _ok(rid, {"skipped": bool(step.result.get("skipped_all"))})+++def _setup_beat_request(sid: str, payload: dict) -> dict | None:+ from agent.onboarding_flow import CARD_TIMEOUT_S+ from tui_gateway import server_requests+ return server_requests.send("setup_beat", sid, dict(payload), timeout=CARD_TIMEOUT_S)+++def _builds_onboarding(agent) -> bool:+ return "setup_beat" in (getattr(agent, "valid_tool_names", None) or ())+++def _onboarding_toolsets(enabled, db, session_id: str):+ """*enabled* plus ``onboarding`` for a chat whose run is in progress. Decided once, at agent build:+ the tool array is part of the cached prefix, so a finished run keeps setup_beat (as a refusal)+ until the session is rebuilt."""+ from agent.onboarding_flow import is_active+ from agent.onboarding_record import load+ if not enabled or "onboarding" in enabled:+ return enabled+ return [*enabled, "onboarding"] if is_active(load(db if db is not None else _get_db(), session_id)) else enabled+++def _carry_onboarding_toolset(enabled, agent):+ """A tool refresh keeps the onboarding toolset the agent was built with."""+ if not enabled or "onboarding" in enabled or "onboarding" not in (getattr(agent, "enabled_toolsets", None) or ()):+ return enabled+ return [*enabled, "onboarding"]+++def _onboarding_prelude(agent, history: list):+ """The opening's scripted step, greeting and name card, while the name beat was never shown. A+ greeting already in the chat (a relaunch) is not said twice."""+ from agent.onboarding_flow import PENDING, is_active+ from agent.onboarding_record import load+ from agent.onboarding_text import GREETING+ if not _builds_onboarding(agent):+ return None+ record = load(agent._session_db, agent.session_id)+ if not is_active(record) or record["beats"]["name"] != PENDING:+ return None+ said = any(m.get("role") == "assistant" and m.get("content") == GREETING for m in history)++ def opening():+ yield ("" if said else GREETING), "setup_beat", {"beat": "name"}+ return opening()+++def _stage_onboarding_turn_note(sid: str, agent, history_empty: bool) -> None:+ """Before a user turn in the onboarding chat, while no card waits: which card is closed and how to+ bring it back. Rides the turn's API-only notes, like the first-contact note."""+ from agent.onboarding_flow import is_active+ from agent.onboarding_record import load+ from agent.onboarding_text import turn_note+ from tui_gateway import server_requests+ if history_empty or not _builds_onboarding(agent) or server_requests.pending_kind(sid) == "setup_beat":+ return+ record = load(agent._session_db, agent.session_id)+ if is_active(record):+ prior = getattr(agent, "_gateway_turn_context_notes", "") or ""+ note = turn_note(record)+ agent._gateway_turn_context_notes = f"{prior}\n\n{note}" if prior else note@method("onboarding.record_failed_start")diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.pyindex 11dba529f5b..3127960e962 100644--- a/tui_gateway/methods_tools.py+++ b/tui_gateway/methods_tools.py@@ -326,7 +326,7 @@ def _refresh_live_sessions(home=None, *, preserve_prefix: bool = False, note: stagent = sess["agent"]try:with _session_profile_runtime_scope(sess):- enabled = _load_enabled_toolsets(getattr(agent, "platform", None))+ enabled = _carry_onboarding_toolset(_load_enabled_toolsets(getattr(agent, "platform", None)), agent)disabled = _load_disabled_toolsets()refresh(agent, enabled_override=enabled, disabled_override=disabled,quiet_mode=True, preserve_prefix=preserve_prefix)diff --git a/tui_gateway/prompt_turn.py b/tui_gateway/prompt_turn.pyindex 0cc90dee8a2..95dd75bfc22 100644--- a/tui_gateway/prompt_turn.py+++ b/tui_gateway/prompt_turn.py@@ -645,6 +645,7 @@ def _stage_first_contact_onboarding_note(session: dict, agent, history_empty: boinstall_has_prior_sessions=_install_has_prior_sessions(session),message=message,setup_handoff=bool(session.get("setup_handoff")),+ onboarding_run_active="setup_beat" in (getattr(agent, "valid_tool_names", None) or ()),)if not note:return@@ -697,6 +698,7 @@ def _prepare_turn_input(sid: str, session: dict, st: _TurnRun, text: Any, images# Install-first-message onboarding (#82750): gateway parity for the TUI/Desktop# surface — no-op unless this is the install's very first message ever._stage_first_contact_onboarding_note(session, agent, not st.history, text if isinstance(text, str) else "")+ _stage_onboarding_turn_note(sid, agent, not st.history)cwd = _session_cwd(session)_register_session_cwd(session)cols = session.get("cols", 80)@@ -796,7 +798,8 @@ def _invoke_agent(if "prelude" in run_params:from agent.initiate_setup_prompt import initiate_setup_preludeprelude = initiate_setup_prelude(- text, _resolve_agent_platform(_session_source(session)), agent.valid_tool_names, st.history)+ text, _resolve_agent_platform(_session_source(session)), agent.valid_tool_names, st.history,+ ) or _onboarding_prelude(agent, st.history)if prelude is not None:run_kwargs["prelude"] = prelude_adopt_submit_user_row(session, agent, run_kwargs["persist_user_message"], text)diff --git a/tui_gateway/server.py b/tui_gateway/server.pyindex e2218e1cb86..aeb1483cdf2 100644--- a/tui_gateway/server.py+++ b/tui_gateway/server.py@@ -2151,7 +2151,7 @@ def _tool_progress_enabled(sid: str) -> bool:# set (test_gateway_lifecycle_set_covers_desktop_card_tools pins the direction that matters)._TOOL_LIFECYCLE_UI_TOOLS = frozenset({"clarify", "manage_connections", "setup_mcp",- "image_generate", "manage_catalog", "delegate_task", "setup_choose", "start_chat",+ "image_generate", "manage_catalog", "delegate_task", "setup_choose", "setup_beat", "start_chat",# File edits are the turn's deliverable — the diff card the user reviews."edit_file", "patch", "write_file",})@@ -2693,7 +2693,7 @@ def _make_agent(reasoning_config=(reasoning_config_override if reasoning_config_override is not None else _load_reasoning_config(str(model or ""))),service_tier=service_tier_override if service_tier_override is not None else _load_service_tier(),- enabled_toolsets=_load_enabled_toolsets(platform),+ enabled_toolsets=_onboarding_toolsets(_load_enabled_toolsets(platform), session_db, session_id or key),disabled_toolsets=_load_disabled_toolsets(),# OpenRouter provider_routing prefs (gateway + CLI parity).providers_allowed=_pr.get("only"), providers_ignored=_pr.get("ignore"), providers_order=_pr.get("order"),diff --git a/tui_gateway/server_requests.py b/tui_gateway/server_requests.pyindex 5da7bb3bd06..dfd39d84248 100644--- a/tui_gateway/server_requests.py+++ b/tui_gateway/server_requests.py@@ -325,13 +325,14 @@ def lock_answer(request_id: str, question_id: str, answer: str | None) -> list[sreturn remaining-def cancel(sid: str | None = None, reason: str = "interrupted") -> int:+def cancel(sid: str | None = None, reason: str = "interrupted", *, method: str | None = None) -> int:"""Withdraw open requests — only *sid*'s (session.interrupt must not touch other sessions'), or- every one when *sid* is None (shutdown). Blocked waits return None (a batch returns its locked- answers with ``outcome: cancelled``); queue-backed requests run ``on_result(None)`` so their- owner can settle. Returns the number withdrawn."""+ every one when *sid* is None (shutdown); *method* narrows it to one request kind. Blocked waits+ return None (a batch returns its locked answers with ``outcome: cancelled``); queue-backed requests+ run ``on_result(None)`` so their owner can settle. Returns the number withdrawn."""with _lock:- targets = [req for req in _open.values() if sid is None or req.sid == sid]+ targets = [req for req in _open.values()+ if (sid is None or req.sid == sid) and (method is None or req.method == method)]for req in targets:_open.pop(req.id, None)if req.qids is not None: