Skip to content

The agent that grows with you

fix(tui): bind complete.slash and skills.reload to the calling session's workspace

teknium1d5bfdb5d7e70
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.ts
index a3990d6bf8d..22abb8c358e 100644
--- a/apps/shared/src/gateway-contract.generated.ts
+++ b/apps/shared/src/gateway-contract.generated.ts
@@ -1401,8 +1401,10 @@ export interface CompletionItem {
meta?: string
kind?: string | null
}
+/** ``session_id`` binds skill completions to that session's profile and workspace (project skills). */
export interface CompleteSlashParams {
text?: string | null
+ session_id?: string | null
}
/** ``replace_from`` is the column the accepted item replaces from. */
export interface CompleteSlashResult {
@@ -3409,7 +3411,10 @@ export interface SkillInspectInfo {
skill_md_preview?: string | null
[key: string]: unknown
}
-export type SkillsReloadParams = Record<string, never>
+/** ``session_id`` binds the rescan to that session's profile and workspace (project skills). */
+export interface SkillsReloadParams {
+ session_id?: string | null
+}
export interface SkillsReloadResult {
output: string
result: SkillsReloadDiff
diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.json
index ddd394afbbf..c9bb42c9aab 100644
--- a/apps/shared/src/gateway-contract.openrpc.json
+++ b/apps/shared/src/gateway-contract.openrpc.json
@@ -7615,6 +7615,7 @@
},
"CompleteSlashParams": {
"additionalProperties": false,
+ "description": "``session_id`` binds skill completions to that session's profile and workspace (project skills).",
"properties": {
"text": {
"anyOf": [
@@ -7627,6 +7628,18 @@
],
"default": null,
"title": "Text"
+ },
+ "session_id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Session Id"
}
},
"title": "CompleteSlashParams",
@@ -28181,7 +28194,21 @@
},
"SkillsReloadParams": {
"additionalProperties": false,
- "properties": {},
+ "description": "``session_id`` binds the rescan to that session's profile and workspace (project skills).",
+ "properties": {
+ "session_id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Session Id"
+ }
+ },
"title": "SkillsReloadParams",
"type": "object"
},
diff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.py
index 982be8017ae..e37383ad473 100644
--- a/tests/tui_gateway/test_tui_gateway_server.py
+++ b/tests/tui_gateway/test_tui_gateway_server.py
@@ -3124,12 +3124,9 @@ def test_expand_skill_invocation_for_replay_leaves_ordinary_text_alone(monkeypat
assert server._expand_skill_invocation_for_replay("/status", "t") == "/status"
-def test_command_dispatch_and_catalog_resolve_project_skills_from_the_session_cwd(tmp_path, monkeypatch):
- # TUI/desktop: the RPC thread has no session context and the terminal scope / process env resolve a
- # placeholder ``terminal.cwd`` to $HOME, so project skills of the session's repo never registered and
- # ``/<name>`` died with "not a quick/plugin/bundle/skill command". Two sessions in two trusted repos
- # in ONE process must each catalog and dispatch their own repo's skill (the cached registry is
- # keyed by project root, not just platform + home).
+def _two_repo_project_skill_sessions(tmp_path, monkeypatch) -> tuple[Path, Path]:
+ """Two trusted repos (``alpha-skill`` / ``beta-skill``) bound to sessions ``sid-a`` / ``sid-b``, in a
+ launch shape whose process cwd and TERMINAL_CWD both point at a non-project dir."""
import agent.skill_commands as skill_commands
import agent.skill_utils as skill_utils
import tools.skills_tool as skills_tool
@@ -3162,7 +3159,18 @@ def test_command_dispatch_and_catalog_resolve_project_skills_from_the_session_cw
monkeypatch.setattr(server, "_sessions", {
"sid-a": {"session_key": "key-a", "cwd": str(repo_a)},
"sid-b": {"session_key": "key-b", "cwd": str(repo_b)}})
+ return repo_a, repo_b
+
+def test_command_dispatch_and_catalog_resolve_project_skills_from_the_session_cwd(tmp_path, monkeypatch):
+ # TUI/desktop: the RPC thread has no session context and the terminal scope / process env resolve a
+ # placeholder ``terminal.cwd`` to $HOME, so project skills of the session's repo never registered and
+ # ``/<name>`` died with "not a quick/plugin/bundle/skill command". Two sessions in two trusted repos
+ # in ONE process must each catalog and dispatch their own repo's skill (the cached registry is
+ # keyed by project root, not just platform + home).
+ import agent.skill_utils as skill_utils
+
+ _two_repo_project_skill_sessions(tmp_path, monkeypatch)
for sid, own, other in (("sid-a", "alpha-skill", "beta-skill"), ("sid-b", "beta-skill", "alpha-skill")):
catalog = server._methods["commands.catalog"]("c", {"session_id": sid})["result"]
assert f"/{own}" in catalog["skills"] and f"/{other}" not in catalog["skills"]
@@ -3175,6 +3183,24 @@ def test_command_dispatch_and_catalog_resolve_project_skills_from_the_session_cw
assert skill_utils.find_project_root() is None
+def test_complete_slash_and_skills_reload_are_bound_to_the_session_cwd(tmp_path, monkeypatch):
+ # The '/' popup and /reload-skills ran the registry unbound: the popup never offered a project skill
+ # ``command.dispatch`` accepts, and a rescan after that dispatch reported the session's project skills
+ # as "Removed" and republished a registry without them.
+ import agent.skill_commands as skill_commands
+
+ _two_repo_project_skill_sessions(tmp_path, monkeypatch)
+ items = server._methods["complete.slash"]("s", {"text": "/alph", "session_id": "sid-a"})["result"]["items"]
+ assert [i["text"] for i in items if i["kind"] == "skill"] == ["alpha-skill"]
+ assert server._methods["command.dispatch"]("d", {"name": "alpha-skill", "arg": "", "session_id": "sid-a"})[
+ "result"]["type"] == "skill"
+ reload = server._methods["skills.reload"]("r", {"session_id": "sid-a"})["result"]
+ assert reload["result"]["removed"] == [] and "/alpha-skill" in skill_commands._skill_commands, reload["output"]
+ # Another session's reload resolves ITS repo, not the launch env.
+ other = server._methods["skills.reload"]("r", {"session_id": "sid-b"})["result"]
+ assert {i["name"] for i in other["result"]["added"]} == {"beta-skill"}, other["output"]
+
+
def test_history_to_messages_types_a_legacy_auto_continue_row():
# A crash-interrupted turn used to be typed only AFTER it finished, so a
# turn killed a second time (or any row written before turn-start typing
diff --git a/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py b/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py
index 9bf5801335b..987959c454e 100644
--- a/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py
+++ b/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py
@@ -47,7 +47,10 @@ method("complete.path", params=CompletePathParams, result=CompletionItemsResult,
class CompleteSlashParams(Params):
+ """``session_id`` binds skill completions to that session's profile and workspace (project skills)."""
+
text: str | None = None
+ session_id: str | None = None
class CompleteSlashResult(Result):
diff --git a/tui_gateway/contracts/tools_mcp_plugins.py b/tui_gateway/contracts/tools_mcp_plugins.py
index 2d59cc9e333..7f4a7f528e2 100644
--- a/tui_gateway/contracts/tools_mcp_plugins.py
+++ b/tui_gateway/contracts/tools_mcp_plugins.py
@@ -204,7 +204,9 @@ method("skills.manage", params=SkillsManageParams, result=SkillsManageResult,
class SkillsReloadParams(Params):
- pass
+ """``session_id`` binds the rescan to that session's profile and workspace (project skills)."""
+
+ session_id: str | None = None
class SkillCommandRef(Result):
diff --git a/tui_gateway/methods_complete.py b/tui_gateway/methods_complete.py
index 2fda7eb9cbb..63dc24a79f8 100644
--- a/tui_gateway/methods_complete.py
+++ b/tui_gateway/methods_complete.py
@@ -277,11 +277,15 @@ def _(rid, params: dict) -> dict:
from prompt_toolkit.formatted_text import to_plain_text
from agent.skill_commands import get_skill_commands
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)):
+ skill_commands, skill_bundles = dict(get_skill_commands()), dict(get_skill_bundles())
completer = SlashCommandCompleter(
- skill_commands_provider=lambda: get_skill_commands(), skill_bundles_provider=lambda: get_skill_bundles())
+ skill_commands_provider=lambda: skill_commands, skill_bundles_provider=lambda: skill_bundles)
# `kind` reaches the TUI as data (from the providers, not sniffed from ⚡/▣ glyphs):
# skills/bundles are the only completions for an inline `/skill` typed mid-message.
- skill_names = {key.lstrip("/").lower() for key in (*get_skill_commands(), *get_skill_bundles())}
+ skill_names = {key.lstrip("/").lower() for key in (*skill_commands, *skill_bundles)}
def to_items(doc: Document) -> list[dict]:
# display/display_meta are FormattedText; the TUI contract is a plain string
diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.py
index ce1f35b0df0..14d97875e21 100644
--- a/tui_gateway/methods_tools.py
+++ b/tui_gateway/methods_tools.py
@@ -1184,7 +1184,10 @@ def _(rid, params: dict) -> dict:
@_rpc("skills.reload", 5025)
def _(rid, params: dict) -> dict:
- result = _tools_mod("agent.skill_commands").reload_skills()
+ # 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)):
+ 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."])
for label, items in (("Added skills:", added), ("Removed skills:", removed)):