Files
Agent-System/internal/workflowscope/flags.go
T
weichenandCursor fac5704303 feat(workflowscope): score document hits by workflow relation weight
Keep WORKFLOW_SCOPE_MODE=strict as the default so cross-workflow mentions stay blocked until weighted mode is turned on.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-21 09:07:50 +00:00

56 lines
1.1 KiB
Go

package workflowscope
import (
"os"
"strings"
"sync"
)
// Mode 是工作流作用域裁决开关。默认 strict,与「命中他流即拦截」的现状一致。
type Mode string
const (
ModeStrict Mode = "strict"
ModeWeighted Mode = "weighted"
)
const EnvWorkflowScopeMode = "WORKFLOW_SCOPE_MODE"
var (
modeMu sync.RWMutex
activeMode = parseMode(os.Getenv(EnvWorkflowScopeMode))
)
func parseMode(raw string) Mode {
switch strings.ToLower(strings.TrimSpace(raw)) {
case "weighted":
return ModeWeighted
case "", "strict":
return ModeStrict
default:
// 未知值 fail-safe,保持现状拦截。
return ModeStrict
}
}
// CurrentMode 返回进程启动时快照的裁决模式。
func CurrentMode() Mode {
modeMu.RLock()
defer modeMu.RUnlock()
return activeMode
}
// SetModeForTest 仅供测试切换模式。
func SetModeForTest(mode Mode) {
modeMu.Lock()
activeMode = parseMode(string(mode))
modeMu.Unlock()
}
// ResetModeForTest 恢复为环境变量(或默认 strict)。
func ResetModeForTest() {
modeMu.Lock()
activeMode = parseMode(os.Getenv(EnvWorkflowScopeMode))
modeMu.Unlock()
}