Introduce PI_CHANGE_REPORT_NARRATIVE (default off). When on, consume typed narrative bound to input digest only; malformed/timeout paths fully fall back without mixing fields or lowering server risk. Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package docrevision
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
// EnvPIChangeReportNarrative gates optional PI change-report narrative enrichment.
|
|
// Default off: deterministic fallback only.
|
|
const EnvPIChangeReportNarrative = "PI_CHANGE_REPORT_NARRATIVE"
|
|
|
|
var (
|
|
flagsMu sync.RWMutex
|
|
narrativeOn = envBool(EnvPIChangeReportNarrative, false)
|
|
)
|
|
|
|
func envBool(key string, def bool) bool {
|
|
v := strings.TrimSpace(os.Getenv(key))
|
|
if v == "" {
|
|
return def
|
|
}
|
|
return v == "1" || strings.EqualFold(v, "true") || strings.EqualFold(v, "yes")
|
|
}
|
|
|
|
// PIChangeReportNarrativeEnabled reports whether PI narrative enrichment is on.
|
|
func PIChangeReportNarrativeEnabled() bool {
|
|
flagsMu.RLock()
|
|
defer flagsMu.RUnlock()
|
|
return narrativeOn
|
|
}
|
|
|
|
// SetPIChangeReportNarrativeForTest overrides the flag in tests.
|
|
func SetPIChangeReportNarrativeForTest(on bool) {
|
|
flagsMu.Lock()
|
|
narrativeOn = on
|
|
flagsMu.Unlock()
|
|
}
|
|
|
|
// ResetPIChangeReportNarrativeForTest restores the flag from the process environment.
|
|
func ResetPIChangeReportNarrativeForTest() {
|
|
flagsMu.Lock()
|
|
narrativeOn = envBool(EnvPIChangeReportNarrative, false)
|
|
flagsMu.Unlock()
|
|
}
|