- 只翻注释/文档字符串:剥离注释后代码行逐字节不变(机械校验只剩允许的行尾注释形态) - 裁决编号与 design 节号(02.4.3 / 11.4.2 / design/05 §9 等)逐字保留 - 复核:go build 绿;orchestration 及其子包(audit/comm)测试绿;gofmt 干净
105 lines
3.2 KiB
Go
105 lines
3.2 KiB
Go
package orchestration
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/loop"
|
|
)
|
|
|
|
// SubAgentResult 是 SubAgent 在某一时刻的快照。它既用作 MergedResult 中每个子代理的
|
|
// 条目,也用作 (*SubAgent).Snapshot 供监控使用的返回值。
|
|
type SubAgentResult struct {
|
|
// ID 是子代理 id。
|
|
ID string
|
|
// Goal 是子代理的目标。
|
|
Goal string
|
|
// RoleID 是绑定的角色/persona。
|
|
RoleID string
|
|
// PersonaID 是子代理运行时充当的目标角色(空 = 派发回合的角色),其指令与记忆
|
|
// 作用域为本次运行所用(design/22 §8-2)。
|
|
PersonaID string
|
|
// Mode 是绑定的行为模式。
|
|
Mode string
|
|
// AttachInfo 是随派发提供的附加文本。
|
|
AttachInfo string
|
|
// Status 是终结态(或当前状态)。
|
|
Status Status
|
|
// Summary 是收尾时写入的执行摘要。
|
|
Summary string
|
|
// Text 是运行成功时的循环结果文本。
|
|
Text string
|
|
// Steps 是运行成功时执行的循环步数。
|
|
Steps int
|
|
// Err 是结束失败/中止运行的那个错误(成功时为 nil)。
|
|
Err error
|
|
// StartedAt 是子代理开始运行的时间。
|
|
StartedAt time.Time
|
|
// FinishedAt 是子代理收尾的时间。
|
|
FinishedAt time.Time
|
|
}
|
|
|
|
// MergedResult 聚合每个已派发子代理的结果,由 (*Scheduler).Join 产出。
|
|
type MergedResult struct {
|
|
// Agents 持有每个已派发子代理的一个条目,按派发顺序排列。
|
|
Agents []SubAgentResult
|
|
// Total 是已派发子代理的数量。
|
|
Total int
|
|
// Succeeded 是以 StatusDone 结束的子代理数量。
|
|
Succeeded int
|
|
// Failed 是以 StatusFailed 结束的子代理数量。
|
|
Failed int
|
|
// Aborted 是以 StatusAborted 结束的子代理数量。
|
|
Aborted int
|
|
// Summary 是全部子代理的单行聚合摘要。
|
|
Summary string
|
|
}
|
|
|
|
// summaryTextMax 限制摘要中出现的结论文本字符数上限。
|
|
const summaryTextMax = 80
|
|
|
|
// doneSummary 构建子代理成功时写入的执行摘要。
|
|
func doneSummary(res *loop.Result) string {
|
|
if res == nil {
|
|
return "完成"
|
|
}
|
|
text := compactText(res.Text, summaryTextMax)
|
|
if res.StopReason != "" {
|
|
return fmt.Sprintf("完成 (%s, 步骤=%d): %s", res.StopReason, res.Steps, text)
|
|
}
|
|
return fmt.Sprintf("完成 (步骤=%d): %s", res.Steps, text)
|
|
}
|
|
|
|
// failedSummary 构建子代理失败时写入的摘要。
|
|
func failedSummary(err error) string {
|
|
if err == nil {
|
|
return "失败"
|
|
}
|
|
return "失败: " + err.Error()
|
|
}
|
|
|
|
// canceledSummary 构建子代理被中止时写入的摘要。
|
|
func canceledSummary() string {
|
|
return "中止: 已取消"
|
|
}
|
|
|
|
// timeoutSummary 构建子代理超时写入的摘要。
|
|
func timeoutSummary(d time.Duration) string {
|
|
return fmt.Sprintf("中止: 超时 (%s)", d)
|
|
}
|
|
|
|
// timeoutSummaryFor 是按子代理生效时限渲染的超时摘要:无期限(0)时不再
|
|
// 显示误导性的 "(0s)",只说明超时本身。
|
|
func timeoutSummaryFor(d time.Duration) string {
|
|
if d <= 0 {
|
|
return "中止: 超时"
|
|
}
|
|
return timeoutSummary(d)
|
|
}
|
|
|
|
// summarizeMerged 产出合并结果的单行聚合摘要。
|
|
func summarizeMerged(r *MergedResult) string {
|
|
return fmt.Sprintf("子代理汇总: 共 %d 个, %d 成功, %d 失败, %d 中止",
|
|
r.Total, r.Succeeded, r.Failed, r.Aborted)
|
|
}
|