@@ -11,10 +11,12 @@ import (
1111 "time"
1212
1313 "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes"
14+ "github.com/wavetermdev/waveterm/pkg/waveobj"
1415 "github.com/wavetermdev/waveterm/pkg/wcore"
1516 "github.com/wavetermdev/waveterm/pkg/wshrpc"
1617 "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient"
1718 "github.com/wavetermdev/waveterm/pkg/wshutil"
19+ "github.com/wavetermdev/waveterm/pkg/wstore"
1820)
1921
2022type TermGetScrollbackToolInput struct {
@@ -23,15 +25,22 @@ type TermGetScrollbackToolInput struct {
2325 Count int `json:"count,omitempty"`
2426}
2527
28+ type CommandInfo struct {
29+ Command string `json:"command"`
30+ Status string `json:"status"`
31+ ExitCode * int `json:"exitcode,omitempty"`
32+ }
33+
2634type TermGetScrollbackToolOutput struct {
27- TotalLines int `json:"total_lines"`
28- LineStart int `json:"line_start"`
29- LineEnd int `json:"line_end"`
30- ReturnedLines int `json:"returned_lines"`
31- Content string `json:"content"`
32- SinceLastOutputSec * int `json:"since_last_output_sec,omitempty"`
33- HasMore bool `json:"has_more"`
34- NextStart * int `json:"next_start"`
35+ TotalLines int `json:"totallines"`
36+ LineStart int `json:"linestart"`
37+ LineEnd int `json:"lineend"`
38+ ReturnedLines int `json:"returnedlines"`
39+ Content string `json:"content"`
40+ SinceLastOutputSec * int `json:"sincelastoutputsec,omitempty"`
41+ HasMore bool `json:"hasmore"`
42+ NextStart * int `json:"nextstart"`
43+ LastCommand * CommandInfo `json:"lastcommand,omitempty"`
3544}
3645
3746func parseTermGetScrollbackInput (input any ) (* TermGetScrollbackToolInput , error ) {
@@ -76,7 +85,7 @@ func GetTermGetScrollbackToolDefinition(tabId string) uctypes.ToolDefinition {
7685 return uctypes.ToolDefinition {
7786 Name : "term_get_scrollback" ,
7887 DisplayName : "Get Terminal Scrollback" ,
79- Description : "Fetch terminal scrollback from a widget as plain text. Index 0 is the most recent line; indices increase going upward (older lines)." ,
88+ Description : "Fetch terminal scrollback from a widget as plain text. Index 0 is the most recent line; indices increase going upward (older lines). Also returns last command and exit code if shell integration is enabled. " ,
8089 ToolLogName : "term:getscrollback" ,
8190 InputSchema : map [string ]any {
8291 "type" : "object" ,
@@ -155,6 +164,24 @@ func GetTermGetScrollbackToolDefinition(tabId string) uctypes.ToolDefinition {
155164 nextStart = & effectiveLineEnd
156165 }
157166
167+ blockORef := waveobj .MakeORef (waveobj .OType_Block , fullBlockId )
168+ rtInfo := wstore .GetRTInfo (blockORef )
169+
170+ var lastCommand * CommandInfo
171+ if rtInfo != nil && rtInfo .ShellIntegration && rtInfo .ShellLastCmd != "" {
172+ cmdInfo := & CommandInfo {
173+ Command : rtInfo .ShellLastCmd ,
174+ }
175+ if rtInfo .ShellState == "running-command" {
176+ cmdInfo .Status = "running"
177+ } else if rtInfo .ShellState == "ready" {
178+ cmdInfo .Status = "completed"
179+ exitCode := rtInfo .ShellLastCmdExitCode
180+ cmdInfo .ExitCode = & exitCode
181+ }
182+ lastCommand = cmdInfo
183+ }
184+
158185 return & TermGetScrollbackToolOutput {
159186 TotalLines : result .TotalLines ,
160187 LineStart : result .LineStart ,
@@ -164,6 +191,7 @@ func GetTermGetScrollbackToolDefinition(tabId string) uctypes.ToolDefinition {
164191 SinceLastOutputSec : sinceLastOutputSec ,
165192 HasMore : hasMore ,
166193 NextStart : nextStart ,
194+ LastCommand : lastCommand ,
167195 }, nil
168196 },
169197 }
0 commit comments