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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ clue
AGENT.md

dist/
refs/
bin/
refs/
prototypes/
47 changes: 0 additions & 47 deletions .zed/tasks.json

This file was deleted.

67 changes: 47 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
run/new:
go run ./main.go
run/latest:
go run ./main.go -n=false
run/gemini:
go run ./main.go --provider=google
debug/cli:
go run ./main.go --tui=false
serve:
go run ./main.go serve
list/models:
go run ./main.go list
list/conversations:
go run ./main.go conversation -l
build:
$(eval VERSION := $(shell cat VERSION))
go build -ldflags="-s -X 'github.com/honganh1206/tinker/cmd.Version=$(VERSION)'" -o bin/tinker main.go
GOCMD=go
GOBUILD=$(GOCMD) build
GORUN=$(GOCMD) run
GOTOOL=$(GOCMD) tool
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
BINARY_NAME=tinker
BINARY_UNIX=$(BINARY_NAME)_unix
BIN_DIR=./bin

all: test build
build:
$(GOBUILD) -o $(BIN_DIR)/$(BINARY_NAME) -v
test:
$(GOTEST) ./...
coverage:
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
$(GOTEST) ./... -coverprofile=coverage.out
$(GOTOOL) cover -html=coverage.out
benchmark:
go test ./... -bench=. -benchmem
$(GOTEST) ./... -bench=. -benchmem
clean:
$(GOCLEAN)
rm -f $(BIN_DIR)/$(BINARY_NAME)
rm -f $(BIN_DIR)/$(BINARY_UNIX)
# run:
# $(GORUN)

# Cross compilation
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BIN_DIR)/$(BINARY_UNIX) -v
# run/new:
# go run ./main.go
# run/latest:
# go run ./main.go -n=false
# run/gemini:
# go run ./main.go --provider=google
# debug/cli:
# go run ./main.go --tui=false
# serve:
# go run ./main.go serve
# list/models:
# go run ./main.go list
# list/conversations:
# go run ./main.go conversation -l
# build:
# $(eval VERSION := $(shell cat VERSION))
# go build -ldflags="-s -X 'github.com/honganh1206/tinker/cmd.Version=$(VERSION)'" -o bin/tinker main.go

68 changes: 60 additions & 8 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/honganh1206/tinker/inference"
"github.com/honganh1206/tinker/mcp"
"github.com/honganh1206/tinker/message"
"github.com/honganh1206/tinker/schema"
"github.com/honganh1206/tinker/server/api"
"github.com/honganh1206/tinker/server/data"
"github.com/honganh1206/tinker/tools"
Expand Down Expand Up @@ -145,17 +146,69 @@ func (a *Agent) executeTool(id, name string, input json.RawMessage, onDelta func
result = a.executeLocalTool(id, name, input)
}

// TODO: Shorten the relative/absolute path and underline it.
// For content to edit, remove it from the display?
isError := false
if toolResult, ok := result.(message.ToolResultBlock); ok && toolResult.IsError {
onDelta(fmt.Sprintf("[red::]\u2717 %s failed[-]\n\n", name))
} else {
onDelta(fmt.Sprintf("[green::]\u2713 %s %s[-]\n\n", name, input))
isError = true
}
onDelta(FormatToolResultMessage(name, input, isError))

return result
}

func FormatToolResultMessage(name string, input json.RawMessage, isError bool) string {
var detail string

switch name {
case tools.ToolNameReadFile:
i, err := schema.DecodeRaw[tools.ReadFileInput](input)
if err == nil {
detail = i.Path
}
return ui.FormatToolResult(ui.ToolResultFormat{Name: "Read", Detail: detail, IsError: isError})

case tools.ToolNameEditFile:
i, err := schema.DecodeRaw[tools.EditFileInput](input)
if err == nil {
detail = i.Path
}
return ui.FormatToolResult(ui.ToolResultFormat{Name: "Edit", Detail: detail, IsError: isError})

case tools.ToolNameListFiles:
i, err := schema.DecodeRaw[tools.ListFilesInput](input)
if err == nil {
detail = i.Path
}
return ui.FormatListFilesToolResult(ui.ToolResultFormat{Name: "List", Detail: detail, IsError: isError})

case tools.ToolNameBash:
i, err := schema.DecodeRaw[tools.BashInput](input)
if err == nil {
detail = i.Command
}
return ui.FormatToolResult(ui.ToolResultFormat{Name: "Bash", Detail: detail, IsError: isError})

case tools.ToolNameFinder:
i, err := schema.DecodeRaw[tools.FinderInput](input)
if err == nil {
detail = i.Query
}
return ui.FormatToolResult(ui.ToolResultFormat{Name: "Finder", Detail: detail, IsError: isError})

case tools.ToolNameGrepSearch:
i, err := schema.DecodeRaw[tools.GrepSearchInput](input)
if err == nil {
detail = i.Pattern
}
return ui.FormatToolResult(ui.ToolResultFormat{Name: "Grep", Detail: detail, IsError: isError})

case tools.ToolNamePlanRead, tools.ToolNamePlanWrite:
return ui.FormatToolResult(ui.ToolResultFormat{Name: "Plan", IsError: isError})

default:
return ui.FormatToolResult(ui.ToolResultFormat{Name: name, IsError: isError})
}
}

func (a *Agent) executeMCPTool(id, name string, input json.RawMessage, toolDetails mcp.ToolDetails) message.ContentBlock {
var args map[string]any

Expand Down Expand Up @@ -298,9 +351,7 @@ func (a *Agent) runSubagent(id, name, toolDescription string, rawInput json.RawM
// The OG input from the user gets processed by the main agent
// and the subagent will consume the processed input.
// This is for the maybe future of task delegation
var input struct {
Query string `json:"query"`
}
var input tools.FinderInput

err := json.Unmarshal(rawInput, &input)
if err != nil {
Expand Down Expand Up @@ -349,3 +400,4 @@ func (a *Agent) streamResponse(ctx context.Context, onDelta func(string)) (*mess

return msg, nil
}

2 changes: 2 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ func RunServer(cmd *cobra.Command, args []string) error {
return err
}
fmt.Printf("Running background server on %s\n", ln.Addr().String())
// TODO: Can this be on a separate goroutine?
// so when I execute the command I return to my current shell session?
err = server.Serve(ln)
if errors.Is(err, http.ErrServerClosed) {
return nil
Expand Down
Loading