From 0b6540e33c21dc0e7f58a57f81c6541098825462 Mon Sep 17 00:00:00 2001 From: LHaghfoss Date: Tue, 24 Nov 2026 15:15:43 +0100 Subject: [PATCH] fix(mcp): ask agents to name their thread with the first tool call --- rustcode/engine/src/orchestration.rs | 4 ++-- rustcode/engine/src/orchestration/tests.rs | 5 +++-- rustcode/engine/src/tools/misc/orchestration_tools.rs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/rustcode/engine/src/orchestration.rs b/rustcode/engine/src/orchestration.rs index 5d8091249..af5eb7c73 100644 --- a/rustcode/engine/src/orchestration.rs +++ b/rustcode/engine/src/orchestration.rs @@ -354,7 +354,7 @@ pub const PROMPT_HINT_V14: &str = "\n\nRustCode's threads: `list_sessions`, `sea pub const PROMPT_HINT_V15: &str = "\n\nRustCode's threads: `list_sessions`, `search_sessions`, `read_session`, `list_worktrees` and `list_projects` answer what the user asks about their threads, projects and past work, so ask them instead of looking for that data elsewhere, and pass `all_projects` to reach every project. Given a thread id, `read_session` it before answering about it, and `read_activity` pages what RustCode recorded about it (events, retries, provider attempts) as metadata, never prompts. `thread_usage` totals tokens and the cost each harness reported (never a price RustCode computed) by harness, model, day, project or thread; `query_data` runs one read-only SQL statement over what the harnesses recorded (turns, tool_calls, threads, daily_usage). `list_harnesses` shows what can run and its named accounts, `list_pull_requests` this project's pull requests, `list_pending_requests` which threads wait on the user, and `answer_request` answers one of those on a thread in your own tree. `start_session` and `fan_out` take a harness's named `account`; `start_session`, `fan_out` and `message_session` give other threads work, and `message_session` reaches any project with user approval, attaches files by path and takes `steer: true` for mid-turn input (otherwise queued); `wait_session` returns their answers; `manage_queue` lists, edits, cancels or steers what this thread queued on a busy one. `thread_status` reports a delegate's worktree, branch, pull request and checks; `merge_when_green` merges it once green; `cleanup_worktree` removes its worktree and branch and settles it; `worktree_status` reports a worktree's branch, its distance from the branch it tracks, changed files, last commit and pull request; `handoff_worktree` moves a delegate's work into the user's checkout, or a thread's checkout work into a worktree of its own, and keeps every commit. The thread tools take another paired computer's id or name, as `list_machines` lists them, in `machine`: omitted, they act on this computer, and a remote thread's id carries its machine. Name one only when the user did. Delegates use `$TMPDIR/rustcode/`, never a shared `/tmp` path. A thread `start_session` or `fan_out` starts is a delegate, shown nested under this one: give it a whole task; a Claude Code thread has no subagent tool, so delegate through `start_session` or `fan_out`. For a thread the user will follow up themselves, pass `standalone: true`: it is a thread of their own at the top level of its project, nothing is delivered back and `wait_session` does not apply, so name its session id to them. `update_session`, `organize_threads`, `configure_session`, `transfer_session` and `interrupt_session` manage them. Those, answering, merge, cleanup and handoff change other threads, so do them only when the user asks; the user approves, and a card for another machine names it. Stay lean: every call resends this thread's context, so leave reading code, diffs, logs and CI to delegates, and check their pull requests with `thread_status`. Wait on all links in one `wait_session` with `link_ids`, or end the turn: the app wakes this thread when a child finishes. Call `list_harnesses` once. Projects: `read_project` reads a folder's git remote, branch and default branch; `create_project` registers a folder (an empty one gets `git init`), `clone_project` clones a URL into a parent folder, `update_project` sets a project's display name or the harness and model new threads in it start on, and `remove_project` unregisters one without deleting any files. Scheduled work: `schedule_task` adds a prompt that runs on a cron expression or once at an ISO time, `list_scheduled_tasks`, `delete_scheduled_task` and `run_scheduled_task_now` manage what the scheduler daemon holds; the daemon is `rustcode daemon start`, and without it nothing runs. Do both only when the user asks; the user approves."; /// [`PROMPT_HINT_V15`] for version 16 clients, which reach the rest of the /// thread tools, and a project by its git remote, on another machine. -pub const PROMPT_HINT_V16: &str = "\n\nRustCode's threads: `list_sessions`, `search_sessions`, `read_session`, `list_worktrees` and `list_projects` answer what the user asks about their threads, projects and past work, so ask them instead of looking for that data elsewhere, and pass `all_projects` to reach every project. Given a thread id, `read_session` it before answering about it, and `read_activity` pages what RustCode recorded about it (events, retries, provider attempts) as metadata, never prompts. `thread_usage` totals tokens and the cost each harness reported (never a price RustCode computed) by harness, model, day, project or thread; `query_data` runs one read-only SQL statement over what the harnesses recorded (turns, tool_calls, threads, daily_usage). `list_harnesses` shows what can run and its named accounts, `list_pull_requests` this project's pull requests, `list_pending_requests` which threads wait on the user, and `answer_request` answers one of those on a thread in your own tree. `start_session` and `fan_out` take a harness's named `account`; `start_session`, `fan_out` and `message_session` give other threads work, and `message_session` reaches any project with user approval, attaches files by path and takes `steer: true` for mid-turn input (otherwise queued); `wait_session` returns their answers; `manage_queue` lists, edits, cancels or steers what this thread queued on a busy one. `thread_status` reports a delegate's worktree, branch, pull request and checks; `merge_when_green` merges it once green; `cleanup_worktree` removes its worktree and branch and settles it; `worktree_status` reports a worktree's branch, its distance from the branch it tracks, changed files, last commit and pull request; `handoff_worktree` moves a delegate's work into the user's checkout, or a thread's checkout work into a worktree of its own, and keeps every commit. The thread tools, `list_projects`, `read_project` and `clone_project` take another paired computer's id or name, as `list_machines` lists them, in `machine`: omitted, they act on this computer, and a remote thread's id carries its machine. Name one only when the user did, and never fall back to this computer when it is offline. There a thread starts in the project with this one's git remote; with none, pass `project` from the list the refusal gives, or `clone_project` there. Delegates use `$TMPDIR/rustcode/`, never a shared `/tmp` path. Use `start_session` with `standalone: true` when the user says “start a new thread” or “start an agent in a new thread”. It appears at the top level of the project. Give the user its session id. Use `start_session` without standalone or `fan_out` for delegates only when the user explicitly asks for a delegate or asks for the work to report back here. A native subagent is a helper inside the current thread. Use one only when the user explicitly asks for a subagent and the harness supports it. If “start an agent” alone leaves the intent unclear, ask which they mean before starting anything. `update_session`, `organize_threads`, `configure_session`, `transfer_session` and `interrupt_session` manage them. Those, answering, merge, cleanup and handoff change other threads, so do them only when the user asks; the user approves, and a card for another machine names it. When you start work on a thread whose title is still automatic, call `update_session` once with a short title (6 words or fewer) describing the task; a title the user chose stays. When the user says to settle (\"settle\", \"settle this\", \"settle it\"), call `update_session` with `status: \"settled\"`: on this thread, or on the thread they name. Settling only marks it done: it leaves the active list and the app closes it if it is on screen; it does not merge, push or clean anything up. Stay lean: every call resends this thread's context, so leave reading code, diffs, logs and CI to delegates, and check their pull requests with `thread_status`. Wait on a whole wave in one `wait_session` with `link_ids` and `all: true`, which answers once every link has settled, or end the turn: the app wakes this thread when children finish, several in one wake. Call `list_harnesses` once. Projects: `read_project` reads a folder's git remote, branch and default branch; `create_project` registers a folder (an empty one gets `git init`), `clone_project` clones a URL into a parent folder, `update_project` sets a project's display name or the harness and model new threads in it start on, and `remove_project` unregisters one without deleting any files. Use `request_secret` for credentials instead of asking for them in chat; never read or print the destination file. `manage_settings` lists and reads RustCode's own settings (auto-compact, delegate limits, default access and the rest) and sets or resets one when the user asks, and `manage_capabilities` lists and toggles skills and MCP servers, restarts an MCP server, picks the default harness and switches the theme; the user approves each change, so never edit `settings.json` or `config.toml` by hand. Scheduled work: `schedule_task` adds a prompt that runs on a cron expression or once at an ISO time, `list_scheduled_tasks`, `delete_scheduled_task` and `run_scheduled_task_now` manage what the scheduler daemon holds; the daemon is `rustcode daemon start`, and without it nothing runs. Do both only when the user asks; the user approves."; +pub const PROMPT_HINT_V16: &str = "\n\nRustCode's threads: `list_sessions`, `search_sessions`, `read_session`, `list_worktrees` and `list_projects` answer what the user asks about their threads, projects and past work, so ask them instead of looking for that data elsewhere, and pass `all_projects` to reach every project. Given a thread id, `read_session` it before answering about it, and `read_activity` pages what RustCode recorded about it (events, retries, provider attempts) as metadata, never prompts. `thread_usage` totals tokens and the cost each harness reported (never a price RustCode computed) by harness, model, day, project or thread; `query_data` runs one read-only SQL statement over what the harnesses recorded (turns, tool_calls, threads, daily_usage). `list_harnesses` shows what can run and its named accounts, `list_pull_requests` this project's pull requests, `list_pending_requests` which threads wait on the user, and `answer_request` answers one of those on a thread in your own tree. `start_session` and `fan_out` take a harness's named `account`; `start_session`, `fan_out` and `message_session` give other threads work, and `message_session` reaches any project with user approval, attaches files by path and takes `steer: true` for mid-turn input (otherwise queued); `wait_session` returns their answers; `manage_queue` lists, edits, cancels or steers what this thread queued on a busy one. `thread_status` reports a delegate's worktree, branch, pull request and checks; `merge_when_green` merges it once green; `cleanup_worktree` removes its worktree and branch and settles it; `worktree_status` reports a worktree's branch, its distance from the branch it tracks, changed files, last commit and pull request; `handoff_worktree` moves a delegate's work into the user's checkout, or a thread's checkout work into a worktree of its own, and keeps every commit. The thread tools, `list_projects`, `read_project` and `clone_project` take another paired computer's id or name, as `list_machines` lists them, in `machine`: omitted, they act on this computer, and a remote thread's id carries its machine. Name one only when the user did, and never fall back to this computer when it is offline. There a thread starts in the project with this one's git remote; with none, pass `project` from the list the refusal gives, or `clone_project` there. Delegates use `$TMPDIR/rustcode/`, never a shared `/tmp` path. Use `start_session` with `standalone: true` when the user says “start a new thread” or “start an agent in a new thread”. It appears at the top level of the project. Give the user its session id. Use `start_session` without standalone or `fan_out` for delegates only when the user explicitly asks for a delegate or asks for the work to report back here. A native subagent is a helper inside the current thread. Use one only when the user explicitly asks for a subagent and the harness supports it. If “start an agent” alone leaves the intent unclear, ask which they mean before starting anything. `update_session`, `organize_threads`, `configure_session`, `transfer_session` and `interrupt_session` manage them. Those, answering, merge, cleanup and handoff change other threads, so do them only when the user asks; the user approves, and a card for another machine names it. If you have not named this thread yet, make `update_session` your first tool call, with a short title (6 words or fewer) for the task; do it even if the thread already has a title, since a title the user chose stays and the answer says `title_kept`. When the user says to settle (\"settle\", \"settle this\", \"settle it\"), call `update_session` with `status: \"settled\"`: on this thread, or on the thread they name. Settling only marks it done: it leaves the active list and the app closes it if it is on screen; it does not merge, push or clean anything up. Stay lean: every call resends this thread's context, so leave reading code, diffs, logs and CI to delegates, and check their pull requests with `thread_status`. Wait on a whole wave in one `wait_session` with `link_ids` and `all: true`, which answers once every link has settled, or end the turn: the app wakes this thread when children finish, several in one wake. Call `list_harnesses` once. Projects: `read_project` reads a folder's git remote, branch and default branch; `create_project` registers a folder (an empty one gets `git init`), `clone_project` clones a URL into a parent folder, `update_project` sets a project's display name or the harness and model new threads in it start on, and `remove_project` unregisters one without deleting any files. Use `request_secret` for credentials instead of asking for them in chat; never read or print the destination file. `manage_settings` lists and reads RustCode's own settings (auto-compact, delegate limits, default access and the rest) and sets or resets one when the user asks, and `manage_capabilities` lists and toggles skills and MCP servers, restarts an MCP server, picks the default harness and switches the theme; the user approves each change, so never edit `settings.json` or `config.toml` by hand. Scheduled work: `schedule_task` adds a prompt that runs on a cron expression or once at an ISO time, `list_scheduled_tasks`, `delete_scheduled_task` and `run_scheduled_task_now` manage what the scheduler daemon holds; the daemon is `rustcode daemon start`, and without it nothing runs. Do both only when the user asks; the user approves."; /// The prompt hint a client of `version` gets. pub fn prompt_hint(version: u8) -> &'static str { @@ -395,7 +395,7 @@ pub const MCP_INSTRUCTIONS_LIMIT: usize = 4000; /// What the MCP server tells a version 16 client: the rules that span tools, /// with the ones that protect the user first. What a single tool does is in /// that tool's description, which a client does not cut. -pub const MCP_INSTRUCTIONS_V16: &str = "RustCode's threads, projects, settings and usage. Rules first. Use `request_secret` for credentials instead of asking for them in chat; never read or print the destination file. Change RustCode's settings, skills and MCP servers with `manage_settings` and `manage_capabilities`; never edit `settings.json` or `config.toml` by hand. Tools that change another thread (`update_session`, `organize_threads`, `configure_session`, `transfer_session`, `interrupt_session`, `answer_request`, `merge_when_green`, `cleanup_worktree`, `handoff_worktree`), a project or a loop run only when the user asks; the user approves, and a card for another machine names it. `machine` takes another paired computer's id or name from `list_machines`: omitted, a tool acts on this computer. Name one only when the user did, and never fall back to this computer when it is offline. Delegates use `$TMPDIR/rustcode/`, never a shared `/tmp` path.\n\nQuestions about the user's threads, projects, past work and usage: ask `list_sessions`, `search_sessions`, `read_session`, `list_worktrees`, `list_projects`, `thread_usage` and `query_data` instead of looking for that data elsewhere, and pass `all_projects` to reach every project. Given a thread id, `read_session` it before answering about it.\n\nUse `start_session` with `standalone: true` when the user says “start a new thread” or “start an agent in a new thread”. It appears at the top level of the project. Give the user its session id. Use `start_session` without standalone or `fan_out` for delegates only when the user explicitly asks for a delegate or asks for the work to report back here. A native subagent is a helper inside the current thread. Use one only when the user explicitly asks for a subagent and the harness supports it. If “start an agent” alone leaves the intent unclear, ask which they mean before starting anything. Use `message_session` to send work to an existing thread when the user asks. Stay lean: every call resends this thread's context, so leave reading code, diffs, logs and CI to delegates and check their pull requests with `thread_status`. Wait on a whole wave in one `wait_session` with `link_ids` and `all: true`, or end the turn: the app wakes this thread when children finish. Call `list_harnesses` once.\n\nThis thread: when its title is still automatic, call `update_session` once with a short title (6 words or fewer); a title the user chose stays. When the user says to settle (\"settle\", \"settle this\", \"settle it\"), call `update_session` with `status: \"settled\"` on this thread or the one they name. Settling only marks it done; it does not merge, push or clean anything up."; +pub const MCP_INSTRUCTIONS_V16: &str = "RustCode's threads, projects, settings and usage. Rules first. Name this thread first: if you have not called `update_session` with a title in this thread yet, make it your first tool call, with a short title (6 words or fewer) for the task. Do it even if the thread already has a title; a title the user chose stays and the answer says `title_kept`. Use `request_secret` for credentials instead of asking for them in chat; never read or print the destination file. Change RustCode's settings, skills and MCP servers with `manage_settings` and `manage_capabilities`; never edit `settings.json` or `config.toml` by hand. Tools that change another thread (`update_session`, `organize_threads`, `configure_session`, `transfer_session`, `interrupt_session`, `answer_request`, `merge_when_green`, `cleanup_worktree`, `handoff_worktree`), a project or a loop run only when the user asks; the user approves, and a card for another machine names it. `machine` takes another paired computer's id or name from `list_machines`: omitted, a tool acts on this computer. Name one only when the user did, and never fall back to this computer when it is offline. Delegates use `$TMPDIR/rustcode/`, never a shared `/tmp` path.\n\nQuestions about the user's threads, projects, past work and usage: ask `list_sessions`, `search_sessions`, `read_session`, `list_worktrees`, `list_projects`, `thread_usage` and `query_data` instead of looking for that data elsewhere, and pass `all_projects` to reach every project. Given a thread id, `read_session` it before answering about it.\n\nUse `start_session` with `standalone: true` when the user says “start a new thread” or “start an agent in a new thread”. It appears at the top level of the project. Give the user its session id. Use `start_session` without standalone or `fan_out` for delegates only when the user explicitly asks for a delegate or asks for the work to report back here. A native subagent is a helper inside the current thread. Use one only when the user explicitly asks for a subagent and the harness supports it. If “start an agent” alone leaves the intent unclear, ask which they mean before starting anything. Use `message_session` to send work to an existing thread when the user asks. Stay lean: every call resends this thread's context, so leave reading code, diffs, logs and CI to delegates and check their pull requests with `thread_status`. Wait on a whole wave in one `wait_session` with `link_ids` and `all: true`, or end the turn: the app wakes this thread when children finish. Call `list_harnesses` once.\n\nThis thread: when the user says to settle (\"settle\", \"settle this\", \"settle it\"), call `update_session` with `status: \"settled\"` on this thread or the one they name. Settling only marks it done; it does not merge, push or clean anything up."; /// The setting that lists [`EXTRA_TOOL_NAMES`] to a thread; off by default. pub const ALL_TOOLS_SETTING: &str = "orchestration-all-tools"; diff --git a/rustcode/engine/src/orchestration/tests.rs b/rustcode/engine/src/orchestration/tests.rs index d96ffb3e3..e1e6c04fb 100644 --- a/rustcode/engine/src/orchestration/tests.rs +++ b/rustcode/engine/src/orchestration/tests.rs @@ -297,8 +297,8 @@ fn version_four_adds_the_data_store_tools_only_for_its_clients() { } // Every agent is asked to name its own thread once (issue 3599). assert!(PROMPT_HINT_V16.contains( - "When you start work on a thread whose title is still automatic, call `update_session` once with a short title (6 words or fewer)" - )); + "If you have not named this thread yet, make `update_session` your first tool call" + )); // "Settle" means settling this thread, or the one the user names, and nothing else. assert!(PROMPT_HINT_V16.contains("When the user says to settle")); assert!(PROMPT_HINT_V16.contains("it does not merge, push or clean anything up")); @@ -444,6 +444,7 @@ fn the_mcp_instructions_fit_what_a_client_keeps() { "never fall back to this computer when it is offline", "`link_ids` and `all: true`", "it does not merge, push or clean anything up", + "Name this thread first", CREATE_LOOP, ] { assert!(text.contains(said), "{said}"); diff --git a/rustcode/engine/src/tools/misc/orchestration_tools.rs b/rustcode/engine/src/tools/misc/orchestration_tools.rs index 7b9f975a6..fed2875d9 100644 --- a/rustcode/engine/src/tools/misc/orchestration_tools.rs +++ b/rustcode/engine/src/tools/misc/orchestration_tools.rs @@ -271,7 +271,7 @@ pub const COMPACT_SESSION: Tool = Tool { pub const UPDATE_SESSION: Tool = Tool { name: crate::orchestration::UPDATE_SESSION, - description: "Rename, pin, mark unread (true) or read (false), snooze or change the status of a thread. Omit session_id for this thread; changing another asks the user first. Name this thread once when you start its task, with a short title of 6 words or fewer; a title the user chose stays, and title_kept says so. Status: active (back in the list), review (needs a look), settled (done; what \"settle\" asks; the app closes it). snoozed_until: how long it leaves the list: 1h, evening, tomorrow, next_week or an ISO 8601 time; null brings it back.", + description: "Rename, pin, mark unread (true) or read (false), snooze or change the status of a thread. Omit session_id for this thread; changing another asks the user first. Name this thread with your first tool call if you have not yet, with a short title of 6 words or fewer, even when it already has one; a title the user chose stays, and title_kept says so. Status: active (back in the list), review (needs a look), settled (done; what \"settle\" asks; the app closes it). snoozed_until: how long it leaves the list: 1h, evening, tomorrow, next_week or an ISO 8601 time; null brings it back.", arguments: r#"{"title": "Fix login", "pinned": true, "status": "settled"}"#, handler: orchestration_unavailable, requires_confirmation: false,