tui: clean up agent chat lint
This commit is contained in:
@@ -75,10 +75,6 @@ func (m *chatModel) togglePermissionMode() (tea.Model, tea.Cmd) {
|
||||
return *m, nil
|
||||
}
|
||||
|
||||
func (m chatModel) autoApproveTools() bool {
|
||||
return m.allowAllTools
|
||||
}
|
||||
|
||||
func (m *chatModel) syncApprovalController() {
|
||||
if m.approvalController != nil {
|
||||
m.approvalController.set(m.allowAllTools, m.allowedScopes)
|
||||
|
||||
@@ -873,7 +873,7 @@ func flowTranscriptChangedPrefixStart(before, after []string, printed int) int {
|
||||
return -1
|
||||
}
|
||||
limit := min(printed, len(after))
|
||||
for i := 0; i < limit; i++ {
|
||||
for i := range limit {
|
||||
if before[i] != after[i] {
|
||||
return i
|
||||
}
|
||||
|
||||
@@ -900,10 +900,6 @@ func inputCursorCell(after string) (string, string) {
|
||||
return after[:size], after[size:]
|
||||
}
|
||||
|
||||
func renderInputCursor() string {
|
||||
return renderInputCursorCell("")
|
||||
}
|
||||
|
||||
func renderInputCursorCell(cell string) string {
|
||||
if cell == "" {
|
||||
return chatBlankCursorStyle.Render(inputCursorGlyph)
|
||||
@@ -982,17 +978,6 @@ func truncateInputLine(line string, width int) string {
|
||||
return runewidth.Truncate(line, width, "")
|
||||
}
|
||||
|
||||
func renderPromptRow(text string, width int) []string {
|
||||
if width < 20 {
|
||||
width = 20
|
||||
}
|
||||
lines := wrapChatText(text, width)
|
||||
for i, line := range lines {
|
||||
lines[i] = chatUserStyle.Render(line)
|
||||
}
|
||||
return lines
|
||||
}
|
||||
|
||||
func (m chatModel) slashCommandLines(width int) []string {
|
||||
return m.renderCompletions(m.slashCompletions(), width)
|
||||
}
|
||||
@@ -1312,14 +1297,6 @@ func (m chatModel) helpSummary() string {
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
func (m chatModel) historyMessages() []api.Message {
|
||||
var messages []api.Message
|
||||
if systemPrompt := strings.TrimSpace(m.systemPrompt("")); systemPrompt != "" {
|
||||
messages = append(messages, api.Message{Role: "system", Content: systemPrompt})
|
||||
}
|
||||
return append(messages, m.messages...)
|
||||
}
|
||||
|
||||
func (m chatModel) systemPrompt(extra string) string {
|
||||
var parts []string
|
||||
if strings.TrimSpace(m.opts.SystemPrompt) != "" {
|
||||
|
||||
@@ -125,7 +125,7 @@ func renderMarkdownTable(lines []string, width int) ([]string, int) {
|
||||
}
|
||||
naturalWidths := make([]int, columnCount)
|
||||
for _, row := range rows {
|
||||
for i := 0; i < columnCount; i++ {
|
||||
for i := range columnCount {
|
||||
cell := ""
|
||||
if i < len(row) {
|
||||
cell = row[i]
|
||||
@@ -139,7 +139,7 @@ func renderMarkdownTable(lines []string, width int) ([]string, int) {
|
||||
for rowIndex, row := range rows {
|
||||
wrappedCells := make([][]string, columnCount)
|
||||
rowHeight := 1
|
||||
for i := 0; i < columnCount; i++ {
|
||||
for i := range columnCount {
|
||||
cell := ""
|
||||
if i < len(row) {
|
||||
cell = row[i]
|
||||
@@ -147,9 +147,9 @@ func renderMarkdownTable(lines []string, width int) ([]string, int) {
|
||||
wrappedCells[i] = wrapMarkdownTableCell(cell, widths[i])
|
||||
rowHeight = max(rowHeight, len(wrappedCells[i]))
|
||||
}
|
||||
for lineIndex := 0; lineIndex < rowHeight; lineIndex++ {
|
||||
for lineIndex := range rowHeight {
|
||||
cells := make([]string, columnCount)
|
||||
for i := 0; i < columnCount; i++ {
|
||||
for i := range columnCount {
|
||||
cellLine := ""
|
||||
if lineIndex < len(wrappedCells[i]) {
|
||||
cellLine = wrappedCells[i][lineIndex]
|
||||
|
||||
@@ -219,19 +219,6 @@ func (m chatModel) transcriptLines(width int) []string {
|
||||
return strings.Split(transcript, "\n")
|
||||
}
|
||||
|
||||
func (m chatModel) visibleTranscriptLinesForLines(lines []string, available int) []string {
|
||||
if available <= 0 {
|
||||
return nil
|
||||
}
|
||||
start := 0
|
||||
if len(lines) > available {
|
||||
start = m.visibleTranscriptStartLineForLines(len(lines), available)
|
||||
lines = lines[start : start+available]
|
||||
}
|
||||
lines = m.applyTranscriptSelection(lines, start)
|
||||
return lines
|
||||
}
|
||||
|
||||
func (m chatModel) visibleTranscriptStartLine(width, available int) int {
|
||||
return m.visibleTranscriptStartLineForLines(len(m.transcriptLines(width)), available)
|
||||
}
|
||||
@@ -421,43 +408,6 @@ func normalizedSelectionRangeFor(selection chatSelection) (chatSelectionPoint, c
|
||||
return start, end, true
|
||||
}
|
||||
|
||||
func (m chatModel) applyTranscriptSelection(lines []string, offset int) []string {
|
||||
start, end, ok := m.normalizedSelectionRange()
|
||||
if !ok || len(lines) == 0 {
|
||||
return lines
|
||||
}
|
||||
out := slices.Clone(lines)
|
||||
for i, line := range out {
|
||||
lineIndex := offset + i
|
||||
if lineIndex < start.line || lineIndex > end.line {
|
||||
continue
|
||||
}
|
||||
text := stripChatANSI(line)
|
||||
startCol, endCol := 0, len([]rune(text))
|
||||
if lineIndex == start.line {
|
||||
startCol = displayColumnToRuneIndex(text, start.col)
|
||||
}
|
||||
if lineIndex == end.line {
|
||||
endCol = displayColumnToRuneIndex(text, end.col)
|
||||
}
|
||||
if startCol > endCol {
|
||||
startCol, endCol = endCol, startCol
|
||||
}
|
||||
out[i] = renderSelectedTranscriptLine(text, startCol, endCol)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func renderSelectedTranscriptLine(line string, startCol, endCol int) string {
|
||||
runes := []rune(line)
|
||||
startCol = clamp(startCol, 0, len(runes))
|
||||
endCol = clamp(endCol, 0, len(runes))
|
||||
if startCol == endCol {
|
||||
return line
|
||||
}
|
||||
return string(runes[:startCol]) + chatSelectionStyle.Render(string(runes[startCol:endCol])) + string(runes[endCol:])
|
||||
}
|
||||
|
||||
func displayColumnToRuneIndex(line string, col int) int {
|
||||
if col <= 0 {
|
||||
return 0
|
||||
|
||||
@@ -20,13 +20,6 @@ type chatCaptureClient struct {
|
||||
requests []*api.ChatRequest
|
||||
}
|
||||
|
||||
type chatTestCompactor struct {
|
||||
result coreagent.CompactionResult
|
||||
err error
|
||||
progress []int
|
||||
request coreagent.CompactionRequest
|
||||
}
|
||||
|
||||
func (chatTestClient) Chat(ctx context.Context, req *api.ChatRequest, fn api.ChatResponseFunc) error {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
@@ -48,30 +41,6 @@ func (c *chatCaptureClient) Chat(ctx context.Context, req *api.ChatRequest, fn a
|
||||
})
|
||||
}
|
||||
|
||||
func (c *chatTestCompactor) MaybeCompact(_ context.Context, req coreagent.CompactionRequest) (coreagent.CompactionResult, error) {
|
||||
c.request = req
|
||||
for _, tokens := range c.progress {
|
||||
if req.Progress != nil {
|
||||
req.Progress(coreagent.CompactionProgress{Tokens: tokens})
|
||||
}
|
||||
}
|
||||
return c.result, c.err
|
||||
}
|
||||
|
||||
func nextChatMsg(t *testing.T, ch <-chan tea.Msg) tea.Msg {
|
||||
t.Helper()
|
||||
select {
|
||||
case msg, ok := <-ch:
|
||||
if !ok {
|
||||
t.Fatal("message channel closed")
|
||||
}
|
||||
return msg
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("timed out waiting for chat message")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (chatTestTool) Name() string {
|
||||
return "fake_tool"
|
||||
}
|
||||
|
||||
@@ -40,8 +40,6 @@ var (
|
||||
chatUserBlockStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.AdaptiveColor{Light: "#777777", Dark: "#8a8a8a"})
|
||||
|
||||
chatAssistantStyle = lipgloss.NewStyle()
|
||||
|
||||
chatToolStyle = lipgloss.NewStyle()
|
||||
|
||||
chatInlineCodeStyle = lipgloss.NewStyle().
|
||||
@@ -102,9 +100,6 @@ var (
|
||||
chatPickerMetaStyle = lipgloss.NewStyle().
|
||||
Faint(true)
|
||||
|
||||
chatPickerBorderStyle = lipgloss.NewStyle().
|
||||
Faint(true)
|
||||
|
||||
chatHistoryTitleStyle = lipgloss.NewStyle().
|
||||
Bold(true)
|
||||
|
||||
@@ -128,7 +123,4 @@ var (
|
||||
Faint(true)
|
||||
|
||||
chatHistoryTextStyle = lipgloss.NewStyle()
|
||||
|
||||
chatSelectionStyle = lipgloss.NewStyle().
|
||||
Reverse(true)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user