batch

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

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

func BuildSubtaskGraph(subtasks []feature.Subtask) (map[string][]string, error)

BuildSubtaskGraph 解析 subtask depends 欄位,建立鄰接表(依賴方向:被依賴者 → 依賴者)。 subtask A depends B → 邊 B→A(B 完成後 A 才能跑)。 若有重複 subtask ID 或 depends 引用不存在的 ID,回傳 error。

func DetectSubtaskCycle

func DetectSubtaskCycle(subtasks []feature.Subtask, adj map[string][]string) []string

DetectSubtaskCycle 用三色 DFS 偵測 subtask 依賴圖中的環形依賴。 有環回傳環路徑(subtask ID slice,依實際依賴方向排列);無環回傳 nil。

func SubtaskFrontier

func SubtaskFrontier(subtasks []feature.Subtask) ([]string, error)

SubtaskFrontier 回傳所有前置已完成的未完成 subtask ID。 內部先建圖、偵測環(有環回傳 error),再過濾出 frontier。

Types

type BatchPlan

type BatchPlan struct {
	GeneratedAt time.Time       `json:"generatedAt"`
	Clusters    []Cluster       `json:"clusters"`
	Schedule    []ScheduleEntry `json:"schedule"`
}

BatchPlan 是 batch 的完整執行計畫

func PlanBatch

func PlanBatch(features []feature.Feature, hubRepos []string, maxChainLength int) (*BatchPlan, error)

PlanBatch 從 features 產生完整的 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 的排程

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL