mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
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>
46 lines
2.1 KiB
TypeScript
46 lines
2.1 KiB
TypeScript
/** The Run tool window's agent tabs: starting them, and archiving finished ones. */
|
|
import type { IpcPath } from "@/bindings";
|
|
import { agentRunSettings } from "@/platform/workflowSettings";
|
|
import { agentConfig, agentName } from "./agentConfig";
|
|
import { closeSession, isLive, startRun, useRun, type RunSession } from "./store";
|
|
|
|
export interface AgentRunRequest {
|
|
name: string;
|
|
command: string;
|
|
cwd: IpcPath;
|
|
env: Record<string, string>;
|
|
}
|
|
|
|
/** Starts an agent's command in its tab (reused once its last command finished). */
|
|
export async function startAgentRun(request: AgentRunRequest): Promise<void> {
|
|
const config = agentConfig(request.name, request.command, request.cwd, request.env);
|
|
const existing = useRun.getState().sessions.find((s) => s.config.id === config.id);
|
|
// The backend refuses a running name first; nothing here stops a run on the agent's behalf.
|
|
if (existing && isLive(existing)) throw new Error(`${request.name} is still running`);
|
|
const session = await startRun(config, existing?.id);
|
|
if (!session || session.status === "failed") throw new Error("The command did not start");
|
|
}
|
|
|
|
const endedAt = (s: RunSession) => s.endedAt ?? s.startedAt;
|
|
|
|
/** Finished agent tabs beyond the newest `limit`: the archive, newest first. Running ones never are. */
|
|
export function archivedAgentSessions(sessions: readonly RunSession[], limit: number): RunSession[] {
|
|
return sessions
|
|
.filter((s) => agentName(s.config) !== null && !isLive(s))
|
|
.sort((a, b) => endedAt(b) - endedAt(a))
|
|
.slice(Math.max(0, limit));
|
|
}
|
|
|
|
/** Closes the oldest archived agent tabs beyond the archive limit. */
|
|
export function trimAgentArchive() {
|
|
const { tabLimit, archiveLimit } = agentRunSettings();
|
|
const archived = archivedAgentSessions(useRun.getState().sessions, tabLimit);
|
|
for (const s of archived.slice(archiveLimit)) closeSession(s.id, { agentTabClosed: false });
|
|
}
|
|
|
|
/** Closes every archived agent tab. */
|
|
export function closeAgentArchive() {
|
|
const archived = archivedAgentSessions(useRun.getState().sessions, agentRunSettings().tabLimit);
|
|
for (const s of archived) closeSession(s.id);
|
|
}
|