Documentation
¶
Index ¶
- func BuildBatchReport(ws *protocol.Workspace, plan *BatchPlan, statusMap map[string]feature.Status, ...) protocol.BatchReport
- func BuildSubtaskGraph(subtasks []feature.Subtask) (map[string][]string, error)
- func DetectSubtaskCycle(subtasks []feature.Subtask, adj map[string][]string) []string
- func SubtaskFrontier(subtasks []feature.Subtask) ([]string, error)
- type BatchPlan
- type Cluster
- type ScheduleEntry
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildBatchReport ¶
func BuildBatchReport(ws *protocol.Workspace, plan *BatchPlan, statusMap map[string]feature.Status, runner string, startedAt, finishedAt time.Time, outcome, runningFeature, panicMsg string) protocol.BatchReport
BuildBatchReport 從一次 batch run 的進度快照組出 protocol.BatchReport。
遍歷 plan.Schedule 的每個 feature:用 ws.ReadState 取 round / 耗時(UpdatedAt-CreatedAt)/ stopReason, ws.LoadFeature 取 name,statusMap 取最終 status;缺 state 的 feature 耗時與 round 記 0。 統計 Completed(feature.BatchCompleted 為真)/ Failed(blocked、needs-attention)/ Remaining(Total 扣除前兩者)。 outcome 由呼叫端依結束原因傳入(completed / stopped / interrupted / crashed), runningFeature 與 panicMsg 僅 interrupted / crashed 時有意義,其餘傳空字串即可。
Example ¶
root, _ := os.MkdirTemp("", "batch-report-example-*")
defer os.RemoveAll(root)
os.MkdirAll(filepath.Join(root, protocol.DirName), 0o755)
ws := &protocol.Workspace{Root: root}
plan := &BatchPlan{Schedule: []ScheduleEntry{
{FeatureID: "F001"},
{FeatureID: "F002"},
}}
statusMap := map[string]feature.Status{
"F001": feature.StatusDone,
"F002": feature.StatusBlocked,
}
started := time.Unix(0, 0)
finished := time.Unix(12, 0)
r := BuildBatchReport(ws, plan, statusMap, "claude", started, finished, protocol.BatchOutcomeCompleted, "", "")
fmt.Printf("outcome=%s total=%d completed=%d failed=%d remaining=%d durationMs=%d\n",
r.Outcome, r.Total, r.Completed, r.Failed, r.Remaining, r.DurationMs)
Output: outcome=completed total=2 completed=1 failed=1 remaining=0 durationMs=12000
func BuildSubtaskGraph ¶
BuildSubtaskGraph 解析 subtask depends 欄位,建立鄰接表(依賴方向:被依賴者 → 依賴者)。 subtask A depends B → 邊 B→A(B 完成後 A 才能跑)。 若有重複 subtask ID 或 depends 引用不存在的 ID,回傳 error。
func DetectSubtaskCycle ¶
DetectSubtaskCycle 用三色 DFS 偵測 subtask 依賴圖中的環形依賴。 有環回傳環路徑(subtask ID slice,依實際依賴方向排列);無環回傳 nil。
Types ¶
type BatchPlan ¶
type BatchPlan struct {
GeneratedAt time.Time `json:"generatedAt"`
Clusters []Cluster `json:"clusters"`
Schedule []ScheduleEntry `json:"schedule"`
}
BatchPlan 是 batch 的完整執行計畫
type Cluster ¶
type Cluster struct {
ID string `json:"id"`
Features []string `json:"features"`
Chains [][]string `json:"chains"`
}
Cluster 是有依賴或共用 repo 的 feature 群
type ScheduleEntry ¶
type ScheduleEntry struct {
FeatureID string `json:"featureId"`
Slot int `json:"slot"`
CanStartAfter []string `json:"canStartAfter"`
}
ScheduleEntry 是 batch-plan.json 裡每個 feature 的排程