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
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: K9s Lint
name: Lint

on:
pull_request:
branches: [master]
branches: [main]

jobs:
golangci:
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: K9s Test
name: Test

on:
workflow_dispatch:
push:
branches:
- master
- main
tags:
- rc*
- v*
pull_request:
branches:
- master
- main
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -28,6 +28,4 @@ jobs:
run: go env -w CGO_ENABLED=0

- name: Run Tests
run: make test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: go test ./...
56 changes: 56 additions & 0 deletions .idx/dev.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# To learn more about how to use Nix to configure your environment
# see: https://firebase.google.com/docs/studio/customize-workspace
{ pkgs, ... }: {
# Which nixpkgs channel to use.
channel = "stable-24.05"; # or "unstable"

# Use https://search.nixos.org/packages to find packages
packages = [
pkgs.go
# pkgs.python311
# pkgs.python311Packages.pip
# pkgs.nodejs_20
# pkgs.nodePackages.nodemon
];

# Sets environment variables in the workspace
env = {};
idx = {
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
extensions = [
# "vscodevim.vim"
];

# Enable previews
previews = {
enable = true;
previews = {
# web = {
# # Example: run "npm run dev" with PORT set to IDX's defined port for previews,
# # and show it in IDX's web preview panel
# command = ["npm" "run" "dev"];
# manager = "web";
# env = {
# # Environment variables to set for your server
# PORT = "$PORT";
# };
# };
};
};

# Workspace lifecycle hooks
workspace = {
# Runs when a workspace is first created
onCreate = {
# Example: install JS dependencies from NPM
# npm-install = "npm install";
};
# Runs when the workspace is (re)started
onStart = {
# Example: start a background task to watch and re-build backend code
# watch-backend = "npm run watch-backend";
run-go-app = "go run main.go";
};
};
};
}
12 changes: 7 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func Load() (*Config, error) {
// Automatically bind all config keys to environment variables
configType := reflect.TypeOf(*config)
for _, key := range EnumerateConfigKeys(configType, "") {
viper.BindEnv(key)
_ = viper.BindEnv(key)
}

viper.AutomaticEnv()
Expand Down Expand Up @@ -177,9 +177,10 @@ func TryInferType(key, value string) any {
if key == fullKey {
switch field.Type.Kind() {
case reflect.Bool:
if value == "true" {
switch value {
case "true":
typedValue = true
} else if value == "false" {
case "false":
typedValue = false
}
case reflect.Int, reflect.Int64, reflect.Int32:
Expand All @@ -205,9 +206,10 @@ func TryInferType(key, value string) any {
if ntag == nestedKey {
switch nf.Type.Kind() {
case reflect.Bool:
if value == "true" {
switch value {
case "true":
typedValue = true
} else if value == "false" {
case "false":
typedValue = false
}
case reflect.Int, reflect.Int64, reflect.Int32:
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ require (
github.com/nyaosorg/go-readline-ny v1.9.1
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand All @@ -28,13 +30,15 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nyaosorg/go-box/v2 v2.2.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
18 changes: 9 additions & 9 deletions internal/ai_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (c *AiClient) ChatCompletion(ctx context.Context, messages []Message, model
logger.Error("Failed to send request: %v", err)
return "", fmt.Errorf("failed to send request: %w", err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()

// Read the response
body, err := io.ReadAll(resp.Body)
Expand Down Expand Up @@ -194,7 +194,7 @@ func debugChatMessages(chatMessages []ChatMessage, response string) {

debugDir := fmt.Sprintf("%s/debug", configDir)
if _, err := os.Stat(debugDir); os.IsNotExist(err) {
os.Mkdir(debugDir, 0755)
_ = os.Mkdir(debugDir, 0755)
}

debugFileName := fmt.Sprintf("%s/debug-%s.txt", debugDir, timestamp)
Expand All @@ -204,9 +204,9 @@ func debugChatMessages(chatMessages []ChatMessage, response string) {
logger.Error("Failed to create debug file: %v", err)
return
}
defer file.Close()
defer func() { _ = file.Close() }()

file.WriteString("================== SENT CHAT MESSAGES ==================\n\n")
_, _ = file.WriteString("================== SENT CHAT MESSAGES ==================\n\n")

for i, msg := range chatMessages {
role := "assistant"
Expand All @@ -218,11 +218,11 @@ func debugChatMessages(chatMessages []ChatMessage, response string) {
}
timeStr := msg.Timestamp.Format(time.RFC3339)

file.WriteString(fmt.Sprintf("Message %d: Role=%s, Time=%s\n", i+1, role, timeStr))
file.WriteString(fmt.Sprintf("Content:\n%s\n\n", msg.Content))
_, _ = fmt.Fprintf(file, "Message %d: Role=%s, Time=%s\n", i+1, role, timeStr)
_, _ = fmt.Fprintf(file, "Content:\n%s\n\n", msg.Content)
}

file.WriteString("================== RECEIVED RESPONSE ==================\n\n")
file.WriteString(response)
file.WriteString("\n\n================== END DEBUG ==================\n")
_, _ = file.WriteString("================== RECEIVED RESPONSE ==================\n\n")
_, _ = file.WriteString(response)
_, _ = file.WriteString("\n\n================== END DEBUG ==================\n")
}
2 changes: 1 addition & 1 deletion internal/ai_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAzureOpenAIEndpoint(t *testing.T) {
t.Errorf("missing api-key header")
}
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"choices":[{"message":{"content":"ok"}}]}`))
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"ok"}}]}`))
}))
defer server.Close()

Expand Down
2 changes: 1 addition & 1 deletion internal/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (c *CLIInterface) Start(initMessage string) error {
historyLines = append(historyLines, history.At(i))
}
historyData := strings.Join(historyLines, "\n")
os.WriteFile(historyFilePath, []byte(historyData), 0644)
_ = os.WriteFile(historyFilePath, []byte(historyData), 0644)
}

// Process the input (preserving multiline content)
Expand Down
6 changes: 3 additions & 3 deletions internal/chat_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ func (m *Manager) ProcessSubCommand(command string) {

case prefixMatch(commandPrefix, "/clear"):
m.Messages = []ChatMessage{}
system.TmuxClearPane(m.PaneId)
_ = system.TmuxClearPane(m.PaneId)
return

case prefixMatch(commandPrefix, "/reset"):
m.Status = ""
m.Messages = []ChatMessage{}
system.TmuxClearPane(m.PaneId)
system.TmuxClearPane(m.ExecPane.Id)
_ = system.TmuxClearPane(m.PaneId)
_ = system.TmuxClearPane(m.ExecPane.Id)
return

case prefixMatch(commandPrefix, "/exit"):
Expand Down
6 changes: 3 additions & 3 deletions internal/config_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func formatConfigValue(sb *strings.Builder, prefix string, val reflect.Value, ov

// Handle nested structs
if field.Kind() == reflect.Struct {
sb.WriteString(fmt.Sprintf("%s%s:\n", indentStr, tag))
_, _ = fmt.Fprintf(sb, "%s%s:\n", indentStr, tag)
formatConfigValue(sb, key, field, overrides, indent+1)
continue
}
Expand All @@ -144,9 +144,9 @@ func formatConfigValue(sb *strings.Builder, prefix string, val reflect.Value, ov

// Check if there's a session override for this key
if override, exists := overrides[key]; exists {
sb.WriteString(fmt.Sprintf("%s%s: %v", indentStr, tag, override))
_, _ = fmt.Fprintf(sb, "%s%s: %v", indentStr, tag, override)
} else {
sb.WriteString(fmt.Sprintf("%s%s: %s", indentStr, tag, valueStr))
_, _ = fmt.Fprintf(sb, "%s%s: %s", indentStr, tag, valueStr)
}

sb.WriteString("\n")
Expand Down
8 changes: 4 additions & 4 deletions internal/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/fatih/color"
)

func (m *Manager) confirmedToExec(command string, prompt string, edit bool) (bool, string) {
func (m *Manager) confirmedToExecFn(command string, prompt string, edit bool) (bool, string) {
isSafe, _ := m.whitelistCheck(command)
if isSafe {
return true, command
Expand All @@ -36,7 +36,7 @@ func (m *Manager) confirmedToExec(command string, prompt string, edit bool) (boo
fmt.Printf("Error initializing readline: %v\n", err)
return false, ""
}
defer rl.Close()
defer func() { _ = rl.Close() }()

confirmInput, err := rl.Readline()
if err != nil {
Expand Down Expand Up @@ -71,7 +71,7 @@ func (m *Manager) confirmedToExec(command string, prompt string, edit bool) (boo
fmt.Printf("Error initializing readline for edit: %v\n", editErr)
return false, ""
}
defer editRl.Close()
defer func() { _ = editRl.Close() }()

// Use ReadlineWithDefault to prefill the command
editedCommand, editErr := editRl.ReadlineWithDefault(command)
Expand All @@ -96,7 +96,7 @@ func (m *Manager) confirmedToExec(command string, prompt string, edit bool) (boo
return false, ""
default:
// any other input is retry confirmation
return m.confirmedToExec(command, prompt, edit)
return m.confirmedToExecFn(command, prompt, edit)
}
}

Expand Down
3 changes: 1 addition & 2 deletions internal/countdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (m *Manager) Countdown(seconds int) {
fmt.Println("Error opening keyboard:", err)
return
}
defer keyboard.Close()
defer func() { _ = keyboard.Close() }()

// Create a channel for keyboard events
keyChan := make(chan keyboard.Key, 10)
Expand Down Expand Up @@ -52,7 +52,6 @@ func (m *Manager) Countdown(seconds int) {
// Just continue execution without exiting the function
remaining = 0 // Set remaining to 0 to end the countdown loop
renderCountdown(remaining, seconds, paused, highlightColor, dimColor, pauseColor)
break
case keyboard.KeyCtrlC: // Ctrl+C
m.Status = ""
m.WatchMode = false
Expand Down
18 changes: 5 additions & 13 deletions internal/exec_pane.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (m *Manager) GetAvailablePane() system.TmuxPaneDetails {
func (m *Manager) InitExecPane() {
availablePane := m.GetAvailablePane()
if availablePane.Id == "" {
system.TmuxCreateNewPane(m.PaneId)
_, _ = system.TmuxCreateNewPane(m.PaneId)
availablePane = m.GetAvailablePane()
}
m.ExecPane = &availablePane
Expand All @@ -55,12 +55,12 @@ func (m *Manager) PrepareExecPane() {
return
}

system.TmuxSendCommandToPane(m.ExecPane.Id, ps1Command, true)
system.TmuxSendCommandToPane(m.ExecPane.Id, "C-l", false)
_ = system.TmuxSendCommandToPane(m.ExecPane.Id, ps1Command, true)
_ = system.TmuxSendCommandToPane(m.ExecPane.Id, "C-l", false)
}

func (m *Manager) ExecWaitCapture(command string) (CommandExecHistory, error) {
system.TmuxSendCommandToPane(m.ExecPane.Id, command, true)
_ = system.TmuxSendCommandToPane(m.ExecPane.Id, command, true)
m.ExecPane.Refresh(m.GetMaxCaptureLines())

m.Println("")
Expand Down Expand Up @@ -100,7 +100,7 @@ func (m *Manager) parseExecPaneCommandHistory() {
line := scanner.Text()
match := promptRegex.FindStringSubmatch(line)

if match != nil && len(match) >= 2 { // We need at least the status code match[1]
if len(match) >= 2 { // We need at least the status code match[1]
// --- Found a prompt line ---
// This prompt line *terminates* the previous command block
// and provides its status code. It might also start a new command block.
Expand Down Expand Up @@ -132,10 +132,6 @@ func (m *Manager) parseExecPaneCommandHistory() {
// Reset for the next block
outputBuilder.Reset()
currentCommand = nil // Mark as no active command temporarily
} else {
// Optional: Handle status code on the very first prompt if needed.
// Currently, the status on the first prompt is ignored as there's
// no *previous* command within the parsed text to assign it to.
}

// 2. If this prompt line ALSO contains a command, start the NEW block
Expand All @@ -145,10 +141,6 @@ func (m *Manager) parseExecPaneCommandHistory() {
Code: -1, // Default/Unknown: Status code is determined by the *next* prompt
// Output will be collected in outputBuilder starting from the next line
}
} else {
// This prompt line only indicates the end status of the previous command
// (like the final "[i] [~/r/tmuxai][16:56][2]»" line).
// No new command starts here, so currentCommand remains nil.
}

} else {
Expand Down
Loading
Loading