Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
738 changes: 738 additions & 0 deletions cmd/sin-code/internal/agentloop/coverage_test.go

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions cmd/sin-code/internal/agentloop/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,15 @@ type Loop struct {

// TournamentRunner is the interface for fusion verify-tournaments (issue
// #290). The loop calls ShouldRun to check if a verify-fail warrants a
// tournament fan-out, and Run to execute it. On success, Run returns the
// winner's output and token count. On failure, the loop falls back to
// the legacy same-model retry. Defined here (not in internal/fusion) to
// avoid a circular import (fusion imports agentloop for Result).
// tournament fan-out, and Run to execute it. The prompt is passed so the
// tournament can fan it out to each provider — without it, forked sessions
// would run with an empty task. On success, Run returns the winner's output
// and token count. On failure, the loop falls back to the legacy same-model
// retry. Defined here (not in internal/fusion) to avoid a circular import
// (fusion imports agentloop for Result).
type TournamentRunner interface {
ShouldRun(vr verify.Result) bool
Run(ctx context.Context) (output string, tokens int, err error)
Run(ctx context.Context, prompt string) (output string, tokens int, err error)
}

// saveHistoryHook is a test seam for injecting a mock around session
Expand Down Expand Up @@ -565,7 +567,7 @@ func (l *Loop) Run(ctx context.Context, sess *session.Session, prompt string) (*
if l.TournamentRunner != nil &&
(l.Gate.Mode() == verify.ModePoC || l.Gate.Mode() == verify.ModeOracle) &&
l.TournamentRunner.ShouldRun(res) {
output, tokens, terr := l.TournamentRunner.Run(ctx)
output, tokens, terr := l.TournamentRunner.Run(ctx, prompt)
if terr == nil && output != "" {
l.fire(ctx, hooks.VerifyPass, "", map[string]any{
"mode": "poc", "report": "fusion tournament: winner passed verify-gate",
Expand Down
35 changes: 34 additions & 1 deletion cmd/sin-code/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,21 @@ test.auto_generate = %v
test.timeout_seconds = %d
test.use_llm = %v
test.repair_rounds = %d

# Worktree conflict prediction (issue #319).
# conflict_check: off|warn|abort — action when git merge-tree predicts conflicts
# target_branch: integration branch to compare against when creating a worktree
worktree.conflict_check = %q
worktree.target_branch = %q
`, cfg.Theme, cfg.DefaultTimeout, cfg.DefaultFormat, cfg.MCPServerEnabled,
cfg.LLMBaseURL, cfg.LLMAPIKey, cfg.LLMModel, cfg.LLMMaxTokens, cfg.LLMTemperature,
cfg.LLMStyle,
cfg.AgentVerifyMode, cfg.AgentMaxTurns, cfg.AgentHeadless, cfg.AgentYolo,
strings.Join(cfg.AgentLoopRequiredTools, ","), strings.Join(cfg.AgentLoopForbiddenTools, ","),
strings.Join(cfg.ToolsAllow, ","), strings.Join(cfg.ToolsDeny, ","),
cfg.PathsMCPConfig, cfg.PathsSkillsDir,
cfg.TestCoverageThreshold, cfg.TestMutationThreshold, cfg.TestAutoGenerate, cfg.TestTimeoutSeconds, cfg.TestUseLLM, cfg.TestRepairRounds)
cfg.TestCoverageThreshold, cfg.TestMutationThreshold, cfg.TestAutoGenerate, cfg.TestTimeoutSeconds, cfg.TestUseLLM, cfg.TestRepairRounds,
cfg.WorktreeConflictCheck, cfg.WorktreeTargetBranch)
}

func initConfig() error {
Expand Down Expand Up @@ -637,6 +644,10 @@ func getConfigValueFrom(key string, cfg SinCodeConfig) (string, error) {
return fmt.Sprintf("%v", cfg.AgentLoopFrustrationDetection), nil
case "permission.yolo_risk_threshold":
return cfg.PermissionYoloRiskThreshold, nil
case "worktree.conflict_check":
return cfg.WorktreeConflictCheck, nil
case "worktree.target_branch":
return cfg.WorktreeTargetBranch, nil
default:
return "", fmt.Errorf("unknown config key: %q", key)
}
Expand Down Expand Up @@ -810,6 +821,13 @@ func setConfigValueIn(key, value string, cfg *SinCodeConfig) error {
cfg.AgentLoopFrustrationDetection = value == "true" || value == "1"
case "permission.yolo_risk_threshold":
cfg.PermissionYoloRiskThreshold = value
case "worktree.conflict_check":
if value != "off" && value != "warn" && value != "abort" {
return fmt.Errorf("worktree.conflict_check must be 'off', 'warn', or 'abort', got %q", value)
}
cfg.WorktreeConflictCheck = value
case "worktree.target_branch":
cfg.WorktreeTargetBranch = value
default:
return fmt.Errorf("unknown config key: %q", key)
}
Expand Down Expand Up @@ -869,6 +887,8 @@ func configPairs(cfg SinCodeConfig, mask bool) []configPair {
{"agentloop.compaction_threshold", fmt.Sprintf("%v", cfg.AgentLoopCompactionThreshold)},
{"agentloop.frustration_detection", fmt.Sprintf("%v", cfg.AgentLoopFrustrationDetection)},
{"permission.yolo_risk_threshold", cfg.PermissionYoloRiskThreshold},
{"worktree.conflict_check", cfg.WorktreeConflictCheck},
{"worktree.target_branch", cfg.WorktreeTargetBranch},
}
sort.Slice(pairs, func(i, j int) bool { return pairs[i].Key < pairs[j].Key })
return pairs
Expand Down Expand Up @@ -937,6 +957,10 @@ func showJSON(cfg SinCodeConfig, mask bool) error {
"mcp_config": cfg.PathsMCPConfig,
"skills_dir": cfg.PathsSkillsDir,
},
"worktree": map[string]any{
"conflict_check": cfg.WorktreeConflictCheck,
"target_branch": cfg.WorktreeTargetBranch,
},
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
Expand All @@ -961,6 +985,8 @@ func showTOML(cfg SinCodeConfig, mask bool) error {
TestCoverageThreshold: cfg.TestCoverageThreshold, TestMutationThreshold: cfg.TestMutationThreshold,
TestAutoGenerate: cfg.TestAutoGenerate, TestTimeoutSeconds: cfg.TestTimeoutSeconds,
TestUseLLM: cfg.TestUseLLM, TestRepairRounds: cfg.TestRepairRounds,
WorktreeConflictCheck: cfg.WorktreeConflictCheck,
WorktreeTargetBranch: cfg.WorktreeTargetBranch,
}))
return nil
}
Expand Down Expand Up @@ -1015,6 +1041,9 @@ func validateConfig(cfg SinCodeConfig) []string {
if cfg.AgentLoopCompactionThreshold <= 0 || cfg.AgentLoopCompactionThreshold > 1 {
issues = append(issues, fmt.Sprintf("agentloop.compaction_threshold must be in (0,1], got %v", cfg.AgentLoopCompactionThreshold))
}
if cfg.WorktreeConflictCheck != "" && cfg.WorktreeConflictCheck != "off" && cfg.WorktreeConflictCheck != "warn" && cfg.WorktreeConflictCheck != "abort" {
issues = append(issues, fmt.Sprintf("worktree.conflict_check must be 'off', 'warn', or 'abort', got %q", cfg.WorktreeConflictCheck))
}
return issues
}

Expand Down Expand Up @@ -1122,6 +1151,10 @@ func applyMap(cfg *SinCodeConfig, m map[string]string) {
cfg.AgentLoopFrustrationDetection = val == "true" || val == "1"
case "permission.yolo_risk_threshold":
cfg.PermissionYoloRiskThreshold = val
case "worktree.conflict_check":
cfg.WorktreeConflictCheck = val
case "worktree.target_branch":
cfg.WorktreeTargetBranch = val
}
}
}
Loading
Loading