MCPcopy
hub / github.com/RedPlanetHQ/core / tryRespawn

Function tryRespawn

packages/cli/src/server/api/coding/coding_xterm_session.ts:64–108  ·  view source on GitHub ↗
(
	sessionId: string,
	meta: {agent: string; dir: string},
)

Source from the content-addressed store, hash-verified

62}
63
64function tryRespawn(
65 sessionId: string,
66 meta: {agent: string; dir: string},
67): {ok: true; pid?: number} | {ok: false; reason: string} {
68 const config = getAgentConfig(meta.agent);
69 if (!config) {
70 return {
71 ok: false,
72 reason: `agent "${meta.agent}" not configured on this gateway`,
73 };
74 }
75 const args = buildResumeArgs(config, {sessionId});
76 if (args.length === 0) {
77 return {
78 ok: false,
79 reason: `agent "${meta.agent}" has no resumeArgs configured`,
80 };
81 }
82
83 const startedAt = Date.now();
84 upsertSession({sessionId, agent: meta.agent, dir: meta.dir, startedAt});
85 gatewayLog(
86 `xterm resume: agent=${meta.agent} dir=${meta.dir} sessionId=${sessionId}`,
87 );
88 const {pid, error} = startAgentProcess(
89 sessionId,
90 config,
91 args,
92 meta.dir,
93 gatewayLog,
94 meta.agent,
95 );
96 if (error) {
97 gatewayLog(`xterm resume FAILED: ${error}`);
98 return {ok: false, reason: `failed to spawn: ${error}`};
99 }
100 upsertSession({
101 sessionId,
102 agent: meta.agent,
103 dir: meta.dir,
104 pid,
105 startedAt,
106 });
107 return {ok: true, pid};
108}
109
110export const xtermSessionRoute: FastifyPluginAsync = async (app) => {
111 app.get<{Querystring: {session_id?: string}}>(

Callers 1

xtermSessionRouteFunction · 0.85

Calls 5

getAgentConfigFunction · 0.90
buildResumeArgsFunction · 0.90
upsertSessionFunction · 0.90
gatewayLogFunction · 0.90
startAgentProcessFunction · 0.90

Tested by

no test coverage detected