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

Method handleListProcesses

agent/agentproc/api.go:121–149  ·  view source on GitHub ↗

handleListProcesses lists all tracked processes.

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

119
120// handleListProcesses lists all tracked processes.
121func (api *API) handleListProcesses(rw http.ResponseWriter, r *http.Request) {
122 ctx := r.Context()
123
124 var chatID string
125 if chatContext, ok := agentchat.FromContext(ctx); ok {
126 chatID = chatContext.ID.String()
127 }
128
129 infos := api.manager.list(chatID)
130
131 // Sort by running state (running first), then by started_at
132 // descending so the most recent processes appear first.
133 sort.Slice(infos, func(i, j int) bool {
134 if infos[i].Running != infos[j].Running {
135 return infos[i].Running
136 }
137 return infos[i].StartedAt > infos[j].StartedAt
138 })
139
140 // Cap the response to avoid bloating LLM context.
141 const maxListProcesses = 10
142 if len(infos) > maxListProcesses {
143 infos = infos[:maxListProcesses]
144 }
145
146 httpapi.Write(ctx, rw, http.StatusOK, workspacesdk.ListProcessesResponse{
147 Processes: infos,
148 })
149}
150
151// handleProcessOutput returns the output of a process.
152func (api *API) handleProcessOutput(rw http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 5

FromContextFunction · 0.92
WriteFunction · 0.92
ContextMethod · 0.65
StringMethod · 0.45
listMethod · 0.45

Tested by

no test coverage detected