added freeride skill
This commit is contained in:
parent
6421f146a9
commit
36a5838182
38 changed files with 3616 additions and 29 deletions
162
cmd/freeride-diag/main.go
Normal file
162
cmd/freeride-diag/main.go
Normal file
|
|
@ -0,0 +1,162 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Model struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
ContextLength int `json:"context_length"`
|
||||||
|
Pricing struct {
|
||||||
|
Prompt string `json:"prompt"`
|
||||||
|
Completion string `json:"completion"`
|
||||||
|
} `json:"pricing"`
|
||||||
|
Created int64 `json:"created"`
|
||||||
|
Score float64
|
||||||
|
LastError string
|
||||||
|
IsReachable bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
apiKey := os.Getenv("OPENROUTER_API_KEY")
|
||||||
|
if apiKey == "" {
|
||||||
|
fmt.Println("❌ Error: OPENROUTER_API_KEY environment variable is not set.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("🔍 Fetching all models from OpenRouter...")
|
||||||
|
models, err := fetchModels(apiKey)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("❌ Failed to fetch models: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
var freeModels []Model
|
||||||
|
for _, m := range models {
|
||||||
|
if m.Pricing.Prompt == "0" && m.Pricing.Completion == "0" {
|
||||||
|
// Scoring logic (same as tool)
|
||||||
|
score := 0.0
|
||||||
|
score += float64(m.ContextLength) / 128000.0 * 0.4
|
||||||
|
if m.Created > 0 {
|
||||||
|
ageInDays := float64(time.Now().Unix()-m.Created) / 86400.0
|
||||||
|
if ageInDays < 365 {
|
||||||
|
score += (1.0 - ageInDays/365.0) * 0.2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.Score = score
|
||||||
|
freeModels = append(freeModels, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(freeModels, func(i, j int) bool {
|
||||||
|
return freeModels[i].Score > freeModels[j].Score
|
||||||
|
})
|
||||||
|
|
||||||
|
fmt.Printf("✅ Found %d free models. Testing connectivity until we find 3 working ones...\n\n", len(freeModels))
|
||||||
|
|
||||||
|
successCount := 0
|
||||||
|
for i := range freeModels {
|
||||||
|
if successCount >= 3 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
m := &freeModels[i]
|
||||||
|
fmt.Printf("[%d/%d] Testing %s... ", i+1, len(freeModels), m.ID)
|
||||||
|
|
||||||
|
err := testModel(apiKey, m.ID)
|
||||||
|
if err == nil {
|
||||||
|
m.IsReachable = true
|
||||||
|
successCount++
|
||||||
|
fmt.Println("✅ OK")
|
||||||
|
} else {
|
||||||
|
m.LastError = err.Error()
|
||||||
|
fmt.Printf("❌ FAIL (%v)\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("\n--- FINAL RECOMMENDATIONS ---")
|
||||||
|
header := fmt.Sprintf("%-50s | %-15s | %-10s", "Model ID", "Context", "Status")
|
||||||
|
fmt.Println(header)
|
||||||
|
fmt.Println(strings.Repeat("-", len(header)))
|
||||||
|
|
||||||
|
for i, m := range freeModels {
|
||||||
|
if i >= 10 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
status := "Unknown"
|
||||||
|
if i < 5 {
|
||||||
|
if m.IsReachable {
|
||||||
|
status = "✅ OK"
|
||||||
|
} else {
|
||||||
|
status = "❌ FAIL"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Printf("%-50s | %-15d | %-10s\n", m.ID, m.ContextLength, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, m := range freeModels {
|
||||||
|
if m.IsReachable {
|
||||||
|
fmt.Printf(
|
||||||
|
"\n🚀 SUCCESS! Use this model for testing: \n go run cmd/picoclaw/main.go agent --model openrouter/%s\n",
|
||||||
|
m.ID,
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchModels(apiKey string) ([]Model, error) {
|
||||||
|
req, _ := http.NewRequest("GET", "https://openrouter.ai/api/v1/models", nil)
|
||||||
|
req.Header.Set("Authorization", "Bearer "+apiKey)
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var result struct {
|
||||||
|
Data []Model `json:"data"`
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func testModel(apiKey, modelID string) error {
|
||||||
|
payload := map[string]any{
|
||||||
|
"model": modelID,
|
||||||
|
"messages": []map[string]string{
|
||||||
|
{"role": "user", "content": "ping"},
|
||||||
|
},
|
||||||
|
"max_tokens": 10,
|
||||||
|
}
|
||||||
|
body, _ := json.Marshal(payload)
|
||||||
|
|
||||||
|
req, _ := http.NewRequest("POST", "https://openrouter.ai/api/v1/chat/completions", bytes.NewReader(body))
|
||||||
|
req.Header.Set("Authorization", "Bearer "+apiKey)
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
client := &http.Client{Timeout: 10 * time.Second}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
respBody, _ := io.ReadAll(resp.Body)
|
||||||
|
return fmt.Errorf("HTTP %d: %s", resp.StatusCode, string(respBody))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
104
cmd/picoclaw/internal/freeride/command.go
Normal file
104
cmd/picoclaw/internal/freeride/command.go
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
package freeride
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/sipeed/picoclaw/cmd/picoclaw/internal"
|
||||||
|
"github.com/sipeed/picoclaw/pkg/tools"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewFreerideCommand returns a new cobra.Command for managing OpenRouter free models.
|
||||||
|
func NewFreerideCommand() *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "freeride",
|
||||||
|
Short: "Manage OpenRouter free models and fallbacks",
|
||||||
|
Long: "FreeRide automatically discovers and configures OpenRouter's best free models as fallbacks for your PicoClaw agent.",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
return cmd.Help()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.AddCommand(
|
||||||
|
newListCommand(),
|
||||||
|
newAutoCommand(),
|
||||||
|
newStatusCommand(),
|
||||||
|
newSetTimeoutCommand(),
|
||||||
|
)
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func newListCommand() *cobra.Command {
|
||||||
|
var limit int
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "list",
|
||||||
|
Short: "List available free models from OpenRouter",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
t := tools.NewFreeRideTool(internal.GetConfigPath(), nil)
|
||||||
|
result := t.Execute(context.Background(), map[string]any{
|
||||||
|
"command": "list",
|
||||||
|
"limit": float64(limit),
|
||||||
|
})
|
||||||
|
fmt.Println(result.ForLLM)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cmd.Flags().IntVarP(&limit, "limit", "l", 10, "Number of models to list")
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func newAutoCommand() *cobra.Command {
|
||||||
|
var limit int
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "auto",
|
||||||
|
Short: "Automatically configure best free models as fallbacks",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
t := tools.NewFreeRideTool(internal.GetConfigPath(), nil)
|
||||||
|
result := t.Execute(context.Background(), map[string]any{
|
||||||
|
"command": "auto",
|
||||||
|
"limit": float64(limit),
|
||||||
|
})
|
||||||
|
fmt.Println(result.ForLLM)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cmd.Flags().IntVarP(&limit, "limit", "l", 5, "Number of fallbacks to configure")
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func newStatusCommand() *cobra.Command {
|
||||||
|
return &cobra.Command{
|
||||||
|
Use: "status",
|
||||||
|
Short: "Check current FreeRide configuration",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
t := tools.NewFreeRideTool(internal.GetConfigPath(), nil)
|
||||||
|
result := t.Execute(context.Background(), map[string]any{
|
||||||
|
"command": "status",
|
||||||
|
})
|
||||||
|
fmt.Println(result.ForLLM)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newSetTimeoutCommand() *cobra.Command {
|
||||||
|
var timeout int
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "settimeout",
|
||||||
|
Short: "Set request timeout for all OpenRouter models",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
t := tools.NewFreeRideTool(internal.GetConfigPath(), nil)
|
||||||
|
result := t.Execute(context.Background(), map[string]any{
|
||||||
|
"command": "settimeout",
|
||||||
|
"timeout": float64(timeout),
|
||||||
|
})
|
||||||
|
fmt.Println(result.ForLLM)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cmd.Flags().IntVarP(&timeout, "timeout", "t", 300, "Request timeout in seconds (default 300)")
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
45
cmd/picoclaw/internal/onboard/workspace/AGENT.md
Normal file
45
cmd/picoclaw/internal/onboard/workspace/AGENT.md
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
---
|
||||||
|
name: pico
|
||||||
|
description: >
|
||||||
|
The default general-purpose assistant for everyday conversation, problem
|
||||||
|
solving, and workspace help.
|
||||||
|
---
|
||||||
|
|
||||||
|
You are Pico, the default assistant for this workspace.
|
||||||
|
Your name is PicoClaw 🦞.
|
||||||
|
## Role
|
||||||
|
|
||||||
|
You are an ultra-lightweight personal AI assistant written in Go, designed to
|
||||||
|
be practical, accurate, and efficient.
|
||||||
|
|
||||||
|
## Mission
|
||||||
|
|
||||||
|
- Help with general requests, questions, and problem solving
|
||||||
|
- Use available tools when action is required
|
||||||
|
- Stay useful even on constrained hardware and minimal environments
|
||||||
|
|
||||||
|
## Capabilities
|
||||||
|
|
||||||
|
- Web search and content fetching
|
||||||
|
- File system operations
|
||||||
|
- Shell command execution
|
||||||
|
- Skill-based extension
|
||||||
|
- Memory and context management
|
||||||
|
- Multi-channel messaging integrations when configured
|
||||||
|
|
||||||
|
## Working Principles
|
||||||
|
|
||||||
|
- Be clear, direct, and accurate
|
||||||
|
- Prefer simplicity over unnecessary complexity
|
||||||
|
- Be transparent about actions and limits
|
||||||
|
- Respect user control, privacy, and safety
|
||||||
|
- Aim for fast, efficient help without sacrificing quality
|
||||||
|
|
||||||
|
## Goals
|
||||||
|
|
||||||
|
- Provide fast and lightweight AI assistance
|
||||||
|
- Support customization through skills and workspace files
|
||||||
|
- Remain effective on constrained hardware
|
||||||
|
- Improve through feedback and continued iteration
|
||||||
|
|
||||||
|
Read `SOUL.md` as part of your identity and communication style.
|
||||||
19
cmd/picoclaw/internal/onboard/workspace/SOUL.md
Normal file
19
cmd/picoclaw/internal/onboard/workspace/SOUL.md
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Soul
|
||||||
|
|
||||||
|
I am PicoClaw: calm, helpful, and practical.
|
||||||
|
|
||||||
|
## Personality
|
||||||
|
|
||||||
|
- Helpful and friendly
|
||||||
|
- Concise and to the point
|
||||||
|
- Curious and eager to learn
|
||||||
|
- Honest and transparent
|
||||||
|
- Calm under uncertainty
|
||||||
|
|
||||||
|
## Values
|
||||||
|
|
||||||
|
- Accuracy over speed
|
||||||
|
- User privacy and safety
|
||||||
|
- Transparency in actions
|
||||||
|
- Continuous improvement
|
||||||
|
- Simplicity over unnecessary complexity
|
||||||
21
cmd/picoclaw/internal/onboard/workspace/USER.md
Normal file
21
cmd/picoclaw/internal/onboard/workspace/USER.md
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# User
|
||||||
|
|
||||||
|
Information about the user goes here.
|
||||||
|
|
||||||
|
## Preferences
|
||||||
|
|
||||||
|
- Communication style: (casual/formal)
|
||||||
|
- Timezone: (your timezone)
|
||||||
|
- Language: (your preferred language)
|
||||||
|
|
||||||
|
## Personal Information
|
||||||
|
|
||||||
|
- Name: (optional)
|
||||||
|
- Location: (optional)
|
||||||
|
- Occupation: (optional)
|
||||||
|
|
||||||
|
## Learning Goals
|
||||||
|
|
||||||
|
- What the user wants to learn from AI
|
||||||
|
- Preferred interaction style
|
||||||
|
- Areas of interest
|
||||||
21
cmd/picoclaw/internal/onboard/workspace/memory/MEMORY.md
Normal file
21
cmd/picoclaw/internal/onboard/workspace/memory/MEMORY.md
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Long-term Memory
|
||||||
|
|
||||||
|
This file stores important information that should persist across sessions.
|
||||||
|
|
||||||
|
## User Information
|
||||||
|
|
||||||
|
(Important facts about user)
|
||||||
|
|
||||||
|
## Preferences
|
||||||
|
|
||||||
|
(User preferences learned over time)
|
||||||
|
|
||||||
|
## Important Notes
|
||||||
|
|
||||||
|
(Things to remember)
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
- Model preferences
|
||||||
|
- Channel settings
|
||||||
|
- Skills enabled
|
||||||
|
|
@ -0,0 +1,129 @@
|
||||||
|
---
|
||||||
|
name: agent-browser
|
||||||
|
description: "Browser automation via agent-browser CLI. Use when the user needs to navigate websites, fill forms, click buttons, take screenshots, extract data, or test web apps."
|
||||||
|
metadata: {"nanobot":{"emoji":"🌐","requires":{"bins":["agent-browser"]},"install":[{"id":"npm","kind":"npm","package":"agent-browser","global":true,"bins":["agent-browser"],"label":"Install agent-browser (npm)"}]}}
|
||||||
|
---
|
||||||
|
|
||||||
|
# Agent Browser
|
||||||
|
|
||||||
|
CLI browser automation via Chrome/Chromium CDP. Install: `npm i -g agent-browser && agent-browser install`.
|
||||||
|
|
||||||
|
**Before using this skill**, verify the tool is available by running `which agent-browser`. If the command is not found, tell the user that browser automation requires the `agent-browser` CLI and Chromium, which are only available in the heavy container image. Do not attempt to install it at runtime.
|
||||||
|
|
||||||
|
## Core Workflow
|
||||||
|
|
||||||
|
1. `agent-browser open <url>` — navigate
|
||||||
|
2. `agent-browser snapshot -i` — get interactive elements with refs (`@e1`, `@e2`, ...)
|
||||||
|
3. Interact using refs — `click @e1`, `fill @e2 "text"`
|
||||||
|
4. Re-snapshot after any navigation or DOM change — refs are invalidated
|
||||||
|
|
||||||
|
```bash
|
||||||
|
agent-browser open https://example.com/form
|
||||||
|
agent-browser snapshot -i
|
||||||
|
# @e1 [input] "Email", @e2 [input] "Password", @e3 [button] "Submit"
|
||||||
|
agent-browser fill @e1 "user@example.com"
|
||||||
|
agent-browser fill @e2 "secret"
|
||||||
|
agent-browser click @e3
|
||||||
|
agent-browser wait --load networkidle
|
||||||
|
agent-browser snapshot -i
|
||||||
|
```
|
||||||
|
|
||||||
|
Chain commands with `&&` when you don't need intermediate output:
|
||||||
|
```bash
|
||||||
|
agent-browser open https://example.com && agent-browser wait --load networkidle && agent-browser snapshot -i
|
||||||
|
```
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Navigation
|
||||||
|
agent-browser open <url>
|
||||||
|
agent-browser close
|
||||||
|
|
||||||
|
# Snapshot
|
||||||
|
agent-browser snapshot -i # Interactive elements with refs
|
||||||
|
agent-browser snapshot -s "#selector" # Scope to CSS selector
|
||||||
|
|
||||||
|
# Interaction (use @refs from snapshot)
|
||||||
|
agent-browser click @e1
|
||||||
|
agent-browser fill @e2 "text" # Clear + type
|
||||||
|
agent-browser type @e2 "text" # Type without clearing
|
||||||
|
agent-browser select @e1 "option"
|
||||||
|
agent-browser check @e1
|
||||||
|
agent-browser press Enter
|
||||||
|
agent-browser scroll down 500
|
||||||
|
|
||||||
|
# Get info
|
||||||
|
agent-browser get text @e1
|
||||||
|
agent-browser get url
|
||||||
|
agent-browser get title
|
||||||
|
|
||||||
|
# Wait
|
||||||
|
agent-browser wait @e1 # Wait for element
|
||||||
|
agent-browser wait --load networkidle # Wait for network idle
|
||||||
|
agent-browser wait --url "**/dashboard" # Wait for URL pattern
|
||||||
|
agent-browser wait --text "Welcome" # Wait for text
|
||||||
|
agent-browser wait 2000 # Wait ms
|
||||||
|
|
||||||
|
# Capture
|
||||||
|
agent-browser screenshot # Screenshot to temp dir
|
||||||
|
agent-browser screenshot --full # Full page
|
||||||
|
agent-browser screenshot --annotate # With numbered element labels ([N] -> @eN)
|
||||||
|
agent-browser pdf output.pdf
|
||||||
|
|
||||||
|
# Semantic locators (when refs unavailable)
|
||||||
|
agent-browser find text "Sign In" click
|
||||||
|
agent-browser find label "Email" fill "user@test.com"
|
||||||
|
agent-browser find role button click --name "Submit"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Authentication
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Option 1: Import from user's running Chrome
|
||||||
|
agent-browser --auto-connect state save ./auth.json
|
||||||
|
agent-browser --state ./auth.json open https://app.example.com
|
||||||
|
|
||||||
|
# Option 2: Persistent profile
|
||||||
|
agent-browser --profile ~/.myapp open https://app.example.com/login
|
||||||
|
# ... login once, all future runs are authenticated
|
||||||
|
|
||||||
|
# Option 3: Session name (auto-save/restore)
|
||||||
|
agent-browser --session-name myapp open https://app.example.com/login
|
||||||
|
# ... login, close, next run state is restored
|
||||||
|
|
||||||
|
# Option 4: State file
|
||||||
|
agent-browser state save auth.json
|
||||||
|
agent-browser state load auth.json
|
||||||
|
```
|
||||||
|
|
||||||
|
## Iframes
|
||||||
|
|
||||||
|
Iframe content is inlined in snapshots. Interact with iframe refs directly — no frame switch needed.
|
||||||
|
|
||||||
|
## Parallel Sessions
|
||||||
|
|
||||||
|
```bash
|
||||||
|
agent-browser --session s1 open https://site-a.com
|
||||||
|
agent-browser --session s2 open https://site-b.com
|
||||||
|
agent-browser session list
|
||||||
|
```
|
||||||
|
|
||||||
|
## JavaScript Eval
|
||||||
|
|
||||||
|
```bash
|
||||||
|
agent-browser eval 'document.title'
|
||||||
|
|
||||||
|
# Complex JS — use --stdin to avoid shell quoting issues
|
||||||
|
agent-browser eval --stdin <<'EVALEOF'
|
||||||
|
JSON.stringify(Array.from(document.querySelectorAll("a")).map(a => a.href))
|
||||||
|
EVALEOF
|
||||||
|
```
|
||||||
|
|
||||||
|
## Cleanup
|
||||||
|
|
||||||
|
Always close sessions when done:
|
||||||
|
```bash
|
||||||
|
agent-browser close
|
||||||
|
agent-browser --session s1 close
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
# FreeRide Skill
|
||||||
|
|
||||||
|
FreeRide gives you unlimited free AI in PicoClaw by automatically managing OpenRouter's free models.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
- `/freeride auto`: Auto-configure best model + fallbacks.
|
||||||
|
- `/freeride list`: See all 30+ free models ranked.
|
||||||
|
- `/freeride status`: Check your current setup.
|
||||||
|
|
||||||
|
## How it works
|
||||||
|
|
||||||
|
The skill uses the `freeride` tool to fetch free models from OpenRouter, ranks them by context length, capabilities, recency, and provider trust, and then updates your PicoClaw configuration with the best models as fallbacks.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
Ensure you have your OpenRouter API key set in your K3s secrets or environment variables as `OPENROUTER_API_KEY`.
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
---
|
||||||
|
name: github
|
||||||
|
description: "Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries."
|
||||||
|
metadata: {"nanobot":{"emoji":"🐙","requires":{"bins":["gh"]},"install":[{"id":"brew","kind":"brew","formula":"gh","bins":["gh"],"label":"Install GitHub CLI (brew)"},{"id":"apt","kind":"apt","package":"gh","bins":["gh"],"label":"Install GitHub CLI (apt)"}]}}
|
||||||
|
---
|
||||||
|
|
||||||
|
# GitHub Skill
|
||||||
|
|
||||||
|
Use the `gh` CLI to interact with GitHub. Always specify `--repo owner/repo` when not in a git directory, or use URLs directly.
|
||||||
|
|
||||||
|
## Pull Requests
|
||||||
|
|
||||||
|
Check CI status on a PR:
|
||||||
|
```bash
|
||||||
|
gh pr checks 55 --repo owner/repo
|
||||||
|
```
|
||||||
|
|
||||||
|
List recent workflow runs:
|
||||||
|
```bash
|
||||||
|
gh run list --repo owner/repo --limit 10
|
||||||
|
```
|
||||||
|
|
||||||
|
View a run and see which steps failed:
|
||||||
|
```bash
|
||||||
|
gh run view <run-id> --repo owner/repo
|
||||||
|
```
|
||||||
|
|
||||||
|
View logs for failed steps only:
|
||||||
|
```bash
|
||||||
|
gh run view <run-id> --repo owner/repo --log-failed
|
||||||
|
```
|
||||||
|
|
||||||
|
## API for Advanced Queries
|
||||||
|
|
||||||
|
The `gh api` command is useful for accessing data not available through other subcommands.
|
||||||
|
|
||||||
|
Get PR with specific fields:
|
||||||
|
```bash
|
||||||
|
gh api repos/owner/repo/pulls/55 --jq '.title, .state, .user.login'
|
||||||
|
```
|
||||||
|
|
||||||
|
## JSON Output
|
||||||
|
|
||||||
|
Most commands support `--json` for structured output. You can use `--jq` to filter:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
gh issue list --repo owner/repo --json number,title --jq '.[] | "\(.number): \(.title)"'
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
---
|
||||||
|
name: hardware
|
||||||
|
description: Read and control I2C and SPI peripherals on Sipeed boards (LicheeRV Nano, MaixCAM, NanoKVM).
|
||||||
|
homepage: https://wiki.sipeed.com/hardware/en/lichee/RV_Nano/1_intro.html
|
||||||
|
metadata: {"nanobot":{"emoji":"🔧","requires":{"tools":["i2c","spi"]}}}
|
||||||
|
---
|
||||||
|
|
||||||
|
# Hardware (I2C / SPI)
|
||||||
|
|
||||||
|
Use the `i2c` and `spi` tools to interact with sensors, displays, and other peripherals connected to the board.
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
```
|
||||||
|
# 1. Find available buses
|
||||||
|
i2c detect
|
||||||
|
|
||||||
|
# 2. Scan for connected devices
|
||||||
|
i2c scan (bus: "1")
|
||||||
|
|
||||||
|
# 3. Read from a sensor (e.g. AHT20 temperature/humidity)
|
||||||
|
i2c read (bus: "1", address: 0x38, register: 0xAC, length: 6)
|
||||||
|
|
||||||
|
# 4. SPI devices
|
||||||
|
spi list
|
||||||
|
spi read (device: "2.0", length: 4)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Before You Start — Pinmux Setup
|
||||||
|
|
||||||
|
Most I2C/SPI pins are shared with WiFi on Sipeed boards. You must configure pinmux before use.
|
||||||
|
|
||||||
|
See `references/board-pinout.md` for board-specific commands.
|
||||||
|
|
||||||
|
**Common steps:**
|
||||||
|
1. Stop WiFi if using shared pins: `/etc/init.d/S30wifi stop`
|
||||||
|
2. Load i2c-dev module: `modprobe i2c-dev`
|
||||||
|
3. Configure pinmux with `devmem` (board-specific)
|
||||||
|
4. Verify with `i2c detect` and `i2c scan`
|
||||||
|
|
||||||
|
## Safety
|
||||||
|
|
||||||
|
- **Write operations** require `confirm: true` — always confirm with the user first
|
||||||
|
- I2C addresses are validated to 7-bit range (0x03-0x77)
|
||||||
|
- SPI modes are validated (0-3 only)
|
||||||
|
- Maximum per-transaction: 256 bytes (I2C), 4096 bytes (SPI)
|
||||||
|
|
||||||
|
## Common Devices
|
||||||
|
|
||||||
|
See `references/common-devices.md` for register maps and usage of popular sensors:
|
||||||
|
AHT20, BME280, SSD1306 OLED, MPU6050 IMU, DS3231 RTC, INA219 power monitor, PCA9685 PWM, and more.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
| Problem | Solution |
|
||||||
|
|---------|----------|
|
||||||
|
| No I2C buses found | `modprobe i2c-dev` and check device tree |
|
||||||
|
| Permission denied | Run as root or add user to `i2c` group |
|
||||||
|
| No devices on scan | Check wiring, pull-up resistors (4.7k typical), and pinmux |
|
||||||
|
| Bus number changed | I2C adapter numbers can shift between boots; use `i2c detect` to find current assignment |
|
||||||
|
| WiFi stopped working | I2C-1/SPI-2 share pins with WiFi SDIO; can't use both simultaneously |
|
||||||
|
| `devmem` not found | Download separately or use `busybox devmem` |
|
||||||
|
| SPI transfer returns all zeros | Check MISO wiring and device power |
|
||||||
|
| SPI transfer returns all 0xFF | Device not responding; check CS pin and clock polarity (mode) |
|
||||||
|
|
@ -0,0 +1,131 @@
|
||||||
|
# Board Pinout & Pinmux Reference
|
||||||
|
|
||||||
|
## LicheeRV Nano (SG2002)
|
||||||
|
|
||||||
|
### I2C Buses
|
||||||
|
|
||||||
|
| Bus | Pins | Notes |
|
||||||
|
|-----|------|-------|
|
||||||
|
| I2C-1 | P18 (SCL), P21 (SDA) | **Shared with WiFi SDIO** — must stop WiFi first |
|
||||||
|
| I2C-3 | Available on header | Check device tree for pin assignment |
|
||||||
|
| I2C-5 | Software (BitBang) | Slower but no pin conflicts |
|
||||||
|
|
||||||
|
### SPI Buses
|
||||||
|
|
||||||
|
| Bus | Pins | Notes |
|
||||||
|
|-----|------|-------|
|
||||||
|
| SPI-2 | P18 (CS), P21 (MISO), P22 (MOSI), P23 (SCK) | **Shared with WiFi** — must stop WiFi first |
|
||||||
|
| SPI-4 | Software (BitBang) | Slower but no pin conflicts |
|
||||||
|
|
||||||
|
### Setup Steps for I2C-1
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Stop WiFi (shares pins with I2C-1)
|
||||||
|
/etc/init.d/S30wifi stop
|
||||||
|
|
||||||
|
# 2. Configure pinmux for I2C-1
|
||||||
|
devmem 0x030010D0 b 0x2 # P18 → I2C1_SCL
|
||||||
|
devmem 0x030010DC b 0x2 # P21 → I2C1_SDA
|
||||||
|
|
||||||
|
# 3. Load i2c-dev module
|
||||||
|
modprobe i2c-dev
|
||||||
|
|
||||||
|
# 4. Verify
|
||||||
|
ls /dev/i2c-*
|
||||||
|
```
|
||||||
|
|
||||||
|
### Setup Steps for SPI-2
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Stop WiFi (shares pins with SPI-2)
|
||||||
|
/etc/init.d/S30wifi stop
|
||||||
|
|
||||||
|
# 2. Configure pinmux for SPI-2
|
||||||
|
devmem 0x030010D0 b 0x1 # P18 → SPI2_CS
|
||||||
|
devmem 0x030010DC b 0x1 # P21 → SPI2_MISO
|
||||||
|
devmem 0x030010E0 b 0x1 # P22 → SPI2_MOSI
|
||||||
|
devmem 0x030010E4 b 0x1 # P23 → SPI2_SCK
|
||||||
|
|
||||||
|
# 3. Verify
|
||||||
|
ls /dev/spidev*
|
||||||
|
```
|
||||||
|
|
||||||
|
### Max Tested SPI Speed
|
||||||
|
- SPI-2 hardware: tested up to **93 MHz**
|
||||||
|
- `spidev_test` is pre-installed on the official image for loopback testing
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## MaixCAM
|
||||||
|
|
||||||
|
### I2C Buses
|
||||||
|
|
||||||
|
| Bus | Pins | Notes |
|
||||||
|
|-----|------|-------|
|
||||||
|
| I2C-1 | Overlaps with WiFi | Not recommended |
|
||||||
|
| I2C-3 | Overlaps with WiFi | Not recommended |
|
||||||
|
| I2C-5 | A15 (SCL), A27 (SDA) | **Recommended** — software I2C, no conflicts |
|
||||||
|
|
||||||
|
### Setup Steps for I2C-5
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Configure pins using pinmap utility
|
||||||
|
# (MaixCAM uses a pinmap tool instead of devmem)
|
||||||
|
# Refer to: https://wiki.sipeed.com/hardware/en/maixcam/gpio.html
|
||||||
|
|
||||||
|
# Load i2c-dev
|
||||||
|
modprobe i2c-dev
|
||||||
|
|
||||||
|
# Verify
|
||||||
|
ls /dev/i2c-*
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## MaixCAM2
|
||||||
|
|
||||||
|
### I2C Buses
|
||||||
|
|
||||||
|
| Bus | Pins | Notes |
|
||||||
|
|-----|------|-------|
|
||||||
|
| I2C-6 | A1 (SCL), A0 (SDA) | Available on header |
|
||||||
|
| I2C-7 | Available | Check device tree |
|
||||||
|
|
||||||
|
### Setup Steps
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Configure pinmap for I2C-6
|
||||||
|
# A1 → I2C6_SCL, A0 → I2C6_SDA
|
||||||
|
# Refer to MaixCAM2 documentation for pinmap commands
|
||||||
|
|
||||||
|
modprobe i2c-dev
|
||||||
|
ls /dev/i2c-*
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## NanoKVM
|
||||||
|
|
||||||
|
Uses the same SG2002 SoC as LicheeRV Nano. GPIO and I2C access follows the same pinmux procedure. Refer to the LicheeRV Nano section above.
|
||||||
|
|
||||||
|
Check NanoKVM-specific pin headers for available I2C/SPI lines:
|
||||||
|
- https://wiki.sipeed.com/hardware/en/kvm/NanoKVM/introduction.html
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Common Issues
|
||||||
|
|
||||||
|
### devmem not found
|
||||||
|
The `devmem` utility may not be in the default image. Options:
|
||||||
|
- Use `busybox devmem` if busybox is installed
|
||||||
|
- Download devmem from the Sipeed package repository
|
||||||
|
- Cross-compile from source (single C file)
|
||||||
|
|
||||||
|
### Dynamic bus numbering
|
||||||
|
I2C adapter numbers can change between boots depending on driver load order. Always use `i2c detect` to find current bus assignments rather than hardcoding bus numbers.
|
||||||
|
|
||||||
|
### Permissions
|
||||||
|
`/dev/i2c-*` and `/dev/spidev*` typically require root access. Options:
|
||||||
|
- Run picoclaw as root
|
||||||
|
- Add user to `i2c` and `spi` groups
|
||||||
|
- Create udev rules: `SUBSYSTEM=="i2c-dev", MODE="0666"`
|
||||||
|
|
@ -0,0 +1,78 @@
|
||||||
|
# Common I2C/SPI Device Reference
|
||||||
|
|
||||||
|
## I2C Devices
|
||||||
|
|
||||||
|
### AHT20 — Temperature & Humidity
|
||||||
|
- **Address:** 0x38
|
||||||
|
- **Init:** Write `[0xBE, 0x08, 0x00]` then wait 10ms
|
||||||
|
- **Measure:** Write `[0xAC, 0x33, 0x00]`, wait 80ms, read 6 bytes
|
||||||
|
- **Parse:** Status=byte[0], Humidity=(byte[1]<<12|byte[2]<<4|byte[3]>>4)/2^20*100, Temp=(byte[3]&0x0F<<16|byte[4]<<8|byte[5])/2^20*200-50
|
||||||
|
- **Notes:** No register addressing — write command bytes directly (omit `register` param)
|
||||||
|
|
||||||
|
### BME280 / BMP280 — Temperature, Humidity, Pressure
|
||||||
|
- **Address:** 0x76 or 0x77 (SDO pin selects)
|
||||||
|
- **Chip ID register:** 0xD0 → BMP280=0x58, BME280=0x60
|
||||||
|
- **Data registers:** 0xF7-0xFE (pressure, temperature, humidity)
|
||||||
|
- **Config:** Write 0xF2 (humidity oversampling), 0xF4 (temp/press oversampling + mode), 0xF5 (standby, filter)
|
||||||
|
- **Forced measurement:** Write `[0x25]` to register 0xF4, wait 40ms, read 8 bytes from 0xF7
|
||||||
|
- **Calibration:** Read 26 bytes from 0x88 and 7 bytes from 0xE1 for compensation formulas
|
||||||
|
- **Also available via SPI** (mode 0 or 3)
|
||||||
|
|
||||||
|
### SSD1306 — 128x64 OLED Display
|
||||||
|
- **Address:** 0x3C (or 0x3D if SA0 high)
|
||||||
|
- **Command prefix:** 0x00 (write to register 0x00)
|
||||||
|
- **Data prefix:** 0x40 (write to register 0x40)
|
||||||
|
- **Init sequence:** `[0xAE, 0xD5, 0x80, 0xA8, 0x3F, 0xD3, 0x00, 0x40, 0x8D, 0x14, 0x20, 0x00, 0xA1, 0xC8, 0xDA, 0x12, 0x81, 0xCF, 0xD9, 0xF1, 0xDB, 0x40, 0xA4, 0xA6, 0xAF]`
|
||||||
|
- **Display on:** 0xAF, **Display off:** 0xAE
|
||||||
|
- **Also available via SPI** (faster, recommended for animations)
|
||||||
|
|
||||||
|
### MPU6050 — 6-axis Accelerometer + Gyroscope
|
||||||
|
- **Address:** 0x68 (or 0x69 if AD0 high)
|
||||||
|
- **WHO_AM_I:** Register 0x75 → should return 0x68
|
||||||
|
- **Wake up:** Write `[0x00]` to register 0x6B (clear sleep bit)
|
||||||
|
- **Read accel:** 6 bytes from register 0x3B (XH,XL,YH,YL,ZH,ZL) — signed 16-bit, default ±2g
|
||||||
|
- **Read gyro:** 6 bytes from register 0x43 — signed 16-bit, default ±250°/s
|
||||||
|
- **Read temp:** 2 bytes from register 0x41 — Temp°C = value/340 + 36.53
|
||||||
|
|
||||||
|
### DS3231 — Real-Time Clock
|
||||||
|
- **Address:** 0x68
|
||||||
|
- **Read time:** 7 bytes from register 0x00 (seconds, minutes, hours, day, date, month, year) — BCD encoded
|
||||||
|
- **Set time:** Write 7 BCD bytes to register 0x00
|
||||||
|
- **Temperature:** 2 bytes from register 0x11 (signed, 0.25°C resolution)
|
||||||
|
- **Status:** Register 0x0F — bit 2 = busy, bit 0 = alarm 1 flag
|
||||||
|
|
||||||
|
### INA219 — Current & Power Monitor
|
||||||
|
- **Address:** 0x40-0x4F (A0,A1 pin selectable)
|
||||||
|
- **Config:** Register 0x00 — set voltage range, gain, ADC resolution
|
||||||
|
- **Shunt voltage:** Register 0x01 (signed 16-bit, LSB=10µV)
|
||||||
|
- **Bus voltage:** Register 0x02 (bits 15:3, LSB=4mV)
|
||||||
|
- **Power:** Register 0x03 (after calibration)
|
||||||
|
- **Current:** Register 0x04 (after calibration)
|
||||||
|
- **Calibration:** Register 0x05 — set based on shunt resistor value
|
||||||
|
|
||||||
|
### PCA9685 — 16-Channel PWM / Servo Controller
|
||||||
|
- **Address:** 0x40-0x7F (A0-A5 selectable, default 0x40)
|
||||||
|
- **Mode 1:** Register 0x00 — bit 4=sleep, bit 5=auto-increment
|
||||||
|
- **Set PWM freq:** Sleep → write prescale to 0xFE → wake. Prescale = round(25MHz / (4096 × freq)) - 1
|
||||||
|
- **Channel N on/off:** Registers 0x06+4*N to 0x09+4*N (ON_L, ON_H, OFF_L, OFF_H)
|
||||||
|
- **Servo 0°-180°:** ON=0, OFF=150-600 (at 50Hz). Typical: 0°=150, 90°=375, 180°=600
|
||||||
|
|
||||||
|
### AT24C256 — 256Kbit EEPROM
|
||||||
|
- **Address:** 0x50-0x57 (A0-A2 selectable)
|
||||||
|
- **Read:** Write 2-byte address (high, low), then read N bytes
|
||||||
|
- **Write:** Write 2-byte address + up to 64 bytes (page write), wait 5ms for write cycle
|
||||||
|
- **Page size:** 64 bytes. Writes that cross page boundary wrap around.
|
||||||
|
|
||||||
|
## SPI Devices
|
||||||
|
|
||||||
|
### MCP3008 — 8-Channel 10-bit ADC
|
||||||
|
- **Interface:** SPI mode 0, max 3.6 MHz @ 5V
|
||||||
|
- **Read channel N:** Send `[0x01, (0x80 | N<<4), 0x00]`, result in last 10 bits of bytes 1-2
|
||||||
|
- **Formula:** value = ((byte[1] & 0x03) << 8) | byte[2]
|
||||||
|
- **Voltage:** value × Vref / 1024
|
||||||
|
|
||||||
|
### W25Q128 — 128Mbit SPI Flash
|
||||||
|
- **Interface:** SPI mode 0 or 3, up to 104 MHz
|
||||||
|
- **Read ID:** Send `[0x9F, 0, 0, 0]` → manufacturer + device ID
|
||||||
|
- **Read data:** Send `[0x03, addr_high, addr_mid, addr_low]` + N zero bytes
|
||||||
|
- **Status:** Send `[0x05, 0]` → bit 0 = BUSY
|
||||||
|
|
@ -0,0 +1,371 @@
|
||||||
|
---
|
||||||
|
name: skill-creator
|
||||||
|
description: Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Skill Creator
|
||||||
|
|
||||||
|
This skill provides guidance for creating effective skills.
|
||||||
|
|
||||||
|
## About Skills
|
||||||
|
|
||||||
|
Skills are modular, self-contained packages that extend the agent's capabilities by providing
|
||||||
|
specialized knowledge, workflows, and tools. Think of them as "onboarding guides" for specific
|
||||||
|
domains or tasks—they transform the agent from a general-purpose agent into a specialized agent
|
||||||
|
equipped with procedural knowledge that no model can fully possess.
|
||||||
|
|
||||||
|
### What Skills Provide
|
||||||
|
|
||||||
|
1. Specialized workflows - Multi-step procedures for specific domains
|
||||||
|
2. Tool integrations - Instructions for working with specific file formats or APIs
|
||||||
|
3. Domain expertise - Company-specific knowledge, schemas, business logic
|
||||||
|
4. Bundled resources - Scripts, references, and assets for complex and repetitive tasks
|
||||||
|
|
||||||
|
## Core Principles
|
||||||
|
|
||||||
|
### Concise is Key
|
||||||
|
|
||||||
|
The context window is a public good. Skills share the context window with everything else the agent needs: system prompt, conversation history, other Skills' metadata, and the actual user request.
|
||||||
|
|
||||||
|
**Default assumption: the agent is already very smart.** Only add context the agent doesn't already have. Challenge each piece of information: "Does the agent really need this explanation?" and "Does this paragraph justify its token cost?"
|
||||||
|
|
||||||
|
Prefer concise examples over verbose explanations.
|
||||||
|
|
||||||
|
### Set Appropriate Degrees of Freedom
|
||||||
|
|
||||||
|
Match the level of specificity to the task's fragility and variability:
|
||||||
|
|
||||||
|
**High freedom (text-based instructions)**: Use when multiple approaches are valid, decisions depend on context, or heuristics guide the approach.
|
||||||
|
|
||||||
|
**Medium freedom (pseudocode or scripts with parameters)**: Use when a preferred pattern exists, some variation is acceptable, or configuration affects behavior.
|
||||||
|
|
||||||
|
**Low freedom (specific scripts, few parameters)**: Use when operations are fragile and error-prone, consistency is critical, or a specific sequence must be followed.
|
||||||
|
|
||||||
|
Think of the agent as exploring a path: a narrow bridge with cliffs needs specific guardrails (low freedom), while an open field allows many routes (high freedom).
|
||||||
|
|
||||||
|
### Anatomy of a Skill
|
||||||
|
|
||||||
|
Every skill consists of a required SKILL.md file and optional bundled resources:
|
||||||
|
|
||||||
|
```
|
||||||
|
skill-name/
|
||||||
|
├── SKILL.md (required)
|
||||||
|
│ ├── YAML frontmatter metadata (required)
|
||||||
|
│ │ ├── name: (required)
|
||||||
|
│ │ └── description: (required)
|
||||||
|
│ └── Markdown instructions (required)
|
||||||
|
└── Bundled Resources (optional)
|
||||||
|
├── scripts/ - Executable code (Python/Bash/etc.)
|
||||||
|
├── references/ - Documentation intended to be loaded into context as needed
|
||||||
|
└── assets/ - Files used in output (templates, icons, fonts, etc.)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### SKILL.md (required)
|
||||||
|
|
||||||
|
Every SKILL.md consists of:
|
||||||
|
|
||||||
|
- **Frontmatter** (YAML): Contains `name` and `description` fields. These are the only fields that the agent reads to determine when the skill gets used, thus it is very important to be clear and comprehensive in describing what the skill is, and when it should be used.
|
||||||
|
- **Body** (Markdown): Instructions and guidance for using the skill. Only loaded AFTER the skill triggers (if at all).
|
||||||
|
|
||||||
|
#### Bundled Resources (optional)
|
||||||
|
|
||||||
|
##### Scripts (`scripts/`)
|
||||||
|
|
||||||
|
Executable code (Python/Bash/etc.) for tasks that require deterministic reliability or are repeatedly rewritten.
|
||||||
|
|
||||||
|
- **When to include**: When the same code is being rewritten repeatedly or deterministic reliability is needed
|
||||||
|
- **Example**: `scripts/rotate_pdf.py` for PDF rotation tasks
|
||||||
|
- **Benefits**: Token efficient, deterministic, may be executed without loading into context
|
||||||
|
- **Note**: Scripts may still need to be read by the agent for patching or environment-specific adjustments
|
||||||
|
|
||||||
|
##### References (`references/`)
|
||||||
|
|
||||||
|
Documentation and reference material intended to be loaded as needed into context to inform the agent's process and thinking.
|
||||||
|
|
||||||
|
- **When to include**: For documentation that the agent should reference while working
|
||||||
|
- **Examples**: `references/finance.md` for financial schemas, `references/mnda.md` for company NDA template, `references/policies.md` for company policies, `references/api_docs.md` for API specifications
|
||||||
|
- **Use cases**: Database schemas, API documentation, domain knowledge, company policies, detailed workflow guides
|
||||||
|
- **Benefits**: Keeps SKILL.md lean, loaded only when the agent determines it's needed
|
||||||
|
- **Best practice**: If files are large (>10k words), include grep search patterns in SKILL.md
|
||||||
|
- **Avoid duplication**: Information should live in either SKILL.md or references files, not both. Prefer references files for detailed information unless it's truly core to the skill—this keeps SKILL.md lean while making information discoverable without hogging the context window. Keep only essential procedural instructions and workflow guidance in SKILL.md; move detailed reference material, schemas, and examples to references files.
|
||||||
|
|
||||||
|
##### Assets (`assets/`)
|
||||||
|
|
||||||
|
Files not intended to be loaded into context, but rather used within the output the agent produces.
|
||||||
|
|
||||||
|
- **When to include**: When the skill needs files that will be used in the final output
|
||||||
|
- **Examples**: `assets/logo.png` for brand assets, `assets/slides.pptx` for PowerPoint templates, `assets/frontend-template/` for HTML/React boilerplate, `assets/font.ttf` for typography
|
||||||
|
- **Use cases**: Templates, images, icons, boilerplate code, fonts, sample documents that get copied or modified
|
||||||
|
- **Benefits**: Separates output resources from documentation, enables the agent to use files without loading them into context
|
||||||
|
|
||||||
|
#### What to Not Include in a Skill
|
||||||
|
|
||||||
|
A skill should only contain essential files that directly support its functionality. Do NOT create extraneous documentation or auxiliary files, including:
|
||||||
|
|
||||||
|
- README.md
|
||||||
|
- INSTALLATION_GUIDE.md
|
||||||
|
- QUICK_REFERENCE.md
|
||||||
|
- CHANGELOG.md
|
||||||
|
- etc.
|
||||||
|
|
||||||
|
The skill should only contain the information needed for an AI agent to do the job at hand. It should not contain auxiliary context about the process that went into creating it, setup and testing procedures, user-facing documentation, etc. Creating additional documentation files just adds clutter and confusion.
|
||||||
|
|
||||||
|
### Progressive Disclosure Design Principle
|
||||||
|
|
||||||
|
Skills use a three-level loading system to manage context efficiently:
|
||||||
|
|
||||||
|
1. **Metadata (name + description)** - Always in context (~100 words)
|
||||||
|
2. **SKILL.md body** - When skill triggers (<5k words)
|
||||||
|
3. **Bundled resources** - As needed by the agent (Unlimited because scripts can be executed without reading into context window)
|
||||||
|
|
||||||
|
#### Progressive Disclosure Patterns
|
||||||
|
|
||||||
|
Keep SKILL.md body to the essentials and under 500 lines to minimize context bloat. Split content into separate files when approaching this limit. When splitting out content into other files, it is very important to reference them from SKILL.md and describe clearly when to read them, to ensure the reader of the skill knows they exist and when to use them.
|
||||||
|
|
||||||
|
**Key principle:** When a skill supports multiple variations, frameworks, or options, keep only the core workflow and selection guidance in SKILL.md. Move variant-specific details (patterns, examples, configuration) into separate reference files.
|
||||||
|
|
||||||
|
**Pattern 1: High-level guide with references**
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
# PDF Processing
|
||||||
|
|
||||||
|
## Quick start
|
||||||
|
|
||||||
|
Extract text with pdfplumber:
|
||||||
|
[code example]
|
||||||
|
|
||||||
|
## Advanced features
|
||||||
|
|
||||||
|
- **Form filling**: See [FORMS.md](FORMS.md) for complete guide
|
||||||
|
- **API reference**: See [REFERENCE.md](REFERENCE.md) for all methods
|
||||||
|
- **Examples**: See [EXAMPLES.md](EXAMPLES.md) for common patterns
|
||||||
|
```
|
||||||
|
|
||||||
|
the agent loads FORMS.md, REFERENCE.md, or EXAMPLES.md only when needed.
|
||||||
|
|
||||||
|
**Pattern 2: Domain-specific organization**
|
||||||
|
|
||||||
|
For Skills with multiple domains, organize content by domain to avoid loading irrelevant context:
|
||||||
|
|
||||||
|
```
|
||||||
|
bigquery-skill/
|
||||||
|
├── SKILL.md (overview and navigation)
|
||||||
|
└── reference/
|
||||||
|
├── finance.md (revenue, billing metrics)
|
||||||
|
├── sales.md (opportunities, pipeline)
|
||||||
|
├── product.md (API usage, features)
|
||||||
|
└── marketing.md (campaigns, attribution)
|
||||||
|
```
|
||||||
|
|
||||||
|
When a user asks about sales metrics, the agent only reads sales.md.
|
||||||
|
|
||||||
|
Similarly, for skills supporting multiple frameworks or variants, organize by variant:
|
||||||
|
|
||||||
|
```
|
||||||
|
cloud-deploy/
|
||||||
|
├── SKILL.md (workflow + provider selection)
|
||||||
|
└── references/
|
||||||
|
├── aws.md (AWS deployment patterns)
|
||||||
|
├── gcp.md (GCP deployment patterns)
|
||||||
|
└── azure.md (Azure deployment patterns)
|
||||||
|
```
|
||||||
|
|
||||||
|
When the user chooses AWS, the agent only reads aws.md.
|
||||||
|
|
||||||
|
**Pattern 3: Conditional details**
|
||||||
|
|
||||||
|
Show basic content, link to advanced content:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
# DOCX Processing
|
||||||
|
|
||||||
|
## Creating documents
|
||||||
|
|
||||||
|
Use docx-js for new documents. See [DOCX-JS.md](DOCX-JS.md).
|
||||||
|
|
||||||
|
## Editing documents
|
||||||
|
|
||||||
|
For simple edits, modify the XML directly.
|
||||||
|
|
||||||
|
**For tracked changes**: See [REDLINING.md](REDLINING.md)
|
||||||
|
**For OOXML details**: See [OOXML.md](OOXML.md)
|
||||||
|
```
|
||||||
|
|
||||||
|
the agent reads REDLINING.md or OOXML.md only when the user needs those features.
|
||||||
|
|
||||||
|
**Important guidelines:**
|
||||||
|
|
||||||
|
- **Avoid deeply nested references** - Keep references one level deep from SKILL.md. All reference files should link directly from SKILL.md.
|
||||||
|
- **Structure longer reference files** - For files longer than 100 lines, include a table of contents at the top so the agent can see the full scope when previewing.
|
||||||
|
|
||||||
|
## Skill Creation Process
|
||||||
|
|
||||||
|
Skill creation involves these steps:
|
||||||
|
|
||||||
|
1. Understand the skill with concrete examples
|
||||||
|
2. Plan reusable skill contents (scripts, references, assets)
|
||||||
|
3. Initialize the skill (run init_skill.py)
|
||||||
|
4. Edit the skill (implement resources and write SKILL.md)
|
||||||
|
5. Package the skill (run package_skill.py)
|
||||||
|
6. Iterate based on real usage
|
||||||
|
|
||||||
|
Follow these steps in order, skipping only if there is a clear reason why they are not applicable.
|
||||||
|
|
||||||
|
### Skill Naming
|
||||||
|
|
||||||
|
- Use lowercase letters, digits, and hyphens only; normalize user-provided titles to hyphen-case (e.g., "Plan Mode" -> `plan-mode`).
|
||||||
|
- When generating names, generate a name under 64 characters (letters, digits, hyphens).
|
||||||
|
- Prefer short, verb-led phrases that describe the action.
|
||||||
|
- Namespace by tool when it improves clarity or triggering (e.g., `gh-address-comments`, `linear-address-issue`).
|
||||||
|
- Name the skill folder exactly after the skill name.
|
||||||
|
|
||||||
|
### Step 1: Understanding the Skill with Concrete Examples
|
||||||
|
|
||||||
|
Skip this step only when the skill's usage patterns are already clearly understood. It remains valuable even when working with an existing skill.
|
||||||
|
|
||||||
|
To create an effective skill, clearly understand concrete examples of how the skill will be used. This understanding can come from either direct user examples or generated examples that are validated with user feedback.
|
||||||
|
|
||||||
|
For example, when building an image-editor skill, relevant questions include:
|
||||||
|
|
||||||
|
- "What functionality should the image-editor skill support? Editing, rotating, anything else?"
|
||||||
|
- "Can you give some examples of how this skill would be used?"
|
||||||
|
- "I can imagine users asking for things like 'Remove the red-eye from this image' or 'Rotate this image'. Are there other ways you imagine this skill being used?"
|
||||||
|
- "What would a user say that should trigger this skill?"
|
||||||
|
|
||||||
|
To avoid overwhelming users, avoid asking too many questions in a single message. Start with the most important questions and follow up as needed for better effectiveness.
|
||||||
|
|
||||||
|
Conclude this step when there is a clear sense of the functionality the skill should support.
|
||||||
|
|
||||||
|
### Step 2: Planning the Reusable Skill Contents
|
||||||
|
|
||||||
|
To turn concrete examples into an effective skill, analyze each example by:
|
||||||
|
|
||||||
|
1. Considering how to execute on the example from scratch
|
||||||
|
2. Identifying what scripts, references, and assets would be helpful when executing these workflows repeatedly
|
||||||
|
|
||||||
|
Example: When building a `pdf-editor` skill to handle queries like "Help me rotate this PDF," the analysis shows:
|
||||||
|
|
||||||
|
1. Rotating a PDF requires re-writing the same code each time
|
||||||
|
2. A `scripts/rotate_pdf.py` script would be helpful to store in the skill
|
||||||
|
|
||||||
|
Example: When designing a `frontend-webapp-builder` skill for queries like "Build me a todo app" or "Build me a dashboard to track my steps," the analysis shows:
|
||||||
|
|
||||||
|
1. Writing a frontend webapp requires the same boilerplate HTML/React each time
|
||||||
|
2. An `assets/hello-world/` template containing the boilerplate HTML/React project files would be helpful to store in the skill
|
||||||
|
|
||||||
|
Example: When building a `big-query` skill to handle queries like "How many users have logged in today?" the analysis shows:
|
||||||
|
|
||||||
|
1. Querying BigQuery requires re-discovering the table schemas and relationships each time
|
||||||
|
2. A `references/schema.md` file documenting the table schemas would be helpful to store in the skill
|
||||||
|
|
||||||
|
To establish the skill's contents, analyze each concrete example to create a list of the reusable resources to include: scripts, references, and assets.
|
||||||
|
|
||||||
|
### Step 3: Initializing the Skill
|
||||||
|
|
||||||
|
At this point, it is time to actually create the skill.
|
||||||
|
|
||||||
|
Skip this step only if the skill being developed already exists, and iteration or packaging is needed. In this case, continue to the next step.
|
||||||
|
|
||||||
|
When creating a new skill from scratch, always run the `init_skill.py` script. The script conveniently generates a new template skill directory that automatically includes everything a skill requires, making the skill creation process much more efficient and reliable.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scripts/init_skill.py <skill-name> --path <output-directory> [--resources scripts,references,assets] [--examples]
|
||||||
|
```
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scripts/init_skill.py my-skill --path skills/public
|
||||||
|
scripts/init_skill.py my-skill --path skills/public --resources scripts,references
|
||||||
|
scripts/init_skill.py my-skill --path skills/public --resources scripts --examples
|
||||||
|
```
|
||||||
|
|
||||||
|
The script:
|
||||||
|
|
||||||
|
- Creates the skill directory at the specified path
|
||||||
|
- Generates a SKILL.md template with proper frontmatter and TODO placeholders
|
||||||
|
- Optionally creates resource directories based on `--resources`
|
||||||
|
- Optionally adds example files when `--examples` is set
|
||||||
|
|
||||||
|
After initialization, customize the SKILL.md and add resources as needed. If you used `--examples`, replace or delete placeholder files.
|
||||||
|
|
||||||
|
### Step 4: Edit the Skill
|
||||||
|
|
||||||
|
When editing the (newly-generated or existing) skill, remember that the skill is being created for another instance of the agent to use. Include information that would be beneficial and non-obvious to the agent. Consider what procedural knowledge, domain-specific details, or reusable assets would help another the agent instance execute these tasks more effectively.
|
||||||
|
|
||||||
|
#### Learn Proven Design Patterns
|
||||||
|
|
||||||
|
Consult these helpful guides based on your skill's needs:
|
||||||
|
|
||||||
|
- **Multi-step processes**: See references/workflows.md for sequential workflows and conditional logic
|
||||||
|
- **Specific output formats or quality standards**: See references/output-patterns.md for template and example patterns
|
||||||
|
|
||||||
|
These files contain established best practices for effective skill design.
|
||||||
|
|
||||||
|
#### Start with Reusable Skill Contents
|
||||||
|
|
||||||
|
To begin implementation, start with the reusable resources identified above: `scripts/`, `references/`, and `assets/` files. Note that this step may require user input. For example, when implementing a `brand-guidelines` skill, the user may need to provide brand assets or templates to store in `assets/`, or documentation to store in `references/`.
|
||||||
|
|
||||||
|
Added scripts must be tested by actually running them to ensure there are no bugs and that the output matches what is expected. If there are many similar scripts, only a representative sample needs to be tested to ensure confidence that they all work while balancing time to completion.
|
||||||
|
|
||||||
|
If you used `--examples`, delete any placeholder files that are not needed for the skill. Only create resource directories that are actually required.
|
||||||
|
|
||||||
|
#### Update SKILL.md
|
||||||
|
|
||||||
|
**Writing Guidelines:** Always use imperative/infinitive form.
|
||||||
|
|
||||||
|
##### Frontmatter
|
||||||
|
|
||||||
|
Write the YAML frontmatter with `name` and `description`:
|
||||||
|
|
||||||
|
- `name`: The skill name
|
||||||
|
- `description`: This is the primary triggering mechanism for your skill, and helps the agent understand when to use the skill.
|
||||||
|
- Include both what the Skill does and specific triggers/contexts for when to use it.
|
||||||
|
- Include all "when to use" information here - Not in the body. The body is only loaded after triggering, so "When to Use This Skill" sections in the body are not helpful to the agent.
|
||||||
|
- Example description for a `docx` skill: "Comprehensive document creation, editing, and analysis with support for tracked changes, comments, formatting preservation, and text extraction. Use when the agent needs to work with professional documents (.docx files) for: (1) Creating new documents, (2) Modifying or editing content, (3) Working with tracked changes, (4) Adding comments, or any other document tasks"
|
||||||
|
|
||||||
|
Do not include any other fields in YAML frontmatter.
|
||||||
|
|
||||||
|
##### Body
|
||||||
|
|
||||||
|
Write instructions for using the skill and its bundled resources.
|
||||||
|
|
||||||
|
### Step 5: Packaging a Skill
|
||||||
|
|
||||||
|
Once development of the skill is complete, it must be packaged into a distributable .skill file that gets shared with the user. The packaging process automatically validates the skill first to ensure it meets all requirements:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scripts/package_skill.py <path/to/skill-folder>
|
||||||
|
```
|
||||||
|
|
||||||
|
Optional output directory specification:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scripts/package_skill.py <path/to/skill-folder> ./dist
|
||||||
|
```
|
||||||
|
|
||||||
|
The packaging script will:
|
||||||
|
|
||||||
|
1. **Validate** the skill automatically, checking:
|
||||||
|
|
||||||
|
- YAML frontmatter format and required fields
|
||||||
|
- Skill naming conventions and directory structure
|
||||||
|
- Description completeness and quality
|
||||||
|
- File organization and resource references
|
||||||
|
|
||||||
|
2. **Package** the skill if validation passes, creating a .skill file named after the skill (e.g., `my-skill.skill`) that includes all files and maintains the proper directory structure for distribution. The .skill file is a zip file with a .skill extension.
|
||||||
|
|
||||||
|
If validation fails, the script will report the errors and exit without creating a package. Fix any validation errors and run the packaging command again.
|
||||||
|
|
||||||
|
### Step 6: Iterate
|
||||||
|
|
||||||
|
After testing the skill, users may request improvements. Often this happens right after using the skill, with fresh context of how the skill performed.
|
||||||
|
|
||||||
|
**Iteration workflow:**
|
||||||
|
|
||||||
|
1. Use the skill on real tasks
|
||||||
|
2. Notice struggles or inefficiencies
|
||||||
|
3. Identify how SKILL.md or bundled resources should be updated
|
||||||
|
4. Implement changes and test again
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
---
|
||||||
|
name: summarize
|
||||||
|
description: Summarize or extract text/transcripts from URLs, podcasts, and local files (great fallback for “transcribe this YouTube/video”).
|
||||||
|
homepage: https://summarize.sh
|
||||||
|
metadata: {"nanobot":{"emoji":"🧾","requires":{"bins":["summarize"]},"install":[{"id":"brew","kind":"brew","formula":"steipete/tap/summarize","bins":["summarize"],"label":"Install summarize (brew)"}]}}
|
||||||
|
---
|
||||||
|
|
||||||
|
# Summarize
|
||||||
|
|
||||||
|
Fast CLI to summarize URLs, local files, and YouTube links.
|
||||||
|
|
||||||
|
## When to use (trigger phrases)
|
||||||
|
|
||||||
|
Use this skill immediately when the user asks any of:
|
||||||
|
- “use summarize.sh”
|
||||||
|
- “what’s this link/video about?”
|
||||||
|
- “summarize this URL/article”
|
||||||
|
- “transcribe this YouTube/video” (best-effort transcript extraction; no `yt-dlp` needed)
|
||||||
|
|
||||||
|
## Quick start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
summarize "https://example.com" --model google/gemini-3-flash-preview
|
||||||
|
summarize "/path/to/file.pdf" --model google/gemini-3-flash-preview
|
||||||
|
summarize "https://youtu.be/dQw4w9WgXcQ" --youtube auto
|
||||||
|
```
|
||||||
|
|
||||||
|
## YouTube: summary vs transcript
|
||||||
|
|
||||||
|
Best-effort transcript (URLs only):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
summarize "https://youtu.be/dQw4w9WgXcQ" --youtube auto --extract-only
|
||||||
|
```
|
||||||
|
|
||||||
|
If the user asked for a transcript but it’s huge, return a tight summary first, then ask which section/time range to expand.
|
||||||
|
|
||||||
|
## Model + keys
|
||||||
|
|
||||||
|
Set the API key for your chosen provider:
|
||||||
|
- OpenAI: `OPENAI_API_KEY`
|
||||||
|
- Anthropic: `ANTHROPIC_API_KEY`
|
||||||
|
- xAI: `XAI_API_KEY`
|
||||||
|
- Google: `GEMINI_API_KEY` (aliases: `GOOGLE_GENERATIVE_AI_API_KEY`, `GOOGLE_API_KEY`)
|
||||||
|
|
||||||
|
Default model is `google/gemini-3-flash-preview` if none is set.
|
||||||
|
|
||||||
|
## Useful flags
|
||||||
|
|
||||||
|
- `--length short|medium|long|xl|xxl|<chars>`
|
||||||
|
- `--max-output-tokens <count>`
|
||||||
|
- `--extract-only` (URLs only)
|
||||||
|
- `--json` (machine readable)
|
||||||
|
- `--firecrawl auto|off|always` (fallback extraction)
|
||||||
|
- `--youtube auto` (Apify fallback if `APIFY_API_TOKEN` set)
|
||||||
|
|
||||||
|
## Config
|
||||||
|
|
||||||
|
Optional config file: `~/.summarize/config.json`
|
||||||
|
|
||||||
|
```json
|
||||||
|
{ "model": "openai/gpt-5.4" }
|
||||||
|
```
|
||||||
|
|
||||||
|
Optional services:
|
||||||
|
- `FIRECRAWL_API_KEY` for blocked sites
|
||||||
|
- `APIFY_API_TOKEN` for YouTube fallback
|
||||||
121
cmd/picoclaw/internal/onboard/workspace/skills/tmux/SKILL.md
Normal file
121
cmd/picoclaw/internal/onboard/workspace/skills/tmux/SKILL.md
Normal file
|
|
@ -0,0 +1,121 @@
|
||||||
|
---
|
||||||
|
name: tmux
|
||||||
|
description: Remote-control tmux sessions for interactive CLIs by sending keystrokes and scraping pane output.
|
||||||
|
metadata: {"nanobot":{"emoji":"🧵","os":["darwin","linux"],"requires":{"bins":["tmux"]}}}
|
||||||
|
---
|
||||||
|
|
||||||
|
# tmux Skill
|
||||||
|
|
||||||
|
Use tmux only when you need an interactive TTY. Prefer exec background mode for long-running, non-interactive tasks.
|
||||||
|
|
||||||
|
## Quickstart (isolated socket, exec tool)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
SOCKET_DIR="${NANOBOT_TMUX_SOCKET_DIR:-${TMPDIR:-/tmp}/nanobot-tmux-sockets}"
|
||||||
|
mkdir -p "$SOCKET_DIR"
|
||||||
|
SOCKET="$SOCKET_DIR/nanobot.sock"
|
||||||
|
SESSION=nanobot-python
|
||||||
|
|
||||||
|
tmux -S "$SOCKET" new -d -s "$SESSION" -n shell
|
||||||
|
tmux -S "$SOCKET" send-keys -t "$SESSION":0.0 -- 'PYTHON_BASIC_REPL=1 python3 -q' Enter
|
||||||
|
tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":0.0 -S -200
|
||||||
|
```
|
||||||
|
|
||||||
|
After starting a session, always print monitor commands:
|
||||||
|
|
||||||
|
```
|
||||||
|
To monitor:
|
||||||
|
tmux -S "$SOCKET" attach -t "$SESSION"
|
||||||
|
tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":0.0 -S -200
|
||||||
|
```
|
||||||
|
|
||||||
|
## Socket convention
|
||||||
|
|
||||||
|
- Use `NANOBOT_TMUX_SOCKET_DIR` environment variable.
|
||||||
|
- Default socket path: `"$NANOBOT_TMUX_SOCKET_DIR/nanobot.sock"`.
|
||||||
|
|
||||||
|
## Targeting panes and naming
|
||||||
|
|
||||||
|
- Target format: `session:window.pane` (defaults to `:0.0`).
|
||||||
|
- Keep names short; avoid spaces.
|
||||||
|
- Inspect: `tmux -S "$SOCKET" list-sessions`, `tmux -S "$SOCKET" list-panes -a`.
|
||||||
|
|
||||||
|
## Finding sessions
|
||||||
|
|
||||||
|
- List sessions on your socket: `{baseDir}/scripts/find-sessions.sh -S "$SOCKET"`.
|
||||||
|
- Scan all sockets: `{baseDir}/scripts/find-sessions.sh --all` (uses `NANOBOT_TMUX_SOCKET_DIR`).
|
||||||
|
|
||||||
|
## Sending input safely
|
||||||
|
|
||||||
|
- Prefer literal sends: `tmux -S "$SOCKET" send-keys -t target -l -- "$cmd"`.
|
||||||
|
- Control keys: `tmux -S "$SOCKET" send-keys -t target C-c`.
|
||||||
|
|
||||||
|
## Watching output
|
||||||
|
|
||||||
|
- Capture recent history: `tmux -S "$SOCKET" capture-pane -p -J -t target -S -200`.
|
||||||
|
- Wait for prompts: `{baseDir}/scripts/wait-for-text.sh -t session:0.0 -p 'pattern'`.
|
||||||
|
- Attaching is OK; detach with `Ctrl+b d`.
|
||||||
|
|
||||||
|
## Spawning processes
|
||||||
|
|
||||||
|
- For python REPLs, set `PYTHON_BASIC_REPL=1` (non-basic REPL breaks send-keys flows).
|
||||||
|
|
||||||
|
## Windows / WSL
|
||||||
|
|
||||||
|
- tmux is supported on macOS/Linux. On Windows, use WSL and install tmux inside WSL.
|
||||||
|
- This skill is gated to `darwin`/`linux` and requires `tmux` on PATH.
|
||||||
|
|
||||||
|
## Orchestrating Coding Agents (Codex, Claude Code)
|
||||||
|
|
||||||
|
tmux excels at running multiple coding agents in parallel:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
SOCKET="${TMPDIR:-/tmp}/codex-army.sock"
|
||||||
|
|
||||||
|
# Create multiple sessions
|
||||||
|
for i in 1 2 3 4 5; do
|
||||||
|
tmux -S "$SOCKET" new-session -d -s "agent-$i"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Launch agents in different workdirs
|
||||||
|
tmux -S "$SOCKET" send-keys -t agent-1 "cd /tmp/project1 && codex --yolo 'Fix bug X'" Enter
|
||||||
|
tmux -S "$SOCKET" send-keys -t agent-2 "cd /tmp/project2 && codex --yolo 'Fix bug Y'" Enter
|
||||||
|
|
||||||
|
# Poll for completion (check if prompt returned)
|
||||||
|
for sess in agent-1 agent-2; do
|
||||||
|
if tmux -S "$SOCKET" capture-pane -p -t "$sess" -S -3 | grep -q "❯"; then
|
||||||
|
echo "$sess: DONE"
|
||||||
|
else
|
||||||
|
echo "$sess: Running..."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Get full output from completed session
|
||||||
|
tmux -S "$SOCKET" capture-pane -p -t agent-1 -S -500
|
||||||
|
```
|
||||||
|
|
||||||
|
**Tips:**
|
||||||
|
- Use separate git worktrees for parallel fixes (no branch conflicts)
|
||||||
|
- `pnpm install` first before running codex in fresh clones
|
||||||
|
- Check for shell prompt (`❯` or `$`) to detect completion
|
||||||
|
- Codex needs `--yolo` or `--full-auto` for non-interactive fixes
|
||||||
|
|
||||||
|
## Cleanup
|
||||||
|
|
||||||
|
- Kill a session: `tmux -S "$SOCKET" kill-session -t "$SESSION"`.
|
||||||
|
- Kill all sessions on a socket: `tmux -S "$SOCKET" list-sessions -F '#{session_name}' | xargs -r -n1 tmux -S "$SOCKET" kill-session -t`.
|
||||||
|
- Remove everything on the private socket: `tmux -S "$SOCKET" kill-server`.
|
||||||
|
|
||||||
|
## Helper: wait-for-text.sh
|
||||||
|
|
||||||
|
`{baseDir}/scripts/wait-for-text.sh` polls a pane for a regex (or fixed string) with a timeout.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
{baseDir}/scripts/wait-for-text.sh -t session:0.0 -p 'pattern' [-F] [-T 20] [-i 0.5] [-l 2000]
|
||||||
|
```
|
||||||
|
|
||||||
|
- `-t`/`--target` pane target (required)
|
||||||
|
- `-p`/`--pattern` regex to match (required); add `-F` for fixed string
|
||||||
|
- `-T` timeout seconds (integer, default 15)
|
||||||
|
- `-i` poll interval seconds (default 0.5)
|
||||||
|
- `-l` history lines to search (integer, default 1000)
|
||||||
112
cmd/picoclaw/internal/onboard/workspace/skills/tmux/scripts/find-sessions.sh
Executable file
112
cmd/picoclaw/internal/onboard/workspace/skills/tmux/scripts/find-sessions.sh
Executable file
|
|
@ -0,0 +1,112 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<'USAGE'
|
||||||
|
Usage: find-sessions.sh [-L socket-name|-S socket-path|-A] [-q pattern]
|
||||||
|
|
||||||
|
List tmux sessions on a socket (default tmux socket if none provided).
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-L, --socket tmux socket name (passed to tmux -L)
|
||||||
|
-S, --socket-path tmux socket path (passed to tmux -S)
|
||||||
|
-A, --all scan all sockets under NANOBOT_TMUX_SOCKET_DIR
|
||||||
|
-q, --query case-insensitive substring to filter session names
|
||||||
|
-h, --help show this help
|
||||||
|
USAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
socket_name=""
|
||||||
|
socket_path=""
|
||||||
|
query=""
|
||||||
|
scan_all=false
|
||||||
|
socket_dir="${NANOBOT_TMUX_SOCKET_DIR:-${TMPDIR:-/tmp}/nanobot-tmux-sockets}"
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-L|--socket) socket_name="${2-}"; shift 2 ;;
|
||||||
|
-S|--socket-path) socket_path="${2-}"; shift 2 ;;
|
||||||
|
-A|--all) scan_all=true; shift ;;
|
||||||
|
-q|--query) query="${2-}"; shift 2 ;;
|
||||||
|
-h|--help) usage; exit 0 ;;
|
||||||
|
*) echo "Unknown option: $1" >&2; usage; exit 1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$scan_all" == true && ( -n "$socket_name" || -n "$socket_path" ) ]]; then
|
||||||
|
echo "Cannot combine --all with -L or -S" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$socket_name" && -n "$socket_path" ]]; then
|
||||||
|
echo "Use either -L or -S, not both" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v tmux >/dev/null 2>&1; then
|
||||||
|
echo "tmux not found in PATH" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
list_sessions() {
|
||||||
|
local label="$1"; shift
|
||||||
|
local tmux_cmd=(tmux "$@")
|
||||||
|
|
||||||
|
if ! sessions="$("${tmux_cmd[@]}" list-sessions -F '#{session_name}\t#{session_attached}\t#{session_created_string}' 2>/dev/null)"; then
|
||||||
|
echo "No tmux server found on $label" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$query" ]]; then
|
||||||
|
sessions="$(printf '%s\n' "$sessions" | grep -i -- "$query" || true)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$sessions" ]]; then
|
||||||
|
echo "No sessions found on $label"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Sessions on $label:"
|
||||||
|
printf '%s\n' "$sessions" | while IFS=$'\t' read -r name attached created; do
|
||||||
|
attached_label=$([[ "$attached" == "1" ]] && echo "attached" || echo "detached")
|
||||||
|
printf ' - %s (%s, started %s)\n' "$name" "$attached_label" "$created"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ "$scan_all" == true ]]; then
|
||||||
|
if [[ ! -d "$socket_dir" ]]; then
|
||||||
|
echo "Socket directory not found: $socket_dir" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
shopt -s nullglob
|
||||||
|
sockets=("$socket_dir"/*)
|
||||||
|
shopt -u nullglob
|
||||||
|
|
||||||
|
if [[ "${#sockets[@]}" -eq 0 ]]; then
|
||||||
|
echo "No sockets found under $socket_dir" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit_code=0
|
||||||
|
for sock in "${sockets[@]}"; do
|
||||||
|
if [[ ! -S "$sock" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
list_sessions "socket path '$sock'" -S "$sock" || exit_code=$?
|
||||||
|
done
|
||||||
|
exit "$exit_code"
|
||||||
|
fi
|
||||||
|
|
||||||
|
tmux_cmd=(tmux)
|
||||||
|
socket_label="default socket"
|
||||||
|
|
||||||
|
if [[ -n "$socket_name" ]]; then
|
||||||
|
tmux_cmd+=(-L "$socket_name")
|
||||||
|
socket_label="socket name '$socket_name'"
|
||||||
|
elif [[ -n "$socket_path" ]]; then
|
||||||
|
tmux_cmd+=(-S "$socket_path")
|
||||||
|
socket_label="socket path '$socket_path'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
list_sessions "$socket_label" "${tmux_cmd[@]:1}"
|
||||||
83
cmd/picoclaw/internal/onboard/workspace/skills/tmux/scripts/wait-for-text.sh
Executable file
83
cmd/picoclaw/internal/onboard/workspace/skills/tmux/scripts/wait-for-text.sh
Executable file
|
|
@ -0,0 +1,83 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<'USAGE'
|
||||||
|
Usage: wait-for-text.sh -t target -p pattern [options]
|
||||||
|
|
||||||
|
Poll a tmux pane for text and exit when found.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-t, --target tmux target (session:window.pane), required
|
||||||
|
-p, --pattern regex pattern to look for, required
|
||||||
|
-F, --fixed treat pattern as a fixed string (grep -F)
|
||||||
|
-T, --timeout seconds to wait (integer, default: 15)
|
||||||
|
-i, --interval poll interval in seconds (default: 0.5)
|
||||||
|
-l, --lines number of history lines to inspect (integer, default: 1000)
|
||||||
|
-h, --help show this help
|
||||||
|
USAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
target=""
|
||||||
|
pattern=""
|
||||||
|
grep_flag="-E"
|
||||||
|
timeout=15
|
||||||
|
interval=0.5
|
||||||
|
lines=1000
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-t|--target) target="${2-}"; shift 2 ;;
|
||||||
|
-p|--pattern) pattern="${2-}"; shift 2 ;;
|
||||||
|
-F|--fixed) grep_flag="-F"; shift ;;
|
||||||
|
-T|--timeout) timeout="${2-}"; shift 2 ;;
|
||||||
|
-i|--interval) interval="${2-}"; shift 2 ;;
|
||||||
|
-l|--lines) lines="${2-}"; shift 2 ;;
|
||||||
|
-h|--help) usage; exit 0 ;;
|
||||||
|
*) echo "Unknown option: $1" >&2; usage; exit 1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z "$target" || -z "$pattern" ]]; then
|
||||||
|
echo "target and pattern are required" >&2
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! [[ "$timeout" =~ ^[0-9]+$ ]]; then
|
||||||
|
echo "timeout must be an integer number of seconds" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! [[ "$lines" =~ ^[0-9]+$ ]]; then
|
||||||
|
echo "lines must be an integer" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v tmux >/dev/null 2>&1; then
|
||||||
|
echo "tmux not found in PATH" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# End time in epoch seconds (integer, good enough for polling)
|
||||||
|
start_epoch=$(date +%s)
|
||||||
|
deadline=$((start_epoch + timeout))
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
# -J joins wrapped lines, -S uses negative index to read last N lines
|
||||||
|
pane_text="$(tmux capture-pane -p -J -t "$target" -S "-${lines}" 2>/dev/null || true)"
|
||||||
|
|
||||||
|
if printf '%s\n' "$pane_text" | grep $grep_flag -- "$pattern" >/dev/null 2>&1; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
now=$(date +%s)
|
||||||
|
if (( now >= deadline )); then
|
||||||
|
echo "Timed out after ${timeout}s waiting for pattern: $pattern" >&2
|
||||||
|
echo "Last ${lines} lines from $target:" >&2
|
||||||
|
printf '%s\n' "$pane_text" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep "$interval"
|
||||||
|
done
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
---
|
||||||
|
name: weather
|
||||||
|
description: Get current weather and forecasts with verified location matching (no API key required).
|
||||||
|
homepage: https://wttr.in/:help
|
||||||
|
metadata: {"nanobot":{"emoji":"🌤️","requires":{"bins":["curl"]}}}
|
||||||
|
---
|
||||||
|
|
||||||
|
# Weather
|
||||||
|
|
||||||
|
Use the most reliable location match first. For Chinese city names or other non-Latin input, prefer `wttr.in` with the original query because it resolves native names directly. Use Open-Meteo for structured current conditions and forecasts only after you have confirmed the exact city.
|
||||||
|
|
||||||
|
## Accuracy Rules
|
||||||
|
|
||||||
|
- Always restate the matched location, region/country, and observation time in the final answer.
|
||||||
|
- Do not trust the first geocoding hit blindly. Check `country`, `admin1`, `admin2`, and `population`.
|
||||||
|
- For Chinese city queries, do not send Hanzi directly to Open-Meteo geocoding unless the top result is obviously correct. Prefer `wttr.in` with the original Chinese name, or geocode the English/pinyin city name instead.
|
||||||
|
- If multiple plausible matches remain, ask a follow-up question or state the assumption clearly.
|
||||||
|
- Use `timezone=auto` when calling Open-Meteo so the reported time matches the location.
|
||||||
|
|
||||||
|
## wttr.in (best for direct city-name queries)
|
||||||
|
|
||||||
|
Quick current conditions:
|
||||||
|
```bash
|
||||||
|
curl -s "https://wttr.in/London?format=%l:+%c+%t+%h+%w"
|
||||||
|
```
|
||||||
|
|
||||||
|
Chinese city example:
|
||||||
|
```bash
|
||||||
|
curl -s "https://wttr.in/%E6%88%90%E9%83%BD?format=%l:+%c+%t+%h+%w"
|
||||||
|
curl -s "https://wttr.in/%E4%B8%8A%E6%B5%B7?format=%l:+%c+%t+%h+%w"
|
||||||
|
```
|
||||||
|
|
||||||
|
JSON output if you need more detail:
|
||||||
|
```bash
|
||||||
|
curl -s "https://wttr.in/Chengdu?format=j1"
|
||||||
|
```
|
||||||
|
|
||||||
|
Tips:
|
||||||
|
- URL-encode spaces: `New York` -> `New+York`
|
||||||
|
- URL-encode non-ASCII text before sending the request
|
||||||
|
- Use `?m` for metric units and `?u` for US units
|
||||||
|
|
||||||
|
## Open-Meteo (best for structured forecasts)
|
||||||
|
|
||||||
|
1. Geocode the city and verify the returned location metadata:
|
||||||
|
```bash
|
||||||
|
curl -s "https://geocoding-api.open-meteo.com/v1/search?name=Chengdu&count=3&language=en&format=json"
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Query current weather and today's forecast with the verified coordinates:
|
||||||
|
```bash
|
||||||
|
curl -s "https://api.open-meteo.com/v1/forecast?latitude=30.66667&longitude=104.06667¤t=temperature_2m,relative_humidity_2m,weather_code,wind_speed_10m&daily=weather_code,temperature_2m_max,temperature_2m_min&forecast_days=1&timezone=auto"
|
||||||
|
```
|
||||||
|
|
||||||
|
Important:
|
||||||
|
- For Chinese inputs like `成都`, geocoding `name=%E6%88%90%E9%83%BD` may return smaller homonym locations first. Prefer `Chengdu` after verifying it matches Sichuan, China.
|
||||||
|
- If geocoding looks suspicious, fall back to `wttr.in` for the original city name instead of presenting a likely wrong result.
|
||||||
|
|
||||||
|
Docs: https://open-meteo.com/en/docs
|
||||||
134
docs/guides/freeride.md
Normal file
134
docs/guides/freeride.md
Normal file
|
|
@ -0,0 +1,134 @@
|
||||||
|
# FreeRide 🦞
|
||||||
|
|
||||||
|
FreeRide is a dynamic model rotation and failover system for PicoClaw that leverages OpenRouter's free model pool. It ensures your agent stays alive even if individual free models become rate-limited or go offline.
|
||||||
|
|
||||||
|
## Key Features
|
||||||
|
|
||||||
|
- **Automatic Discovery**: Scans OpenRouter for the best currently available free models.
|
||||||
|
- **Dynamic Failover**: Automatically rotates through a pool of models when errors (like 429 Rate Limiting) occur.
|
||||||
|
- **Intelligent Ranking**: Models are scored and ranked based on context length, capabilities (tools/vision), and provider trust.
|
||||||
|
- **K3s Ready**: Designed to work seamlessly in Kubernetes environments with secure API key management.
|
||||||
|
- **Visual Provenance (🦞)**: Responses generated via a fallback model are clearly marked with a "lobster" emoji and the model name, providing transparency about which model handled your request.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
FreeRide is implemented as a native PicoClaw tool. For production environments (especially in the **main branch**), ensure you follow the [Security Configuration](../security/security_configuration.md) to manage your API keys safely.
|
||||||
|
|
||||||
|
### 1. Enable the Tool
|
||||||
|
Ensure the `skills` tool is enabled in your `config.json` (FreeRide is bundled with the skills system):
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"tools": {
|
||||||
|
"skills": {
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Set the API Key
|
||||||
|
FreeRide requires an OpenRouter API key. Even for free models, many providers require a key for identification and higher rate limits.
|
||||||
|
|
||||||
|
PicoClaw supports dynamic environment variable resolution using the `env://` scheme.
|
||||||
|
|
||||||
|
In **Local Mode** or **Docker**, set the environment variable:
|
||||||
|
```bash
|
||||||
|
export OPENROUTER_API_KEY="sk-or-v1-..."
|
||||||
|
```
|
||||||
|
|
||||||
|
Then in your `config.json`, use:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"api_keys": ["env://OPENROUTER_API_KEY"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
*(Note: `freeride auto` will automatically configure this for you.)*
|
||||||
|
|
||||||
|
In **K3s Mode**, add the secret to your cluster (see below).
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
You can interact with FreeRide directly through the agent:
|
||||||
|
|
||||||
|
### `freeride auto`
|
||||||
|
**The most important command.** This command:
|
||||||
|
1. Fetches the current list of ~28+ free models.
|
||||||
|
2. Ranks them by quality.
|
||||||
|
3. Automatically populates your `config.json`'s `model_list`.
|
||||||
|
4. Adds the top 5 models to your agent's `model_fallbacks` list.
|
||||||
|
5. Reloads the agent configuration instantly.
|
||||||
|
|
||||||
|
### `freeride status`
|
||||||
|
Shows your current primary model and the active fallback rotation pool.
|
||||||
|
|
||||||
|
### `freeride list [limit]`
|
||||||
|
Displays the current top-ranked free models available on OpenRouter without modifying your configuration.
|
||||||
|
|
||||||
|
### `freeride settimeout [seconds]`
|
||||||
|
Sets the request timeout for all OpenRouter models. Default is 300 seconds (5 minutes). Use this if you need longer timeouts for complex tasks:
|
||||||
|
```bash
|
||||||
|
picoclaw freeride settimeout 600 # 10 minutes
|
||||||
|
```
|
||||||
|
|
||||||
|
## K3s Deployment & Secrets
|
||||||
|
|
||||||
|
When running PicoClaw on K3s, follow these steps to manage your secrets safely.
|
||||||
|
|
||||||
|
### Adding the Secret
|
||||||
|
If you are creating the secrets for the first time:
|
||||||
|
```bash
|
||||||
|
kubectl create secret generic picoclaw-secrets \
|
||||||
|
--namespace agi \
|
||||||
|
--from-literal=openrouter-api-key="YOUR_KEY_HERE"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Updating Existing Secrets (Safe Patching)
|
||||||
|
If `picoclaw-secrets` already exists and you want to add the OpenRouter key without losing your Telegram or NVIDIA keys, use **`kubectl patch`**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl patch secret picoclaw-secrets \
|
||||||
|
--namespace agi \
|
||||||
|
--type='json' \
|
||||||
|
-p='[{"op": "add", "path": "/data/openrouter-api-key", "value":"'$(echo -n "YOUR_KEY_HERE" | base64 -w0)'"}]'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Deployment Configuration
|
||||||
|
Ensure your `deployment.yaml` maps the secret to the environment variable:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
env:
|
||||||
|
- name: OPENROUTER_API_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: picoclaw-secrets
|
||||||
|
key: openrouter-api-key
|
||||||
|
```
|
||||||
|
|
||||||
|
## Cooldown Persistence & Timing ❄️
|
||||||
|
|
||||||
|
To prevent the agent from "hanging" or retrying known-failed models, PicoClaw uses a two-pronged approach:
|
||||||
|
|
||||||
|
### 1. Zero-Amnesia Persistence
|
||||||
|
Model failures (e.g., 429 Rate Limits) are saved to `~/.picoclaw/cooldowns.json`. This ensures that if you restart the agent, it **remembers** which models were saturated and skips them instantly. You no longer have to wait through a series of timeouts every time you restart.
|
||||||
|
|
||||||
|
### 2. Generous 5 Minute Timeout
|
||||||
|
The default request timeout for LLM calls is **300 seconds (5 minutes)**. Free models can be slower than paid ones, and complex agentic tasks (multi-step reasoning, file operations, debugging) need time to complete. If a free model truly can't handle the request, it will return an error rather than hanging indefinitely - allowing the agent to fail over to the next fallback.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
- **404 Errors**: Ensure the model is still available on OpenRouter using `freeride list`. If it's gone, run `freeride auto` to refresh your fallback pool.
|
||||||
|
- **429 Rate Limiting**: This is common with free models. PicoClaw will automatically try the next model in your `model_fallbacks` list and persist the cooldown to `cooldowns.json`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Legal & Responsible Use 🛡️
|
||||||
|
|
||||||
|
FreeRide is provided for **personal assistance, educational research, and infrastructure failover** purposes only. By using this capability, you acknowledge and agree to the following:
|
||||||
|
|
||||||
|
1. **Terms of Service**: You are responsible for complying with [OpenRouter's Terms of Service](https://openrouter.ai/terms) and the individual "Acceptable Use Policies" of each model provider (e.g., Google, Meta, Mistral).
|
||||||
|
2. **No Guarantee of Service**: Free models are provided "as-is" by third parties. They may be withdrawn, rate-limited, or modified at any time without notice.
|
||||||
|
3. **No Reselling**: You should not use FreeRide to build commercial services that "resell" free model access in a way that violates provider licenses (check specific model licenses like Llama 3 Community or Qwen for commercial usage thresholds).
|
||||||
|
4. **Rate Limit Respect**: PicoClaw handles failover automatically, but users should not use FreeRide to intentionally overwhelm or evade the fair-use rate limits of providers.
|
||||||
|
|
||||||
|
*PicoClaw is an independent tool and is not affiliated with OpenRouter or any specific LLM provider.*
|
||||||
854
examples/freeride-config.json
Normal file
854
examples/freeride-config.json
Normal file
|
|
@ -0,0 +1,854 @@
|
||||||
|
{
|
||||||
|
"session": {
|
||||||
|
"dimensions": [
|
||||||
|
"chat"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"version": 3,
|
||||||
|
"isolation": {},
|
||||||
|
"agents": {
|
||||||
|
"defaults": {
|
||||||
|
"workspace": "/home/stevef/.picoclaw/workspace",
|
||||||
|
"restrict_to_workspace": true,
|
||||||
|
"allow_read_outside_workspace": false,
|
||||||
|
"provider": "nvidia",
|
||||||
|
"model_name": "nemotron-120b",
|
||||||
|
"model_fallbacks": [
|
||||||
|
"meta-llama-llama-3.3-70b-instruct:free",
|
||||||
|
"qwen-qwen3-coder:free",
|
||||||
|
"openrouter-elephant-alpha",
|
||||||
|
"google-gemma-4-26b-a4b-it:free",
|
||||||
|
"google-gemma-4-31b-it:free",
|
||||||
|
"nvidia-nemotron-3-super-120b-a12b:free",
|
||||||
|
"qwen-qwen3-next-80b-a3b-instruct:free",
|
||||||
|
"nvidia-nemotron-nano-9b-v2:free"
|
||||||
|
],
|
||||||
|
"max_tokens": 32768,
|
||||||
|
"max_tool_iterations": 50,
|
||||||
|
"summarize_message_threshold": 20,
|
||||||
|
"summarize_token_percent": 75,
|
||||||
|
"steering_mode": "one-at-a-time",
|
||||||
|
"subturn": {
|
||||||
|
"max_depth": 10,
|
||||||
|
"max_concurrent": 5,
|
||||||
|
"default_timeout_minutes": 20,
|
||||||
|
"default_token_budget": 100000,
|
||||||
|
"concurrency_timeout_sec": 10
|
||||||
|
},
|
||||||
|
"tool_feedback": {
|
||||||
|
"enabled": true,
|
||||||
|
"max_args_length": 300
|
||||||
|
},
|
||||||
|
"split_on_marker": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"channel_list": {
|
||||||
|
"dingtalk": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "dingtalk",
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"client_id": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"discord": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "discord",
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"proxy": "",
|
||||||
|
"mention_only": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"feishu": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "feishu",
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"app_id": "",
|
||||||
|
"random_reaction_emoji": [
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"is_lark": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"irc": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "irc",
|
||||||
|
"allow_from": [
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"server": "",
|
||||||
|
"tls": false,
|
||||||
|
"nick": "",
|
||||||
|
"sasl_user": "",
|
||||||
|
"channels": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"line": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "line",
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {
|
||||||
|
"mention_only": true
|
||||||
|
},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"webhook_host": "0.0.0.0",
|
||||||
|
"webhook_port": 18791,
|
||||||
|
"webhook_path": "/webhook/line"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"maixcam": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "maixcam",
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"host": "0.0.0.0",
|
||||||
|
"port": 18790
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"matrix": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "matrix",
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {
|
||||||
|
"mention_only": true
|
||||||
|
},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": true,
|
||||||
|
"text": [
|
||||||
|
"Thinking... 💭"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"homeserver": "https://matrix.org",
|
||||||
|
"user_id": "",
|
||||||
|
"join_on_invite": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"onebot": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "onebot",
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"ws_url": "ws://127.0.0.1:3001",
|
||||||
|
"reconnect_interval": 5,
|
||||||
|
"group_trigger_prefix": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pico": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "pico",
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"ping_interval": 30,
|
||||||
|
"read_timeout": 60,
|
||||||
|
"write_timeout": 10,
|
||||||
|
"max_connections": 100
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pico_client": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "pico_client",
|
||||||
|
"allow_from": [
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"url": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"qq": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "qq",
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"app_id": "",
|
||||||
|
"max_message_length": 2000,
|
||||||
|
"max_base64_file_size_mib": 0,
|
||||||
|
"send_markdown": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"slack": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "slack",
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {}
|
||||||
|
},
|
||||||
|
"telegram": {
|
||||||
|
"enabled": true,
|
||||||
|
"type": "telegram",
|
||||||
|
"allow_from": [
|
||||||
|
"-5274005272",
|
||||||
|
"8271300679"
|
||||||
|
],
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": true,
|
||||||
|
"text": [
|
||||||
|
"Thinking... 💭"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"base_url": "",
|
||||||
|
"proxy": "",
|
||||||
|
"streaming": {
|
||||||
|
"enabled": true,
|
||||||
|
"throttle_seconds": 3,
|
||||||
|
"min_growth_chars": 200
|
||||||
|
},
|
||||||
|
"use_markdown_v2": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"vk": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "vk",
|
||||||
|
"allow_from": [
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"group_id": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"wecom": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "wecom",
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"bot_id": "",
|
||||||
|
"websocket_url": "wss://openws.work.weixin.qq.com",
|
||||||
|
"send_thinking_message": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"weixin": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "weixin",
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"base_url": "https://ilinkai.weixin.qq.com/",
|
||||||
|
"cdn_base_url": "https://novac2c.cdn.weixin.qq.com/c2c",
|
||||||
|
"proxy": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"whatsapp": {
|
||||||
|
"enabled": false,
|
||||||
|
"type": "whatsapp",
|
||||||
|
"reasoning_channel_id": "",
|
||||||
|
"group_trigger": {},
|
||||||
|
"typing": {},
|
||||||
|
"placeholder": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"bridge_url": "ws://localhost:3001",
|
||||||
|
"use_native": false,
|
||||||
|
"session_store_path": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"model_list": [
|
||||||
|
{
|
||||||
|
"model_name": "glm-4.7",
|
||||||
|
"model": "zhipu/glm-4.7",
|
||||||
|
"api_base": "https://open.bigmodel.cn/api/paas/v4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "gpt-5.4",
|
||||||
|
"model": "openai/gpt-5.4",
|
||||||
|
"api_base": "https://api.openai.com/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "claude-sonnet-4.6",
|
||||||
|
"model": "anthropic/claude-sonnet-4.6",
|
||||||
|
"api_base": "https://api.anthropic.com/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "deepseek-chat",
|
||||||
|
"model": "deepseek/deepseek-chat",
|
||||||
|
"api_base": "https://api.deepseek.com/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "gemini-2.0-flash",
|
||||||
|
"model": "gemini/gemini-2.0-flash-exp",
|
||||||
|
"api_base": "https://generativelanguage.googleapis.com/v1beta"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "qwen-plus",
|
||||||
|
"model": "qwen/qwen-plus",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "moonshot-v1-8k",
|
||||||
|
"model": "moonshot/moonshot-v1-8k",
|
||||||
|
"api_base": "https://api.moonshot.cn/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "llama-3.3-70b",
|
||||||
|
"model": "groq/llama-3.3-70b-versatile",
|
||||||
|
"api_base": "https://api.groq.com/openai/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "openrouter-nemotron",
|
||||||
|
"model": "nvidia/nemotron-3-super-120b-a12b:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://openrouter.ai/api/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "openrouter-elephant",
|
||||||
|
"model": "openrouter/elephant-alpha",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://openrouter.ai/api/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "openrouter-free",
|
||||||
|
"model": "arcee-ai/trinity-large-preview:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://openrouter.ai/api/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "google-gemma-3-27b-it:free",
|
||||||
|
"model": "google/gemma-3-27b-it:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://openrouter.ai/api/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "qwen-qwen3-coder:free",
|
||||||
|
"model": "qwen/qwen3-coder:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://openrouter.ai/api/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "nvidia-nemotron-4-340b-instruct:free",
|
||||||
|
"model": "nvidia/nemotron-4-340b-instruct:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://openrouter.ai/api/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "mistralai-pixtral-12b:free",
|
||||||
|
"model": "mistralai/pixtral-12b:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://openrouter.ai/api/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "google-gemma-3-26b-a4b-it:free",
|
||||||
|
"model": "google/gemma-3-26b-a4b-it:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://openrouter.ai/api/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "openrouter-auto",
|
||||||
|
"model": "auto",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://openrouter.ai/api/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "openrouter-gpt-5.4",
|
||||||
|
"model": "openai/gpt-5.4",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://openrouter.ai/api/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "nvidia/llama-3.1-nemotron-70b-instruct",
|
||||||
|
"model": "nvidia/llama-3.1-nemotron-70b-instruct",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://integrate.api.nvidia.com/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "meta/llama-3.1-70b-instruct",
|
||||||
|
"model": "meta/llama-3.1-70b-instruct",
|
||||||
|
"api_base": "https://integrate.api.nvidia.com/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "meta/llama-3.1-405b-instruct",
|
||||||
|
"model": "meta/llama-3.1-405b-instruct",
|
||||||
|
"api_base": "https://integrate.api.nvidia.com/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "meta/llama-3.3-70b-instruct",
|
||||||
|
"model": "meta/llama-3.3-70b-instruct",
|
||||||
|
"api_base": "https://integrate.api.nvidia.com/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "azure-grok",
|
||||||
|
"model": "openai/grok-4-fast-non-reasoning",
|
||||||
|
"api_base": "https://TestSJF.openai.azure.com/openai/v1/",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "cerebras-llama-3.3-70b",
|
||||||
|
"model": "cerebras/llama-3.3-70b",
|
||||||
|
"api_base": "https://api.cerebras.ai/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "vivgrid-auto",
|
||||||
|
"model": "vivgrid/auto",
|
||||||
|
"api_base": "https://api.vivgrid.com/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "ark-code-latest",
|
||||||
|
"model": "volcengine/ark-code-latest",
|
||||||
|
"api_base": "https://ark.cn-beijing.volces.com/api/v3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "doubao-pro",
|
||||||
|
"model": "volcengine/doubao-pro-32k",
|
||||||
|
"api_base": "https://ark.cn-beijing.volces.com/api/v3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "deepseek-v3",
|
||||||
|
"model": "shengsuanyun/deepseek-v3",
|
||||||
|
"api_base": "https://api.shengsuanyun.com/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "copilot-gpt-5.4",
|
||||||
|
"model": "github-copilot/gpt-5.4",
|
||||||
|
"api_base": "http://localhost:4321",
|
||||||
|
"auth_method": "oauth"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "llama3",
|
||||||
|
"model": "ollama/llama3",
|
||||||
|
"api_base": "http://localhost:11434/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "mistral-small",
|
||||||
|
"model": "mistral/mistral-small-latest",
|
||||||
|
"api_base": "https://api.mistral.ai/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "deepseek-v3.2",
|
||||||
|
"model": "avian/deepseek/deepseek-v3.2",
|
||||||
|
"api_base": "https://api.avian.io/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "kimi-k2.5",
|
||||||
|
"model": "avian/moonshotai/kimi-k2.5",
|
||||||
|
"api_base": "https://api.avian.io/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "MiniMax-M2.5",
|
||||||
|
"model": "minimax/MiniMax-M2.5",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://api.minimaxi.com/v1",
|
||||||
|
"extra_body": {
|
||||||
|
"reasoning_split": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "LongCat-Flash-Thinking",
|
||||||
|
"model": "longcat/LongCat-Flash-Thinking",
|
||||||
|
"api_base": "https://api.longcat.chat/openai"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "modelscope-qwen",
|
||||||
|
"model": "modelscope/Qwen/Qwen3-235B-A22B-Instruct-2507",
|
||||||
|
"api_base": "https://api-inference.modelscope.cn/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "local-model",
|
||||||
|
"model": "vllm/custom-model",
|
||||||
|
"api_base": "http://localhost:8000/v1",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "meta-llama-llama-3.3-70b-instruct:free",
|
||||||
|
"model": "meta-llama/llama-3.3-70b-instruct:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "qwen-qwen3-coder:free",
|
||||||
|
"model": "qwen/qwen3-coder:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "mistralai-pixtral-12b:free",
|
||||||
|
"model": "mistralai/pixtral-12b:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "nvidia-nemotron-4-340b-instruct:free",
|
||||||
|
"model": "nvidia/nemotron-4-340b-instruct:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "azure-gpt5",
|
||||||
|
"model": "azure/my-gpt5-deployment",
|
||||||
|
"api_base": "https://your-resource.openai.azure.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "google-gemma-3-26b-a4b-it:free",
|
||||||
|
"model": "google/gemma-3-26b-a4b-it:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "google-gemma-3-31b-it:free",
|
||||||
|
"model": "google/gemma-3-31b-it:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "nvidia-nemotron-3-super-120b-a12b:free",
|
||||||
|
"model": "nvidia/nemotron-3-super-120b-a12b:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "nemotron-120b",
|
||||||
|
"model": "nvidia/nemotron-3-super-120b-a12b",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"api_base": "https://integrate.api.nvidia.com/v1",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "qwen-qwen3-next-80b-a3b-instruct:free",
|
||||||
|
"model": "qwen/qwen3-next-80b-a3b-instruct:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "nvidia-nemotron-nano-9b-v2:free",
|
||||||
|
"model": "nvidia/nemotron-nano-9b-v2:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "openrouter-elephant-alpha",
|
||||||
|
"model": "openrouter/elephant-alpha",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "minimax-minimax-m2.5:free",
|
||||||
|
"model": "minimax/minimax-m2.5:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "arcee-ai-trinity-large-preview:free",
|
||||||
|
"model": "arcee-ai/trinity-large-preview:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "google-lyria-3-pro-preview",
|
||||||
|
"model": "google/lyria-3-pro-preview",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "google-lyria-3-clip-preview",
|
||||||
|
"model": "google/lyria-3-clip-preview",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "nvidia-nemotron-3-nano-30b-a3b:free",
|
||||||
|
"model": "nvidia/nemotron-3-nano-30b-a3b:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "nvidia-nemotron-nano-12b-v2-vl:free",
|
||||||
|
"model": "nvidia/nemotron-nano-12b-v2-vl:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "openai-gpt-oss-120b:free",
|
||||||
|
"model": "openai/gpt-oss-120b:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "openai-gpt-oss-20b:free",
|
||||||
|
"model": "openai/gpt-oss-20b:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "google-gemma-4-26b-a4b-it:free",
|
||||||
|
"model": "google/gemma-4-26b-a4b-it:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "google-gemma-4-31b-it:free",
|
||||||
|
"model": "google/gemma-4-31b-it:free",
|
||||||
|
"protocol": "openrouter",
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"gateway": {
|
||||||
|
"host": "0.0.0.0",
|
||||||
|
"port": 18790,
|
||||||
|
"hot_reload": true,
|
||||||
|
"log_level": "info"
|
||||||
|
},
|
||||||
|
"hooks": {
|
||||||
|
"enabled": false,
|
||||||
|
"defaults": {
|
||||||
|
"observer_timeout_ms": 500,
|
||||||
|
"interceptor_timeout_ms": 5000,
|
||||||
|
"approval_timeout_ms": 60000
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tools": {
|
||||||
|
"allow_read_paths": null,
|
||||||
|
"allow_write_paths": null,
|
||||||
|
"filter_sensitive_data": true,
|
||||||
|
"filter_min_length": 8,
|
||||||
|
"web": {
|
||||||
|
"enabled": true,
|
||||||
|
"brave": {
|
||||||
|
"enabled": false,
|
||||||
|
"max_results": 5
|
||||||
|
},
|
||||||
|
"tavily": {
|
||||||
|
"enabled": false,
|
||||||
|
"base_url": "",
|
||||||
|
"max_results": 5
|
||||||
|
},
|
||||||
|
"sogou": {
|
||||||
|
"enabled": true,
|
||||||
|
"max_results": 5
|
||||||
|
},
|
||||||
|
"duckduckgo": {
|
||||||
|
"enabled": true,
|
||||||
|
"max_results": 5
|
||||||
|
},
|
||||||
|
"perplexity": {
|
||||||
|
"enabled": false,
|
||||||
|
"max_results": 5
|
||||||
|
},
|
||||||
|
"searxng": {
|
||||||
|
"enabled": false,
|
||||||
|
"base_url": "",
|
||||||
|
"max_results": 5
|
||||||
|
},
|
||||||
|
"glm_search": {
|
||||||
|
"enabled": false,
|
||||||
|
"base_url": "https://open.bigmodel.cn/api/paas/v4/web_search",
|
||||||
|
"search_engine": "search_std",
|
||||||
|
"max_results": 5
|
||||||
|
},
|
||||||
|
"baidu_search": {
|
||||||
|
"enabled": false,
|
||||||
|
"base_url": "https://qianfan.baidubce.com/v2/ai_search/web_search",
|
||||||
|
"max_results": 10
|
||||||
|
},
|
||||||
|
"provider": "auto",
|
||||||
|
"prefer_native": true,
|
||||||
|
"fetch_limit_bytes": 10485760,
|
||||||
|
"format": "plaintext"
|
||||||
|
},
|
||||||
|
"cron": {
|
||||||
|
"enabled": true,
|
||||||
|
"exec_timeout_minutes": 5,
|
||||||
|
"allow_command": true
|
||||||
|
},
|
||||||
|
"exec": {
|
||||||
|
"enabled": true,
|
||||||
|
"enable_deny_patterns": true,
|
||||||
|
"allow_remote": true,
|
||||||
|
"custom_deny_patterns": null,
|
||||||
|
"custom_allow_patterns": null,
|
||||||
|
"timeout_seconds": 60
|
||||||
|
},
|
||||||
|
"skills": {
|
||||||
|
"enabled": true,
|
||||||
|
"registries": {
|
||||||
|
"clawhub": {
|
||||||
|
"base_url": "https://clawhub.ai",
|
||||||
|
"download_path": "",
|
||||||
|
"enabled": true,
|
||||||
|
"max_response_size": 0,
|
||||||
|
"max_zip_size": 0,
|
||||||
|
"search_path": "",
|
||||||
|
"skills_path": "",
|
||||||
|
"timeout": 0
|
||||||
|
},
|
||||||
|
"github": {
|
||||||
|
"base_url": "https://github.com",
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"github": {},
|
||||||
|
"max_concurrent_searches": 2,
|
||||||
|
"search_cache": {
|
||||||
|
"max_size": 50,
|
||||||
|
"ttl_seconds": 300
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"media_cleanup": {
|
||||||
|
"enabled": true,
|
||||||
|
"max_age_minutes": 30,
|
||||||
|
"interval_minutes": 5
|
||||||
|
},
|
||||||
|
"mcp": {
|
||||||
|
"enabled": false,
|
||||||
|
"discovery": {
|
||||||
|
"enabled": false,
|
||||||
|
"ttl": 5,
|
||||||
|
"max_search_results": 5,
|
||||||
|
"use_bm25": true,
|
||||||
|
"use_regex": false
|
||||||
|
},
|
||||||
|
"max_inline_text_chars": 16384
|
||||||
|
},
|
||||||
|
"append_file": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"edit_file": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"find_skills": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"i2c": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"install_skill": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"list_dir": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"message": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"read_file": {
|
||||||
|
"enabled": true,
|
||||||
|
"mode": "bytes",
|
||||||
|
"max_read_file_size": 65536
|
||||||
|
},
|
||||||
|
"send_file": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"send_tts": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"spawn": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"spawn_status": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"spi": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"subagent": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"web_fetch": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"write_file": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"freeride": {
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"heartbeat": {
|
||||||
|
"enabled": true,
|
||||||
|
"interval": 30
|
||||||
|
},
|
||||||
|
"devices": {
|
||||||
|
"enabled": false,
|
||||||
|
"monitor_usb": true
|
||||||
|
},
|
||||||
|
"voice": {
|
||||||
|
"echo_transcription": false
|
||||||
|
},
|
||||||
|
"build_info": {
|
||||||
|
"version": "0.1.0",
|
||||||
|
"git_commit": "054b55fd",
|
||||||
|
"build_time": "2026-03-23T10:15:13+0100",
|
||||||
|
"go_version": "go1.26.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -117,6 +117,9 @@ func NewAgentInstance(
|
||||||
if cfg.Tools.IsToolEnabled("append_file") {
|
if cfg.Tools.IsToolEnabled("append_file") {
|
||||||
toolsRegistry.Register(tools.NewAppendFileTool(workspace, restrict, allowWritePaths))
|
toolsRegistry.Register(tools.NewAppendFileTool(workspace, restrict, allowWritePaths))
|
||||||
}
|
}
|
||||||
|
if cfg.Tools.IsToolEnabled("freeride") {
|
||||||
|
toolsRegistry.Register(tools.NewFreeRideTool(config.GetDefaultConfigPath(), nil))
|
||||||
|
}
|
||||||
|
|
||||||
sessionsDir := filepath.Join(workspace, "sessions")
|
sessionsDir := filepath.Join(workspace, "sessions")
|
||||||
sessions := initSessionStore(sessionsDir)
|
sessions := initSessionStore(sessionsDir)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ package agent
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sipeed/picoclaw/pkg/audio/tts"
|
"github.com/sipeed/picoclaw/pkg/audio/tts"
|
||||||
|
|
@ -44,6 +45,10 @@ func NewAgentLoop(
|
||||||
var stateManager *state.Manager
|
var stateManager *state.Manager
|
||||||
if defaultAgent != nil {
|
if defaultAgent != nil {
|
||||||
stateManager = state.NewManager(defaultAgent.Workspace)
|
stateManager = state.NewManager(defaultAgent.Workspace)
|
||||||
|
// Enable persistent cooldowns so that model rate limits/failures
|
||||||
|
// are remembered across agent restarts.
|
||||||
|
cooldownPath := filepath.Join(filepath.Dir(filepath.Clean(defaultAgent.Workspace)), "cooldowns.json")
|
||||||
|
_ = cooldown.SetPersistencePath(cooldownPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
eventBus := NewEventBus()
|
eventBus := NewEventBus()
|
||||||
|
|
|
||||||
|
|
@ -37,14 +37,20 @@ func candidateFromModelConfig(
|
||||||
return providers.FallbackCandidate{}, false
|
return providers.FallbackCandidate{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
ref := providers.ParseModelRef(ensureProtocolModel(mc.Model), defaultProvider)
|
provider := providers.NormalizeProvider(mc.Protocol)
|
||||||
if ref == nil {
|
model := mc.Model
|
||||||
return providers.FallbackCandidate{}, false
|
if provider == "" {
|
||||||
|
ref := providers.ParseModelRef(ensureProtocolModel(model), defaultProvider)
|
||||||
|
if ref == nil {
|
||||||
|
return providers.FallbackCandidate{}, false
|
||||||
|
}
|
||||||
|
provider = ref.Provider
|
||||||
|
model = ref.Model
|
||||||
}
|
}
|
||||||
|
|
||||||
return providers.FallbackCandidate{
|
return providers.FallbackCandidate{
|
||||||
Provider: ref.Provider,
|
Provider: provider,
|
||||||
Model: ref.Model,
|
Model: model,
|
||||||
RPM: mc.RPM,
|
RPM: mc.RPM,
|
||||||
IdentityKey: modelConfigIdentityKey(mc),
|
IdentityKey: modelConfigIdentityKey(mc),
|
||||||
}, true
|
}, true
|
||||||
|
|
|
||||||
|
|
@ -530,8 +530,9 @@ type VoiceConfig struct {
|
||||||
// Default protocol is "openai" if no prefix is specified.
|
// Default protocol is "openai" if no prefix is specified.
|
||||||
type ModelConfig struct {
|
type ModelConfig struct {
|
||||||
// Required fields
|
// Required fields
|
||||||
ModelName string `json:"model_name"` // User-facing alias for the model
|
ModelName string `json:"model_name"` // User-facing alias for the model
|
||||||
Model string `json:"model"` // Protocol/model-identifier (e.g., "openai/gpt-4o", "anthropic/claude-sonnet-4.6")
|
Model string `json:"model"` // Protocol/model-identifier (e.g., "openai/gpt-4o", "anthropic/claude-sonnet-4.6")
|
||||||
|
Protocol string `json:"protocol,omitempty"` // Explicit protocol (e.g., "openai", "openrouter", "anthropic")
|
||||||
|
|
||||||
// HTTP-based providers
|
// HTTP-based providers
|
||||||
APIBase string `json:"api_base,omitempty"` // API endpoint URL
|
APIBase string `json:"api_base,omitempty"` // API endpoint URL
|
||||||
|
|
@ -822,6 +823,7 @@ type ToolsConfig struct {
|
||||||
Subagent ToolConfig `json:"subagent" yaml:"-" envPrefix:"PICOCLAW_TOOLS_SUBAGENT_"`
|
Subagent ToolConfig `json:"subagent" yaml:"-" envPrefix:"PICOCLAW_TOOLS_SUBAGENT_"`
|
||||||
WebFetch ToolConfig `json:"web_fetch" yaml:"-" envPrefix:"PICOCLAW_TOOLS_WEB_FETCH_"`
|
WebFetch ToolConfig `json:"web_fetch" yaml:"-" envPrefix:"PICOCLAW_TOOLS_WEB_FETCH_"`
|
||||||
WriteFile ToolConfig `json:"write_file" yaml:"-" envPrefix:"PICOCLAW_TOOLS_WRITE_FILE_"`
|
WriteFile ToolConfig `json:"write_file" yaml:"-" envPrefix:"PICOCLAW_TOOLS_WRITE_FILE_"`
|
||||||
|
Freeride ToolConfig `json:"freeride" yaml:"-" envPrefix:"PICOCLAW_TOOLS_FREERIDE_"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsFilterSensitiveDataEnabled returns true if sensitive data filtering is enabled
|
// IsFilterSensitiveDataEnabled returns true if sensitive data filtering is enabled
|
||||||
|
|
@ -1422,6 +1424,7 @@ func expandMultiKeyModels(models []*ModelConfig) []*ModelConfig {
|
||||||
MaxTokensField: m.MaxTokensField,
|
MaxTokensField: m.MaxTokensField,
|
||||||
RequestTimeout: m.RequestTimeout,
|
RequestTimeout: m.RequestTimeout,
|
||||||
ThinkingLevel: m.ThinkingLevel,
|
ThinkingLevel: m.ThinkingLevel,
|
||||||
|
Protocol: m.Protocol,
|
||||||
ExtraBody: m.ExtraBody,
|
ExtraBody: m.ExtraBody,
|
||||||
CustomHeaders: m.CustomHeaders,
|
CustomHeaders: m.CustomHeaders,
|
||||||
UserAgent: m.UserAgent,
|
UserAgent: m.UserAgent,
|
||||||
|
|
@ -1441,6 +1444,7 @@ func expandMultiKeyModels(models []*ModelConfig) []*ModelConfig {
|
||||||
ConnectMode: m.ConnectMode,
|
ConnectMode: m.ConnectMode,
|
||||||
Workspace: m.Workspace,
|
Workspace: m.Workspace,
|
||||||
RPM: m.RPM,
|
RPM: m.RPM,
|
||||||
|
Protocol: m.Protocol,
|
||||||
MaxTokensField: m.MaxTokensField,
|
MaxTokensField: m.MaxTokensField,
|
||||||
RequestTimeout: m.RequestTimeout,
|
RequestTimeout: m.RequestTimeout,
|
||||||
ThinkingLevel: m.ThinkingLevel,
|
ThinkingLevel: m.ThinkingLevel,
|
||||||
|
|
@ -1507,6 +1511,8 @@ func (t *ToolsConfig) IsToolEnabled(name string) bool {
|
||||||
return t.SendTTS.Enabled
|
return t.SendTTS.Enabled
|
||||||
case "write_file":
|
case "write_file":
|
||||||
return t.WriteFile.Enabled
|
return t.WriteFile.Enabled
|
||||||
|
case "freeride":
|
||||||
|
return t.Freeride.Enabled
|
||||||
case "mcp":
|
case "mcp":
|
||||||
return t.MCP.Enabled
|
return t.MCP.Enabled
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package config
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -300,6 +301,9 @@ func resolveKey(v string) (string, error) {
|
||||||
if resolver == nil {
|
if resolver == nil {
|
||||||
resolver = credential.NewResolver("")
|
resolver = credential.NewResolver("")
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(v, "env://") {
|
||||||
|
return os.Getenv(strings.TrimPrefix(v, "env://")), nil
|
||||||
|
}
|
||||||
if strings.HasPrefix(v, "enc://") || strings.HasPrefix(v, "file://") {
|
if strings.HasPrefix(v, "enc://") || strings.HasPrefix(v, "file://") {
|
||||||
decrypted, err := resolver.Resolve(v)
|
decrypted, err := resolver.Resolve(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -55,3 +55,10 @@ func GetHome() string {
|
||||||
}
|
}
|
||||||
return homePath
|
return homePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDefaultConfigPath() string {
|
||||||
|
if cfgPath := os.Getenv(EnvConfig); cfgPath != "" {
|
||||||
|
return cfgPath
|
||||||
|
}
|
||||||
|
return filepath.Join(GetHome(), "config.json")
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package providers
|
package providers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"math"
|
"math"
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -11,11 +13,12 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// CooldownTracker manages per-provider cooldown state for the fallback chain.
|
// CooldownTracker manages per-provider cooldown state for the fallback chain.
|
||||||
// Thread-safe via sync.RWMutex. In-memory only (resets on restart).
|
// Thread-safe via sync.RWMutex. Supports persistence to disk.
|
||||||
type CooldownTracker struct {
|
type CooldownTracker struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
entries map[string]*cooldownEntry
|
entries map[string]*cooldownEntry
|
||||||
failureWindow time.Duration
|
failureWindow time.Duration
|
||||||
|
persistPath string
|
||||||
nowFunc func() time.Time // for testing
|
nowFunc func() time.Time // for testing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,6 +66,8 @@ func (ct *CooldownTracker) MarkFailure(provider string, reason FailoverReason) {
|
||||||
} else {
|
} else {
|
||||||
entry.CooldownEnd = now.Add(calculateStandardCooldown(entry.ErrorCount))
|
entry.CooldownEnd = now.Add(calculateStandardCooldown(entry.ErrorCount))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ct.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarkSuccess resets all counters and cooldowns for a provider.
|
// MarkSuccess resets all counters and cooldowns for a provider.
|
||||||
|
|
@ -80,6 +85,8 @@ func (ct *CooldownTracker) MarkSuccess(provider string) {
|
||||||
entry.CooldownEnd = time.Time{}
|
entry.CooldownEnd = time.Time{}
|
||||||
entry.DisabledUntil = time.Time{}
|
entry.DisabledUntil = time.Time{}
|
||||||
entry.DisabledReason = ""
|
entry.DisabledReason = ""
|
||||||
|
|
||||||
|
ct.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsAvailable returns true if the provider is not in cooldown or disabled.
|
// IsAvailable returns true if the provider is not in cooldown or disabled.
|
||||||
|
|
@ -162,6 +169,59 @@ func (ct *CooldownTracker) FailureCount(provider string, reason FailoverReason)
|
||||||
return entry.FailureCounts[reason]
|
return entry.FailureCounts[reason]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetPersistencePath sets the path for state persistence and triggers an immediate load.
|
||||||
|
func (ct *CooldownTracker) SetPersistencePath(path string) error {
|
||||||
|
ct.mu.Lock()
|
||||||
|
defer ct.mu.Unlock()
|
||||||
|
|
||||||
|
ct.persistPath = path
|
||||||
|
return ct.load()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct *CooldownTracker) save() {
|
||||||
|
if ct.persistPath == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := json.MarshalIndent(ct.entries, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = os.WriteFile(ct.persistPath, data, 0o644)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct *CooldownTracker) load() error {
|
||||||
|
if ct.persistPath == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := os.ReadFile(ct.persistPath)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var saved map[string]*cooldownEntry
|
||||||
|
if err := json.Unmarshal(data, &saved); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter out expired cooldowns during load
|
||||||
|
now := ct.nowFunc()
|
||||||
|
ct.entries = make(map[string]*cooldownEntry)
|
||||||
|
for k, v := range saved {
|
||||||
|
if (!v.CooldownEnd.IsZero() && now.Before(v.CooldownEnd)) ||
|
||||||
|
(!v.DisabledUntil.IsZero() && now.Before(v.DisabledUntil)) {
|
||||||
|
ct.entries[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (ct *CooldownTracker) getOrCreate(provider string) *cooldownEntry {
|
func (ct *CooldownTracker) getOrCreate(provider string) *cooldownEntry {
|
||||||
entry := ct.entries[provider]
|
entry := ct.entries[provider]
|
||||||
if entry == nil {
|
if entry == nil {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,82 @@
|
||||||
package providers
|
package providers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestCooldown_Persistence(t *testing.T) {
|
||||||
|
tempDir := t.TempDir()
|
||||||
|
persistPath := filepath.Join(tempDir, "cooldowns.json")
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
ct, current := newTestTracker(now)
|
||||||
|
if err := ct.SetPersistencePath(persistPath); err != nil {
|
||||||
|
t.Fatalf("SetPersistencePath failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Mark a failure and verify it saves
|
||||||
|
ct.MarkFailure("openai", FailoverRateLimit) // 1 min cooldown
|
||||||
|
if ct.IsAvailable("openai") {
|
||||||
|
t.Error("openai should be in cooldown")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(persistPath); os.IsNotExist(err) {
|
||||||
|
t.Fatal("persistence file was not created")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Create a NEW tracker and load the file
|
||||||
|
ct2, _ := newTestTracker(now)
|
||||||
|
if err := ct2.SetPersistencePath(persistPath); err != nil {
|
||||||
|
t.Fatalf("SetPersistencePath on second tracker failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ct2.IsAvailable("openai") {
|
||||||
|
t.Error("newly loaded tracker should still have openai in cooldown")
|
||||||
|
}
|
||||||
|
if ct2.ErrorCount("openai") != 1 {
|
||||||
|
t.Errorf("error count = %d, want 1", ct2.ErrorCount("openai"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Mark success and verify it clears and persists
|
||||||
|
ct2.MarkSuccess("openai")
|
||||||
|
if !ct2.IsAvailable("openai") {
|
||||||
|
t.Error("openai should be available after success")
|
||||||
|
}
|
||||||
|
|
||||||
|
ct3, _ := newTestTracker(now)
|
||||||
|
if err := ct3.SetPersistencePath(persistPath); err != nil {
|
||||||
|
t.Fatalf("SetPersistencePath on third tracker failed: %v", err)
|
||||||
|
}
|
||||||
|
if !ct3.IsAvailable("openai") {
|
||||||
|
t.Error("fourth tracker should see openai as available after success was persisted")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Verify expiration filtering
|
||||||
|
ct3.MarkFailure("anthropic", FailoverRateLimit) // 1 min cooldown
|
||||||
|
*current = now.Add(2 * time.Minute) // Advance time past expiration
|
||||||
|
|
||||||
|
ct4, ct4Current := newTestTracker(*current) // ct4 sees the future
|
||||||
|
if err := ct4.SetPersistencePath(persistPath); err != nil {
|
||||||
|
t.Fatalf("SetPersistencePath on fourth tracker failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since current time (2 min later) is past the 1 min cooldown, it should be filtered out on load
|
||||||
|
if !ct4.IsAvailable("anthropic") {
|
||||||
|
t.Error("anthropic should be available (expired cooldown filtered on load)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify that MarkFailure on ct4 uses the correct time
|
||||||
|
ct4.MarkFailure("groq", FailoverRateLimit)
|
||||||
|
if ct4.IsAvailable("groq") {
|
||||||
|
t.Error("groq should be in cooldown on ct4")
|
||||||
|
}
|
||||||
|
_ = ct4Current // keep compiler happy
|
||||||
|
}
|
||||||
|
|
||||||
func newTestTracker(now time.Time) (*CooldownTracker, *time.Time) {
|
func newTestTracker(now time.Time) (*CooldownTracker, *time.Time) {
|
||||||
current := now
|
current := now
|
||||||
ct := NewCooldownTracker()
|
ct := NewCooldownTracker()
|
||||||
|
|
|
||||||
|
|
@ -257,6 +257,8 @@ func classifyByStatus(status int) FailoverReason {
|
||||||
return FailoverRateLimit
|
return FailoverRateLimit
|
||||||
case status == 400:
|
case status == 400:
|
||||||
return FailoverFormat
|
return FailoverFormat
|
||||||
|
case status == 404:
|
||||||
|
return FailoverNotFound
|
||||||
case transientStatusCodes[status]:
|
case transientStatusCodes[status]:
|
||||||
return FailoverTimeout
|
return FailoverTimeout
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ func TestClassifyError_StatusCodes(t *testing.T) {
|
||||||
{523, FailoverTimeout},
|
{523, FailoverTimeout},
|
||||||
{524, FailoverTimeout},
|
{524, FailoverTimeout},
|
||||||
{529, FailoverTimeout},
|
{529, FailoverTimeout},
|
||||||
|
{404, FailoverNotFound},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
@ -427,6 +428,7 @@ func TestFailoverError_IsRetriable(t *testing.T) {
|
||||||
{FailoverOverloaded, true},
|
{FailoverOverloaded, true},
|
||||||
{FailoverFormat, false},
|
{FailoverFormat, false},
|
||||||
{FailoverContextOverflow, false},
|
{FailoverContextOverflow, false},
|
||||||
|
{FailoverNotFound, true},
|
||||||
{FailoverUnknown, true},
|
{FailoverUnknown, true},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,19 +84,38 @@ func createCodexAuthProvider() (LLMProvider, error) {
|
||||||
return NewCodexProviderWithTokenSource(cred.AccessToken, cred.AccountID, createCodexTokenSource()), nil
|
return NewCodexProviderWithTokenSource(cred.AccessToken, cred.AccountID, createCodexTokenSource()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isKnownProtocol(p string) bool {
|
||||||
|
if _, ok := protocolMetaByName[p]; ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
switch p {
|
||||||
|
case "anthropic", "azure", "azure-openai", "bedrock", "github-copilot", "github-copilot-chat", "copilot", "claude":
|
||||||
|
return true
|
||||||
|
case "antigravity", "claude-cli", "codex-cli", "cli", "fs", "memory", "dummy":
|
||||||
|
return true
|
||||||
|
case "elevenlabs", "openai-tts":
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// ExtractProtocol extracts the protocol prefix and model identifier from a model string.
|
// ExtractProtocol extracts the protocol prefix and model identifier from a model string.
|
||||||
// If no prefix is specified, it defaults to "openai".
|
// If no prefix is specified, it defaults to "openai".
|
||||||
// Examples:
|
|
||||||
// - "openai/gpt-4o" -> ("openai", "gpt-4o")
|
|
||||||
// - "anthropic/claude-sonnet-4.6" -> ("anthropic", "claude-sonnet-4.6")
|
|
||||||
// - "gpt-4o" -> ("openai", "gpt-4o") // default protocol
|
|
||||||
func ExtractProtocol(model string) (protocol, modelID string) {
|
func ExtractProtocol(model string) (protocol, modelID string) {
|
||||||
model = strings.TrimSpace(model)
|
model = strings.TrimSpace(model)
|
||||||
protocol, modelID, found := strings.Cut(model, "/")
|
p, m, found := strings.Cut(model, "/")
|
||||||
if !found {
|
if !found {
|
||||||
return "openai", model
|
return "openai", model
|
||||||
}
|
}
|
||||||
return protocol, modelID
|
|
||||||
|
// Only treat as protocol if it's in our known list.
|
||||||
|
// This prevents organizational model IDs like "google/gemma" or "anthropic/claude"
|
||||||
|
// from having their prefixes stripped when used with OpenAI-compatible providers (OpenRouter).
|
||||||
|
if isKnownProtocol(p) {
|
||||||
|
return p, m
|
||||||
|
}
|
||||||
|
|
||||||
|
return "openai", model
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveAPIBase returns the configured API base, or the protocol default when
|
// ResolveAPIBase returns the configured API base, or the protocol default when
|
||||||
|
|
@ -128,6 +147,16 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol, modelID := ExtractProtocol(cfg.Model)
|
protocol, modelID := ExtractProtocol(cfg.Model)
|
||||||
|
if cfg.Protocol != "" {
|
||||||
|
protocol = cfg.Protocol
|
||||||
|
// If protocol was explicitly set, modelID should be the full model string
|
||||||
|
// unless it was already prefixed with the SAME protocol.
|
||||||
|
if p, m, found := strings.Cut(cfg.Model, "/"); found && strings.EqualFold(p, protocol) {
|
||||||
|
modelID = m
|
||||||
|
} else {
|
||||||
|
modelID = cfg.Model
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
userAgent := cfg.UserAgent
|
userAgent := cfg.UserAgent
|
||||||
if userAgent == "" {
|
if userAgent == "" {
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ func TestExtractProtocol(t *testing.T) {
|
||||||
wantModelID: "gpt-4",
|
wantModelID: "gpt-4",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multiple slashes",
|
name: "multiple slashes (nvidia organizational prefix)",
|
||||||
model: "nvidia/meta/llama-3.1-8b",
|
model: "nvidia/meta/llama-3.1-8b",
|
||||||
wantProtocol: "nvidia",
|
wantProtocol: "nvidia",
|
||||||
wantModelID: "meta/llama-3.1-8b",
|
wantModelID: "meta/llama-3.1-8b",
|
||||||
|
|
@ -538,19 +538,6 @@ func TestCreateProviderFromConfig_MissingAPIKey(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateProviderFromConfig_UnknownProtocol(t *testing.T) {
|
|
||||||
cfg := &config.ModelConfig{
|
|
||||||
ModelName: "test-unknown",
|
|
||||||
Model: "unknown-protocol/model",
|
|
||||||
}
|
|
||||||
cfg.SetAPIKey("test-key")
|
|
||||||
|
|
||||||
_, _, err := CreateProviderFromConfig(cfg)
|
|
||||||
if err == nil {
|
|
||||||
t.Fatal("CreateProviderFromConfig() expected error for unknown protocol")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCreateProviderFromConfig_NilConfig(t *testing.T) {
|
func TestCreateProviderFromConfig_NilConfig(t *testing.T) {
|
||||||
_, _, err := CreateProviderFromConfig(nil)
|
_, _, err := CreateProviderFromConfig(nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,6 @@ var stripModelPrefixProviders = map[string]struct{}{
|
||||||
"litellm": {},
|
"litellm": {},
|
||||||
"venice": {},
|
"venice": {},
|
||||||
"moonshot": {},
|
"moonshot": {},
|
||||||
"nvidia": {},
|
|
||||||
"groq": {},
|
"groq": {},
|
||||||
"ollama": {},
|
"ollama": {},
|
||||||
"deepseek": {},
|
"deepseek": {},
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ const (
|
||||||
FailoverFormat FailoverReason = "format"
|
FailoverFormat FailoverReason = "format"
|
||||||
FailoverContextOverflow FailoverReason = "context_overflow"
|
FailoverContextOverflow FailoverReason = "context_overflow"
|
||||||
FailoverOverloaded FailoverReason = "overloaded"
|
FailoverOverloaded FailoverReason = "overloaded"
|
||||||
|
FailoverNotFound FailoverReason = "not_found"
|
||||||
FailoverUnknown FailoverReason = "unknown"
|
FailoverUnknown FailoverReason = "unknown"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
404
pkg/tools/freeride.go
Normal file
404
pkg/tools/freeride.go
Normal file
|
|
@ -0,0 +1,404 @@
|
||||||
|
package tools
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/sipeed/picoclaw/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FreeRideTool adapts the FreeRide logic (from clawhub/free-ride) for PicoClaw.
|
||||||
|
// It manages OpenRouter's free models and configures them as fallbacks.
|
||||||
|
type FreeRideTool struct {
|
||||||
|
configPath string
|
||||||
|
reloadFunc func() error
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFreeRideTool(configPath string, reloadFunc func() error) *FreeRideTool {
|
||||||
|
return &FreeRideTool{
|
||||||
|
configPath: configPath,
|
||||||
|
reloadFunc: reloadFunc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *FreeRideTool) Name() string {
|
||||||
|
return "freeride"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *FreeRideTool) Description() string {
|
||||||
|
return "FreeRide gives you unlimited free AI in PicoClaw by automatically managing OpenRouter's free models. " +
|
||||||
|
"Use 'auto' to configure best model + fallbacks, or 'list' to see available free models."
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *FreeRideTool) Parameters() map[string]any {
|
||||||
|
return map[string]any{
|
||||||
|
"type": "object",
|
||||||
|
"properties": map[string]any{
|
||||||
|
"command": map[string]any{
|
||||||
|
"type": "string",
|
||||||
|
"enum": []string{"auto", "list", "status", "settimeout"},
|
||||||
|
"description": "The command to run: 'auto' (configures models), 'list' (shows free models), 'status' (checks current setup), 'settimeout' (sets request timeout)",
|
||||||
|
},
|
||||||
|
"limit": map[string]any{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "For 'list', how many models to show. For 'auto', how many fallbacks to configure.",
|
||||||
|
"default": 5,
|
||||||
|
},
|
||||||
|
"timeout": map[string]any{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "For 'settimeout', the request timeout in seconds (default 300)",
|
||||||
|
"default": 300,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": []string{"command"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type openRouterModel struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
ContextLength int `json:"context_length"`
|
||||||
|
Pricing struct {
|
||||||
|
Prompt string `json:"prompt"`
|
||||||
|
Completion string `json:"completion"`
|
||||||
|
} `json:"pricing"`
|
||||||
|
SupportedParameters []string `json:"supported_parameters"`
|
||||||
|
Created int64 `json:"created"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *FreeRideTool) Execute(ctx context.Context, args map[string]any) *ToolResult {
|
||||||
|
cmd, _ := args["command"].(string)
|
||||||
|
limit := 5
|
||||||
|
if l, ok := args["limit"].(float64); ok {
|
||||||
|
limit = int(l)
|
||||||
|
}
|
||||||
|
timeout := 300
|
||||||
|
switch v := args["timeout"].(type) {
|
||||||
|
case float64:
|
||||||
|
timeout = int(v)
|
||||||
|
case int:
|
||||||
|
timeout = v
|
||||||
|
}
|
||||||
|
|
||||||
|
switch cmd {
|
||||||
|
case "list":
|
||||||
|
return t.handleList(ctx, limit)
|
||||||
|
case "auto":
|
||||||
|
return t.handleAuto(ctx, limit)
|
||||||
|
case "status":
|
||||||
|
return t.handleStatus()
|
||||||
|
case "settimeout":
|
||||||
|
return t.handleSetTimeout(timeout)
|
||||||
|
default:
|
||||||
|
return ErrorResult(fmt.Sprintf("unknown command: %s", cmd))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *FreeRideTool) fetchFreeModels(ctx context.Context) ([]openRouterModel, error) {
|
||||||
|
req, err := http.NewRequestWithContext(ctx, "GET", "https://openrouter.ai/api/v1/models", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("OpenRouter API returned status %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
var wrapper struct {
|
||||||
|
Data []openRouterModel `json:"data"`
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&wrapper); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var freeModels []openRouterModel
|
||||||
|
for _, m := range wrapper.Data {
|
||||||
|
// Only consider free models
|
||||||
|
if m.Pricing.Prompt == "0" || m.Pricing.Prompt == "0.0" || m.Pricing.Prompt == "0.00" {
|
||||||
|
// CRITICAL: PeakClaw requires tool support for its steering logic.
|
||||||
|
// Filter out models that don't explicitly support function calling.
|
||||||
|
hasTools := false
|
||||||
|
for _, p := range m.SupportedParameters {
|
||||||
|
if p == "tools" {
|
||||||
|
hasTools = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !hasTools {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Blacklist known tool-blind models with inaccurate metadata
|
||||||
|
lowerID := strings.ToLower(m.ID)
|
||||||
|
if strings.Contains(lowerID, "lyria") || strings.Contains(lowerID, "liquid") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
freeModels = append(freeModels, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rank models
|
||||||
|
sort.Slice(freeModels, func(i, j int) bool {
|
||||||
|
return scoreModel(freeModels[i]) > scoreModel(freeModels[j])
|
||||||
|
})
|
||||||
|
|
||||||
|
return freeModels, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func scoreModel(m openRouterModel) float64 {
|
||||||
|
score := 0.0
|
||||||
|
|
||||||
|
// Context length (40%) - normalize against 128k
|
||||||
|
ctxScore := float64(m.ContextLength) / 128000.0
|
||||||
|
if ctxScore > 1.0 {
|
||||||
|
ctxScore = 1.0
|
||||||
|
}
|
||||||
|
score += ctxScore * 0.4
|
||||||
|
|
||||||
|
// Capabilities (30%) - tools, vision, prompt caching, etc.
|
||||||
|
capabilityScore := 0.0
|
||||||
|
for _, p := range m.SupportedParameters {
|
||||||
|
if p == "tools" {
|
||||||
|
capabilityScore += 0.5
|
||||||
|
}
|
||||||
|
if p == "response_format" {
|
||||||
|
capabilityScore += 0.5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if capabilityScore > 1.0 {
|
||||||
|
capabilityScore = 1.0
|
||||||
|
}
|
||||||
|
score += capabilityScore * 0.3
|
||||||
|
|
||||||
|
// Recency (20%) - newer is better
|
||||||
|
// Normalize against 2 years ago
|
||||||
|
twoYearsAgo := time.Now().AddDate(-2, 0, 0).Unix()
|
||||||
|
now := time.Now().Unix()
|
||||||
|
if m.Created > twoYearsAgo {
|
||||||
|
recencyScore := float64(m.Created-twoYearsAgo) / float64(now-twoYearsAgo)
|
||||||
|
score += recencyScore * 0.2
|
||||||
|
}
|
||||||
|
|
||||||
|
// Provider Trust (10%) - hardcoded list of trusted names
|
||||||
|
trustNames := []string{
|
||||||
|
"google",
|
||||||
|
"meta",
|
||||||
|
"nvidia",
|
||||||
|
"mistral",
|
||||||
|
"anthropic",
|
||||||
|
"openai",
|
||||||
|
"microsoft",
|
||||||
|
"qwen",
|
||||||
|
"deepseek",
|
||||||
|
}
|
||||||
|
for _, name := range trustNames {
|
||||||
|
if strings.Contains(strings.ToLower(m.ID), name) {
|
||||||
|
score += 0.1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return score
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *FreeRideTool) handleList(ctx context.Context, limit int) *ToolResult {
|
||||||
|
models, err := t.fetchFreeModels(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return ErrorResult(fmt.Errorf("failed to fetch models: %w", err).Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(models) == 0 {
|
||||||
|
return SilentResult("No free models found on OpenRouter.")
|
||||||
|
}
|
||||||
|
|
||||||
|
var sb strings.Builder
|
||||||
|
sb.WriteString(fmt.Sprintf("Found %d free models on OpenRouter (ranked by quality):\n\n", len(models)))
|
||||||
|
for i, m := range models {
|
||||||
|
if i >= limit {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
sb.WriteString(fmt.Sprintf("%d. **%s** (%s)\n", i+1, m.Name, m.ID))
|
||||||
|
sb.WriteString(fmt.Sprintf(" Context: %d tokens | Score: %.2f\n", m.ContextLength, scoreModel(m)))
|
||||||
|
sb.WriteString(fmt.Sprintf(" Parameters: %s\n\n", strings.Join(m.SupportedParameters, ", ")))
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserResult(sb.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *FreeRideTool) handleAuto(ctx context.Context, limit int) *ToolResult {
|
||||||
|
models, err := t.fetchFreeModels(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return ErrorResult(fmt.Errorf("failed to fetch models: %w", err).Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(models) == 0 {
|
||||||
|
return ErrorResult("No free models found on OpenRouter.")
|
||||||
|
}
|
||||||
|
|
||||||
|
cfgObj, err := config.LoadConfig(t.configPath)
|
||||||
|
if err != nil {
|
||||||
|
return ErrorResult(fmt.Errorf("failed to load config: %w", err).Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Add models to ModelList if not present
|
||||||
|
// 2. Collect all valid free models for fallbacks (new AND existing)
|
||||||
|
var fallbackModels []string
|
||||||
|
for i, m := range models {
|
||||||
|
if i >= limit {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
modelName := strings.ReplaceAll(m.ID, "/", "-")
|
||||||
|
if !modelExists(cfgObj, modelName) {
|
||||||
|
mc := &config.ModelConfig{
|
||||||
|
ModelName: modelName,
|
||||||
|
Model: m.ID,
|
||||||
|
Protocol: "openrouter",
|
||||||
|
Enabled: true,
|
||||||
|
}
|
||||||
|
mc.SetAPIKey("env://OPENROUTER_API_KEY")
|
||||||
|
cfgObj.ModelList = append(cfgObj.ModelList, mc)
|
||||||
|
}
|
||||||
|
fallbackModels = append(fallbackModels, modelName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Set fallbacks for the default agent
|
||||||
|
if len(fallbackModels) > 0 {
|
||||||
|
// Update AgentDefaults fallbacks
|
||||||
|
cfgObj.Agents.Defaults.ModelFallbacks = append(cfgObj.Agents.Defaults.ModelFallbacks, fallbackModels...)
|
||||||
|
// Deduplicate fallbacks
|
||||||
|
cfgObj.Agents.Defaults.ModelFallbacks = uniqueStrings(cfgObj.Agents.Defaults.ModelFallbacks)
|
||||||
|
|
||||||
|
if err := config.SaveConfig(t.configPath, cfgObj); err != nil {
|
||||||
|
return ErrorResult(fmt.Errorf("failed to save config: %w", err).Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := fmt.Sprintf(
|
||||||
|
"Success! Added %d free models as fallbacks: %s.\n",
|
||||||
|
len(fallbackModels),
|
||||||
|
strings.Join(fallbackModels, ", "),
|
||||||
|
)
|
||||||
|
msg += "Re-loading configuration to apply changes..."
|
||||||
|
|
||||||
|
if t.reloadFunc != nil {
|
||||||
|
if err := t.reloadFunc(); err != nil {
|
||||||
|
return ErrorResult(fmt.Sprintf("%s\nFailed to reload: %v", msg, err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserResult(msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserResult(
|
||||||
|
"No new free models to add. Your configuration is up to date.",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *FreeRideTool) handleStatus() *ToolResult {
|
||||||
|
cfgObj, err := config.LoadConfig(t.configPath)
|
||||||
|
if err != nil {
|
||||||
|
return ErrorResult(fmt.Errorf("failed to load config: %w", err).Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
var sb strings.Builder
|
||||||
|
sb.WriteString("FreeRide Status:\n")
|
||||||
|
sb.WriteString(fmt.Sprintf("- Primary Model: %s\n", cfgObj.Agents.Defaults.GetModelName()))
|
||||||
|
sb.WriteString(fmt.Sprintf("- Fallback Models: %s\n", strings.Join(cfgObj.Agents.Defaults.ModelFallbacks, ", ")))
|
||||||
|
|
||||||
|
// Check for OpenRouter models in fallbacks
|
||||||
|
openRouterCount := 0
|
||||||
|
for _, fb := range cfgObj.Agents.Defaults.ModelFallbacks {
|
||||||
|
if strings.Contains(strings.ToLower(fb), "openrouter") || isKnownOpenRouterAlias(cfgObj, fb) {
|
||||||
|
openRouterCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.WriteString(fmt.Sprintf("- Managed Free Models: %d\n", openRouterCount))
|
||||||
|
|
||||||
|
return UserResult(sb.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *FreeRideTool) handleSetTimeout(timeoutSeconds int) *ToolResult {
|
||||||
|
if timeoutSeconds < 30 {
|
||||||
|
return ErrorResult("timeout must be at least 30 seconds")
|
||||||
|
}
|
||||||
|
|
||||||
|
cfgObj, err := config.LoadConfig(t.configPath)
|
||||||
|
if err != nil {
|
||||||
|
return ErrorResult(fmt.Errorf("failed to load config: %w", err).Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
updated := 0
|
||||||
|
for _, mc := range cfgObj.ModelList {
|
||||||
|
// Only update OpenRouter models (free models)
|
||||||
|
protocol := strings.ToLower(mc.Protocol)
|
||||||
|
if protocol == "openrouter" {
|
||||||
|
mc.RequestTimeout = timeoutSeconds
|
||||||
|
updated++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if updated == 0 {
|
||||||
|
return ErrorResult("no OpenRouter models found in config. Run 'freeride auto' first.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := config.SaveConfig(t.configPath, cfgObj); err != nil {
|
||||||
|
return ErrorResult(fmt.Errorf("failed to save config: %w", err).Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("Set request timeout to %d seconds for %d OpenRouter models.\n", timeoutSeconds, updated)
|
||||||
|
msg += "Re-loading configuration to apply changes..."
|
||||||
|
|
||||||
|
if t.reloadFunc != nil {
|
||||||
|
if err := t.reloadFunc(); err != nil {
|
||||||
|
return ErrorResult(fmt.Sprintf("%s\nFailed to reload: %v", msg, err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserResult(msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func modelExists(cfg *config.Config, modelName string) bool {
|
||||||
|
for _, m := range cfg.ModelList {
|
||||||
|
if m.ModelName == modelName {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func isKnownOpenRouterAlias(cfg *config.Config, modelName string) bool {
|
||||||
|
for _, m := range cfg.ModelList {
|
||||||
|
if m.ModelName == modelName {
|
||||||
|
if strings.HasPrefix(m.Model, "openrouter/") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if strings.ToLower(m.Protocol) == "openrouter" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func uniqueStrings(input []string) []string {
|
||||||
|
keys := make(map[string]bool)
|
||||||
|
list := []string{}
|
||||||
|
for _, entry := range input {
|
||||||
|
if _, value := keys[entry]; !value {
|
||||||
|
keys[entry] = true
|
||||||
|
list = append(list, entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
316
pkg/tools/freeride_test.go
Normal file
316
pkg/tools/freeride_test.go
Normal file
|
|
@ -0,0 +1,316 @@
|
||||||
|
package tools
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/sipeed/picoclaw/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFreeRideTool_List(t *testing.T) {
|
||||||
|
// Mock OpenRouter API
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(map[string]any{
|
||||||
|
"data": []map[string]any{
|
||||||
|
{
|
||||||
|
"id": "google/gemini-pro-1.5",
|
||||||
|
"name": "Gemini Pro 1.5",
|
||||||
|
"context_length": 128000,
|
||||||
|
"pricing": map[string]string{
|
||||||
|
"prompt": "0",
|
||||||
|
"completion": "0",
|
||||||
|
},
|
||||||
|
"created": 1700000000,
|
||||||
|
"supported_parameters": []string{"tools"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "meta-llama/llama-3-8b",
|
||||||
|
"name": "Llama 3 8B",
|
||||||
|
"context_length": 8000,
|
||||||
|
"pricing": map[string]string{
|
||||||
|
"prompt": "0.0001",
|
||||||
|
"completion": "0.0001",
|
||||||
|
},
|
||||||
|
"created": 1700000000,
|
||||||
|
"supported_parameters": []string{"tools"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
// Override default transport to use mock server
|
||||||
|
oldTransport := http.DefaultClient.Transport
|
||||||
|
http.DefaultClient.Transport = &mockTransport{server.URL}
|
||||||
|
defer func() { http.DefaultClient.Transport = oldTransport }()
|
||||||
|
|
||||||
|
tool := NewFreeRideTool("config.json", nil)
|
||||||
|
result := tool.Execute(context.Background(), map[string]any{
|
||||||
|
"command": "list",
|
||||||
|
})
|
||||||
|
|
||||||
|
if result.IsError {
|
||||||
|
t.Fatalf("Expected no error, got %s", result.ForLLM)
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Silent {
|
||||||
|
t.Errorf("Expected non-silent result")
|
||||||
|
}
|
||||||
|
|
||||||
|
output := result.ForLLM
|
||||||
|
if !contains(output, "Gemini Pro 1.5") {
|
||||||
|
t.Errorf("Expected Gemini Pro 1.5 in output, got %s", output)
|
||||||
|
}
|
||||||
|
if contains(output, "Llama 3 8B") {
|
||||||
|
t.Errorf("Did not expect paid model Llama 3 8B in output, got %s", output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFreeRideTool_Auto(t *testing.T) {
|
||||||
|
os.Setenv("OPENROUTER_API_KEY", "sk-test-key")
|
||||||
|
defer os.Unsetenv("OPENROUTER_API_KEY")
|
||||||
|
|
||||||
|
tempDir, err := os.MkdirTemp("", "freeride-test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
|
||||||
|
configPath := filepath.Join(tempDir, "config.json")
|
||||||
|
initialCfg := &config.Config{
|
||||||
|
ModelList: []*config.ModelConfig{},
|
||||||
|
}
|
||||||
|
initialCfg.Agents.Defaults.ModelName = "existing-model"
|
||||||
|
|
||||||
|
if err := config.SaveConfig(configPath, initialCfg); err != nil {
|
||||||
|
t.Fatalf("failed to save initial config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mock OpenRouter API
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(map[string]any{
|
||||||
|
"data": []map[string]any{
|
||||||
|
{
|
||||||
|
"id": "google/gemini-pro-1.5",
|
||||||
|
"name": "Gemini Pro 1.5",
|
||||||
|
"context_length": 128000,
|
||||||
|
"pricing": map[string]string{
|
||||||
|
"prompt": "0",
|
||||||
|
"completion": "0",
|
||||||
|
},
|
||||||
|
"created": 1700000000,
|
||||||
|
"supported_parameters": []string{"tools"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
oldTransport := http.DefaultClient.Transport
|
||||||
|
http.DefaultClient.Transport = &mockTransport{server.URL}
|
||||||
|
defer func() { http.DefaultClient.Transport = oldTransport }()
|
||||||
|
|
||||||
|
var reloadCalled bool
|
||||||
|
reloadFunc := func() error {
|
||||||
|
reloadCalled = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
tool := NewFreeRideTool(configPath, reloadFunc)
|
||||||
|
result := tool.Execute(context.Background(), map[string]any{
|
||||||
|
"command": "auto",
|
||||||
|
})
|
||||||
|
|
||||||
|
if result.IsError {
|
||||||
|
t.Fatalf("Expected no error, got %s", result.ForLLM)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reloadCalled {
|
||||||
|
t.Errorf("Expected reloadFunc to be called")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify config
|
||||||
|
cfg, err := config.LoadConfig(configPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to load updated config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(cfg.ModelList) != 1 {
|
||||||
|
t.Errorf("Expected 1 model in ModelList, got %d", len(cfg.ModelList))
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.ModelList[0].ModelName != "google-gemini-pro-1.5" {
|
||||||
|
t.Errorf("Expected model name google-gemini-pro-1.5, got %s", cfg.ModelList[0].ModelName)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(cfg.Agents.Defaults.ModelFallbacks) != 1 {
|
||||||
|
t.Errorf("Expected 1 fallback, got %d", len(cfg.Agents.Defaults.ModelFallbacks))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFreeRideTool_SetTimeout(t *testing.T) {
|
||||||
|
tempDir, err := os.MkdirTemp("", "freeride-test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
|
||||||
|
configPath := filepath.Join(tempDir, "config.json")
|
||||||
|
initialCfg := &config.Config{
|
||||||
|
ModelList: []*config.ModelConfig{
|
||||||
|
{
|
||||||
|
ModelName: "google-gemini-pro-1.5",
|
||||||
|
Model: "google/gemini-pro-1.5",
|
||||||
|
Protocol: "openrouter",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ModelName: "meta-llama-3-8b",
|
||||||
|
Model: "meta/llama-3-8b",
|
||||||
|
Protocol: "openrouter",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ModelName: "gpt-4o",
|
||||||
|
Model: "openai/gpt-4o",
|
||||||
|
Protocol: "openai",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
initialCfg.Agents.Defaults.ModelName = "gpt-4o"
|
||||||
|
|
||||||
|
if err := config.SaveConfig(configPath, initialCfg); err != nil {
|
||||||
|
t.Fatalf("failed to save initial config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var reloadCalled bool
|
||||||
|
reloadFunc := func() error {
|
||||||
|
reloadCalled = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
tool := NewFreeRideTool(configPath, reloadFunc)
|
||||||
|
result := tool.Execute(context.Background(), map[string]any{
|
||||||
|
"command": "settimeout",
|
||||||
|
"timeout": 180,
|
||||||
|
})
|
||||||
|
|
||||||
|
if result.IsError {
|
||||||
|
t.Fatalf("Expected no error, got %s", result.ForLLM)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reloadCalled {
|
||||||
|
t.Errorf("Expected reloadFunc to be called")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify config
|
||||||
|
cfg, err := config.LoadConfig(configPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to load updated config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should have updated 2 openrouter models
|
||||||
|
if cfg.ModelList[0].RequestTimeout != 180 {
|
||||||
|
t.Errorf("Expected timeout 180 for google-gemini-pro-1.5, got %d", cfg.ModelList[0].RequestTimeout)
|
||||||
|
}
|
||||||
|
if cfg.ModelList[1].RequestTimeout != 180 {
|
||||||
|
t.Errorf("Expected timeout 180 for meta-llama-3-8b, got %d", cfg.ModelList[1].RequestTimeout)
|
||||||
|
}
|
||||||
|
// openai model should NOT be updated
|
||||||
|
if cfg.ModelList[2].RequestTimeout != 0 {
|
||||||
|
t.Errorf("Expected timeout 0 for gpt-4o (non-openrouter), got %d", cfg.ModelList[2].RequestTimeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFreeRideTool_SetTimeout_NoOpenRouterModels(t *testing.T) {
|
||||||
|
tempDir, err := os.MkdirTemp("", "freeride-test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
|
||||||
|
configPath := filepath.Join(tempDir, "config.json")
|
||||||
|
initialCfg := &config.Config{
|
||||||
|
ModelList: []*config.ModelConfig{
|
||||||
|
{
|
||||||
|
ModelName: "gpt-4o",
|
||||||
|
Model: "openai/gpt-4o",
|
||||||
|
Protocol: "openai",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := config.SaveConfig(configPath, initialCfg); err != nil {
|
||||||
|
t.Fatalf("failed to save initial config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tool := NewFreeRideTool(configPath, nil)
|
||||||
|
result := tool.Execute(context.Background(), map[string]any{
|
||||||
|
"command": "settimeout",
|
||||||
|
"timeout": 180,
|
||||||
|
})
|
||||||
|
|
||||||
|
if !result.IsError {
|
||||||
|
t.Fatalf("Expected error when no OpenRouter models, got success")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !contains(result.ForLLM, "no OpenRouter models") {
|
||||||
|
t.Errorf("Expected error message about no OpenRouter models, got %s", result.ForLLM)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFreeRideTool_SetTimeout_MinimumTooLow(t *testing.T) {
|
||||||
|
tempDir, err := os.MkdirTemp("", "freeride-test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
|
||||||
|
configPath := filepath.Join(tempDir, "config.json")
|
||||||
|
initialCfg := &config.Config{
|
||||||
|
ModelList: []*config.ModelConfig{
|
||||||
|
{
|
||||||
|
ModelName: "google-gemini-pro-1.5",
|
||||||
|
Model: "google/gemini-pro-1.5",
|
||||||
|
Protocol: "openrouter",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := config.SaveConfig(configPath, initialCfg); err != nil {
|
||||||
|
t.Fatalf("failed to save initial config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tool := NewFreeRideTool(configPath, nil)
|
||||||
|
result := tool.Execute(context.Background(), map[string]any{
|
||||||
|
"command": "settimeout",
|
||||||
|
"timeout": 20, // too low
|
||||||
|
})
|
||||||
|
|
||||||
|
if !result.IsError {
|
||||||
|
t.Fatalf("Expected error when timeout < 30, got success")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !contains(result.ForLLM, "at least 30") {
|
||||||
|
t.Errorf("Expected error message about minimum 30 seconds, got %s", result.ForLLM)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type mockTransport struct {
|
||||||
|
url string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
|
newReq, _ := http.NewRequest(req.Method, m.url, req.Body)
|
||||||
|
return http.DefaultTransport.RoundTrip(newReq)
|
||||||
|
}
|
||||||
|
|
||||||
|
func contains(s, substr string) bool {
|
||||||
|
return strings.Contains(s, substr)
|
||||||
|
}
|
||||||
28
scratch/check_paths.go
Normal file
28
scratch/check_paths.go
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/sipeed/picoclaw/pkg/agent"
|
||||||
|
"github.com/sipeed/picoclaw/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
cfg, err := config.LoadConfig(os.ExpandEnv("$HOME/.picoclaw/config.json"))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
registry := agent.NewAgentRegistry(cfg, nil)
|
||||||
|
defaultAgent := registry.GetDefaultAgent()
|
||||||
|
if defaultAgent == nil {
|
||||||
|
fmt.Println("No default agent")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cooldownPath := filepath.Join(filepath.Dir(filepath.Clean(defaultAgent.Workspace)), "cooldowns.json")
|
||||||
|
fmt.Printf("Workspace: %s\n", defaultAgent.Workspace)
|
||||||
|
fmt.Printf("Cooldown Path: %s\n", cooldownPath)
|
||||||
|
}
|
||||||
17
workspace/skills/freeride/SKILL.md
Normal file
17
workspace/skills/freeride/SKILL.md
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
# FreeRide Skill
|
||||||
|
|
||||||
|
FreeRide gives you unlimited free AI in PicoClaw by automatically managing OpenRouter's free models.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
- `/freeride auto`: Auto-configure best model + fallbacks.
|
||||||
|
- `/freeride list`: See all 30+ free models ranked.
|
||||||
|
- `/freeride status`: Check your current setup.
|
||||||
|
|
||||||
|
## How it works
|
||||||
|
|
||||||
|
The skill uses the `freeride` tool to fetch free models from OpenRouter, ranks them by context length, capabilities, recency, and provider trust, and then updates your PicoClaw configuration with the best models as fallbacks.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
Ensure you have your OpenRouter API key set in your K3s secrets or environment variables as `OPENROUTER_API_KEY`.
|
||||||
Loading…
Add table
Reference in a new issue