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
2 changes: 2 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This is the Inference Gateway CLI (`infer`), a Go-based command-line tool for ma

**Note: All commands should be run with `flox activate -- <command>` to ensure the proper development environment is activated.**

**IMPORTANT: Always run `task setup` first when working with a fresh checkout of the repository to ensure all dependencies are properly installed.**

### Setup Development Environment
```bash
flox activate -- task setup
Expand Down
14 changes: 3 additions & 11 deletions internal/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,35 @@ func NewServiceContainer(cfg *config.Config) *ServiceContainer {

// initializeDomainServices creates and wires domain service implementations
func (c *ServiceContainer) initializeDomainServices() {
// Create conversation repository
c.conversationRepo = services.NewInMemoryConversationRepository()

// Create model service
c.modelService = services.NewHTTPModelService(
c.config.Gateway.URL,
c.config.Gateway.APIKey,
)

// Create tool service first (needed by chat service)
c.fileService = services.NewLocalFileService()

if c.config.Tools.Enabled {
c.toolService = services.NewLLMToolService(c.config)
c.toolService = services.NewLLMToolService(c.config, c.fileService)
} else {
c.toolService = services.NewNoOpToolService()
}

// Create chat service with tool service
c.chatService = services.NewStreamingChatService(
c.config.Gateway.URL,
c.config.Gateway.APIKey,
c.config.Gateway.Timeout,
c.toolService,
)

// Create file service
c.fileService = services.NewLocalFileService()
}

// initializeUIComponents creates UI components and theme
func (c *ServiceContainer) initializeUIComponents() {
// Create theme based on configuration
c.theme = ui.NewDefaultTheme()

// Create layout manager
c.layout = ui.NewDefaultLayout()

// Create component factory
c.componentFactory = ui.NewComponentFactory(c.theme, c.layout, c.modelService)
}

Expand Down
1 change: 1 addition & 0 deletions internal/domain/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type ToolService interface {
type FileService interface {
ListProjectFiles() ([]string, error)
ReadFile(path string) (string, error)
ReadFileLines(path string, startLine, endLine int) (string, error)
ValidateFile(path string) error
GetFileInfo(path string) (FileInfo, error)
}
Expand Down
41 changes: 41 additions & 0 deletions internal/services/file.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package services

import (
"bufio"
"fmt"
"io/fs"
"os"
Expand Down Expand Up @@ -161,6 +162,46 @@ func (s *LocalFileService) ReadFile(path string) (string, error) {
return string(content), nil
}

func (s *LocalFileService) ReadFileLines(path string, startLine, endLine int) (string, error) {
if err := s.ValidateFile(path); err != nil {
return "", err
}

file, err := os.Open(path)
if err != nil {
return "", fmt.Errorf("failed to open file: %w", err)
}
defer func() {
_ = file.Close()
}()

scanner := bufio.NewScanner(file)
var result strings.Builder
currentLine := 1

for scanner.Scan() {
if startLine > 0 && currentLine < startLine {
currentLine++
continue
}
if endLine > 0 && currentLine > endLine {
break
}

if result.Len() > 0 {
result.WriteString("\n")
}
result.WriteString(scanner.Text())
currentLine++
}

if err := scanner.Err(); err != nil {
return "", fmt.Errorf("failed to read file lines: %w", err)
}

return result.String(), nil
}

func (s *LocalFileService) ValidateFile(path string) error {
if path == "" {
return fmt.Errorf("file path cannot be empty")
Expand Down
Loading