Skip to content

Commit ec6d2ff

Browse files
author
chaoyuepan
committed
improve web fetch
1 parent 3ca0845 commit ec6d2ff

File tree

12 files changed

+43
-27
lines changed

12 files changed

+43
-27
lines changed

agent/orchestrator.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (o *Orchestrator) runLoop(ctx context.Context, state *AgentState) ([]AgentM
138138
// Agent would stop here. Check for follow-up messages.
139139
followUpMessages := o.fetchFollowUpMessages()
140140
if len(followUpMessages) > 0 {
141-
pendingMessages = followUpMessages
141+
pendingMessages = append(pendingMessages, followUpMessages...)
142142
continue
143143
}
144144

@@ -183,8 +183,7 @@ func (o *Orchestrator) streamAssistantResponse(ctx context.Context, state *Agent
183183
}
184184

185185
// Prepare tool definitions
186-
var toolDefs []providers.ToolDefinition
187-
toolDefs = convertToToolDefinitions(state.Tools)
186+
toolDefs := convertToToolDefinitions(state.Tools)
188187

189188
// Emit message start
190189
o.emit(NewEvent(EventMessageStart))

agent/skills.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (l *SkillsLoader) checkBlockingRequirements(skill *Skill) bool {
219219
func (l *SkillsLoader) parseSkillMetadata(content string, skill *Skill) error {
220220
// 首先尝试使用新的 frontmatter 解析器
221221
frontmatter := skills.ParseFrontmatter(content)
222-
if frontmatter != nil && len(frontmatter) > 0 {
222+
if len(frontmatter) > 0 {
223223
// 从 frontmatter 中解析基本字段
224224
if name := frontmatter["name"]; name != "" {
225225
skill.Name = name
@@ -529,7 +529,7 @@ func (l *SkillsLoader) confirmInstall(skillName string, install *SkillInstall) b
529529
fmt.Print("Install now? [Y/n]: ")
530530

531531
var response string
532-
fmt.Scanln(&response)
532+
_, _ = fmt.Scanln(&response)
533533
return strings.ToLower(response) == "y" || response == ""
534534
}
535535

@@ -560,9 +560,9 @@ func (l *SkillsLoader) refreshPath() error {
560560
if homeDir != "" {
561561
shellPaths = append(shellPaths,
562562
homeDir+"/.npm-global/bin", // npm
563-
homeDir+"/.local/share/pnpm", // pnpm
564-
homeDir+"/.yarn/bin", // yarn
565-
homeDir+"/.bun/bin", // bun
563+
homeDir+"/.local/share/pnpm", // pnpm
564+
homeDir+"/.yarn/bin", // yarn
565+
homeDir+"/.bun/bin", // bun
566566
"/opt/homebrew/lib/node_modules/bin", // npm (brew-installed node)
567567
)
568568
}

agent/subagent_registry.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (r *SubagentRegistry) ReleaseRun(runID string) {
196196
r.sweeperStop = nil
197197
}
198198

199-
r.saveToDisk()
199+
_ = r.saveToDisk()
200200
}
201201

202202
// DeleteChildSession 删除子会话
@@ -316,7 +316,7 @@ func (r *SubagentRegistry) sweep() {
316316
zap.String("run_id", runID))
317317
}
318318

319-
r.saveToDisk()
319+
_ = r.saveToDisk()
320320

321321
// 如果没有运行记录了,停止清理器
322322
if len(r.runs) == 0 && r.sweeperStop != nil {
@@ -338,7 +338,7 @@ func (r *SubagentRegistry) Cleanup(runID string, cleanup string, didAnnounce boo
338338
if !didAnnounce {
339339
// 允许重试
340340
record.CleanupHandled = false
341-
r.saveToDisk()
341+
_ = r.saveToDisk()
342342
return
343343
}
344344

@@ -353,7 +353,7 @@ func (r *SubagentRegistry) Cleanup(runID string, cleanup string, didAnnounce boo
353353
record.CleanupCompletedAt = &now
354354
}
355355

356-
r.saveToDisk()
356+
_ = r.saveToDisk()
357357
}
358358

359359
// BeginCleanup 开始清理流程
@@ -375,7 +375,7 @@ func (r *SubagentRegistry) BeginCleanup(runID string) bool {
375375
}
376376

377377
record.CleanupHandled = true
378-
r.saveToDisk()
378+
_ = r.saveToDisk()
379379
return true
380380
}
381381

agent/tools/web.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ func (t *WebTool) WebFetch(ctx context.Context, params map[string]interface{}) (
196196

197197
// 设置 User-Agent
198198
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; goclaw/1.0)")
199+
// 设置 Accept header 优先获取 markdown 格式
200+
req.Header.Set("Accept", "text/markdown, text/html")
199201

200202
// 发送请求
201203
resp, err := t.client.Do(req)

cli/commands/commands.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -981,29 +981,24 @@ func (r *CommandRegistry) searchSkills(query string) string {
981981

982982
for _, skill := range skills {
983983
score := 0.0
984-
matches := []string{}
985984

986985
// 检查名称匹配
987986
if strings.Contains(strings.ToLower(skill.Name), query) {
988987
if strings.EqualFold(skill.Name, query) {
989988
score += 1.0
990-
matches = append(matches, "name (exact)")
991989
} else {
992990
score += 0.8
993-
matches = append(matches, "name")
994991
}
995992
}
996993

997994
// 检查描述匹配
998995
if strings.Contains(strings.ToLower(skill.Description), query) {
999996
score += 0.6
1000-
matches = append(matches, "description")
1001997
}
1002998

1003999
// 检查作者匹配
10041000
if strings.Contains(strings.ToLower(skill.Author), query) {
10051001
score += 0.4
1006-
matches = append(matches, "author")
10071002
}
10081003

10091004
if score > 0 {

cli/commands/tui.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func runTUI(cmd *cobra.Command, args []string) {
232232
}
233233
defer func() {
234234
agentCancel()
235-
tuiAgent.Stop()
235+
_ = tuiAgent.Stop()
236236
}()
237237

238238
// Always create a new session (unless explicitly specified)
@@ -441,6 +441,8 @@ func processTUIDialogue(
441441
}
442442

443443
// runAgentIteration runs a single agent iteration (copied from chat.go)
444+
//
445+
//nolint:unused
444446
func runAgentIteration(
445447
ctx context.Context,
446448
sess *session.Session,
@@ -635,6 +637,8 @@ func runAgentIteration(
635637
}
636638

637639
// getLoadedSkills from session
640+
//
641+
//nolint:unused
638642
func getLoadedSkills(sess *session.Session) []string {
639643
if sess.Metadata == nil {
640644
return []string{}
@@ -646,6 +650,8 @@ func getLoadedSkills(sess *session.Session) []string {
646650
}
647651

648652
// setLoadedSkills in session
653+
//
654+
//nolint:unused
649655
func setLoadedSkills(sess *session.Session, skills []string) {
650656
if sess.Metadata == nil {
651657
sess.Metadata = make(map[string]interface{})
@@ -669,6 +675,8 @@ func getUserInputHistory(sess *session.Session) []string {
669675
}
670676

671677
// findMostRecentTUISession finds the most recently updated tui session
678+
//
679+
//nolint:unused
672680
func findMostRecentTUISession(mgr *session.Manager) string {
673681
keys, err := mgr.List()
674682
if err != nil {
@@ -762,6 +770,8 @@ func (ft *FailureTracker) GetFailedToolNames() []string {
762770
}
763771

764772
// formatToolError 格式化工具错误,提供替代建议
773+
//
774+
//nolint:unused
765775
func formatToolError(toolName string, params map[string]interface{}, err error, availableTools []string) string {
766776
errorMsg := err.Error()
767777

@@ -824,6 +834,8 @@ func formatToolError(toolName string, params map[string]interface{}, err error,
824834
}
825835

826836
// shouldUseErrorGuidance 判断是否需要添加错误处理指导
837+
//
838+
//nolint:unused
827839
func shouldUseErrorGuidance(history []session.Message) bool {
828840
// 检查最近的消息中是否有工具失败
829841
if len(history) == 0 {
@@ -847,6 +859,8 @@ func shouldUseErrorGuidance(history []session.Message) bool {
847859
}
848860

849861
// getAvailableToolNames 获取可用的工具名称列表
862+
//
863+
//nolint:unused
850864
func getAvailableToolNames(toolRegistry *tools.Registry) []string {
851865
if toolRegistry == nil {
852866
return []string{}

internal/builtin_skills.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ func EnsureConfig() (bool, error) {
148148
}
149149

150150
// copyBuiltinSkills 复制内置技能到目标目录
151+
//
152+
//nolint:unused
151153
func copyBuiltinSkills(targetDir string) error {
152154
// 遍历 builtin_skills 目录
153155
entries, err := builtinSkillsFS.ReadDir("builtin_skills")

providers/rotation.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package providers
33
import (
44
"context"
55
"fmt"
6+
"sort"
67
"sync"
78
"time"
89

@@ -153,6 +154,11 @@ func (p *RotationProvider) selectRoundRobin(available []*ProviderProfile) *Provi
153154
return nil
154155
}
155156

157+
// Sort by name to ensure consistent ordering
158+
sort.Slice(available, func(i, j int) bool {
159+
return available[i].Name < available[j].Name
160+
})
161+
156162
profile := available[p.currentIndex%len(available)]
157163
p.currentIndex++
158164
return profile

skills/eligibility_checker.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ func (c *DefaultEligibilityChecker) ShouldInclude(skill *SkillEntry, config Skil
6161

6262
// Check config paths
6363
missingConfig := c.CheckConfigPaths(skill)
64-
if len(missingConfig) > 0 {
65-
return false
66-
}
67-
68-
return true
64+
return len(missingConfig) == 0
6965
}
7066

7167
// CheckOSCompatibility checks if the skill is compatible with the current OS.

skills/install.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ func InstallSkill(ctx context.Context, req InstallRequest) (*InstallResult, erro
187187
if ctx == nil {
188188
ctx = context.Background()
189189
}
190+
ctx, cancel := context.WithTimeout(ctx, timeout)
191+
defer cancel()
190192

191193
// Load skill entries
192194
entries, err := LoadSkillEntries(req.WorkspaceDir, LoadSkillsOptions{

0 commit comments

Comments
 (0)