|
@@ -24,7 +24,7 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func toMarkdown(content string, width int, backgroundColor compat.AdaptiveColor) string {
|
|
func toMarkdown(content string, width int, backgroundColor compat.AdaptiveColor) string {
|
|
|
- r := styles.GetMarkdownRenderer(width, backgroundColor)
|
|
|
|
|
|
|
+ r := styles.GetMarkdownRenderer(width-7, backgroundColor)
|
|
|
content = strings.ReplaceAll(content, app.RootPath+"/", "")
|
|
content = strings.ReplaceAll(content, app.RootPath+"/", "")
|
|
|
rendered, _ := r.Render(content)
|
|
rendered, _ := r.Render(content)
|
|
|
lines := strings.Split(rendered, "\n")
|
|
lines := strings.Split(rendered, "\n")
|
|
@@ -50,9 +50,8 @@ func toMarkdown(content string, width int, backgroundColor compat.AdaptiveColor)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type blockRenderer struct {
|
|
type blockRenderer struct {
|
|
|
- align *lipgloss.Position
|
|
|
|
|
|
|
+ border bool
|
|
|
borderColor *compat.AdaptiveColor
|
|
borderColor *compat.AdaptiveColor
|
|
|
- fullWidth bool
|
|
|
|
|
paddingTop int
|
|
paddingTop int
|
|
|
paddingBottom int
|
|
paddingBottom int
|
|
|
paddingLeft int
|
|
paddingLeft int
|
|
@@ -63,15 +62,9 @@ type blockRenderer struct {
|
|
|
|
|
|
|
|
type renderingOption func(*blockRenderer)
|
|
type renderingOption func(*blockRenderer)
|
|
|
|
|
|
|
|
-func WithFullWidth() renderingOption {
|
|
|
|
|
|
|
+func WithNoBorder() renderingOption {
|
|
|
return func(c *blockRenderer) {
|
|
return func(c *blockRenderer) {
|
|
|
- c.fullWidth = true
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func WithAlign(align lipgloss.Position) renderingOption {
|
|
|
|
|
- return func(c *blockRenderer) {
|
|
|
|
|
- c.align = &align
|
|
|
|
|
|
|
+ c.border = false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -93,6 +86,15 @@ func WithMarginBottom(padding int) renderingOption {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func WithPadding(padding int) renderingOption {
|
|
|
|
|
+ return func(c *blockRenderer) {
|
|
|
|
|
+ c.paddingTop = padding
|
|
|
|
|
+ c.paddingBottom = padding
|
|
|
|
|
+ c.paddingLeft = padding
|
|
|
|
|
+ c.paddingRight = padding
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func WithPaddingLeft(padding int) renderingOption {
|
|
func WithPaddingLeft(padding int) renderingOption {
|
|
|
return func(c *blockRenderer) {
|
|
return func(c *blockRenderer) {
|
|
|
c.paddingLeft = padding
|
|
c.paddingLeft = padding
|
|
@@ -117,10 +119,15 @@ func WithPaddingBottom(padding int) renderingOption {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func renderContentBlock(content string, options ...renderingOption) string {
|
|
|
|
|
|
|
+func renderContentBlock(
|
|
|
|
|
+ content string,
|
|
|
|
|
+ width int,
|
|
|
|
|
+ align lipgloss.Position,
|
|
|
|
|
+ options ...renderingOption,
|
|
|
|
|
+) string {
|
|
|
t := theme.CurrentTheme()
|
|
t := theme.CurrentTheme()
|
|
|
renderer := &blockRenderer{
|
|
renderer := &blockRenderer{
|
|
|
- fullWidth: false,
|
|
|
|
|
|
|
+ border: true,
|
|
|
paddingTop: 1,
|
|
paddingTop: 1,
|
|
|
paddingBottom: 1,
|
|
paddingBottom: 1,
|
|
|
paddingLeft: 2,
|
|
paddingLeft: 2,
|
|
@@ -130,59 +137,42 @@ func renderContentBlock(content string, options ...renderingOption) string {
|
|
|
option(renderer)
|
|
option(renderer)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- style := styles.NewStyle().Foreground(t.TextMuted()).Background(t.BackgroundPanel()).
|
|
|
|
|
- // MarginTop(renderer.marginTop).
|
|
|
|
|
- // MarginBottom(renderer.marginBottom).
|
|
|
|
|
- PaddingTop(renderer.paddingTop).
|
|
|
|
|
- PaddingBottom(renderer.paddingBottom).
|
|
|
|
|
- PaddingLeft(renderer.paddingLeft).
|
|
|
|
|
- PaddingRight(renderer.paddingRight).
|
|
|
|
|
- BorderStyle(lipgloss.ThickBorder())
|
|
|
|
|
-
|
|
|
|
|
- align := lipgloss.Left
|
|
|
|
|
- if renderer.align != nil {
|
|
|
|
|
- align = *renderer.align
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
borderColor := t.BackgroundPanel()
|
|
borderColor := t.BackgroundPanel()
|
|
|
if renderer.borderColor != nil {
|
|
if renderer.borderColor != nil {
|
|
|
borderColor = *renderer.borderColor
|
|
borderColor = *renderer.borderColor
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- switch align {
|
|
|
|
|
- case lipgloss.Left:
|
|
|
|
|
|
|
+ style := styles.NewStyle().
|
|
|
|
|
+ Foreground(t.TextMuted()).
|
|
|
|
|
+ Background(t.BackgroundPanel()).
|
|
|
|
|
+ Width(width).
|
|
|
|
|
+ PaddingTop(renderer.paddingTop).
|
|
|
|
|
+ PaddingBottom(renderer.paddingBottom).
|
|
|
|
|
+ PaddingLeft(renderer.paddingLeft).
|
|
|
|
|
+ PaddingRight(renderer.paddingRight).
|
|
|
|
|
+ AlignHorizontal(lipgloss.Left)
|
|
|
|
|
+
|
|
|
|
|
+ if renderer.border {
|
|
|
style = style.
|
|
style = style.
|
|
|
|
|
+ BorderStyle(lipgloss.ThickBorder()).
|
|
|
BorderLeft(true).
|
|
BorderLeft(true).
|
|
|
BorderRight(true).
|
|
BorderRight(true).
|
|
|
- AlignHorizontal(align).
|
|
|
|
|
BorderLeftForeground(borderColor).
|
|
BorderLeftForeground(borderColor).
|
|
|
BorderLeftBackground(t.Background()).
|
|
BorderLeftBackground(t.Background()).
|
|
|
BorderRightForeground(t.BackgroundPanel()).
|
|
BorderRightForeground(t.BackgroundPanel()).
|
|
|
BorderRightBackground(t.Background())
|
|
BorderRightBackground(t.Background())
|
|
|
- case lipgloss.Right:
|
|
|
|
|
- style = style.
|
|
|
|
|
- BorderRight(true).
|
|
|
|
|
- BorderLeft(true).
|
|
|
|
|
- AlignHorizontal(align).
|
|
|
|
|
- BorderRightForeground(borderColor).
|
|
|
|
|
- BorderRightBackground(t.Background()).
|
|
|
|
|
- BorderLeftForeground(t.BackgroundPanel()).
|
|
|
|
|
- BorderLeftBackground(t.Background())
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if renderer.fullWidth {
|
|
|
|
|
- style = style.Width(layout.Current.Container.Width)
|
|
|
|
|
- }
|
|
|
|
|
content = style.Render(content)
|
|
content = style.Render(content)
|
|
|
content = lipgloss.PlaceHorizontal(
|
|
content = lipgloss.PlaceHorizontal(
|
|
|
- layout.Current.Container.Width,
|
|
|
|
|
- align,
|
|
|
|
|
|
|
+ width,
|
|
|
|
|
+ lipgloss.Left,
|
|
|
content,
|
|
content,
|
|
|
styles.WhitespaceStyle(t.Background()),
|
|
styles.WhitespaceStyle(t.Background()),
|
|
|
)
|
|
)
|
|
|
content = lipgloss.PlaceHorizontal(
|
|
content = lipgloss.PlaceHorizontal(
|
|
|
layout.Current.Viewport.Width,
|
|
layout.Current.Viewport.Width,
|
|
|
- lipgloss.Center,
|
|
|
|
|
|
|
+ align,
|
|
|
content,
|
|
content,
|
|
|
styles.WhitespaceStyle(t.Background()),
|
|
styles.WhitespaceStyle(t.Background()),
|
|
|
)
|
|
)
|
|
@@ -196,24 +186,19 @@ func renderContentBlock(content string, options ...renderingOption) string {
|
|
|
content = content + "\n"
|
|
content = content + "\n"
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return content
|
|
return content
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func calculatePadding() int {
|
|
|
|
|
- if layout.Current.Viewport.Width < 80 {
|
|
|
|
|
- return 5
|
|
|
|
|
- } else if layout.Current.Viewport.Width < 120 {
|
|
|
|
|
- return 15
|
|
|
|
|
- } else {
|
|
|
|
|
- return 20
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func renderText(message opencode.Message, text string, author string) string {
|
|
|
|
|
|
|
+func renderText(
|
|
|
|
|
+ message opencode.Message,
|
|
|
|
|
+ text string,
|
|
|
|
|
+ author string,
|
|
|
|
|
+ showToolDetails bool,
|
|
|
|
|
+ width int,
|
|
|
|
|
+ align lipgloss.Position,
|
|
|
|
|
+ toolCalls ...opencode.ToolInvocationPart,
|
|
|
|
|
+) string {
|
|
|
t := theme.CurrentTheme()
|
|
t := theme.CurrentTheme()
|
|
|
- width := layout.Current.Container.Width
|
|
|
|
|
- padding := calculatePadding()
|
|
|
|
|
|
|
|
|
|
timestamp := time.UnixMilli(int64(message.Metadata.Time.Created)).Local().Format("02 Jan 2006 03:04 PM")
|
|
timestamp := time.UnixMilli(int64(message.Metadata.Time.Created)).Local().Format("02 Jan 2006 03:04 PM")
|
|
|
if time.Now().Format("02 Jan 2006") == timestamp[:11] {
|
|
if time.Now().Format("02 Jan 2006") == timestamp[:11] {
|
|
@@ -222,175 +207,120 @@ func renderText(message opencode.Message, text string, author string) string {
|
|
|
}
|
|
}
|
|
|
info := fmt.Sprintf("%s (%s)", author, timestamp)
|
|
info := fmt.Sprintf("%s (%s)", author, timestamp)
|
|
|
|
|
|
|
|
- textWidth := max(lipgloss.Width(text), lipgloss.Width(info))
|
|
|
|
|
- markdownWidth := min(textWidth, width-padding-4) // -4 for the border and padding
|
|
|
|
|
- if message.Role == opencode.MessageRoleAssistant {
|
|
|
|
|
- markdownWidth = width - padding - 4 - 3
|
|
|
|
|
- }
|
|
|
|
|
- minWidth := max(markdownWidth, (width-4)/2)
|
|
|
|
|
messageStyle := styles.NewStyle().
|
|
messageStyle := styles.NewStyle().
|
|
|
- Width(minWidth).
|
|
|
|
|
Background(t.BackgroundPanel()).
|
|
Background(t.BackgroundPanel()).
|
|
|
Foreground(t.Text())
|
|
Foreground(t.Text())
|
|
|
- if textWidth < minWidth {
|
|
|
|
|
- messageStyle = messageStyle.AlignHorizontal(lipgloss.Right)
|
|
|
|
|
|
|
+ if message.Role == opencode.MessageRoleUser {
|
|
|
|
|
+ messageStyle = messageStyle.Width(width - 6)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
content := messageStyle.Render(text)
|
|
content := messageStyle.Render(text)
|
|
|
if message.Role == opencode.MessageRoleAssistant {
|
|
if message.Role == opencode.MessageRoleAssistant {
|
|
|
- content = toMarkdown(text, markdownWidth, t.BackgroundPanel())
|
|
|
|
|
|
|
+ content = toMarkdown(text, width, t.BackgroundPanel())
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if !showToolDetails && toolCalls != nil && len(toolCalls) > 0 {
|
|
|
|
|
+ content = content + "\n\n"
|
|
|
|
|
+ for _, toolCall := range toolCalls {
|
|
|
|
|
+ title := renderToolTitle(toolCall, message.Metadata, width)
|
|
|
|
|
+ metadata := opencode.MessageMetadataTool{}
|
|
|
|
|
+ if _, ok := message.Metadata.Tool[toolCall.ToolInvocation.ToolCallID]; ok {
|
|
|
|
|
+ metadata = message.Metadata.Tool[toolCall.ToolInvocation.ToolCallID]
|
|
|
|
|
+ }
|
|
|
|
|
+ style := styles.NewStyle()
|
|
|
|
|
+ if _, ok := metadata.ExtraFields["error"]; ok {
|
|
|
|
|
+ style = style.Foreground(t.Error())
|
|
|
|
|
+ }
|
|
|
|
|
+ title = style.Render(title)
|
|
|
|
|
+ title = "∟ " + title + "\n"
|
|
|
|
|
+ content = content + title
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
content = strings.Join([]string{content, info}, "\n")
|
|
content = strings.Join([]string{content, info}, "\n")
|
|
|
|
|
|
|
|
switch message.Role {
|
|
switch message.Role {
|
|
|
case opencode.MessageRoleUser:
|
|
case opencode.MessageRoleUser:
|
|
|
- return renderContentBlock(content,
|
|
|
|
|
- WithAlign(lipgloss.Right),
|
|
|
|
|
|
|
+ return renderContentBlock(
|
|
|
|
|
+ content,
|
|
|
|
|
+ width,
|
|
|
|
|
+ align,
|
|
|
WithBorderColor(t.Secondary()),
|
|
WithBorderColor(t.Secondary()),
|
|
|
)
|
|
)
|
|
|
case opencode.MessageRoleAssistant:
|
|
case opencode.MessageRoleAssistant:
|
|
|
- return renderContentBlock(content,
|
|
|
|
|
- WithAlign(lipgloss.Left),
|
|
|
|
|
|
|
+ return renderContentBlock(
|
|
|
|
|
+ content,
|
|
|
|
|
+ width,
|
|
|
|
|
+ align,
|
|
|
WithBorderColor(t.Accent()),
|
|
WithBorderColor(t.Accent()),
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
return ""
|
|
return ""
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func renderToolInvocation(
|
|
|
|
|
|
|
+func renderToolDetails(
|
|
|
toolCall opencode.ToolInvocationPart,
|
|
toolCall opencode.ToolInvocationPart,
|
|
|
- result *string,
|
|
|
|
|
- metadata opencode.MessageMetadataTool,
|
|
|
|
|
- showDetails bool,
|
|
|
|
|
- isLast bool,
|
|
|
|
|
- contentOnly bool,
|
|
|
|
|
messageMetadata opencode.MessageMetadata,
|
|
messageMetadata opencode.MessageMetadata,
|
|
|
|
|
+ width int,
|
|
|
|
|
+ align lipgloss.Position,
|
|
|
) string {
|
|
) string {
|
|
|
ignoredTools := []string{"todoread"}
|
|
ignoredTools := []string{"todoread"}
|
|
|
if slices.Contains(ignoredTools, toolCall.ToolInvocation.ToolName) {
|
|
if slices.Contains(ignoredTools, toolCall.ToolInvocation.ToolName) {
|
|
|
return ""
|
|
return ""
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- outerWidth := layout.Current.Container.Width
|
|
|
|
|
- innerWidth := outerWidth - 6
|
|
|
|
|
- paddingTop := 0
|
|
|
|
|
- paddingBottom := 0
|
|
|
|
|
- if showDetails {
|
|
|
|
|
- paddingTop = 1
|
|
|
|
|
- if result == nil || *result == "" {
|
|
|
|
|
- paddingBottom = 1
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ toolCallID := toolCall.ToolInvocation.ToolCallID
|
|
|
|
|
+ metadata := opencode.MessageMetadataTool{}
|
|
|
|
|
+ if _, ok := messageMetadata.Tool[toolCallID]; ok {
|
|
|
|
|
+ metadata = messageMetadata.Tool[toolCallID]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- t := theme.CurrentTheme()
|
|
|
|
|
- style := styles.NewStyle().
|
|
|
|
|
- Foreground(t.TextMuted()).
|
|
|
|
|
- Background(t.BackgroundPanel()).
|
|
|
|
|
- Width(outerWidth).
|
|
|
|
|
- PaddingTop(paddingTop).
|
|
|
|
|
- PaddingBottom(paddingBottom).
|
|
|
|
|
- PaddingLeft(2).
|
|
|
|
|
- PaddingRight(2).
|
|
|
|
|
- BorderLeft(true).
|
|
|
|
|
- BorderRight(true).
|
|
|
|
|
- BorderBackground(t.Background()).
|
|
|
|
|
- BorderForeground(t.BackgroundPanel()).
|
|
|
|
|
- BorderStyle(lipgloss.ThickBorder())
|
|
|
|
|
|
|
+ var result *string
|
|
|
|
|
+ if toolCall.ToolInvocation.Result != "" {
|
|
|
|
|
+ result = &toolCall.ToolInvocation.Result
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if toolCall.ToolInvocation.State == "partial-call" {
|
|
if toolCall.ToolInvocation.State == "partial-call" {
|
|
|
- title := renderToolAction(toolCall.ToolInvocation.ToolName)
|
|
|
|
|
- if !showDetails {
|
|
|
|
|
- title = "∟ " + title
|
|
|
|
|
- padding := calculatePadding()
|
|
|
|
|
- style := styles.NewStyle().
|
|
|
|
|
- Background(t.BackgroundPanel()).
|
|
|
|
|
- Width(outerWidth - padding - 4 - 3)
|
|
|
|
|
- return renderContentBlock(style.Render(title),
|
|
|
|
|
- WithAlign(lipgloss.Left),
|
|
|
|
|
- WithBorderColor(t.Accent()),
|
|
|
|
|
- WithPaddingTop(0),
|
|
|
|
|
- WithPaddingBottom(1),
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- style = style.Foreground(t.TextMuted())
|
|
|
|
|
- return style.Render(title)
|
|
|
|
|
|
|
+ title := renderToolTitle(toolCall, messageMetadata, width)
|
|
|
|
|
+ return renderContentBlock(title, width, align)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- toolArgs := ""
|
|
|
|
|
toolArgsMap := make(map[string]any)
|
|
toolArgsMap := make(map[string]any)
|
|
|
if toolCall.ToolInvocation.Args != nil {
|
|
if toolCall.ToolInvocation.Args != nil {
|
|
|
value := toolCall.ToolInvocation.Args
|
|
value := toolCall.ToolInvocation.Args
|
|
|
if m, ok := value.(map[string]any); ok {
|
|
if m, ok := value.(map[string]any); ok {
|
|
|
toolArgsMap = m
|
|
toolArgsMap = m
|
|
|
-
|
|
|
|
|
keys := make([]string, 0, len(toolArgsMap))
|
|
keys := make([]string, 0, len(toolArgsMap))
|
|
|
for key := range toolArgsMap {
|
|
for key := range toolArgsMap {
|
|
|
keys = append(keys, key)
|
|
keys = append(keys, key)
|
|
|
}
|
|
}
|
|
|
slices.Sort(keys)
|
|
slices.Sort(keys)
|
|
|
- firstKey := ""
|
|
|
|
|
- if len(keys) > 0 {
|
|
|
|
|
- firstKey = keys[0]
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- toolArgs = renderArgs(&toolArgsMap, firstKey)
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
body := ""
|
|
body := ""
|
|
|
- error := ""
|
|
|
|
|
finished := result != nil && *result != ""
|
|
finished := result != nil && *result != ""
|
|
|
|
|
+ t := theme.CurrentTheme()
|
|
|
|
|
|
|
|
- er := messageMetadata.Error.AsUnion()
|
|
|
|
|
- switch er.(type) {
|
|
|
|
|
- case nil:
|
|
|
|
|
- default:
|
|
|
|
|
- clientError := er.(opencode.UnknownError)
|
|
|
|
|
- error = clientError.Data.Message
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if error != "" {
|
|
|
|
|
- style = style.BorderLeftForeground(t.Error())
|
|
|
|
|
- error = styles.NewStyle().
|
|
|
|
|
- Foreground(t.Error()).
|
|
|
|
|
- Background(t.BackgroundPanel()).
|
|
|
|
|
- Render(error)
|
|
|
|
|
- error = renderContentBlock(
|
|
|
|
|
- error,
|
|
|
|
|
- WithFullWidth(),
|
|
|
|
|
- WithBorderColor(t.Error()),
|
|
|
|
|
- WithMarginBottom(1),
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- title := ""
|
|
|
|
|
switch toolCall.ToolInvocation.ToolName {
|
|
switch toolCall.ToolInvocation.ToolName {
|
|
|
case "read":
|
|
case "read":
|
|
|
- toolArgs = renderArgs(&toolArgsMap, "filePath")
|
|
|
|
|
- title = fmt.Sprintf("READ %s", toolArgs)
|
|
|
|
|
preview := metadata.ExtraFields["preview"]
|
|
preview := metadata.ExtraFields["preview"]
|
|
|
if preview != nil && toolArgsMap["filePath"] != nil {
|
|
if preview != nil && toolArgsMap["filePath"] != nil {
|
|
|
filename := toolArgsMap["filePath"].(string)
|
|
filename := toolArgsMap["filePath"].(string)
|
|
|
body = preview.(string)
|
|
body = preview.(string)
|
|
|
- body = renderFile(filename, body, WithTruncate(6))
|
|
|
|
|
|
|
+ body = renderFile(filename, body, width, WithTruncate(6))
|
|
|
}
|
|
}
|
|
|
case "edit":
|
|
case "edit":
|
|
|
if filename, ok := toolArgsMap["filePath"].(string); ok {
|
|
if filename, ok := toolArgsMap["filePath"].(string); ok {
|
|
|
- title = fmt.Sprintf("EDIT %s", relative(filename))
|
|
|
|
|
diffField := metadata.ExtraFields["diff"]
|
|
diffField := metadata.ExtraFields["diff"]
|
|
|
if diffField != nil {
|
|
if diffField != nil {
|
|
|
patch := diffField.(string)
|
|
patch := diffField.(string)
|
|
|
var formattedDiff string
|
|
var formattedDiff string
|
|
|
- if layout.Current.Viewport.Width < 80 {
|
|
|
|
|
- formattedDiff, _ = diff.FormatUnifiedDiff(
|
|
|
|
|
- filename,
|
|
|
|
|
- patch,
|
|
|
|
|
- diff.WithWidth(layout.Current.Container.Width-2),
|
|
|
|
|
- )
|
|
|
|
|
- } else {
|
|
|
|
|
- diffWidth := min(layout.Current.Viewport.Width-2, 120)
|
|
|
|
|
- formattedDiff, _ = diff.FormatDiff(filename, patch, diff.WithTotalWidth(diffWidth))
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ formattedDiff, _ = diff.FormatUnifiedDiff(
|
|
|
|
|
+ filename,
|
|
|
|
|
+ patch,
|
|
|
|
|
+ diff.WithWidth(width-2),
|
|
|
|
|
+ )
|
|
|
formattedDiff = strings.TrimSpace(formattedDiff)
|
|
formattedDiff = strings.TrimSpace(formattedDiff)
|
|
|
formattedDiff = styles.NewStyle().
|
|
formattedDiff = styles.NewStyle().
|
|
|
BorderStyle(lipgloss.ThickBorder()).
|
|
BorderStyle(lipgloss.ThickBorder()).
|
|
@@ -400,67 +330,51 @@ func renderToolInvocation(
|
|
|
BorderRight(true).
|
|
BorderRight(true).
|
|
|
Render(formattedDiff)
|
|
Render(formattedDiff)
|
|
|
|
|
|
|
|
- if showDetails {
|
|
|
|
|
- style = style.Width(lipgloss.Width(formattedDiff))
|
|
|
|
|
- title += "\n"
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
body = strings.TrimSpace(formattedDiff)
|
|
body = strings.TrimSpace(formattedDiff)
|
|
|
- body = lipgloss.Place(
|
|
|
|
|
- layout.Current.Viewport.Width,
|
|
|
|
|
- lipgloss.Height(body)+1,
|
|
|
|
|
- lipgloss.Center,
|
|
|
|
|
- lipgloss.Top,
|
|
|
|
|
|
|
+ body = renderContentBlock(
|
|
|
body,
|
|
body,
|
|
|
- styles.WhitespaceStyle(t.Background()),
|
|
|
|
|
|
|
+ width,
|
|
|
|
|
+ align,
|
|
|
|
|
+ WithNoBorder(),
|
|
|
|
|
+ WithPadding(0),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- // Add diagnostics at the bottom if they exist
|
|
|
|
|
- if diagnostics := renderDiagnostics(messageMetadata, filename); diagnostics != "" {
|
|
|
|
|
- body += "\n" + renderContentBlock(diagnostics, WithFullWidth(), WithBorderColor(t.Error()))
|
|
|
|
|
|
|
+ if diagnostics := renderDiagnostics(metadata, filename); diagnostics != "" {
|
|
|
|
|
+ body += "\n" + renderContentBlock(diagnostics, width, align)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ title := renderToolTitle(toolCall, messageMetadata, width)
|
|
|
|
|
+ title = renderContentBlock(title, width, align)
|
|
|
|
|
+ content := title + "\n" + body
|
|
|
|
|
+ return content
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
case "write":
|
|
case "write":
|
|
|
if filename, ok := toolArgsMap["filePath"].(string); ok {
|
|
if filename, ok := toolArgsMap["filePath"].(string); ok {
|
|
|
- title = fmt.Sprintf("WRITE %s", relative(filename))
|
|
|
|
|
if content, ok := toolArgsMap["content"].(string); ok {
|
|
if content, ok := toolArgsMap["content"].(string); ok {
|
|
|
- body = renderFile(filename, content)
|
|
|
|
|
-
|
|
|
|
|
- // Add diagnostics at the bottom if they exist
|
|
|
|
|
- if diagnostics := renderDiagnostics(messageMetadata, filename); diagnostics != "" {
|
|
|
|
|
- body += "\n" + renderContentBlock(diagnostics, WithFullWidth(), WithBorderColor(t.Error()))
|
|
|
|
|
|
|
+ body = renderFile(filename, content, width)
|
|
|
|
|
+ if diagnostics := renderDiagnostics(metadata, filename); diagnostics != "" {
|
|
|
|
|
+ body += "\n\n" + diagnostics
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
case "bash":
|
|
case "bash":
|
|
|
- if description, ok := toolArgsMap["description"].(string); ok {
|
|
|
|
|
- title = fmt.Sprintf("SHELL %s", description)
|
|
|
|
|
- }
|
|
|
|
|
stdout := metadata.JSON.ExtraFields["stdout"]
|
|
stdout := metadata.JSON.ExtraFields["stdout"]
|
|
|
if !stdout.IsNull() {
|
|
if !stdout.IsNull() {
|
|
|
command := toolArgsMap["command"].(string)
|
|
command := toolArgsMap["command"].(string)
|
|
|
stdout := stdout.Raw()
|
|
stdout := stdout.Raw()
|
|
|
body = fmt.Sprintf("```console\n> %s\n%s```", command, stdout)
|
|
body = fmt.Sprintf("```console\n> %s\n%s```", command, stdout)
|
|
|
- body = toMarkdown(body, innerWidth, t.BackgroundPanel())
|
|
|
|
|
- body = renderContentBlock(body, WithFullWidth(), WithMarginBottom(1))
|
|
|
|
|
|
|
+ body = toMarkdown(body, width, t.BackgroundPanel())
|
|
|
}
|
|
}
|
|
|
case "webfetch":
|
|
case "webfetch":
|
|
|
- toolArgs = renderArgs(&toolArgsMap, "url")
|
|
|
|
|
- title = fmt.Sprintf("FETCH %s", toolArgs)
|
|
|
|
|
- if format, ok := toolArgsMap["format"].(string); ok {
|
|
|
|
|
- if result != nil {
|
|
|
|
|
- body = *result
|
|
|
|
|
- body = truncateHeight(body, 10)
|
|
|
|
|
- if format == "html" || format == "markdown" {
|
|
|
|
|
- body = toMarkdown(body, innerWidth, t.BackgroundPanel())
|
|
|
|
|
- }
|
|
|
|
|
- body = renderContentBlock(body, WithFullWidth(), WithMarginBottom(1))
|
|
|
|
|
|
|
+ if format, ok := toolArgsMap["format"].(string); ok && result != nil {
|
|
|
|
|
+ body = *result
|
|
|
|
|
+ body = truncateHeight(body, 10)
|
|
|
|
|
+ if format == "html" || format == "markdown" {
|
|
|
|
|
+ body = toMarkdown(body, width, t.BackgroundPanel())
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
case "todowrite":
|
|
case "todowrite":
|
|
|
- title = fmt.Sprintf("PLAN")
|
|
|
|
|
-
|
|
|
|
|
todos := metadata.JSON.ExtraFields["todos"]
|
|
todos := metadata.JSON.ExtraFields["todos"]
|
|
|
if !todos.IsNull() && finished {
|
|
if !todos.IsNull() && finished {
|
|
|
strTodos := todos.Raw()
|
|
strTodos := todos.Raw()
|
|
@@ -476,120 +390,168 @@ func renderToolInvocation(
|
|
|
body += fmt.Sprintf("- [ ] %s\n", content)
|
|
body += fmt.Sprintf("- [ ] %s\n", content)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- body = toMarkdown(body, innerWidth, t.BackgroundPanel())
|
|
|
|
|
- body = renderContentBlock(body, WithFullWidth(), WithMarginBottom(1))
|
|
|
|
|
|
|
+ body = toMarkdown(body, width, t.BackgroundPanel())
|
|
|
}
|
|
}
|
|
|
case "task":
|
|
case "task":
|
|
|
- if description, ok := toolArgsMap["description"].(string); ok {
|
|
|
|
|
- title = fmt.Sprintf("TASK %s", description)
|
|
|
|
|
- summary := metadata.JSON.ExtraFields["summary"]
|
|
|
|
|
- if !summary.IsNull() {
|
|
|
|
|
- strValue := summary.Raw()
|
|
|
|
|
- toolcalls := gjson.Parse(strValue).Array()
|
|
|
|
|
-
|
|
|
|
|
- steps := []string{}
|
|
|
|
|
- for _, toolcall := range toolcalls {
|
|
|
|
|
- call := toolcall.Value().(map[string]any)
|
|
|
|
|
- if toolInvocation, ok := call["toolInvocation"].(map[string]any); ok {
|
|
|
|
|
- data, _ := json.Marshal(toolInvocation)
|
|
|
|
|
- var toolCall opencode.ToolInvocationPart
|
|
|
|
|
- _ = json.Unmarshal(data, &toolCall)
|
|
|
|
|
-
|
|
|
|
|
- if metadata, ok := call["metadata"].(map[string]any); ok {
|
|
|
|
|
- data, _ = json.Marshal(metadata)
|
|
|
|
|
- var toolMetadata opencode.MessageMetadataTool
|
|
|
|
|
- _ = json.Unmarshal(data, &toolMetadata)
|
|
|
|
|
-
|
|
|
|
|
- step := renderToolInvocation(
|
|
|
|
|
- toolCall,
|
|
|
|
|
- nil,
|
|
|
|
|
- toolMetadata,
|
|
|
|
|
- false,
|
|
|
|
|
- false,
|
|
|
|
|
- true,
|
|
|
|
|
- messageMetadata,
|
|
|
|
|
- )
|
|
|
|
|
- steps = append(steps, step)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ summary := metadata.JSON.ExtraFields["summary"]
|
|
|
|
|
+ if !summary.IsNull() {
|
|
|
|
|
+ strValue := summary.Raw()
|
|
|
|
|
+ toolcalls := gjson.Parse(strValue).Array()
|
|
|
|
|
+
|
|
|
|
|
+ steps := []string{}
|
|
|
|
|
+ for _, toolcall := range toolcalls {
|
|
|
|
|
+ call := toolcall.Value().(map[string]any)
|
|
|
|
|
+ if toolInvocation, ok := call["toolInvocation"].(map[string]any); ok {
|
|
|
|
|
+ data, _ := json.Marshal(toolInvocation)
|
|
|
|
|
+ var toolCall opencode.ToolInvocationPart
|
|
|
|
|
+ _ = json.Unmarshal(data, &toolCall)
|
|
|
|
|
+
|
|
|
|
|
+ if metadata, ok := call["metadata"].(map[string]any); ok {
|
|
|
|
|
+ data, _ = json.Marshal(metadata)
|
|
|
|
|
+ var toolMetadata opencode.MessageMetadataTool
|
|
|
|
|
+ _ = json.Unmarshal(data, &toolMetadata)
|
|
|
|
|
+
|
|
|
|
|
+ step := renderToolTitle(toolCall, messageMetadata, width)
|
|
|
|
|
+ step = "∟ " + step
|
|
|
|
|
+ steps = append(steps, step)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- body = strings.Join(steps, "\n")
|
|
|
|
|
- body = renderContentBlock(body, WithFullWidth(), WithMarginBottom(1))
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ body = strings.Join(steps, "\n")
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
default:
|
|
default:
|
|
|
- toolName := renderToolName(toolCall.ToolInvocation.ToolName)
|
|
|
|
|
- title = fmt.Sprintf("%s %s", toolName, toolArgs)
|
|
|
|
|
if result == nil {
|
|
if result == nil {
|
|
|
empty := ""
|
|
empty := ""
|
|
|
result = &empty
|
|
result = &empty
|
|
|
}
|
|
}
|
|
|
body = *result
|
|
body = *result
|
|
|
body = truncateHeight(body, 10)
|
|
body = truncateHeight(body, 10)
|
|
|
- body = renderContentBlock(body, WithFullWidth(), WithMarginBottom(1))
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if contentOnly {
|
|
|
|
|
- title = "∟ " + title
|
|
|
|
|
- return title
|
|
|
|
|
|
|
+ error := ""
|
|
|
|
|
+ if err, ok := metadata.ExtraFields["error"].(bool); ok && err {
|
|
|
|
|
+ if message, ok := metadata.ExtraFields["message"].(string); ok {
|
|
|
|
|
+ error = message
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if !showDetails {
|
|
|
|
|
- title = "∟ " + title
|
|
|
|
|
- padding := calculatePadding()
|
|
|
|
|
- style := styles.NewStyle().Background(t.BackgroundPanel()).Width(outerWidth - padding - 4 - 3)
|
|
|
|
|
- paddingBottom := 0
|
|
|
|
|
- if isLast {
|
|
|
|
|
- paddingBottom = 1
|
|
|
|
|
- }
|
|
|
|
|
- return renderContentBlock(style.Render(title),
|
|
|
|
|
- WithAlign(lipgloss.Left),
|
|
|
|
|
- WithBorderColor(t.Accent()),
|
|
|
|
|
- WithPaddingTop(0),
|
|
|
|
|
- WithPaddingBottom(paddingBottom),
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ if error != "" {
|
|
|
|
|
+ body = styles.NewStyle().
|
|
|
|
|
+ Foreground(t.Error()).
|
|
|
|
|
+ Background(t.BackgroundPanel()).
|
|
|
|
|
+ Render(error)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if body == "" && error == "" && result != nil {
|
|
if body == "" && error == "" && result != nil {
|
|
|
body = *result
|
|
body = *result
|
|
|
body = truncateHeight(body, 10)
|
|
body = truncateHeight(body, 10)
|
|
|
- body = renderContentBlock(body, WithFullWidth(), WithMarginBottom(1))
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- content := style.Render(title)
|
|
|
|
|
- content = lipgloss.PlaceHorizontal(
|
|
|
|
|
- layout.Current.Viewport.Width,
|
|
|
|
|
- lipgloss.Center,
|
|
|
|
|
- content,
|
|
|
|
|
- styles.WhitespaceStyle(t.Background()),
|
|
|
|
|
- )
|
|
|
|
|
- if showDetails && body != "" && error == "" {
|
|
|
|
|
- content += "\n" + body
|
|
|
|
|
- }
|
|
|
|
|
- if showDetails && error != "" {
|
|
|
|
|
- content += "\n" + error
|
|
|
|
|
- }
|
|
|
|
|
- return content
|
|
|
|
|
|
|
+ title := renderToolTitle(toolCall, messageMetadata, width)
|
|
|
|
|
+ content := title + "\n\n" + body
|
|
|
|
|
+ return renderContentBlock(content, width, align)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func renderToolName(name string) string {
|
|
func renderToolName(name string) string {
|
|
|
switch name {
|
|
switch name {
|
|
|
- case "list":
|
|
|
|
|
- return "LIST"
|
|
|
|
|
case "webfetch":
|
|
case "webfetch":
|
|
|
- return "FETCH"
|
|
|
|
|
- case "todowrite":
|
|
|
|
|
- return "PLAN"
|
|
|
|
|
|
|
+ return "Fetch"
|
|
|
|
|
+ case "todowrite", "todoread":
|
|
|
|
|
+ return "Plan"
|
|
|
default:
|
|
default:
|
|
|
normalizedName := name
|
|
normalizedName := name
|
|
|
if strings.HasPrefix(name, "opencode_") {
|
|
if strings.HasPrefix(name, "opencode_") {
|
|
|
normalizedName = strings.TrimPrefix(name, "opencode_")
|
|
normalizedName = strings.TrimPrefix(name, "opencode_")
|
|
|
}
|
|
}
|
|
|
- return cases.Upper(language.Und).String(normalizedName)
|
|
|
|
|
|
|
+ return cases.Title(language.Und).String(normalizedName)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func renderToolTitle(
|
|
|
|
|
+ toolCall opencode.ToolInvocationPart,
|
|
|
|
|
+ messageMetadata opencode.MessageMetadata,
|
|
|
|
|
+ width int,
|
|
|
|
|
+) string {
|
|
|
|
|
+ // TODO: handle truncate to width
|
|
|
|
|
+
|
|
|
|
|
+ if toolCall.ToolInvocation.State == "partial-call" {
|
|
|
|
|
+ return renderToolAction(toolCall.ToolInvocation.ToolName)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ toolArgs := ""
|
|
|
|
|
+ toolArgsMap := make(map[string]any)
|
|
|
|
|
+ if toolCall.ToolInvocation.Args != nil {
|
|
|
|
|
+ value := toolCall.ToolInvocation.Args
|
|
|
|
|
+ if m, ok := value.(map[string]any); ok {
|
|
|
|
|
+ toolArgsMap = m
|
|
|
|
|
+
|
|
|
|
|
+ keys := make([]string, 0, len(toolArgsMap))
|
|
|
|
|
+ for key := range toolArgsMap {
|
|
|
|
|
+ keys = append(keys, key)
|
|
|
|
|
+ }
|
|
|
|
|
+ slices.Sort(keys)
|
|
|
|
|
+ firstKey := ""
|
|
|
|
|
+ if len(keys) > 0 {
|
|
|
|
|
+ firstKey = keys[0]
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ toolArgs = renderArgs(&toolArgsMap, firstKey)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ title := renderToolName(toolCall.ToolInvocation.ToolName)
|
|
|
|
|
+ switch toolCall.ToolInvocation.ToolName {
|
|
|
|
|
+ case "read":
|
|
|
|
|
+ toolArgs = renderArgs(&toolArgsMap, "filePath")
|
|
|
|
|
+ title = fmt.Sprintf("%s %s", title, toolArgs)
|
|
|
|
|
+ case "edit", "write":
|
|
|
|
|
+ if filename, ok := toolArgsMap["filePath"].(string); ok {
|
|
|
|
|
+ title = fmt.Sprintf("%s %s", title, relative(filename))
|
|
|
|
|
+ }
|
|
|
|
|
+ case "bash", "task":
|
|
|
|
|
+ if description, ok := toolArgsMap["description"].(string); ok {
|
|
|
|
|
+ title = fmt.Sprintf("%s %s", title, description)
|
|
|
|
|
+ }
|
|
|
|
|
+ case "webfetch":
|
|
|
|
|
+ toolArgs = renderArgs(&toolArgsMap, "url")
|
|
|
|
|
+ title = fmt.Sprintf("%s %s", title, toolArgs)
|
|
|
|
|
+ case "todowrite", "todoread":
|
|
|
|
|
+ // title is just the tool name
|
|
|
|
|
+ default:
|
|
|
|
|
+ toolName := renderToolName(toolCall.ToolInvocation.ToolName)
|
|
|
|
|
+ title = fmt.Sprintf("%s %s", toolName, toolArgs)
|
|
|
|
|
+ }
|
|
|
|
|
+ return title
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func renderToolAction(name string) string {
|
|
|
|
|
+ switch name {
|
|
|
|
|
+ case "task":
|
|
|
|
|
+ return "Searching..."
|
|
|
|
|
+ case "bash":
|
|
|
|
|
+ return "Writing command..."
|
|
|
|
|
+ case "edit":
|
|
|
|
|
+ return "Preparing edit..."
|
|
|
|
|
+ case "webfetch":
|
|
|
|
|
+ return "Fetching from the web..."
|
|
|
|
|
+ case "glob":
|
|
|
|
|
+ return "Finding files..."
|
|
|
|
|
+ case "grep":
|
|
|
|
|
+ return "Searching content..."
|
|
|
|
|
+ case "list":
|
|
|
|
|
+ return "Listing directory..."
|
|
|
|
|
+ case "read":
|
|
|
|
|
+ return "Reading file..."
|
|
|
|
|
+ case "write":
|
|
|
|
|
+ return "Preparing write..."
|
|
|
|
|
+ case "todowrite", "todoread":
|
|
|
|
|
+ return "Planning..."
|
|
|
|
|
+ case "patch":
|
|
|
|
|
+ return "Preparing patch..."
|
|
|
|
|
+ }
|
|
|
|
|
+ return "Working..."
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
type fileRenderer struct {
|
|
type fileRenderer struct {
|
|
|
filename string
|
|
filename string
|
|
|
content string
|
|
content string
|
|
@@ -604,7 +566,11 @@ func WithTruncate(height int) fileRenderingOption {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func renderFile(filename string, content string, options ...fileRenderingOption) string {
|
|
|
|
|
|
|
+func renderFile(
|
|
|
|
|
+ filename string,
|
|
|
|
|
+ content string,
|
|
|
|
|
+ width int,
|
|
|
|
|
+ options ...fileRenderingOption) string {
|
|
|
t := theme.CurrentTheme()
|
|
t := theme.CurrentTheme()
|
|
|
renderer := &fileRenderer{
|
|
renderer := &fileRenderer{
|
|
|
filename: filename,
|
|
filename: filename,
|
|
@@ -622,44 +588,12 @@ func renderFile(filename string, content string, options ...fileRenderingOption)
|
|
|
}
|
|
}
|
|
|
content = strings.Join(lines, "\n")
|
|
content = strings.Join(lines, "\n")
|
|
|
|
|
|
|
|
- width := layout.Current.Container.Width - 8
|
|
|
|
|
if renderer.height > 0 {
|
|
if renderer.height > 0 {
|
|
|
content = truncateHeight(content, renderer.height)
|
|
content = truncateHeight(content, renderer.height)
|
|
|
}
|
|
}
|
|
|
content = fmt.Sprintf("```%s\n%s\n```", extension(renderer.filename), content)
|
|
content = fmt.Sprintf("```%s\n%s\n```", extension(renderer.filename), content)
|
|
|
content = toMarkdown(content, width, t.BackgroundPanel())
|
|
content = toMarkdown(content, width, t.BackgroundPanel())
|
|
|
-
|
|
|
|
|
- return renderContentBlock(content, WithFullWidth(), WithMarginBottom(1))
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func renderToolAction(name string) string {
|
|
|
|
|
- switch name {
|
|
|
|
|
- case "task":
|
|
|
|
|
- return "Searching..."
|
|
|
|
|
- case "bash":
|
|
|
|
|
- return "Building command..."
|
|
|
|
|
- case "edit":
|
|
|
|
|
- return "Preparing edit..."
|
|
|
|
|
- case "webfetch":
|
|
|
|
|
- return "Fetching from the web..."
|
|
|
|
|
- case "glob":
|
|
|
|
|
- return "Finding files..."
|
|
|
|
|
- case "grep":
|
|
|
|
|
- return "Searching content..."
|
|
|
|
|
- case "list":
|
|
|
|
|
- return "Listing directory..."
|
|
|
|
|
- case "read":
|
|
|
|
|
- return "Reading file..."
|
|
|
|
|
- case "write":
|
|
|
|
|
- return "Preparing write..."
|
|
|
|
|
- case "todowrite", "todoread":
|
|
|
|
|
- return "Planning..."
|
|
|
|
|
- case "patch":
|
|
|
|
|
- return "Preparing patch..."
|
|
|
|
|
- case "batch":
|
|
|
|
|
- return "Running batch operations..."
|
|
|
|
|
- }
|
|
|
|
|
- return "Working..."
|
|
|
|
|
|
|
+ return content
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func renderArgs(args *map[string]any, titleKey string) string {
|
|
func renderArgs(args *map[string]any, titleKey string) string {
|
|
@@ -704,6 +638,7 @@ func truncateHeight(content string, height int) string {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func relative(path string) string {
|
|
func relative(path string) string {
|
|
|
|
|
+ path = strings.TrimPrefix(path, app.CwdPath+"/")
|
|
|
return strings.TrimPrefix(path, app.RootPath+"/")
|
|
return strings.TrimPrefix(path, app.RootPath+"/")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -730,64 +665,59 @@ type Diagnostic struct {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// renderDiagnostics formats LSP diagnostics for display in the TUI
|
|
// renderDiagnostics formats LSP diagnostics for display in the TUI
|
|
|
-func renderDiagnostics(metadata opencode.MessageMetadata, filePath string) string {
|
|
|
|
|
- diagnosticsData := metadata.JSON.ExtraFields["diagnostics"]
|
|
|
|
|
- if diagnosticsData.IsNull() {
|
|
|
|
|
- return ""
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // diagnosticsData should be a map[string][]Diagnostic
|
|
|
|
|
- strDiagnosticsData := diagnosticsData.Raw()
|
|
|
|
|
- diagnosticsMap := gjson.Parse(strDiagnosticsData).Value().(map[string]any)
|
|
|
|
|
- fileDiagnostics, ok := diagnosticsMap[filePath]
|
|
|
|
|
- if !ok {
|
|
|
|
|
- return ""
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- diagnosticsList, ok := fileDiagnostics.([]any)
|
|
|
|
|
- if !ok {
|
|
|
|
|
- return ""
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- var errorDiagnostics []string
|
|
|
|
|
- for _, diagInterface := range diagnosticsList {
|
|
|
|
|
- diagMap, ok := diagInterface.(map[string]any)
|
|
|
|
|
- if !ok {
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Parse the diagnostic
|
|
|
|
|
- var diag Diagnostic
|
|
|
|
|
- diagBytes, err := json.Marshal(diagMap)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
- if err := json.Unmarshal(diagBytes, &diag); err != nil {
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Only show error diagnostics (severity === 1)
|
|
|
|
|
- if diag.Severity != 1 {
|
|
|
|
|
- continue
|
|
|
|
|
|
|
+func renderDiagnostics(metadata opencode.MessageMetadataTool, filePath string) string {
|
|
|
|
|
+ if diagnosticsData, ok := metadata.ExtraFields["diagnostics"].(map[string]any); ok {
|
|
|
|
|
+ if fileDiagnostics, ok := diagnosticsData[filePath].([]any); ok {
|
|
|
|
|
+ var errorDiagnostics []string
|
|
|
|
|
+ for _, diagInterface := range fileDiagnostics {
|
|
|
|
|
+ diagMap, ok := diagInterface.(map[string]any)
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ // Parse the diagnostic
|
|
|
|
|
+ var diag Diagnostic
|
|
|
|
|
+ diagBytes, err := json.Marshal(diagMap)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := json.Unmarshal(diagBytes, &diag); err != nil {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ // Only show error diagnostics (severity === 1)
|
|
|
|
|
+ if diag.Severity != 1 {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ line := diag.Range.Start.Line + 1 // 1-based
|
|
|
|
|
+ column := diag.Range.Start.Character + 1 // 1-based
|
|
|
|
|
+ errorDiagnostics = append(errorDiagnostics, fmt.Sprintf("Error [%d:%d] %s", line, column, diag.Message))
|
|
|
|
|
+ }
|
|
|
|
|
+ if len(errorDiagnostics) == 0 {
|
|
|
|
|
+ return ""
|
|
|
|
|
+ }
|
|
|
|
|
+ t := theme.CurrentTheme()
|
|
|
|
|
+ var result strings.Builder
|
|
|
|
|
+ for _, diagnostic := range errorDiagnostics {
|
|
|
|
|
+ if result.Len() > 0 {
|
|
|
|
|
+ result.WriteString("\n")
|
|
|
|
|
+ }
|
|
|
|
|
+ result.WriteString(styles.NewStyle().Foreground(t.Error()).Render(diagnostic))
|
|
|
|
|
+ }
|
|
|
|
|
+ return result.String()
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- line := diag.Range.Start.Line + 1 // 1-based
|
|
|
|
|
- column := diag.Range.Start.Character + 1 // 1-based
|
|
|
|
|
- errorDiagnostics = append(errorDiagnostics, fmt.Sprintf("Error [%d:%d] %s", line, column, diag.Message))
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if len(errorDiagnostics) == 0 {
|
|
|
|
|
- return ""
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ return ""
|
|
|
|
|
|
|
|
- t := theme.CurrentTheme()
|
|
|
|
|
- var result strings.Builder
|
|
|
|
|
- for _, diagnostic := range errorDiagnostics {
|
|
|
|
|
- if result.Len() > 0 {
|
|
|
|
|
- result.WriteString("\n")
|
|
|
|
|
- }
|
|
|
|
|
- result.WriteString(styles.NewStyle().Foreground(t.Error()).Render(diagnostic))
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // diagnosticsData should be a map[string][]Diagnostic
|
|
|
|
|
+ // strDiagnosticsData := diagnosticsData.Raw()
|
|
|
|
|
+ // diagnosticsMap := gjson.Parse(strDiagnosticsData).Value().(map[string]any)
|
|
|
|
|
+ // fileDiagnostics, ok := diagnosticsMap[filePath]
|
|
|
|
|
+ // if !ok {
|
|
|
|
|
+ // return ""
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // diagnosticsList, ok := fileDiagnostics.([]any)
|
|
|
|
|
+ // if !ok {
|
|
|
|
|
+ // return ""
|
|
|
|
|
+ // }
|
|
|
|
|
|
|
|
- return result.String()
|
|
|
|
|
}
|
|
}
|