Files
openidea/src/features/run/agentConfig.ts
T
GuoYuandguoyucode 14ee1a97f2 feat(mcp): agent commands in Run tool window tabs, with streamed progress and no timeout cap (#2997)
The MCP server let agents read and edit code but not run a command and follow it, so they ran commands in their own shell, out of the user's sight. New tools run_command, wait_for_run, read_run_output, get_run_status, send_run_input, stop_run and list_runs run each command in a Run tool window tab _agent_<name>: the user sees it and can type into it, rerun, stop or close it, and results then carry interventions and advice so the agent stops and asks. The same name reuses its tab; a running one is refused. Every start asks the user unless tools run without confirmation. Commands run on pipes, with maxLinesCount / truncateMode, offsets to read on, and pattern waits. Finished agent tabs beyond a limit (default 1) move to an Archived (n) menu.

A call still running after a second is answered on an event stream with a progress notification every 15 s, so clients that drop a response not started within a minute keep waiting; the run tools (build_project and execute_run_configuration included) no longer cap timeout. A call is cancelled when its client goes away; the stdio bridge relays streamed answers.

Co-authored-by: guoyucode <29471644+guoyucode@users.noreply.github.com>
2026-11-13 13:23:56 +08:00

39 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** Run configurations of commands agents run through the IDE's MCP server (`run_command`). */
import type { IpcPath, RunConfig } from "@/bindings";
import { workflowSettings } from "@/platform/workflowSettings";
/** Names the agent tab a run belongs to; the backend logs it for the agent. */
export const AGENT_PARAM = "mcp.agentRun";
/** Settings › Tools › Terminal › Shell path, which the backend runs the command line with. */
const SHELL_PARAM = "mcp.agentShell";
/** The agent tab name of a configuration, or `null` for any other run. */
export function agentName(config: Pick<RunConfig, "params">): string | null {
return config.params?.[AGENT_PARAM] ?? null;
}
/**
* The command line of agent tab `name`, with the shell of the IDE's terminal but on pipes (as
* JetBrains' `execute_terminal_command`): programs print plain lines, the console shows them and
* sends the user's input lines.
*/
export function agentConfig(name: string, command: string, cwd: IpcPath, env: Record<string, string>): RunConfig {
const terminal = workflowSettings().terminal;
return {
id: `mcp-agent:${name}`,
name,
kind: "shell",
command,
args: [],
cwd,
env: { ...terminal.env, ...env },
detected: false,
isTest: false,
debugAdapter: null,
allowParallel: true,
params: { [AGENT_PARAM]: name, [SHELL_PARAM]: terminal.shellPath },
// This machine: an agent's command never goes to a default run target.
target: "",
};
}