Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 4 additions & 15 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,18 @@ jobs:
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 5
env:
GOMAXPROCS: 2
GOMEMLIMIT: 256MiB
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
cache: true
go-version: "1.25"

- name: golangci-lint
timeout-minutes: 4
uses: golangci/golangci-lint-action@v7
uses: golangci/golangci-lint-action@v9
with:
version: v2.1.6
args: --timeout=2m --disable=errcheck --enable=govet,ineffassign,staticcheck,unused --new-from-rev=origin/main ./pkg/...
skip-cache: false
version: v2.7.2

build:
name: Build
Expand Down
119 changes: 97 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,108 @@
# golangci-lint configuration (v2.x)
version: "2"

run:
timeout: 5m
tests: true
go: "1.21"

linters:
enable:
- errcheck
- govet
- ineffassign
- staticcheck
- unused
default: all
disable:
# 过于严格/不适用
- depguard # 需要配置依赖白名单
- wrapcheck # 要求所有错误都 wrap
- exhaustruct # 要求所有字段都初始化
- ireturn # 禁止返回接口
- varnamelen # 变量名长度限制
- nlreturn # return 前必须空行
- wsl_v5 # 空行规则过严
- funlen # 函数长度限制
- gocognit # 认知复杂度
- cyclop # 圈复杂度
- lll # 行长度限制
- godox # 禁止 TODO/FIXME
- godot # 注释句号结尾
- mnd # magic number
- err113 # 错误定义规则过严
- gochecknoglobals # 禁止全局变量
- gochecknoinits # 禁止 init 函数
- nonamedreturns # 禁止命名返回
- interfacebloat # 接口方法数限制
- maintidx # 可维护性指数
- nestif # 嵌套 if 检测
- goconst # 常量提取
- dupl # 重复代码
- inamedparam # 接口参数命名
- tagliatelle # struct tag 命名风格
- tagalign # struct tag 对齐
- musttag # 强制 struct tag
- goheader # 文件头检查
- gomoddirectives # go.mod 指令检查
- gomodguard # go.mod 依赖检查
- grouper # 表达式分组
- decorder # 声明顺序
- funcorder # 函数顺序
- containedctx # context 包含检查
- contextcheck # context 检查
- noinlineerr # 禁止内联错误处理
- paralleltest # 要求 t.Parallel()
- testpackage # 要求 _test 包
- tparallel # t.Parallel 检查
# 特定框架
- arangolint # ArangoDB
- ginkgolinter # Ginkgo
- zerologlint # zerolog
- loggercheck # logger 检查
- spancheck # OpenTelemetry
- promlinter # Prometheus
- protogetter # protobuf
- gosmopolitan # i18n
# 已弃用
- wsl
# 注释要求过严
- revive # 与 staticcheck 重复,规则过严
- errname # 错误命名规则
- goprintffuncname # printf 函数命名
# 过于严格的额外检查
- forbidigo # 禁止 fmt.Print* 等函数(示例代码大量使用)
- forcetypeassert # 强制类型断言检查(大量使用 any 类型)
- gosec # 安全检查过严
- unparam # 未使用参数检查
- godoclint # 注释格式过严
- prealloc # 切片预分配建议
- nilnil # nil 返回检查
- noctx # http 请求 context 检查
- nilerr # nil error 检查
- exhaustive # switch 穷尽检查
- gocyclo # 圈复杂度(已有 cyclop)
- errchkjson # JSON 错误检查(示例代码忽略错误)
- errcheck # 错误检查(CI 配置禁用)
# 测试相关的过严检查
- testifylint # testify 用法检查
- thelper # t.Helper() 检查
- usetesting # testing 包使用建议
# 其他过严检查
- predeclared # 预定义标识符遮蔽
- intrange # 整数范围迭代建议
- modernize # 现代化建议
- gocritic # 代码风格建议
- rowserrcheck # sql.Rows 错误检查
- wastedassign # 无用赋值检查
- iface # 接口检查

