MCPcopy Index your code
hub / github.com/coder/coder / ProcessSignal

Function ProcessSignal

coderd/x/chatd/chattool/execute.go:525–565  ·  view source on GitHub ↗

ProcessSignal returns an AgentTool that sends a signal to a tracked process on the workspace agent by its ID.

(options ProcessToolOptions)

Source from the content-addressed store, hash-verified

523// ProcessSignal returns an AgentTool that sends a signal to a
524// tracked process on the workspace agent by its ID.
525func ProcessSignal(options ProcessToolOptions) fantasy.AgentTool {
526 return fantasy.NewAgentTool(
527 "process_signal",
528 "Send a signal to a tracked process. "+
529 "Use \"terminate\" (SIGTERM) for graceful shutdown "+
530 "or \"kill\" (SIGKILL) to force stop. Use the "+
531 "process_id returned by execute with "+
532 "run_in_background=true or from process_list.",
533 func(ctx context.Context, args ProcessSignalArgs, _ fantasy.ToolCall) (fantasy.ToolResponse, error) {
534 if options.GetWorkspaceConn == nil {
535 return fantasy.NewTextErrorResponse("workspace connection resolver is not configured"), nil
536 }
537 if args.ProcessID == "" {
538 return fantasy.NewTextErrorResponse("process_id is required"), nil
539 }
540 if args.Signal != "terminate" && args.Signal != "kill" {
541 return fantasy.NewTextErrorResponse(
542 "signal must be \"terminate\" or \"kill\"",
543 ), nil
544 }
545 conn, err := options.GetWorkspaceConn(ctx)
546 if err != nil {
547 return fantasy.NewTextErrorResponse(err.Error()), nil
548 }
549 if err := conn.SignalProcess(ctx, args.ProcessID, args.Signal); err != nil {
550 return errorResult(fmt.Sprintf("signal process: %v", err)), nil
551 }
552 data, err := json.Marshal(map[string]any{
553 "success": true,
554 "message": fmt.Sprintf(
555 "signal %q sent to process %s",
556 args.Signal, args.ProcessID,
557 ),
558 })
559 if err != nil {
560 return fantasy.NewTextErrorResponse(err.Error()), nil
561 }
562 return fantasy.NewTextResponse(string(data)), nil
563 },
564 )
565}

Callers 1

runChatMethod · 0.92

Calls 4

errorResultFunction · 0.70
SignalProcessMethod · 0.65
ErrorMethod · 0.45
MarshalMethod · 0.45

Tested by

no test coverage detected