Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module neo-code
go 1.25.0

require (
github.com/atotto/clipboard v0.1.4
github.com/charmbracelet/bubbles v1.0.0
github.com/charmbracelet/bubbletea v1.3.10
github.com/charmbracelet/glamour v1.0.0
github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834
github.com/spf13/cobra v1.10.2
github.com/spf13/viper v1.21.0
golang.design/x/clipboard v0.7.1
golang.org/x/net v0.52.0
golang.org/x/sys v0.42.0
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -18,6 +18,7 @@ require (
require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/alecthomas/chroma/v2 v2.20.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/charmbracelet/colorprofile v0.4.3 // indirect
Expand Down Expand Up @@ -57,6 +58,9 @@ require (
github.com/yuin/goldmark v1.7.13 // indirect
github.com/yuin/goldmark-emoji v1.0.6 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/exp/shiny v0.0.0-20250606033433-dcc06ee1d476 // indirect
golang.org/x/image v0.28.0 // indirect
golang.org/x/mobile v0.0.0-20250606033058-a2a15c67f36f // indirect
golang.org/x/term v0.41.0 // indirect
golang.org/x/text v0.35.0 // indirect
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,16 @@ github.com/yuin/goldmark-emoji v1.0.6 h1:QWfF2FYaXwL74tfGOW5izeiZepUDroDJfWubQI9
github.com/yuin/goldmark-emoji v1.0.6/go.mod h1:ukxJDKFpdFb5x0a5HqbdlcKtebh086iJpI31LTKmWuA=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.design/x/clipboard v0.7.1 h1:OEG3CmcYRBNnRwpDp7+uWLiZi3hrMRJpE9JkkkYtz2c=
golang.design/x/clipboard v0.7.1/go.mod h1:i5SiIqj0wLFw9P/1D7vfILFK0KHMk7ydE72HRrUIgkg=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/exp/shiny v0.0.0-20250606033433-dcc06ee1d476 h1:Wdx0vgH5Wgsw+lF//LJKmWOJBLWX6nprsMqnf99rYDE=
golang.org/x/exp/shiny v0.0.0-20250606033433-dcc06ee1d476/go.mod h1:ygj7T6vSGhhm/9yTpOQQNvuAUFziTH7RUiH74EoE2C8=
golang.org/x/image v0.28.0 h1:gdem5JW1OLS4FbkWgLO+7ZeFzYtL3xClb97GaUzYMFE=
golang.org/x/image v0.28.0/go.mod h1:GUJYXtnGKEUgggyzh+Vxt+AviiCcyiwpsl8iQ8MvwGY=
golang.org/x/mobile v0.0.0-20250606033058-a2a15c67f36f h1:/n+PL2HlfqeSiDCuhdBbRNlGS/g2fM4OHufalHaTVG8=
golang.org/x/mobile v0.0.0-20250606033058-a2a15c67f36f/go.mod h1:ESkJ836Z6LpG6mTVAhA48LpfW/8fNR0ifStlH2axyfg=
golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0=
golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
43 changes: 43 additions & 0 deletions internal/runtime/errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package runtime

import (
"bytes"
"context"
"errors"
"log"
"testing"

"neo-code/internal/provider"
)

func TestHandleRunErrorProviderErrorDoesNotWriteStdLog(t *testing.T) {
service := &Service{}
providerErr := &provider.ProviderError{
StatusCode: 401,
Code: "auth_failed",
Message: "Incorrect API key provided",
Retryable: false,
}

var buf bytes.Buffer
oldWriter := log.Writer()
oldFlags := log.Flags()
oldPrefix := log.Prefix()
log.SetOutput(&buf)
log.SetFlags(0)
log.SetPrefix("")
t.Cleanup(func() {
log.SetOutput(oldWriter)
log.SetFlags(oldFlags)
log.SetPrefix(oldPrefix)
})

err := service.handleRunError(context.Background(), "run-1", "session-1", providerErr)
if !errors.Is(err, providerErr) {
t.Fatalf("expected provider error passthrough, got %v", err)
}
if got := buf.String(); got != "" {
t.Fatalf("expected no std log output, got %q", got)
}

}
7 changes: 0 additions & 7 deletions internal/runtime/run_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package runtime
import (
"context"
"errors"
"log"
"math/rand/v2"
"strings"
"time"
Expand Down Expand Up @@ -103,12 +102,6 @@ func (s *Service) handleRunError(ctx context.Context, runID string, sessionID st
return context.Canceled
}

var providerErr *provider.ProviderError
if errors.As(err, &providerErr) {
log.Printf("runtime: provider error (status=%d, code=%s, retryable=%v): %s",
providerErr.StatusCode, providerErr.Code, providerErr.Retryable, providerErr.Message)
}

return err
}

Expand Down
77 changes: 35 additions & 42 deletions internal/tui/core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
type panel = tuistate.Panel

const (
panelSessions panel = tuistate.PanelSessions
panelTranscript panel = tuistate.PanelTranscript
panelActivity panel = tuistate.PanelActivity
panelInput panel = tuistate.PanelInput
Expand All @@ -38,6 +37,7 @@ const (
pickerNone pickerMode = tuistate.PickerNone
pickerProvider pickerMode = tuistate.PickerProvider
pickerModel pickerMode = tuistate.PickerModel
pickerSession pickerMode = tuistate.PickerSession
pickerFile pickerMode = tuistate.PickerFile
pickerHelp pickerMode = tuistate.PickerHelp
)
Expand Down Expand Up @@ -72,11 +72,11 @@ type appComponents struct {
keys keyMap
help help.Model
spinner spinner.Model
sessions list.Model
commandMenu list.Model
commandMenuMeta tuistate.CommandMenuMeta
providerPicker list.Model
modelPicker list.Model
sessionPicker list.Model
helpPicker list.Model
fileBrowser filepicker.Model
progress progress.Model
Expand All @@ -88,24 +88,38 @@ type appComponents struct {

// appRuntimeState 聚合运行期易变字段,降低 App 顶层字段密度。
type appRuntimeState struct {
codeCopyBlocks map[int]string
pendingCopyID int
deferredEventCmd tea.Cmd
nowFn func() time.Time
lastInputEditAt time.Time
lastPasteLikeAt time.Time
inputBurstStart time.Time
inputBurstCount int
pasteMode bool
activeMessages []providertypes.Message
activities []tuistate.ActivityEntry
fileCandidates []string
modelRefreshID string
focus panel
runProgressValue float64
runProgressKnown bool
runProgressLabel string
pendingPermission *permissionPromptState
codeCopyBlocks map[int]string
pendingCopyID int
deferredEventCmd tea.Cmd
nowFn func() time.Time
lastInputEditAt time.Time
lastPasteLikeAt time.Time
inputBurstStart time.Time
inputBurstCount int
pasteMode bool
activeMessages []providertypes.Message
activities []tuistate.ActivityEntry
fileCandidates []string
modelRefreshID string
focus panel
runProgressValue float64
runProgressKnown bool
runProgressLabel string
pendingPermission *permissionPromptState
pendingImageAttachments []pendingImageAttachment
currentModelCapabilities modelCapabilityState
}

type pendingImageAttachment struct {
Path string
MimeType string
Size int64
Name string
}

type modelCapabilityState struct {
supportsImageInput bool
checked bool
}

type App struct {
Expand Down Expand Up @@ -160,18 +174,6 @@ func newApp(container tuibootstrap.Container) (App, error) {
return App{}, err
}
keys := newKeyMap()
delegate := sessionDelegate{styles: uiStyles}
sessionList := list.New([]list.Item{}, delegate, 0, 0)
sessionList.Title = ""
sessionList.SetShowTitle(false)
sessionList.SetShowHelp(false)
sessionList.SetShowStatusBar(false)
sessionList.SetShowFilter(false)
sessionList.SetShowPagination(false)
sessionList.SetFilteringEnabled(true)
sessionList.DisableQuitKeybindings()
sessionList.FilterInput.Prompt = "Filter: "
sessionList.FilterInput.Placeholder = "Type to search sessions"

input := textarea.New()
input.Placeholder = "Ask NeoCode to inspect, edit, or build. Type / to browse commands."
Expand Down Expand Up @@ -237,10 +239,10 @@ func newApp(container tuibootstrap.Container) (App, error) {
keys: keys,
help: h,
spinner: spin,
sessions: sessionList,
commandMenu: commandMenu,
providerPicker: newSelectionPickerItems(nil),
modelPicker: newSelectionPickerItems(nil),
sessionPicker: newSelectionPickerItems(nil),
helpPicker: newHelpPickerItems(nil),
fileBrowser: fileBrowser,
progress: progressBar,
Expand All @@ -259,15 +261,6 @@ func newApp(container tuibootstrap.Container) (App, error) {
styles: uiStyles,
}

if err := app.refreshSessions(); err != nil {
return App{}, err
}
if len(app.state.Sessions) > 0 {
app.state.ActiveSessionID = app.state.Sessions[0].ID
if err := app.refreshMessages(); err != nil {
return App{}, err
}
}
app.syncActiveSessionTitle()
app.syncConfigState(configManager.Get())
if err := app.refreshProviderPicker(); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions internal/tui/core/app/command_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ type sessionItem struct {
Active bool
}

func (s sessionItem) Title() string {
return s.Summary.Title
}

func (s sessionItem) Description() string {
return s.Summary.UpdatedAt.Format("01-02 15:04")
}

func (s sessionItem) FilterValue() string {
return strings.ToLower(s.Summary.Title)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/tui/core/app/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
slashCommandStatus = "/status"
slashCommandProvider = "/provider"
slashCommandModelPick = "/model"
slashCommandSession = "/session"
slashCommandCWD = "/cwd"
slashCommandMemo = "/memo"
slashCommandRemember = "/remember"
Expand All @@ -37,6 +38,7 @@ const (
slashUsageStatus = "/status"
slashUsageProvider = "/provider"
slashUsageModel = "/model"
slashUsageSession = "/session"
slashUsageWorkdir = "/cwd"
slashUsageMemo = "/memo"
slashUsageRemember = "/remember <text>"
Expand All @@ -47,6 +49,8 @@ const (
providerPickerSubtitle = "Up/Down choose, Enter confirm, Esc cancel"
modelPickerTitle = "Select Model"
modelPickerSubtitle = "Up/Down choose, Enter confirm, Esc cancel"
sessionPickerTitle = "Select Session"
sessionPickerSubtitle = "Up/Down choose, Enter confirm, Esc cancel"
helpPickerTitle = "Slash Commands"
helpPickerSubtitle = "Up/Down choose, Enter run, Esc cancel"
filePickerTitle = "Browse Files"
Expand Down Expand Up @@ -76,6 +80,7 @@ const (
statusCompacting = "Compacting context"
statusChooseProvider = "Choose a provider"
statusChooseModel = "Choose a model"
statusChooseSession = "Choose a session"
statusChooseHelp = "Choose a slash command"
statusBrowseFile = "Browse workspace files"
statusPermissionRequired = "Permission required: choose a decision and press Enter"
Expand Down Expand Up @@ -119,6 +124,7 @@ var builtinSlashCommands = []slashCommand{
{Usage: slashUsageForget, Description: "Remove memos matching keyword (/forget <keyword>)"},
{Usage: slashUsageProvider, Description: "Open the interactive provider picker"},
{Usage: slashUsageModel, Description: "Open the interactive model picker"},
{Usage: slashUsageSession, Description: "Switch to another session"},
{Usage: slashUsageExit, Description: "Exit NeoCode"},
}

Expand Down
Loading
Loading