renderCoderPolicy prints coder policy state: active policy file, local override, merge mode, rule count, and the last pattern that matched in this session. Isolated from the main security section so a policy-manager init failure doesn't abort the whole block.
(p string)
| 1490 | // this session. Isolated from the main security section so a policy-manager |
| 1491 | // init failure doesn't abort the whole block. |
| 1492 | func (cli *ChatCLI) renderCoderPolicy(p string) { |
| 1493 | policyPath := i18n.T("cfg.val.unknown") |
| 1494 | localPath := i18n.T("cfg.val.none") |
| 1495 | localMerge := i18n.T("cfg.val.off") |
| 1496 | rulesCount := "0" |
| 1497 | lastRule := i18n.T("cfg.val.no_matches_yet") |
| 1498 | |
| 1499 | if pm, err := coder.NewPolicyManager(cli.logger); err == nil { |
| 1500 | policyPath = pm.ActivePolicyPath() |
| 1501 | if lp := pm.LocalPolicyPath(); strings.TrimSpace(lp) != "" { |
| 1502 | localPath = lp |
| 1503 | if pm.LocalMergeEnabled() { |
| 1504 | localMerge = i18n.T("cfg.val.on") |
| 1505 | } |
| 1506 | } |
| 1507 | rulesCount = fmt.Sprintf("%d", pm.RulesCount()) |
| 1508 | } |
| 1509 | if cli.agentMode != nil && cli.agentMode.lastPolicyMatch != nil { |
| 1510 | lastRule = fmt.Sprintf("%s => %s", |
| 1511 | cli.agentMode.lastPolicyMatch.Pattern, |
| 1512 | cli.agentMode.lastPolicyMatch.Action) |
| 1513 | } |
| 1514 | |
| 1515 | kv(p, i18n.T("cfg.kv.active_policy"), policyPath) |
| 1516 | kv(p, i18n.T("cfg.kv.local_override"), localPath) |
| 1517 | kv(p, i18n.T("cfg.kv.local_merge"), localMerge) |
| 1518 | kv(p, i18n.T("cfg.kv.rule_count"), rulesCount) |
| 1519 | kv(p, i18n.T("cfg.kv.last_match"), lastRule) |
| 1520 | } |
no test coverage detected