Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bdad44de7d | |||
| 432a8db938 | |||
| a536375f41 | |||
| 8a631831df | |||
| 98d0b5200b | |||
| af1c509257 | |||
| 9b1c8b5566 | |||
| 4fca6bc081 | |||
| ebee173df9 | |||
| fa86bd5712 |
@@ -16,12 +16,15 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
run: |
|
run: |
|
||||||
apk add git bash
|
apk add git bash
|
||||||
|
rm -rf /workspace
|
||||||
|
git clone https://hub.gaomia.site/titor/hxclaw.git /workspace
|
||||||
|
|
||||||
- name: Download dependencies
|
- name: Download dependencies
|
||||||
run: go mod download
|
run: cd /workspace && go mod download
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
|
cd /workspace
|
||||||
for p in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64; do
|
for p in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64; do
|
||||||
os=${p%/*}
|
os=${p%/*}
|
||||||
arch=${p#*/}
|
arch=${p#*/}
|
||||||
@@ -31,12 +34,13 @@ jobs:
|
|||||||
done
|
done
|
||||||
|
|
||||||
- name: Checksums
|
- name: Checksums
|
||||||
run: sha256sum hxclaw-* > checksums.txt
|
run: cd /workspace && sha256sum hxclaw-* > checksums.txt
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.release_token }}
|
GITEA_TOKEN: "${{ secrets.release_token }}"
|
||||||
run: |
|
run: |
|
||||||
|
cd /workspace
|
||||||
apk add curl jq
|
apk add curl jq
|
||||||
|
|
||||||
TAG_NAME="${GITHUB_REF#refs/tags/}"
|
TAG_NAME="${GITHUB_REF#refs/tags/}"
|
||||||
|
|||||||
54
agents.md
54
agents.md
@@ -57,20 +57,48 @@
|
|||||||
|
|
||||||
### v0.1.0 已完成功能
|
### v0.1.0 已完成功能
|
||||||
|
|
||||||
1. **流式输出**
|
1. **流式输出(新流程)**
|
||||||
- 实时打印 token
|
- 等待 AI 返回完整响应
|
||||||
- Spinner 显示"思考中..."
|
- Markdown 转译
|
||||||
- 第一个 token 到达时停止 spinner
|
- 模拟流式输出(从配置读取速度)
|
||||||
|
- 效果更好,无残留问题
|
||||||
|
|
||||||
2. **Markdown 渲染**
|
2. **Markdown 渲染**
|
||||||
- 使用 glamour 库渲染 Markdown
|
- 使用 glamour 库渲染 Markdown
|
||||||
- 支持多种主题(dark, light, dracula, tokyo-night 等)
|
- 支持多种主题(dark, light, dracula, tokyo-night 等)
|
||||||
- 通过 GLAMOUR_STYLE 环境变量配置主题
|
- 通过 project.config.yml 配置主题
|
||||||
|
|
||||||
3. **重绘逻辑**
|
3. **项目配置**
|
||||||
- 响应完成后尝试重绘
|
- 通过 project.config.yml 统一管理配置项
|
||||||
- 使用 termenv 库清除屏幕
|
- 支持流式速度、渲染主题、Logo 等配置
|
||||||
- ⚠️ 存在轻微残留 bug(可接受)
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 项目配置
|
||||||
|
|
||||||
|
### project.config.yml
|
||||||
|
|
||||||
|
配置文件位于项目根目录:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# hxclaw 项目配置文件
|
||||||
|
|
||||||
|
# 模拟流式输出配置
|
||||||
|
streaming:
|
||||||
|
simulated_speed_ms: 30 # 模拟流式输出速度(毫秒/字符)
|
||||||
|
|
||||||
|
# Markdown 渲染配置
|
||||||
|
markdown:
|
||||||
|
glamour_style: dark # 渲染主题:dark, light, dracula, tokyo-night 等
|
||||||
|
|
||||||
|
# UI 配置
|
||||||
|
ui:
|
||||||
|
logo: "🦐"
|
||||||
|
```
|
||||||
|
|
||||||
|
配置加载优先级:
|
||||||
|
1. 环境变量 `HXCLAW_CONFIG` 指定路径
|
||||||
|
2. 项目根目录 `project.config.yml`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -82,12 +110,14 @@
|
|||||||
- `charm.land/lipgloss/v2` - 终端样式
|
- `charm.land/lipgloss/v2` - 终端样式
|
||||||
- `charm.land/x/term` - 终端控制
|
- `charm.land/x/term` - 终端控制
|
||||||
- `github.com/muesli/termenv` - 终端环境工具
|
- `github.com/muesli/termenv` - 终端环境工具
|
||||||
|
- `gopkg.in/yaml.v3` - 配置文件解析
|
||||||
|
|
||||||
### 配置文件
|
### 配置文件
|
||||||
|
|
||||||
- `cmd/hxclaw/main.go` - 主入口逻辑
|
- `cmd/hxclaw/main.go` - 主入口逻辑
|
||||||
- `cmd/hxclaw/internal/markdown.go` - Markdown 渲染器
|
- `cmd/hxclaw/internal/markdown.go` - Markdown 渲染器
|
||||||
- `cmd/hxclaw/internal/helpers.go` - 辅助函数
|
- `cmd/hxclaw/internal/helpers.go` - 辅助函数
|
||||||
|
- `cmd/hxclaw/internal/config.go` - 项目配置加载
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -100,14 +130,16 @@
|
|||||||
|
|
||||||
## 待优化
|
## 待优化
|
||||||
|
|
||||||
1. 优化重绘逻辑,解决残留问题
|
1. 优化重绘逻辑,解决残留问题(已通过新流程解决)
|
||||||
2. 添加更多主题支持
|
2. 添加更多主题支持
|
||||||
3. 添加命令-line 参数支持主题选择
|
3. 添加命令行参数支持主题选择
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 构建命令
|
## 构建命令
|
||||||
|
|
||||||
|
picoclaw GitHub地址:https://github.com/sipeed/picoclaw.git
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go build -o hxclaw ./cmd/hxclaw
|
go build -o hxclaw ./cmd/hxclaw
|
||||||
```
|
```
|
||||||
|
|||||||
112
cmd/hxclaw/internal/config.go
Normal file
112
cmd/hxclaw/internal/config.go
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ProjectConfig struct {
|
||||||
|
Streaming StreamingConfig `yaml:"streaming"`
|
||||||
|
Markdown MarkdownConfig `yaml:"markdown"`
|
||||||
|
UI UIConfig `yaml:"ui"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type StreamingConfig struct {
|
||||||
|
LineDelayMs int `yaml:"line_delay_ms"`
|
||||||
|
LastLineDelayMs int `yaml:"last_line_delay_ms"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MarkdownConfig struct {
|
||||||
|
GlamourStyle string `yaml:"glamour_style"`
|
||||||
|
WrapWidth int `yaml:"wrap_width"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UIConfig struct {
|
||||||
|
Logo string `yaml:"logo"`
|
||||||
|
UserPrefix string `yaml:"user_prefix"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
defaultCfg = ProjectConfig{
|
||||||
|
Streaming: StreamingConfig{
|
||||||
|
LineDelayMs: 1000,
|
||||||
|
LastLineDelayMs: 600,
|
||||||
|
},
|
||||||
|
Markdown: MarkdownConfig{
|
||||||
|
GlamourStyle: "dark",
|
||||||
|
WrapWidth: 0,
|
||||||
|
},
|
||||||
|
UI: UIConfig{
|
||||||
|
Logo: "🦐",
|
||||||
|
UserPrefix: "👀 ",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
projCfg *ProjectConfig
|
||||||
|
projCfgLock sync.RWMutex
|
||||||
|
)
|
||||||
|
|
||||||
|
func LoadProjectConfig() error {
|
||||||
|
projCfgLock.Lock()
|
||||||
|
defer projCfgLock.Unlock()
|
||||||
|
|
||||||
|
cfgPath := getConfigPath()
|
||||||
|
if cfgPath == "" {
|
||||||
|
projCfg = &defaultCfg
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := os.ReadFile(cfgPath)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
projCfg = &defaultCfg
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var cfg ProjectConfig
|
||||||
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.Streaming.LineDelayMs <= 0 {
|
||||||
|
cfg.Streaming.LineDelayMs = defaultCfg.Streaming.LineDelayMs
|
||||||
|
}
|
||||||
|
if cfg.Streaming.LastLineDelayMs <= 0 {
|
||||||
|
cfg.Streaming.LastLineDelayMs = defaultCfg.Streaming.LastLineDelayMs
|
||||||
|
}
|
||||||
|
if cfg.Markdown.GlamourStyle == "" {
|
||||||
|
cfg.Markdown.GlamourStyle = defaultCfg.Markdown.GlamourStyle
|
||||||
|
}
|
||||||
|
if cfg.Markdown.WrapWidth < 0 {
|
||||||
|
cfg.Markdown.WrapWidth = 0
|
||||||
|
}
|
||||||
|
if cfg.UI.Logo == "" {
|
||||||
|
cfg.UI.Logo = defaultCfg.UI.Logo
|
||||||
|
}
|
||||||
|
if cfg.UI.UserPrefix == "" {
|
||||||
|
cfg.UI.UserPrefix = defaultCfg.UI.UserPrefix
|
||||||
|
}
|
||||||
|
|
||||||
|
projCfg = &cfg
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetProjectConfig() *ProjectConfig {
|
||||||
|
projCfgLock.RLock()
|
||||||
|
defer projCfgLock.RUnlock()
|
||||||
|
if projCfg == nil {
|
||||||
|
return &defaultCfg
|
||||||
|
}
|
||||||
|
return projCfg
|
||||||
|
}
|
||||||
|
|
||||||
|
func getConfigPath() string {
|
||||||
|
if path := os.Getenv("HXCLAW_CONFIG"); path != "" {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
return filepath.Join(".", "project.config.yml")
|
||||||
|
}
|
||||||
@@ -2,9 +2,11 @@ package internal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"charm.land/glamour/v2"
|
"charm.land/glamour/v2"
|
||||||
|
"github.com/charmbracelet/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RenderMarkdown(md string) string {
|
func RenderMarkdown(md string) string {
|
||||||
@@ -13,10 +15,11 @@ func RenderMarkdown(md string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
style := getStyle()
|
style := getStyle()
|
||||||
|
wrapWidth := getWrapWidth()
|
||||||
|
|
||||||
r, err := glamour.NewTermRenderer(
|
r, err := glamour.NewTermRenderer(
|
||||||
glamour.WithStandardStyle(style),
|
glamour.WithStandardStyle(style),
|
||||||
glamour.WithWordWrap(80),
|
glamour.WithWordWrap(wrapWidth),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return md
|
return md
|
||||||
@@ -43,10 +46,11 @@ func RenderParagraph(text string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
style := getStyle()
|
style := getStyle()
|
||||||
|
wrapWidth := getWrapWidth()
|
||||||
|
|
||||||
r, err := glamour.NewTermRenderer(
|
r, err := glamour.NewTermRenderer(
|
||||||
glamour.WithStandardStyle(style),
|
glamour.WithStandardStyle(style),
|
||||||
glamour.WithWordWrap(80),
|
glamour.WithWordWrap(wrapWidth),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return text
|
return text
|
||||||
@@ -62,9 +66,33 @@ func RenderParagraph(text string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getStyle() string {
|
func getStyle() string {
|
||||||
style := "dark"
|
if cfg := GetProjectConfig(); cfg != nil {
|
||||||
|
if cfg.Markdown.GlamourStyle != "" {
|
||||||
|
return cfg.Markdown.GlamourStyle
|
||||||
|
}
|
||||||
|
}
|
||||||
if s := os.Getenv("GLAMOUR_STYLE"); s != "" {
|
if s := os.Getenv("GLAMOUR_STYLE"); s != "" {
|
||||||
style = s
|
return s
|
||||||
}
|
}
|
||||||
return style
|
return "dark"
|
||||||
|
}
|
||||||
|
|
||||||
|
func getWrapWidth() int {
|
||||||
|
if cfg := GetProjectConfig(); cfg != nil {
|
||||||
|
if cfg.Markdown.WrapWidth > 0 {
|
||||||
|
return cfg.Markdown.WrapWidth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cols := os.Getenv("COLUMNS"); cols != "" {
|
||||||
|
if w, err := strconv.Atoi(cols); err == nil && w > 0 {
|
||||||
|
return w
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
width, _, err := term.GetSize(0)
|
||||||
|
if err != nil || width <= 0 {
|
||||||
|
return 80
|
||||||
|
}
|
||||||
|
return width
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,16 @@ import (
|
|||||||
"github.com/sipeed/picoclaw/pkg/providers"
|
"github.com/sipeed/picoclaw/pkg/providers"
|
||||||
)
|
)
|
||||||
|
|
||||||
var totalCompletionTokens int
|
|
||||||
|
|
||||||
const Logo = "🦐"
|
const Logo = "🦐"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Printf("%s HxClaw - PicoClaw 增强版 CLI\n\n", Logo)
|
if err := internal.LoadProjectConfig(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "错误:加载项目配置失败: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
logo := internal.GetProjectConfig().UI.Logo
|
||||||
|
fmt.Printf("%s HxClaw - PicoClaw 增强版 CLI\n\n", logo)
|
||||||
|
|
||||||
cfg, err := internal.LoadConfig()
|
cfg, err := internal.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -62,7 +66,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func interactiveMode(agentLoop *agent.AgentLoop, sessionKey string) {
|
func interactiveMode(agentLoop *agent.AgentLoop, sessionKey string) {
|
||||||
prompt := fmt.Sprintf("%s You: ", Logo)
|
prompt := internal.GetProjectConfig().UI.UserPrefix
|
||||||
|
|
||||||
rl, err := internal.NewReadline(prompt)
|
rl, err := internal.NewReadline(prompt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -101,7 +105,7 @@ func interactiveMode(agentLoop *agent.AgentLoop, sessionKey string) {
|
|||||||
func simpleInteractiveMode(agentLoop *agent.AgentLoop, sessionKey string) {
|
func simpleInteractiveMode(agentLoop *agent.AgentLoop, sessionKey string) {
|
||||||
reader := internal.NewSimpleReader()
|
reader := internal.NewSimpleReader()
|
||||||
for {
|
for {
|
||||||
fmt.Print(fmt.Sprintf("%s You: ", Logo))
|
fmt.Print(internal.GetProjectConfig().UI.UserPrefix)
|
||||||
line, err := reader.ReadString()
|
line, err := reader.ReadString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == internal.ErrEOF {
|
if err == internal.ErrEOF {
|
||||||
@@ -126,131 +130,78 @@ func simpleInteractiveMode(agentLoop *agent.AgentLoop, sessionKey string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// runWithStreaming 尝试使用流式输出,如果 Provider 不支持则回退到普通模式
|
// runWithStreaming 使用 ProcessDirect 处理请求,支持工具调用和结果显示
|
||||||
func runWithStreaming(agentLoop *agent.AgentLoop, input, sessionKey string) {
|
func runWithStreaming(agentLoop *agent.AgentLoop, input, sessionKey string) {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
agentInstance := agentLoop.GetRegistry().GetDefaultAgent()
|
|
||||||
if agentInstance == nil {
|
|
||||||
fmt.Println("错误:无法获取 Agent 实例")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
provider := agentInstance.Provider
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
// 判断是否支持流式
|
|
||||||
if sp, ok := provider.(providers.StreamingProvider); ok {
|
|
||||||
// 从 session 中获取历史消息
|
|
||||||
history := agentInstance.Sessions.GetHistory(sessionKey)
|
|
||||||
summary := agentInstance.Sessions.GetSummary(sessionKey)
|
|
||||||
|
|
||||||
// 使用 ContextBuilder 构建消息,包含历史
|
|
||||||
messages := agentInstance.ContextBuilder.BuildMessages(
|
|
||||||
history,
|
|
||||||
summary,
|
|
||||||
input,
|
|
||||||
nil, // media
|
|
||||||
"cli", // channel
|
|
||||||
sessionKey,
|
|
||||||
"", // senderID
|
|
||||||
"", // senderDisplayName
|
|
||||||
)
|
|
||||||
|
|
||||||
// 获取工具定义
|
|
||||||
toolDefs := agentInstance.Tools.ToProviderDefs()
|
|
||||||
|
|
||||||
// 启动 spinner,显示 "思考中..."
|
|
||||||
spinner := internal.NewSpinner("思考中...")
|
spinner := internal.NewSpinner("思考中...")
|
||||||
spinner.Start()
|
spinner.Start()
|
||||||
|
|
||||||
fmt.Print("\n")
|
resp, err := agentLoop.ProcessDirect(context.Background(), input, sessionKey)
|
||||||
var result strings.Builder
|
|
||||||
var printedLen int
|
|
||||||
firstToken := true
|
|
||||||
resp, err := sp.ChatStream(ctx, messages, toolDefs, agentInstance.Model, nil, func(accumulated string) {
|
|
||||||
if firstToken && len(accumulated) > 0 {
|
|
||||||
spinner.Stop()
|
spinner.Stop()
|
||||||
firstToken = false
|
|
||||||
}
|
|
||||||
if len(accumulated) > printedLen {
|
|
||||||
newText := accumulated[printedLen:]
|
|
||||||
fmt.Print(newText)
|
|
||||||
os.Stdout.Sync()
|
|
||||||
result.WriteString(newText)
|
|
||||||
printedLen = len(accumulated)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
spinner.Stop()
|
|
||||||
fmt.Printf("流式调用错误: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if result.Len() > 0 {
|
|
||||||
allOutput := result.String()
|
|
||||||
rendered := internal.RenderMarkdown(allOutput)
|
|
||||||
if rendered != allOutput && rendered != "" {
|
|
||||||
lines := strings.Count(allOutput, "\n") + 1
|
|
||||||
output := termenv.DefaultOutput()
|
|
||||||
output.CursorUp(1)
|
|
||||||
output.ClearLine()
|
|
||||||
output.ClearLines(lines)
|
|
||||||
fmt.Print(rendered)
|
|
||||||
fmt.Println()
|
|
||||||
fmt.Println()
|
|
||||||
} else {
|
|
||||||
fmt.Println()
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
|
|
||||||
elapsed := time.Since(startTime)
|
|
||||||
printStats(resp, elapsed)
|
|
||||||
|
|
||||||
agentInstance.Sessions.AddMessage(sessionKey, "user", input)
|
|
||||||
agentInstance.Sessions.AddMessage(sessionKey, "assistant", allOutput)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
response, err := agentLoop.ProcessDirect(ctx, input, sessionKey)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("错误: %v\n", err)
|
fmt.Printf("错误: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rendered := internal.RenderMarkdown(response)
|
|
||||||
if rendered != "" && rendered != response {
|
rendered := internal.RenderMarkdown(resp)
|
||||||
fmt.Printf("\n%s\n\n", rendered)
|
clearSpinnerLine()
|
||||||
|
outputLineByLine(rendered)
|
||||||
|
|
||||||
|
elapsed := time.Since(startTime)
|
||||||
|
printElapsed(elapsed)
|
||||||
|
}
|
||||||
|
|
||||||
|
func clearSpinnerLine() {
|
||||||
|
output := termenv.DefaultOutput()
|
||||||
|
output.ClearLine()
|
||||||
|
fmt.Print("\r")
|
||||||
|
os.Stdout.Sync()
|
||||||
|
}
|
||||||
|
|
||||||
|
func outputLineByLine(text string) {
|
||||||
|
if text == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := strings.Split(text, "\n")
|
||||||
|
totalLines := len(lines)
|
||||||
|
|
||||||
|
cfg := internal.GetProjectConfig()
|
||||||
|
lineDelay := time.Duration(cfg.Streaming.LineDelayMs) * time.Millisecond
|
||||||
|
lastLineDelay := time.Duration(cfg.Streaming.LastLineDelayMs) * time.Millisecond
|
||||||
|
|
||||||
|
for i, line := range lines {
|
||||||
|
if line == "" {
|
||||||
|
fmt.Println()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(line)
|
||||||
|
|
||||||
|
if i < totalLines-1 {
|
||||||
|
time.Sleep(lineDelay)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("\n%s %s\n\n", Logo, response)
|
time.Sleep(lastLineDelay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
iconStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#ffcc80"))
|
iconStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#f0c75e"))
|
||||||
textStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#5c7a9a"))
|
textStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#2b2e32"))
|
||||||
)
|
)
|
||||||
|
|
||||||
func printStats(resp *providers.LLMResponse, elapsed time.Duration) {
|
func printElapsed(elapsed time.Duration) {
|
||||||
if resp == nil || resp.Usage == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
completionTokens := resp.Usage.CompletionTokens
|
|
||||||
if completionTokens <= 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
totalCompletionTokens += completionTokens
|
|
||||||
|
|
||||||
elapsedSec := math.Round(elapsed.Seconds()*10) / 10
|
elapsedSec := math.Round(elapsed.Seconds()*10) / 10
|
||||||
|
|
||||||
thisTokens := formatTokens(completionTokens)
|
|
||||||
totalTokens := formatTokens(totalCompletionTokens)
|
|
||||||
elapsedStr := formatDuration(elapsedSec)
|
elapsedStr := formatDuration(elapsedSec)
|
||||||
|
|
||||||
icon := iconStyle.Render("▣ ")
|
icon := iconStyle.Render("▣ ")
|
||||||
text := textStyle.Render(fmt.Sprintf("Tokens: %s · 耗时: %s · 总Tokens: %s", thisTokens, elapsedStr, totalTokens))
|
text := textStyle.Render(fmt.Sprintf("耗时: %s", elapsedStr))
|
||||||
fmt.Printf(" %s%s\n\n", icon, text)
|
fmt.Printf(" %s%s\n\n", icon, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
go.mod
7
go.mod
@@ -8,7 +8,8 @@ require (
|
|||||||
charm.land/lipgloss/v2 v2.0.2
|
charm.land/lipgloss/v2 v2.0.2
|
||||||
github.com/ergochat/readline v0.1.3
|
github.com/ergochat/readline v0.1.3
|
||||||
github.com/muesli/termenv v0.16.0
|
github.com/muesli/termenv v0.16.0
|
||||||
github.com/sipeed/picoclaw v0.0.0
|
github.com/sipeed/picoclaw v0.2.6
|
||||||
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -92,12 +93,8 @@ require (
|
|||||||
golang.org/x/term v0.41.0 // indirect
|
golang.org/x/term v0.41.0 // indirect
|
||||||
golang.org/x/text v0.35.0 // indirect
|
golang.org/x/text v0.35.0 // indirect
|
||||||
golang.org/x/time v0.15.0 // indirect
|
golang.org/x/time v0.15.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
|
||||||
modernc.org/libc v1.70.0 // indirect
|
modernc.org/libc v1.70.0 // indirect
|
||||||
modernc.org/mathutil v1.7.1 // indirect
|
modernc.org/mathutil v1.7.1 // indirect
|
||||||
modernc.org/memory v1.11.0 // indirect
|
modernc.org/memory v1.11.0 // indirect
|
||||||
modernc.org/sqlite v1.48.2 // indirect
|
modernc.org/sqlite v1.48.2 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
// 开发时指向本地 picoclaw
|
|
||||||
replace github.com/sipeed/picoclaw => /Users/titor/picoclaw
|
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -159,6 +159,8 @@ github.com/segmentio/asm v1.1.3 h1:WM03sfUOENvvKexOLp+pCqgb/WDjsi7EK8gIsICtzhc=
|
|||||||
github.com/segmentio/asm v1.1.3/go.mod h1:Ld3L4ZXGNcSLRg4JBsZ3//1+f/TjYl0Mzen/DQy1EJg=
|
github.com/segmentio/asm v1.1.3/go.mod h1:Ld3L4ZXGNcSLRg4JBsZ3//1+f/TjYl0Mzen/DQy1EJg=
|
||||||
github.com/segmentio/encoding v0.5.4 h1:OW1VRern8Nw6ITAtwSZ7Idrl3MXCFwXHPgqESYfvNt0=
|
github.com/segmentio/encoding v0.5.4 h1:OW1VRern8Nw6ITAtwSZ7Idrl3MXCFwXHPgqESYfvNt0=
|
||||||
github.com/segmentio/encoding v0.5.4/go.mod h1:HS1ZKa3kSN32ZHVZ7ZLPLXWvOVIiZtyJnO1gPH1sKt0=
|
github.com/segmentio/encoding v0.5.4/go.mod h1:HS1ZKa3kSN32ZHVZ7ZLPLXWvOVIiZtyJnO1gPH1sKt0=
|
||||||
|
github.com/sipeed/picoclaw v0.2.6 h1:MqV6hidBW2WVPqE+nmIkjO3sJI/ng0nrAyFDJVHUOBg=
|
||||||
|
github.com/sipeed/picoclaw v0.2.6/go.mod h1:gl9BuZhxUIvrJM1oQXw4Xa8wlmarGGz1y1z6XdcMu3Y=
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||||
|
|||||||
16
project.config.yml
Normal file
16
project.config.yml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# hxclaw 项目配置文件
|
||||||
|
|
||||||
|
# 模拟流式输出配置
|
||||||
|
streaming:
|
||||||
|
line_delay_ms: 1000 # 每行输出后的延迟(毫秒)
|
||||||
|
last_line_delay_ms: 600 # 最后一行延迟(毫秒)
|
||||||
|
|
||||||
|
# Markdown 渲染配置
|
||||||
|
markdown:
|
||||||
|
glamour_style: dark # 渲染主题:dark, light, dracula, tokyo-night 等
|
||||||
|
wrap_width: 0 # 自动换行宽度(0=自动获取终端宽度)
|
||||||
|
|
||||||
|
# UI 配置
|
||||||
|
ui:
|
||||||
|
logo: "🦐"
|
||||||
|
user_prefix: "👀 "
|
||||||
Reference in New Issue
Block a user