talentos 1.3.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/adapters.js +23 -0
- package/dist/agent/codex-policy.js +3 -0
- package/dist/agent/gateway.js +11 -1
- package/dist/agent/mcp-entry.js +4 -1
- package/dist/agent/native/codex-fence-probe.js +629 -0
- package/dist/agent/native/codex-fence.js +162 -0
- package/dist/agent/native/codex-launch.js +86 -0
- package/dist/agent/native/codex-owner-probe.js +145 -4
- package/dist/agent/native/codex-run-command.js +302 -0
- package/dist/agent/native/config.js +8 -2
- package/dist/agent/native/discover.js +137 -0
- package/dist/agent/native/fresh.js +104 -0
- package/dist/agent/native/gate.js +202 -18
- package/dist/agent/native/native-issue.js +1 -0
- package/dist/agent/native/policy.js +63 -14
- package/dist/agent/native/project-requests.js +106 -0
- package/dist/agent/native/projects.js +111 -0
- package/dist/agent/native/touch.js +10 -0
- package/dist/agent/native/workspace.js +20 -5
- package/dist/agent/serve.js +83 -6
- package/dist/args.js +1 -0
- package/dist/commands/agent-native.js +42 -6
- package/dist/commands/agent.js +5 -1
- package/dist/mcp-proxy.js +25 -2
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import { mkdirSync, realpathSync, statSync } from "node:fs";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
import { rootProblem } from "./config.js";
|
|
7
|
+
import { freshBase, SAFE_GIT } from "./fresh.js";
|
|
7
8
|
import { canonical, isInside } from "./paths.js";
|
|
8
9
|
const exec = promisify(execFile);
|
|
9
10
|
const safeId = (value, length) => value
|
|
@@ -41,8 +42,9 @@ export async function prepareWorkspace(input) {
|
|
|
41
42
|
if (!inside(cwd)) {
|
|
42
43
|
throw new Error("The workspace left its folder.");
|
|
43
44
|
}
|
|
45
|
+
let base;
|
|
44
46
|
if (useWorktree) {
|
|
45
|
-
await ensureWorktree(config.root, cwd, thread);
|
|
47
|
+
base = await ensureWorktree(config.root, cwd, thread, input);
|
|
46
48
|
}
|
|
47
49
|
else {
|
|
48
50
|
mkdirSync(cwd, { recursive: true, mode: 0o700 });
|
|
@@ -51,7 +53,7 @@ export async function prepareWorkspace(input) {
|
|
|
51
53
|
if (!(statSync(real).isDirectory() && inside(real))) {
|
|
52
54
|
throw new Error("The workspace left its folder.");
|
|
53
55
|
}
|
|
54
|
-
return { cwd: real, writeRoots: [real] };
|
|
56
|
+
return { cwd: real, writeRoots: [real], ...(base ? { base } : {}) };
|
|
55
57
|
}
|
|
56
58
|
async function hasCommit(root) {
|
|
57
59
|
try {
|
|
@@ -65,7 +67,7 @@ async function hasCommit(root) {
|
|
|
65
67
|
return false;
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
|
-
async function ensureWorktree(root, path, thread) {
|
|
70
|
+
async function ensureWorktree(root, path, thread, fresh) {
|
|
69
71
|
try {
|
|
70
72
|
if (statSync(path).isDirectory()) {
|
|
71
73
|
return;
|
|
@@ -77,11 +79,24 @@ async function ensureWorktree(root, path, thread) {
|
|
|
77
79
|
mkdirSync(join(path, ".."), { recursive: true, mode: 0o700 });
|
|
78
80
|
const branch = `talentos/${thread}`;
|
|
79
81
|
const options = { cwd: root, timeout: 60_000 };
|
|
82
|
+
const base = await freshBase(root, fresh);
|
|
80
83
|
try {
|
|
81
|
-
|
|
84
|
+
// No upstream: a bare `git push` from the thread can never target main.
|
|
85
|
+
await exec("git", [
|
|
86
|
+
...SAFE_GIT,
|
|
87
|
+
"worktree",
|
|
88
|
+
"add",
|
|
89
|
+
"--no-track",
|
|
90
|
+
"-b",
|
|
91
|
+
branch,
|
|
92
|
+
path,
|
|
93
|
+
base.start,
|
|
94
|
+
], options);
|
|
95
|
+
return base;
|
|
82
96
|
}
|
|
83
97
|
catch {
|
|
84
98
|
// The branch survives a deleted folder: reattach it.
|
|
85
|
-
await exec("git", ["worktree", "add", path, branch], options);
|
|
99
|
+
await exec("git", [...SAFE_GIT, "worktree", "add", path, branch], options);
|
|
100
|
+
return;
|
|
86
101
|
}
|
|
87
102
|
}
|
package/dist/agent/serve.js
CHANGED
|
@@ -9,6 +9,9 @@ import { runProvider } from "./adapters.js";
|
|
|
9
9
|
import { AgentGateway, GatewayError } from "./gateway.js";
|
|
10
10
|
import { ApprovalBridge } from "./native/approvals.js";
|
|
11
11
|
import { NativeGate } from "./native/gate.js";
|
|
12
|
+
import { ROOM_ONLY_STATUS } from "./native/native-issue.js";
|
|
13
|
+
import { ProjectRequests } from "./native/project-requests.js";
|
|
14
|
+
import { mirrorOf } from "./native/projects.js";
|
|
12
15
|
import { SessionMap } from "./sessions.js";
|
|
13
16
|
const HEARTBEAT_MS = 20_000;
|
|
14
17
|
const LEASE_SAFETY_MS = 55_000;
|
|
@@ -16,6 +19,8 @@ const LEASE_SAFETY_MS = 55_000;
|
|
|
16
19
|
const NATIVE_RENEW_MS = 10_000;
|
|
17
20
|
const NATIVE_SAFETY_MS = 25_000;
|
|
18
21
|
const IDLE_MS = 30 * 60_000;
|
|
22
|
+
// The room-only reason stays up this long before progress lines resume.
|
|
23
|
+
const FALLBACK_HOLD_MS = 5000;
|
|
19
24
|
export function needsUpdate(current, minimum) {
|
|
20
25
|
if (compareGatewayVersions(minimum, minimum) === undefined) {
|
|
21
26
|
return false;
|
|
@@ -69,6 +74,7 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
69
74
|
const deviceId = randomUUID();
|
|
70
75
|
const gate = options.gate ??
|
|
71
76
|
new NativeGate({ agent: config, directory, home: homeDir() });
|
|
77
|
+
const fallbackHoldMs = options.fallbackHoldMs ?? FALLBACK_HOLD_MS;
|
|
72
78
|
const service = new AbortController();
|
|
73
79
|
const signal = AbortSignal.any([stop, service.signal]);
|
|
74
80
|
let wakeResolve, wakePending = true;
|
|
@@ -88,16 +94,47 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
88
94
|
wake();
|
|
89
95
|
}
|
|
90
96
|
};
|
|
97
|
+
let requests;
|
|
91
98
|
const heartbeat = async () => {
|
|
92
99
|
gate.refresh();
|
|
93
|
-
|
|
100
|
+
// Ids and names only; a registry that cannot be read is not sent.
|
|
101
|
+
const mirror = gate.projects
|
|
102
|
+
? await gate
|
|
103
|
+
.projects()
|
|
104
|
+
.then(mirrorOf)
|
|
105
|
+
.catch(() => undefined)
|
|
106
|
+
: undefined;
|
|
107
|
+
const issue = gate.issue?.();
|
|
108
|
+
const response = await gateway.request("/agent-gateway/heartbeat", {
|
|
109
|
+
cliVersion: version,
|
|
110
|
+
nativeOptIn: gate.reportable(),
|
|
111
|
+
...(mirror ? { projects: mirror } : {}),
|
|
112
|
+
// Why an opted-in computer can't use full setup (an untested Codex),
|
|
113
|
+
// so the owner sees it in the Access menu.
|
|
114
|
+
...(issue ? { nativeIssue: issue } : {}),
|
|
115
|
+
}, signal);
|
|
94
116
|
if (response) {
|
|
95
117
|
minimum = response.cliMinVersion;
|
|
118
|
+
// The server's exact list of Codex versions allowed full setup; the
|
|
119
|
+
// background probe waits for it.
|
|
120
|
+
gate.setCodexTested?.(response.codexFenceTested);
|
|
96
121
|
if (response.pendingJobs > 0 || needsUpdate(version, minimum)) {
|
|
97
122
|
wake();
|
|
98
123
|
}
|
|
124
|
+
if ((response.projectRequests ?? 0) > 0) {
|
|
125
|
+
requests?.poke().catch(() => undefined);
|
|
126
|
+
}
|
|
99
127
|
}
|
|
100
128
|
};
|
|
129
|
+
requests = gate.projects
|
|
130
|
+
? new ProjectRequests({
|
|
131
|
+
directory,
|
|
132
|
+
env: () => gate.loginEnv?.() ?? Promise.resolve(process.env),
|
|
133
|
+
home: homeDir(),
|
|
134
|
+
mirror: () => heartbeat(),
|
|
135
|
+
post: (path, body) => gateway.request(path, body, signal),
|
|
136
|
+
})
|
|
137
|
+
: undefined;
|
|
101
138
|
const heartbeatLoop = async () => {
|
|
102
139
|
while (!signal.aborted) {
|
|
103
140
|
const started = Date.now();
|
|
@@ -156,7 +193,11 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
156
193
|
if (active && jobIds.includes(active.job.jobId)) {
|
|
157
194
|
active.cancel.abort();
|
|
158
195
|
}
|
|
159
|
-
}
|
|
196
|
+
}, requests
|
|
197
|
+
? () => {
|
|
198
|
+
requests?.poke().catch(() => undefined);
|
|
199
|
+
}
|
|
200
|
+
: undefined);
|
|
160
201
|
}
|
|
161
202
|
catch (error) {
|
|
162
203
|
push = false;
|
|
@@ -219,6 +260,8 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
219
260
|
};
|
|
220
261
|
active = current;
|
|
221
262
|
let lastStatusAt = 0;
|
|
263
|
+
// Until then, room progress lines wait so the room-only reason is read.
|
|
264
|
+
let reasonUntil = 0;
|
|
222
265
|
// Monotonic, so a wall-clock change cannot corrupt the marks.
|
|
223
266
|
const receivedAt = performance.now();
|
|
224
267
|
const timings = {};
|
|
@@ -235,10 +278,27 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
235
278
|
lastStatusAt = Date.now();
|
|
236
279
|
const [, prepared] = await Promise.all([
|
|
237
280
|
gateway.request(`/agent-gateway/jobs/${job.jobId}/native-confirm`, { leaseToken: job.leaseToken }, signal),
|
|
238
|
-
gate
|
|
281
|
+
gate
|
|
282
|
+
.prepare(job.packet.thread.id, {
|
|
283
|
+
codexTested: job.native.codexFenceTested,
|
|
284
|
+
projectId: job.native.projectId,
|
|
285
|
+
status: (line) => {
|
|
286
|
+
lastStatusAt = Date.now();
|
|
287
|
+
post(line);
|
|
288
|
+
},
|
|
289
|
+
})
|
|
290
|
+
.catch(() => undefined),
|
|
239
291
|
]);
|
|
240
292
|
owner = prepared;
|
|
241
293
|
current.owner = Boolean(owner);
|
|
294
|
+
// The owner asked for their setup and this computer can't give
|
|
295
|
+
// it: say so in the room (neutral, no version), hold that line a
|
|
296
|
+
// moment, then let progress resume. The owner's Access menu has
|
|
297
|
+
// the detail.
|
|
298
|
+
if (!owner && gate.issue?.()) {
|
|
299
|
+
post(ROOM_ONLY_STATUS);
|
|
300
|
+
reasonUntil = Date.now() + fallbackHoldMs;
|
|
301
|
+
}
|
|
242
302
|
// In a room with other people the server holds what the job
|
|
243
303
|
// posts unless this computer affirms it started clean: none of
|
|
244
304
|
// the owner's own context loaded, every touch reported. Unknown
|
|
@@ -249,9 +309,22 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
249
309
|
.catch(() => undefined);
|
|
250
310
|
}
|
|
251
311
|
}
|
|
312
|
+
// A project's sessions are its own; the root from before projects
|
|
313
|
+
// keeps its key so those threads still resume.
|
|
252
314
|
const sessionKey = owner
|
|
253
|
-
? `${job.packet.thread.id}:owner`
|
|
315
|
+
? `${job.packet.thread.id}:owner${owner.project.legacy ? "" : `:${owner.project.id}`}`
|
|
254
316
|
: job.packet.thread.id;
|
|
317
|
+
// Which code the work started from, on the owner's record.
|
|
318
|
+
const base = owner?.workspace.base;
|
|
319
|
+
const baseRow = base && {
|
|
320
|
+
at: Date.now(),
|
|
321
|
+
decision: "allow",
|
|
322
|
+
seq: 0,
|
|
323
|
+
subagent: false,
|
|
324
|
+
target: base.receipt,
|
|
325
|
+
tier: 0,
|
|
326
|
+
tool: "Workspace",
|
|
327
|
+
};
|
|
255
328
|
const bridge = () => new ApprovalBridge({
|
|
256
329
|
gateway: {
|
|
257
330
|
touch: async (flags) => {
|
|
@@ -281,7 +354,10 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
281
354
|
remember: async (sessionId) => {
|
|
282
355
|
await sessions.remember(sessionKey, sessionId);
|
|
283
356
|
},
|
|
284
|
-
receipts: async (
|
|
357
|
+
receipts: async (hookRows) => {
|
|
358
|
+
const rows = baseRow
|
|
359
|
+
? [baseRow, ...hookRows].map((row, seq) => ({ ...row, seq }))
|
|
360
|
+
: hookRows;
|
|
285
361
|
// The gateway body limit is 32 kB: 50 rows of at most ~250 B.
|
|
286
362
|
for (let at = 0; at < rows.length; at += 50) {
|
|
287
363
|
await gateway.request(`/agent-gateway/jobs/${job.jobId}/receipts`, {
|
|
@@ -294,7 +370,8 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
294
370
|
timings[`${name}Ms`] = Math.round(performance.now() - receivedAt);
|
|
295
371
|
},
|
|
296
372
|
status: (line) => {
|
|
297
|
-
if (Date.now()
|
|
373
|
+
if (Date.now() < reasonUntil ||
|
|
374
|
+
Date.now() - lastStatusAt < 1000) {
|
|
298
375
|
return;
|
|
299
376
|
}
|
|
300
377
|
lastStatusAt = Date.now();
|
package/dist/args.js
CHANGED
|
@@ -23,6 +23,7 @@ const CLI_OPTIONS = {
|
|
|
23
23
|
yes: { type: "boolean" },
|
|
24
24
|
agent: { type: "string" },
|
|
25
25
|
"upload-root": { type: "string" },
|
|
26
|
+
"owner-job-dir": { type: "string" },
|
|
26
27
|
};
|
|
27
28
|
/** Groups whose first positional is a sub-command rather than an argument. */
|
|
28
29
|
const ACTION_GROUPS = new Set(["agent", "mcp", "skills", "memory", "routines"]);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { dirname } from "node:path";
|
|
2
2
|
import { disableNative, enableNative, readNativeConfig, } from "../agent/native/config.js";
|
|
3
3
|
import { NativeGate } from "../agent/native/gate.js";
|
|
4
|
+
import { checkRepo, readProjects, registerRoot, removeProject, } from "../agent/native/projects.js";
|
|
4
5
|
import { agentWorkDir, localAgents, } from "../agent-config.js";
|
|
5
6
|
import { emit } from "../format.js";
|
|
6
7
|
import { homeDir } from "../install.js";
|
|
@@ -8,7 +9,7 @@ import { homeDir } from "../install.js";
|
|
|
8
9
|
// to "let this agent work on this computer when you ask it in a room". The
|
|
9
10
|
// server still needs the owner's own confirmation in TalentOS; this only
|
|
10
11
|
// records consent on this machine and proves the provider can be guarded.
|
|
11
|
-
async function pickAgent(parsed, home) {
|
|
12
|
+
async function pickAgent(parsed, home, command = "native enable") {
|
|
12
13
|
const agents = await localAgents(home);
|
|
13
14
|
const selector = parsed.options.agent;
|
|
14
15
|
let chosen;
|
|
@@ -19,7 +20,7 @@ async function pickAgent(parsed, home) {
|
|
|
19
20
|
chosen = agents[0];
|
|
20
21
|
}
|
|
21
22
|
if (!chosen) {
|
|
22
|
-
throw new Error(
|
|
23
|
+
throw new Error(`Choose a linked agent with \`talentos agent ${command} --agent <id>\`.`);
|
|
23
24
|
}
|
|
24
25
|
return chosen;
|
|
25
26
|
}
|
|
@@ -43,9 +44,6 @@ export async function runAgentNative(parsed, home = homeDir()) {
|
|
|
43
44
|
: `Off. Run talentos agent native enable to let ${agent.name} use your full setup in rooms.`);
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
|
-
if (agent.provider !== "claude_code") {
|
|
47
|
-
throw new Error("Full-setup rooms support Claude Code first. Codex is not available yet.");
|
|
48
|
-
}
|
|
49
47
|
const config = await enableNative({
|
|
50
48
|
agentId: agent.agentId,
|
|
51
49
|
cwd: process.cwd(),
|
|
@@ -60,5 +58,43 @@ export async function runAgentNative(parsed, home = homeDir()) {
|
|
|
60
58
|
await disableNative(directory);
|
|
61
59
|
throw error;
|
|
62
60
|
}
|
|
63
|
-
|
|
61
|
+
// The folder it was enabled in is one of its projects (project #1 if first).
|
|
62
|
+
await registerRoot(directory, config);
|
|
63
|
+
emit(`I'll work in ${shown(config.root, home)}${config.kind === "repo" ? " (each room thread gets its own copy of the branch)" : ""}. TalentOS will ask you to confirm once.${agent.provider === "codex"
|
|
64
|
+
? " Your Codex passed the safety checks on this computer; full setup turns on if TalentOS has verified this Codex version (the Access menu says which)."
|
|
65
|
+
: ""}`);
|
|
66
|
+
}
|
|
67
|
+
// `talentos agent project add | list | remove` (#10987): the escape hatch for a
|
|
68
|
+
// repo the Projects dialog does not list. Same checks and registry as a pick;
|
|
69
|
+
// the running agent mirrors the id and name on its next heartbeat.
|
|
70
|
+
export async function runAgentProject(parsed, home = homeDir()) {
|
|
71
|
+
const action = parsed.args[0];
|
|
72
|
+
if (action !== "add" && action !== "list" && action !== "remove") {
|
|
73
|
+
throw new Error("Use talentos agent project add | list | remove.");
|
|
74
|
+
}
|
|
75
|
+
const agent = await pickAgent(parsed, home, `project ${action}`);
|
|
76
|
+
if (agent.provider !== "claude_code") {
|
|
77
|
+
throw new Error("Projects support Claude Code first. Codex is not available yet.");
|
|
78
|
+
}
|
|
79
|
+
const directory = dirname(agentWorkDir(agent.agentId, home));
|
|
80
|
+
if (action === "add") {
|
|
81
|
+
const project = await registerRoot(directory, await checkRepo(process.cwd(), home));
|
|
82
|
+
emit(`Added ${project.name}. Pick it for a room in that room's members panel.`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const projects = await readProjects(directory);
|
|
86
|
+
if (action === "remove") {
|
|
87
|
+
const match = projects.filter((project) => project.name === parsed.args[1]);
|
|
88
|
+
if (match.length !== 1 || !match[0]) {
|
|
89
|
+
throw new Error("Name one project from `talentos agent project list`, e.g. talentos agent project remove my-app.");
|
|
90
|
+
}
|
|
91
|
+
await removeProject(directory, match[0].id);
|
|
92
|
+
emit(`Removed ${match[0].name}. Its thread folders stay where they are.`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
emit(projects.length > 0
|
|
96
|
+
? projects
|
|
97
|
+
.map((project, index) => `${project.name}${index === 0 ? " (default)" : ""} ${shown(project.root, home)}`)
|
|
98
|
+
.join("\n")
|
|
99
|
+
: "No projects. In a repo, run talentos agent project add.");
|
|
64
100
|
}
|
package/dist/commands/agent.js
CHANGED
|
@@ -96,6 +96,10 @@ export async function runAgent(parsed, dependencies = {}) {
|
|
|
96
96
|
const { runAgentNative } = await import("./agent-native.js");
|
|
97
97
|
return await runAgentNative(parsed, dependencies.home);
|
|
98
98
|
}
|
|
99
|
+
case "project": {
|
|
100
|
+
const { runAgentProject } = await import("./agent-native.js");
|
|
101
|
+
return await runAgentProject(parsed, dependencies.home);
|
|
102
|
+
}
|
|
99
103
|
case "status":
|
|
100
104
|
case "list":
|
|
101
105
|
return await showAgents(parsed);
|
|
@@ -104,7 +108,7 @@ export async function runAgent(parsed, dependencies = {}) {
|
|
|
104
108
|
case "logs":
|
|
105
109
|
return await showLogs(parsed);
|
|
106
110
|
default:
|
|
107
|
-
throw new Error("Use talentos agent link | repair | status | list | unlink | logs | native.");
|
|
111
|
+
throw new Error("Use talentos agent link | repair | status | list | unlink | logs | native | project.");
|
|
108
112
|
}
|
|
109
113
|
}
|
|
110
114
|
export async function installLinkedAgent(parsed, dependencies = {}) {
|
package/dist/mcp-proxy.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
3
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { handleRunCommand, RUN_COMMAND_TOOL, stopAllRunCommands, wireShutdown, } from "./agent/native/codex-run-command.js";
|
|
4
5
|
import { UploadRefusal, uploadFile } from "./upload-file.js";
|
|
5
6
|
// The two server steps behind upload_file. The model sees only upload_file.
|
|
6
7
|
const UPLOAD_STEP_TOOLS = new Set(["prepare_upload", "commit_upload"]);
|
|
@@ -13,17 +14,38 @@ export async function startMcpProxy(client,
|
|
|
13
14
|
// The only folder upload_file reads from: the job's workspace, named by the
|
|
14
15
|
// launcher. Never a tool argument, never this process's own folder; without
|
|
15
16
|
// it upload_file refuses.
|
|
16
|
-
root
|
|
17
|
+
root,
|
|
18
|
+
// An owner-native Codex job's folder (#10987). When set, the proxy also serves
|
|
19
|
+
// run_command, the one-shot shell fence; it is the sole shell gate, so the
|
|
20
|
+
// command is classified here whether the model or a forged stdin write asked.
|
|
21
|
+
ownerJobDir) {
|
|
17
22
|
const server = new Server({ name: "talentos", version: "1.0.0" }, { capabilities: { tools: {} } });
|
|
23
|
+
// Job Stop kills Codex, which kills this child proxy; and if Codex crashes or
|
|
24
|
+
// is SIGKILLed its stdin pipe to us closes. Either way we abort and kill any
|
|
25
|
+
// in-flight one-shot command, so nothing outlives the job (run_command
|
|
26
|
+
// children run in their own process groups and would otherwise be orphaned).
|
|
27
|
+
const shutdownSignal = wireShutdown({
|
|
28
|
+
signals: ["SIGTERM", "SIGINT", "SIGHUP"],
|
|
29
|
+
stdin: process.stdin,
|
|
30
|
+
});
|
|
31
|
+
process.once("exit", () => stopAllRunCommands());
|
|
18
32
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
19
33
|
const listed = await client.listTools();
|
|
34
|
+
const tools = listed.tools.filter((tool) => !UPLOAD_STEP_TOOLS.has(tool.name));
|
|
20
35
|
return {
|
|
21
36
|
...listed,
|
|
22
|
-
tools:
|
|
37
|
+
tools: ownerJobDir ? [...tools, RUN_COMMAND_TOOL] : tools,
|
|
23
38
|
};
|
|
24
39
|
});
|
|
25
40
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
26
41
|
const { name, arguments: args = {} } = request.params;
|
|
42
|
+
if (name === "run_command" && ownerJobDir) {
|
|
43
|
+
return await handleRunCommand({
|
|
44
|
+
command: args.command,
|
|
45
|
+
jobDir: ownerJobDir,
|
|
46
|
+
signal: shutdownSignal,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
27
49
|
if (name === "upload_file") {
|
|
28
50
|
return await runUpload(client, args, root);
|
|
29
51
|
}
|
|
@@ -35,6 +57,7 @@ root) {
|
|
|
35
57
|
}
|
|
36
58
|
return await client.callTool({ name, arguments: args });
|
|
37
59
|
});
|
|
60
|
+
server.onclose = () => stopAllRunCommands();
|
|
38
61
|
await server.connect(new StdioServerTransport());
|
|
39
62
|
}
|
|
40
63
|
async function runUpload(client, args, root) {
|
package/package.json
CHANGED