Skip to content

Commit 100356e

Browse files
authored
refactor: cleanup dead code and turn on dead code detection in CI (#515)
* cleanup dead code. Signed-off-by: Kai Xia <kaix+github@fastmail.com> * add these two back with flag. Signed-off-by: Kai Xia <kaix+github@fastmail.com> * fix ci Signed-off-by: Kai Xia <kaix+github@fastmail.com> * remove this confusing line Signed-off-by: Kai Xia <kaix+github@fastmail.com> * make fmt Signed-off-by: Kai Xia <kaix+github@fastmail.com> * remove unused method. picked up by golangci-lint run Signed-off-by: Kai Xia <kaix+github@fastmail.com> --------- Signed-off-by: Kai Xia <kaix+github@fastmail.com>
1 parent 18ba888 commit 100356e

File tree

8 files changed

+17
-142
lines changed

8 files changed

+17
-142
lines changed

.golangci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ linters:
6666
- testifylint
6767
- thelper
6868
- unparam
69-
- unused
7069
- usestdlibvars
7170
- usetesting
7271
- wastedassign
@@ -152,6 +151,9 @@ linters:
152151
- gocognit
153152
- gocyclo
154153
path: _test\.go$
154+
- linters:
155+
- nolintlint
156+
path: 'pkg/tools/(i2c\.go|spi\.go)$'
155157

156158
issues:
157159
max-issues-per-linter: 0

pkg/agent/context.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -288,25 +288,6 @@ func (cb *ContextBuilder) AddAssistantMessage(
288288
return messages
289289
}
290290

291-
func (cb *ContextBuilder) loadSkills() string {
292-
allSkills := cb.skillsLoader.ListSkills()
293-
if len(allSkills) == 0 {
294-
return ""
295-
}
296-
297-
var skillNames []string
298-
for _, s := range allSkills {
299-
skillNames = append(skillNames, s.Name)
300-
}
301-
302-
content := cb.skillsLoader.LoadSkillsForContext(skillNames)
303-
if content == "" {
304-
return ""
305-
}
306-
307-
return "# Skill Definitions\n\n" + content
308-
}
309-
310291
// GetSkillsInfo returns information about loaded skills.
311292
func (cb *ContextBuilder) GetSkillsInfo() map[string]any {
312293
allSkills := cb.skillsLoader.ListSkills()

pkg/channels/wecom_app.go

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -571,61 +571,6 @@ func (c *WeComAppChannel) sendTextMessage(ctx context.Context, accessToken, user
571571
return nil
572572
}
573573

574-
// sendMarkdownMessage sends a markdown message to a user
575-
func (c *WeComAppChannel) sendMarkdownMessage(ctx context.Context, accessToken, userID, content string) error {
576-
apiURL := fmt.Sprintf("%s/cgi-bin/message/send?access_token=%s", wecomAPIBase, accessToken)
577-
578-
msg := WeComMarkdownMessage{
579-
ToUser: userID,
580-
MsgType: "markdown",
581-
AgentID: c.config.AgentID,
582-
}
583-
msg.Markdown.Content = content
584-
585-
jsonData, err := json.Marshal(msg)
586-
if err != nil {
587-
return fmt.Errorf("failed to marshal message: %w", err)
588-
}
589-
590-
// Use configurable timeout (default 5 seconds)
591-
timeout := c.config.ReplyTimeout
592-
if timeout <= 0 {
593-
timeout = 5
594-
}
595-
596-
reqCtx, cancel := context.WithTimeout(ctx, time.Duration(timeout)*time.Second)
597-
defer cancel()
598-
599-
req, err := http.NewRequestWithContext(reqCtx, http.MethodPost, apiURL, bytes.NewBuffer(jsonData))
600-
if err != nil {
601-
return fmt.Errorf("failed to create request: %w", err)
602-
}
603-
req.Header.Set("Content-Type", "application/json")
604-
605-
client := &http.Client{Timeout: time.Duration(timeout) * time.Second}
606-
resp, err := client.Do(req)
607-
if err != nil {
608-
return fmt.Errorf("failed to send message: %w", err)
609-
}
610-
defer resp.Body.Close()
611-
612-
body, err := io.ReadAll(resp.Body)
613-
if err != nil {
614-
return fmt.Errorf("failed to read response: %w", err)
615-
}
616-
617-
var sendResp WeComSendMessageResponse
618-
if err := json.Unmarshal(body, &sendResp); err != nil {
619-
return fmt.Errorf("failed to parse response: %w", err)
620-
}
621-
622-
if sendResp.ErrCode != 0 {
623-
return fmt.Errorf("API error: %s (code: %d)", sendResp.ErrMsg, sendResp.ErrCode)
624-
}
625-
626-
return nil
627-
}
628-
629574
// handleHealth handles health check requests
630575
func (c *WeComAppChannel) handleHealth(w http.ResponseWriter, r *http.Request) {
631576
status := map[string]any{

pkg/devices/sources/usb_linux.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ var usbClassToCapability = map[string]string{
3535
}
3636

3737
type USBMonitor struct {
38-
cmd *exec.Cmd
39-
cancel context.CancelFunc
40-
mu sync.Mutex
38+
cmd *exec.Cmd
39+
mu sync.Mutex
4140
}
4241

4342
func NewUSBMonitor() *USBMonitor {

pkg/providers/antigravity_provider.go

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -404,64 +404,6 @@ type antigravityJSONResponse struct {
404404
} `json:"usageMetadata"`
405405
}
406406

407-
func (p *AntigravityProvider) parseJSONResponse(body []byte) (*LLMResponse, error) {
408-
var resp antigravityJSONResponse
409-
if err := json.Unmarshal(body, &resp); err != nil {
410-
return nil, fmt.Errorf("parsing antigravity response: %w", err)
411-
}
412-
413-
if len(resp.Candidates) == 0 {
414-
return nil, fmt.Errorf("antigravity: no candidates in response")
415-
}
416-
417-
candidate := resp.Candidates[0]
418-
var contentParts []string
419-
var toolCalls []ToolCall
420-
421-
for _, part := range candidate.Content.Parts {
422-
if part.Text != "" {
423-
contentParts = append(contentParts, part.Text)
424-
}
425-
if part.FunctionCall != nil {
426-
argumentsJSON, _ := json.Marshal(part.FunctionCall.Args)
427-
toolCalls = append(toolCalls, ToolCall{
428-
ID: fmt.Sprintf("call_%s_%d", part.FunctionCall.Name, time.Now().UnixNano()),
429-
Name: part.FunctionCall.Name,
430-
Arguments: part.FunctionCall.Args,
431-
Function: &FunctionCall{
432-
Name: part.FunctionCall.Name,
433-
Arguments: string(argumentsJSON),
434-
ThoughtSignature: extractPartThoughtSignature(part.ThoughtSignature, part.ThoughtSignatureSnake),
435-
},
436-
})
437-
}
438-
}
439-
440-
finishReason := "stop"
441-
if len(toolCalls) > 0 {
442-
finishReason = "tool_calls"
443-
}
444-
if candidate.FinishReason == "MAX_TOKENS" {
445-
finishReason = "length"
446-
}
447-
448-
var usage *UsageInfo
449-
if resp.UsageMetadata.TotalTokenCount > 0 {
450-
usage = &UsageInfo{
451-
PromptTokens: resp.UsageMetadata.PromptTokenCount,
452-
CompletionTokens: resp.UsageMetadata.CandidatesTokenCount,
453-
TotalTokens: resp.UsageMetadata.TotalTokenCount,
454-
}
455-
}
456-
457-
return &LLMResponse{
458-
Content: strings.Join(contentParts, ""),
459-
ToolCalls: toolCalls,
460-
FinishReason: finishReason,
461-
Usage: usage,
462-
}, nil
463-
}
464-
465407
func (p *AntigravityProvider) parseSSEResponse(body string) (*LLMResponse, error) {
466408
var contentParts []string
467409
var toolCalls []ToolCall

pkg/providers/fallback_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ func successRun(content string) func(ctx context.Context, provider, model string
1717
}
1818
}
1919

20-
func failRun(err error) func(ctx context.Context, provider, model string) (*LLMResponse, error) {
21-
return func(ctx context.Context, provider, model string) (*LLMResponse, error) {
22-
return nil, err
23-
}
24-
}
25-
2620
func TestFallback_SingleCandidate_Success(t *testing.T) {
2721
ct := NewCooldownTracker()
2822
fc := NewFallbackChain(ct)

pkg/tools/i2c.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,19 @@ func (t *I2CTool) detect() *ToolResult {
117117
return SilentResult(fmt.Sprintf("Found %d I2C bus(es):\n%s", len(buses), string(result)))
118118
}
119119

120+
// Helper functions for I2C operations (used by platform-specific implementations)
121+
120122
// isValidBusID checks that a bus identifier is a simple number (prevents path injection)
123+
//
124+
//nolint:unused // Used by i2c_linux.go
121125
func isValidBusID(id string) bool {
122126
matched, _ := regexp.MatchString(`^\d+$`, id)
123127
return matched
124128
}
125129

126130
// parseI2CAddress extracts and validates an I2C address from args
131+
//
132+
//nolint:unused // Used by i2c_linux.go
127133
func parseI2CAddress(args map[string]any) (int, *ToolResult) {
128134
addrFloat, ok := args["address"].(float64)
129135
if !ok {
@@ -137,6 +143,8 @@ func parseI2CAddress(args map[string]any) (int, *ToolResult) {
137143
}
138144

139145
// parseI2CBus extracts and validates an I2C bus from args
146+
//
147+
//nolint:unused // Used by i2c_linux.go
140148
func parseI2CBus(args map[string]any) (string, *ToolResult) {
141149
bus, ok := args["bus"].(string)
142150
if !ok || bus == "" {

pkg/tools/spi.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ func (t *SPITool) list() *ToolResult {
119119
return SilentResult(fmt.Sprintf("Found %d SPI device(s):\n%s", len(devices), string(result)))
120120
}
121121

122+
// Helper function for SPI operations (used by platform-specific implementations)
123+
122124
// parseSPIArgs extracts and validates common SPI parameters
125+
//
126+
//nolint:unused // Used by spi_linux.go
123127
func parseSPIArgs(args map[string]any) (device string, speed uint32, mode uint8, bits uint8, errMsg string) {
124128
dev, ok := args["device"].(string)
125129
if !ok || dev == "" {

0 commit comments

Comments
 (0)