Files
weichenandCursor fedf671a48
ci / vet-and-test (push) Successful in 5s
ci / docker-checkout-hostgateway (push) Successful in 3s
Import the current agent-native module as a fresh history.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-29 12:29:04 +00:00

48 lines
1.1 KiB
Go

package exec
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
)
type StubBackend struct{}
func (s *StubBackend) Name() string { return "stub" }
func (s *StubBackend) Execute(ctx context.Context, req Request) (*Result, error) {
patches := make(map[string][]byte)
for _, target := range req.Targets {
outPath := filepath.Join(req.WorkDir, target)
_ = os.MkdirAll(filepath.Dir(outPath), 0o755)
var content []byte
if strings.HasSuffix(target, ".json") {
// 若原文件已存在且为有效 JSON,保留其内容
if existing, err := os.ReadFile(outPath); err == nil {
var dummy interface{}
if json.Unmarshal(existing, &dummy) == nil {
content = existing
}
}
if len(content) == 0 {
content = []byte(`{"status":"mock_ok"}`)
}
} else {
content = []byte(fmt.Sprintf("# 模拟生成结果\n\n- 目标文件: %s\n- 提示词摘要: %s\n", target, req.Prompt))
}
_ = os.WriteFile(outPath, content, 0o644)
patches[target] = content
}
return &Result{
Success: true,
Patches: patches,
Logs: "Stub agent execution completed.",
}, nil
}