Files
memoryweave/go/internal/api/routes/conflicts.go
T
小唯 886c0c20e2 style(gofmt): 全仓 66 文件对齐 gofmt 1.25
gofmt -l 实测 66 文件不合规(历史遗留+gofmt 1.25 规范化:
单行 if/for/case 展开成块、Go1.19+ doc 注释 // 与段落 // 空行)。
本 commit 只含格式化,零逻辑改动:
- 66/66 文件「去注释+去空白+分号归一」后 token 流与 HEAD 完全一致
- go build ./... exit 0;go vet ./... exit 0(改前后一致)
- go test ./... 17 包全 ok(改前后一致)
验收: gofmt -l . 为空;git diff -w 非空系 gofmt 1.25 非纯空白特性,
非逻辑改动(等价性以 token 流 + test 兜底)。
2026-10-10 15:51:25 +08:00

60 lines
1.6 KiB
Go

// 织忆 MemoryWeave — 冲突管理 API
package routes
import (
"encoding/json"
"net/http"
"github.com/xiaoxue/memoryweave/internal/governance"
"github.com/xiaoxue/memoryweave/internal/selfoptimize"
)
type ConflictAPI struct {
Detector *governance.ConflictDetector
}
func NewConflictAPI(d *governance.ConflictDetector) *ConflictAPI {
return &ConflictAPI{Detector: d}
}
// GET /api/v1/conflicts
func (ca *ConflictAPI) List(w http.ResponseWriter, r *http.Request) {
list := ca.Detector.ListActive()
pending := 0
for _, c := range list {
if c.Status == "pending" {
pending++
}
}
respond(w, 200, map[string]interface{}{
"conflicts": list, "count": len(list), "pending": pending,
})
}
// POST /api/v1/conflicts/resolve
func (ca *ConflictAPI) Resolve(w http.ResponseWriter, r *http.Request) {
var req struct {
ConflictID string `json:"conflict_id"`
Resolution string `json:"resolution"` // keep_left / keep_right / merge / dismiss
Winner string `json:"winner"` // id of the winning memory
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
respondError(w, 400, "invalid body")
return
}
if req.ConflictID == "" || req.Resolution == "" {
respondError(w, 400, "conflict_id and resolution required")
return
}
err := ca.Detector.Resolve(req.ConflictID, req.Resolution, req.Winner)
if err != nil {
respondError(w, 500, "resolve failed: "+err.Error())
return
}
selfoptimize.Dash.RecordConflictResolved(true)
PushConflictResolved("system", req.ConflictID, req.Resolution)
respond(w, 200, map[string]string{"status": "resolved", "conflict_id": req.ConflictID})
}