The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): scope the new-chat slash palette to the rail-selected profile (#124651, salvage #124845)
chelsealong3fe934aabfdc
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-slash-completions.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-slash-completions.test.tsxindex 4cc1ec9f81d..aad05c65b2a 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-slash-completions.test.tsx+++ b/apps/desktop/src/app/chat/composer/hooks/use-slash-completions.test.tsx@@ -41,11 +41,11 @@ const RANKED_CATALOG = {const commandsOf = (items: readonly Unstable_TriggerItem[]) =>items.map(item => (item.metadata as { command?: string })?.command)-function harness(gateway: HermesGateway) {+function harness(gateway: HermesGateway, options: { profile?: string } = {}) {const api: { search?: (query: string) => readonly Unstable_TriggerItem[] } = {}function Probe() {- const { adapter } = useSlashCompletions({ gateway })+ const { adapter } = useSlashCompletions({ gateway, ...options })api.search = adapter.searchreturn null@@ -95,6 +95,19 @@ describe('useSlashCompletions', () => {expect(request).toHaveBeenCalledTimes(2)})+ // A draft has no session yet, so the backend would otherwise scan the LAUNCH+ // profile's skills; the tile's rail-selected profile must ride along (#124651).+ it('scopes a sessionless catalog and typed lookup to the routed profile', async () => {+ const request = vi.fn().mockResolvedValue({ ...CATALOG, items: [] })+ const api = harness({ request } as unknown as HermesGateway, { profile: 's6probe-b' })++ await completions(api, '')+ await completions(api, 'b-only')++ expect(request).toHaveBeenCalledWith('commands.catalog', { profile: 's6probe-b' })+ expect(request).toHaveBeenCalledWith('complete.slash', { text: '/b-only', profile: 's6probe-b' })+ })+// A `/` typed mid-message is a reference dropped into prose, so the trigger// filters the list to skills (use-composer-trigger). A bare mid-message `/`// resolves to the same empty query as an opening `/`, so that filter runsdiff --git a/apps/desktop/src/app/chat/composer/hooks/use-slash-completions.ts b/apps/desktop/src/app/chat/composer/hooks/use-slash-completions.tsindex 4e16dfa3787..1dcb380d4aa 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-slash-completions.ts+++ b/apps/desktop/src/app/chat/composer/hooks/use-slash-completions.ts@@ -62,6 +62,8 @@ export function useSlashCompletions(options: {* session's repo, so the catalog and each query are fetched and cached per* session. */sessionId?: string | null+ /** The tile's routed profile: scopes the palette while a draft has no session yet (#124651). */+ profile?: string | null/** Desktop theme list — `/skin` is owned client-side, so its arg completions* come from here, not the backend (whose skin list is CLI/TUI-only). */skinThemes?: DesktopThemeCommandOption[]@@ -70,12 +72,18 @@ export function useSlashCompletions(options: {adapter: Unstable_TriggerAdapterloading: boolean} {- const { gateway, sessionId, skinThemes, activeSkin } = options+ const { gateway, sessionId, profile, skinThemes, activeSkin } = optionsconst { locale } = useI18n()const enabled = Boolean(gateway)const epoch = useStore($slashCompletionsEpoch)- const sessionParams = useMemo(() => (sessionId ? { session_id: sessionId } : {}), [sessionId])- const catalogKey = sessionId ? `catalog:${sessionId}` : 'catalog'++ const sessionParams = useMemo(+ () => (sessionId ? { session_id: sessionId } : profile ? { profile } : {}),+ [sessionId, profile]+ )++ const scopeKey = sessionId ?? (profile ? `profile:${profile}` : '')+ const catalogKey = scopeKey ? `catalog:${scopeKey}` : 'catalog'// Warm argument_mode before the first `/` so Space treats /review as text.useEffect(() => {@@ -206,7 +214,7 @@ export function useSlashCompletions(options: {return { items, query }}- const result = await cachedSlashCompletion(`slash:${sessionId ?? ''}:${text.toLowerCase()}`, () =>+ const result = await cachedSlashCompletion(`slash:${scopeKey}:${text.toLowerCase()}`, () =>gateway.request<{ items?: CompletionEntry[]; replace_from?: number }>('complete.slash', {text,...sessionParams@@ -274,7 +282,7 @@ export function useSlashCompletions(options: {return { items: [], query }}},- [gateway, skinThemes, activeSkin, sessionId, catalogKey, sessionParams]+ [gateway, skinThemes, activeSkin, scopeKey, catalogKey, sessionParams])const toItem = useCallback((entry: CompletionEntry, index: number): Unstable_TriggerItem => {@@ -316,9 +324,9 @@ export function useSlashCompletions(options: {return true}- return hasCachedSlashCompletion(query ? `slash:${sessionId ?? ''}:${text.toLowerCase()}` : catalogKey)+ return hasCachedSlashCompletion(query ? `slash:${scopeKey}:${text.toLowerCase()}` : catalogKey)},- [skinThemes, sessionId, catalogKey]+ [skinThemes, scopeKey, catalogKey])return useLiveCompletionAdapter({ enabled, epoch: `${epoch}:${locale}`, fetcher, isCached, toItem })diff --git a/apps/desktop/src/app/chat/composer/index.tsx b/apps/desktop/src/app/chat/composer/index.tsxindex ad18f5058fd..7ebfb838275 100644--- a/apps/desktop/src/app/chat/composer/index.tsx+++ b/apps/desktop/src/app/chat/composer/index.tsx@@ -119,6 +119,7 @@ export function ChatBar({focusKey,gateway,maxRecordingSeconds = 120,+ profile,queueSessionKey,sessionId,state,@@ -280,6 +281,7 @@ export function ChatBar({const slash = useSlashCompletions({activeSkin: themeName,gateway: gateway ?? null,+ profile: profile ?? null,sessionId: sessionId ?? null,skinThemes: availableThemes})diff --git a/apps/desktop/src/app/chat/composer/types.ts b/apps/desktop/src/app/chat/composer/types.tsindex 00cb67d91c9..bfe81d1345b 100644--- a/apps/desktop/src/app/chat/composer/types.ts+++ b/apps/desktop/src/app/chat/composer/types.ts@@ -45,6 +45,8 @@ export interface ChatBarProps {gateway?: HermesGateway | nullqueueSessionKey?: string | nullsessionId?: string | null+ /** The tile's routed profile: scopes the slash palette while a draft has no session yet. */+ profile?: string | nullcwd?: string | nullonCancel: () => Promise<void> | voidonAddContextRef?: (refText: string, label?: string, detail?: string) => voiddiff --git a/apps/desktop/src/app/chat/index.tsx b/apps/desktop/src/app/chat/index.tsxindex d4852865777..51485ae70b6 100644--- a/apps/desktop/src/app/chat/index.tsx+++ b/apps/desktop/src/app/chat/index.tsx@@ -902,6 +902,7 @@ const ChatViewContent = memo(function ChatViewContent({onSteerHidden={onSteerHidden}onSubmit={onSubmit}onTranscribeAudio={onTranscribeAudio}+ profile={modelOptionsProfile || activeGatewayProfile}queueSessionKey={queueSessionKey}sessionId={activeSessionId}state={chatBarState}diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.tsindex d3abd3c30ce..59ee1b628b6 100644--- a/apps/shared/src/gateway-contract.generated.ts+++ b/apps/shared/src/gateway-contract.generated.ts@@ -1691,10 +1691,11 @@ export interface CompletionItem {meta?: stringkind?: string | null}-/** ``session_id`` binds skill completions to that session's profile and workspace (project skills). */+/** ``session_id`` binds skill completions to that session's profile and workspace (project skills); ``profile`` scopes a session-less request (a new-chat draft). */export interface CompleteSlashParams {text?: string | nullsession_id?: string | null+ profile?: string | null}/** ``replace_from`` is the column the accepted item replaces from. */export interface CompleteSlashResult {@@ -3793,9 +3794,10 @@ export interface SkillInspectInfo {skill_md_preview?: string | null[key: string]: unknown}-/** ``session_id`` binds the rescan to that session's profile and workspace (project skills). */+/** ``session_id`` binds the rescan to that session's profile and workspace (project skills); ``profile`` scopes a session-less rescan. */export interface SkillsReloadParams {session_id?: string | null+ profile?: string | null}export interface SkillsReloadResult {output: stringdiff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.jsonindex 7c88345254e..4a92d2b62a8 100644--- a/apps/shared/src/gateway-contract.openrpc.json+++ b/apps/shared/src/gateway-contract.openrpc.json@@ -8060,7 +8060,7 @@},"CompleteSlashParams": {"additionalProperties": false,- "description": "``session_id`` binds skill completions to that session's profile and workspace (project skills).",+ "description": "``session_id`` binds skill completions to that session's profile and workspace (project skills);\n``profile`` scopes a session-less request (a new-chat draft).","properties": {"text": {"anyOf": [@@ -8085,6 +8085,18 @@],"default": null,"title": "Session Id"+ },+ "profile": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Profile"}},"title": "CompleteSlashParams",@@ -32080,7 +32092,7 @@},"SkillsReloadParams": {"additionalProperties": false,- "description": "``session_id`` binds the rescan to that session's profile and workspace (project skills).",+ "description": "``session_id`` binds the rescan to that session's profile and workspace (project skills);\n``profile`` scopes a session-less rescan.","properties": {"session_id": {"anyOf": [@@ -32093,6 +32105,18 @@],"default": null,"title": "Session Id"+ },+ "profile": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Profile"}},"title": "SkillsReloadParams",diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.pyindex 3df44602d04..87852708a9c 100644--- a/tests/tui_gateway/test_protocol.py+++ b/tests/tui_gateway/test_protocol.py@@ -1263,6 +1263,46 @@ def test_slash_exec_scopes_skill_lookup_to_session_profile(server, tmp_path):assert resp["error"]["code"] == 4018+def test_sessionless_slash_palette_follows_profile_param(server, tmp_path, monkeypatch):+ """A Desktop draft has no session yet: ``commands.catalog`` / ``complete.slash`` must scan the+ named ``profile``'s home, not the launch profile's — A→B→A under multiplexing (#124651)."""+ import agent.skill_commands as sc_mod+ from agent.secret_scope import is_multiplex_active, set_multiplex_active++ root = tmp_path / "hermes_home"+ for name in ("s6probe-a", "s6probe-b"):+ skill_dir = tmp_path / f"external_{name}" / f"{name}-only"+ skill_dir.mkdir(parents=True)+ (skill_dir / "SKILL.md").write_text(f"---\nname: {name}-only\ndescription: Only in {name}.\n---\n\n# x\n")+ (root / "profiles" / name).mkdir(parents=True)+ (root / "profiles" / name / "config.yaml").write_text(+ f"skills:\n external_dirs:\n - {skill_dir.parent}\n")+ monkeypatch.setenv("HERMES_HOME", str(root))+ monkeypatch.setattr(server, "_hermes_home", str(root))++ def palette(profile):+ catalog = server.handle_request({"id": "r1", "method": "commands.catalog", "params": {"profile": profile}})+ typed = server.handle_request({+ "id": "r2", "method": "complete.slash", "params": {"text": "/s6probe", "profile": profile}})+ assert "result" in catalog and "result" in typed, (catalog, typed)+ return set(catalog["result"]["skills"]), {item["text"].strip("/") for item in typed["result"]["items"]}++ previous = is_multiplex_active()+ set_multiplex_active(True)+ try:+ with (+ patch("tools.skills_tool.SKILLS_DIR", tmp_path / "no-local-skills"),+ patch.object(sc_mod, "_skill_commands", {}),+ patch.object(sc_mod, "_skill_commands_platform", None),+ patch.object(sc_mod, "_skill_commands_home", None),+ ):+ assert palette("s6probe-a") == ({"/s6probe-a-only"}, {"s6probe-a-only"})+ assert palette("s6probe-b") == ({"/s6probe-b-only"}, {"s6probe-b-only"})+ assert palette("s6probe-a") == ({"/s6probe-a-only"}, {"s6probe-a-only"})+ finally:+ set_multiplex_active(previous)++class _BannerWorker:"""Stand-in for the slash worker's current skill path: ok-reply the banner."""diff --git a/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py b/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.pyindex 305c829aadf..27b483acb42 100644--- a/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py+++ b/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py@@ -48,10 +48,12 @@ method("complete.path", params=CompletePathParams, result=CompletionItemsResult,class CompleteSlashParams(Params):- """``session_id`` binds skill completions to that session's profile and workspace (project skills)."""+ """``session_id`` binds skill completions to that session's profile and workspace (project skills);+ ``profile`` scopes a session-less request (a new-chat draft)."""text: str | None = Nonesession_id: str | None = None+ profile: str | None = Noneclass CompleteSlashResult(Result):diff --git a/tui_gateway/contracts/tools_mcp_plugins.py b/tui_gateway/contracts/tools_mcp_plugins.pyindex 90b97850a93..64a93dbbb80 100644--- a/tui_gateway/contracts/tools_mcp_plugins.py+++ b/tui_gateway/contracts/tools_mcp_plugins.py@@ -205,9 +205,11 @@ method("skills.manage", params=SkillsManageParams, result=SkillsManageResult,class SkillsReloadParams(Params):- """``session_id`` binds the rescan to that session's profile and workspace (project skills)."""+ """``session_id`` binds the rescan to that session's profile and workspace (project skills);+ ``profile`` scopes a session-less rescan."""session_id: str | None = None+ profile: str | None = Noneclass SkillCommandRef(Result):diff --git a/tui_gateway/methods_complete.py b/tui_gateway/methods_complete.pyindex 863b7505458..3585d7d4cda 100644--- a/tui_gateway/methods_complete.py+++ b/tui_gateway/methods_complete.py@@ -286,7 +286,9 @@ def _(rid, params: dict) -> dict:from agent.skill_bundles import get_skill_bundles# Skill/bundle lookups are home- and cwd-keyed: bind the calling session's profile and workspace so# the popup offers the project-local skills ``command.dispatch`` accepts for that session (#114359).- with _session_home_scope(_sessions.get(params.get("session_id", "")), cwd=_completion_cwd(params)):+ # A new-chat draft has no session yet: it names its rail-selected ``profile`` instead (#124651).+ with _session_home_scope(_sessions.get(params.get("session_id", "")), cwd=_completion_cwd(params),+ profile=params.get("profile")):skill_commands, skill_bundles = dict(get_skill_commands()), dict(get_skill_bundles())completer = SlashCommandCompleter(skill_commands_provider=lambda: skill_commands, skill_bundles_provider=lambda: skill_bundles)diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.pyindex d1b7e1abbfd..2e3d02a40f2 100644--- a/tui_gateway/methods_tools.py+++ b/tui_gateway/methods_tools.py@@ -491,7 +491,7 @@ def _(rid, params: dict) -> dict:the built-in-name collision notice for skills that have no ``/<name>`` (empty when none). Skilldiscovery is bound to the calling session's profile and workspace (``_completion_cwd``: its record,else the cwd a new session would be seeded with) so project-local skills register for the repo the- session is actually in (#114359)."""+ session is actually in (#114359); a session-less draft is bound to ``params['profile']`` (#124651)."""cat = _Catalog()_catalog_registry(cat)warning = ""@@ -505,7 +505,8 @@ def _(rid, params: dict) -> dict:warning = warning or f"plugin command discovery unavailable: {e}"skills: dict[str, dict] = {}try:- with _session_home_scope(_sessions.get(params.get("session_id", "")), cwd=_completion_cwd(params)):+ with _session_home_scope(_sessions.get(params.get("session_id", "")), cwd=_completion_cwd(params),+ profile=params.get("profile")):collision_note = _catalog_skills(cat, skills) # always runs: skills must list even when a loader failedwarning = warning or collision_noteexcept Exception as e:@@ -589,7 +590,7 @@ def _run_plugin_command(handler, arg: str, session=None) -> str:@contextlib.contextmanager-def _session_home_scope(session, cwd: str | None = None):+def _session_home_scope(session, cwd: str | None = None, profile: str | None = None):"""Bind HERMES_HOME and the logical cwd to the session for the block.Skill/bundle/quick-command resolution is home-keyed (``skills.external_dirs``, ``skill-bundles/``,@@ -598,10 +599,13 @@ def _session_home_scope(session, cwd: str | None = None):are cwd-keyed (``find_project_root`` reads the session-bound cwd first): these RPCs run on the socketthread with no session context, where the terminal scope resolves a placeholder ``terminal.cwd`` to``$HOME`` and no project skill ever registers or dispatches (#114359). ``cwd`` overrides the session- record (a session-less catalog request binds the workspace a new session would be seeded with)."""+ record (a session-less catalog request binds the workspace a new session would be seeded with).+ ``profile`` scopes a session-less call (a Desktop draft names its rail-selected profile) (#124651)."""hc = _tools_mod("hermes_constants")rc = _tools_mod("agent.runtime_cwd")profile_home = session.get("profile_home") if session else None+ if not session and profile:+ profile_home = str(_profile_home(profile) or "") or Nonecwd = cwd or (str(session.get("cwd") or "") if session else "")token = hc.set_hermes_home_override(profile_home) if profile_home else Nonecwd_token = rc.set_session_cwd(cwd) if cwd else None@@ -1337,7 +1341,8 @@ def _(rid, params: dict) -> dict:def _(rid, params: dict) -> dict:# Bound like ``commands.catalog``: an unbound rescan runs against the launch env, reports the session's# project skills as "Removed" and republishes a registry without them (#114359).- with _session_home_scope(_sessions.get(params.get("session_id", "")), cwd=_completion_cwd(params)):+ with _session_home_scope(_sessions.get(params.get("session_id", "")), cwd=_completion_cwd(params),+ profile=params.get("profile")):result = _tools_mod("agent.skill_commands").reload_skills()added, removed = result.get("added") or [], result.get("removed") or []lines = ["Reloading skills..."] + ([] if added or removed else ["No new skills detected."])