-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathspawn.ts
More file actions
49 lines (44 loc) · 1.83 KB
/
spawn.ts
File metadata and controls
49 lines (44 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { tool } from "@opencode-ai/plugin";
import { manager } from "../manager.ts";
import { checkCommandPermission, checkWorkdirPermission } from "../permissions.ts";
import DESCRIPTION from "./spawn.txt";
export const ptySpawn = tool({
description: DESCRIPTION,
args: {
command: tool.schema.string().describe("The command/executable to run"),
args: tool.schema.array(tool.schema.string()).optional().describe("Arguments to pass to the command"),
workdir: tool.schema.string().optional().describe("Working directory for the PTY session"),
env: tool.schema.record(tool.schema.string(), tool.schema.string()).optional().describe("Additional environment variables"),
title: tool.schema.string().optional().describe("Human-readable title for the session"),
description: tool.schema.string().describe("Clear, concise description of what this PTY session is for in 5-10 words"),
notifyOnExit: tool.schema.boolean().optional().describe("If true, sends a notification to the session when the process exits (default: false)"),
},
async execute(args, ctx) {
await checkCommandPermission(args.command, args.args ?? []);
if (args.workdir) {
await checkWorkdirPermission(args.workdir);
}
const sessionId = ctx.sessionID;
const info = await manager.spawn({
command: args.command,
args: args.args,
workdir: args.workdir,
env: args.env,
title: args.title,
description: args.description,
parentSessionId: sessionId,
notifyOnExit: args.notifyOnExit,
});
const output = [
`<pty_spawned>`,
`ID: ${info.id}`,
`Title: ${info.title}`,
`Command: ${info.command} ${info.args.join(" ")}`,
`Workdir: ${info.workdir}`,
`PID: ${info.pid}`,
`Status: ${info.status}`,
`</pty_spawned>`,
].join("\n");
return output;
},
});