settings:
errcheck:
check-type-assertions: false
check-blank: false
exclude-functions:
- fmt.Fprintf
- fmt.Fprintln
- fmt.Printf
- fmt.Println
- (io.Closer).Close
govet:
enable-all: true
disable:
- fieldalignment
- shadow
- shadow # 变量遮蔽检查(Go 常见模式)
misspell:
locale: US
nakedret:
max-func-lines: 30
gocritic: {}
exhaustive:
default-signifies-exhaustive: true

formatters:
enable:
- gofmt
- goimports

issues:
max-issues-per-linter: 0
Expand Down
19 changes: 10 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
repos:
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: go-fmt
args: [-w]
- id: go-vet-repo-mod
- id: golangci-lint-repo-mod
args: [--timeout=5m]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand All @@ -18,3 +9,13 @@ repos:
- id: check-added-large-files
args: ["--maxkb=1000"]
- id: check-merge-conflict

- repo: local
hooks:
- id: golangci-lint
name: golangci-lint
description: Run golangci-lint to lint and fix Go code
entry: golangci-lint run --new --fix
types: [go]
language: system
pass_filenames: false
38 changes: 19 additions & 19 deletions docs/content/02.core-concepts/13.session-recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,16 @@ func createMyRecoveryHook() types.RecoveryHook {
if !shouldTriggerRecovery(ctx.OriginalMessage) {
return &types.RecoveryResult{ShouldRecover: false}
}

// 2. 检查项目状态
hasProjectFile := checkProjectFile(ctx.WorkDir)
if !ctx.SessionState.HasHistory && !hasProjectFile {
return &types.RecoveryResult{ShouldRecover: false}
}

// 3. 构建恢复消息
enhancedMsg := buildRecoveryMessage(ctx)

return &types.RecoveryResult{
ShouldRecover: true,
EnhancedMessage: enhancedMsg,
Expand All @@ -172,7 +172,7 @@ func sendMessage(ctx context.Context, ag *agent.Agent, message string) error {
if recovered {
log.Printf("Session recovery triggered")
}

return ag.Send(ctx, finalMessage)
}
```
Expand All @@ -189,7 +189,7 @@ import (
"os"
"path/filepath"
"strings"

"github.com/astercloud/aster/pkg/types"
)

Expand All @@ -201,7 +201,7 @@ func createRecoveryHook() types.RecoveryHook {
if !isRecoveryTriggerMessage(ctx.OriginalMessage) {
return &types.RecoveryResult{ShouldRecover: false}
}

// 检查项目文件
hasProjectFile := false
if ctx.WorkDir != "" {
Expand All @@ -210,28 +210,28 @@ func createRecoveryHook() types.RecoveryHook {
hasProjectFile = true
}
}

// 需要恢复的条件:有历史消息 或 有项目文件
if !ctx.SessionState.HasHistory && !hasProjectFile {
return &types.RecoveryResult{ShouldRecover: false}
}

// 构建恢复指令
var sb strings.Builder
sb.WriteString("【会话恢复】这是一个恢复的会话,你需要先理解当前项目状态再响应用户。\n\n")
sb.WriteString("请按以下步骤操作:\n")
sb.WriteString("1. 首先使用 Read 工具读取 AGENTS.md 文件,了解项目信息和当前步骤\n")
sb.WriteString("2. 如果存在 _briefs 目录,读取其中的文件了解已收集的需求\n")
sb.WriteString("3. 根据上下文理解用户的意图,然后继续之前的工作\n\n")

if ctx.WorkDir != "" {
sb.WriteString(fmt.Sprintf("工作目录: %s\n\n", ctx.WorkDir))
}

sb.WriteString("---\n\n")
sb.WriteString("用户消息: ")
sb.WriteString(ctx.OriginalMessage)

return &types.RecoveryResult{
ShouldRecover: true,
EnhancedMessage: sb.String(),
Expand All @@ -245,19 +245,19 @@ func isRecoveryTriggerMessage(message string) bool {
if len(message) > 20 {
return false // 长消息通常是新的指令
}

triggers := []string{
"继续", "好", "好的", "可以", "下一步", "然后呢", "接下来",
"continue", "ok", "okay", "yes", "next", "go on",
}

messageLower := strings.ToLower(message)
for _, trigger := range triggers {
if strings.Contains(messageLower, trigger) {
return true
}
}

return false
}
```
Expand Down Expand Up @@ -311,13 +311,13 @@ sequenceDiagram
App->>Agent: SendMessage("继续")
Agent->>Agent: GetSessionState()
Note over Agent: HasHistory=true<br/>IsResumed=true

Agent->>Hook: RecoveryHook(ctx)
Hook->>Hook: 检查触发条件
Hook->>Hook: 检查项目文件
Hook->>Hook: 构建增强消息
Hook-->>Agent: RecoveryResult{ShouldRecover: true, EnhancedMessage: "..."}

Agent->>Agent: Send(enhancedMessage)
Agent->>Agent: 读取 AGENTS.md
Agent->>Agent: 理解项目状态
Expand All @@ -340,9 +340,9 @@ func (a *Agent) GetSessionState(ctx context.Context) *types.SessionState

```go
func (a *Agent) ProcessRecovery(
ctx context.Context,
message string,
workDir string,
ctx context.Context,
message string,
workDir string,
metadata map[string]any,
) (enhancedMessage string, recovered bool)
```
Expand Down
6 changes: 3 additions & 3 deletions docs/content/02.core-concepts/14.session-sqlite.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ graph TB
Agent --> SessionService[Session Service]
SessionService --> SQLite[SQLite Store]
SQLite --> DBFile[(sessions.db)]

subgraph "数据表"
DBFile --> Sessions[sessions 表]
DBFile --> Events[events 表]
end

style SQLite fill:#3b82f6
style DBFile fill:#10b981
```
Expand Down Expand Up @@ -263,7 +263,7 @@ func cleanupOldSessions(service *sqlite.Service, maxAge time.Duration) error {
AppName: "my-app",
UserID: "user-123",
})

cutoff := time.Now().Add(-maxAge)
for _, sess := range sessions {
if sess.UpdatedAt().Before(cutoff) {
Expand Down
6 changes: 3 additions & 3 deletions docs/content/02.core-concepts/15.recipe.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ instructions: |
1. 分析代码质量和可读性
2. 发现潜在的 Bug 和安全问题
3. 提供改进建议和最佳实践

请遵循以下原则:
- 给出具体的代码示例
- 解释为什么某些做法更好
Expand Down Expand Up @@ -388,11 +388,11 @@ version: "1.0" # 使用语义化版本
instructions: |
# 角色定义
你是一个专业的...

# 行为准则
1. 规则一
2. 规则二

# 输出格式
请按以下格式输出...
```
Expand Down
5 changes: 2 additions & 3 deletions docs/content/04.memory/12.logic-memory-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,6 @@ func TestLogicMemoryE2E(t *testing.T) {

---

**计划制定时间**:2025-12-04
**预计完成时间**:2025-12-30(4 周)
**计划制定时间**:2025-12-04
**预计完成时间**:2025-12-30(4 周)
**置信度**:高(基于 Aster SDK 和 YunJin 的实际代码分析)

2 changes: 1 addition & 1 deletion docs/content/04.memory/14.rules-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ type DatabaseLoader struct {

func (l *DatabaseLoader) LoadGlobalRules(ctx context.Context) ([]*Rule, error) {
// 从数据库查询全局规则
rows, err := l.db.QueryContext(ctx,
rows, err := l.db.QueryContext(ctx,
"SELECT id, title, content, priority FROM rules WHERE scope = 'global' AND enabled = true")
// ...
}
Expand Down
Loading