MCPcopy
hub / github.com/wavetermdev/waveterm / GetTermCommandOutputToolDefinition

Function GetTermCommandOutputToolDefinition

pkg/aiusechat/tools_term.go:244–301  ·  view source on GitHub ↗
(tabId string)

Source from the content-addressed store, hash-verified

242}
243
244func GetTermCommandOutputToolDefinition(tabId string) uctypes.ToolDefinition {
245 return uctypes.ToolDefinition{
246 Name: "term_command_output",
247 DisplayName: "Get Last Command Output",
248 Description: "Retrieve output from the most recent command in a terminal widget. Requires shell integration to be enabled. Returns the command text, exit code, and up to 1000 lines of output.",
249 ToolLogName: "term:commandoutput",
250 InputSchema: map[string]any{
251 "type": "object",
252 "properties": map[string]any{
253 "widget_id": map[string]any{
254 "type": "string",
255 "description": "8-character widget ID of the terminal widget",
256 },
257 },
258 "required": []string{"widget_id"},
259 "additionalProperties": false,
260 },
261 ToolCallDesc: func(input any, output any, toolUseData *uctypes.UIMessageDataToolUse) string {
262 parsed, err := parseTermCommandOutputInput(input)
263 if err != nil {
264 return fmt.Sprintf("error parsing input: %v", err)
265 }
266 return fmt.Sprintf("reading last command output from %s", parsed.WidgetId)
267 },
268 ToolAnyCallback: func(input any, toolUseData *uctypes.UIMessageDataToolUse) (any, error) {
269 parsed, err := parseTermCommandOutputInput(input)
270 if err != nil {
271 return nil, err
272 }
273
274 ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
275 defer cancelFn()
276
277 fullBlockId, err := wcore.ResolveBlockIdFromPrefix(ctx, tabId, parsed.WidgetId)
278 if err != nil {
279 return nil, err
280 }
281
282 blockORef := waveobj.MakeORef(waveobj.OType_Block, fullBlockId)
283 rtInfo := wstore.GetRTInfo(blockORef)
284 if rtInfo == nil || !rtInfo.ShellIntegration {
285 return nil, fmt.Errorf("shell integration is not enabled for this terminal")
286 }
287
288 output, err := getTermScrollbackOutput(
289 tabId,
290 parsed.WidgetId,
291 wshrpc.CommandTermGetScrollbackLinesData{
292 LastCommand: true,
293 },
294 )
295 if err != nil {
296 return nil, fmt.Errorf("failed to get command output: %w", err)
297 }
298 return output, nil
299 },
300 }
301}

Callers

nothing calls this directly

Calls 5

ResolveBlockIdFromPrefixFunction · 0.92
MakeORefFunction · 0.92
GetRTInfoFunction · 0.92
getTermScrollbackOutputFunction · 0.85

Tested by

no test coverage detected