11// Policy doctor health-check factories for one policy scope.
22import type { HealthCheck } from "openclaw/plugin-sdk/health" ;
33import { repairPolicyAutomaticNarrower } from "../automatic-repairs.js" ;
4+ import { createPolicyScopedChecks } from "../check-factory.js" ;
45import { CHECK_IDS } from "../check-ids.js" ;
56import type { PolicyDoctorCheckDeps } from "../types.js" ;
67
@@ -10,109 +11,66 @@ export function createPolicyChannelProviderChecks(
1011 const {
1112 channelIdsFromFindings,
1213 disableChannels,
13- evaluatePolicy,
14- findingsForCheck,
1514 workspaceRepairsDisabledResult,
1615 workspaceRepairsEnabled,
1716 } = deps ;
1817
19- const policyChannelsDeniedProviderCheck : HealthCheck = {
20- id : CHECK_IDS . policyDeniedChannelProvider ,
21- kind : "plugin" ,
22- description : "Configured channels satisfy policy deny rules." ,
23- source : "policy" ,
24- async detect ( ctx ) {
25- return findingsForCheck ( await evaluatePolicy ( ctx ) , CHECK_IDS . policyDeniedChannelProvider ) ;
26- } ,
27- async repair ( ctx , findings ) {
28- if ( ! workspaceRepairsEnabled ( ctx ) ) {
29- return workspaceRepairsDisabledResult ( "channel config" ) ;
30- }
31- const channelIds = channelIdsFromFindings ( findings ) ;
32- if ( channelIds . length === 0 ) {
18+ return createPolicyScopedChecks ( deps , [
19+ [
20+ CHECK_IDS . policyDeniedChannelProvider ,
21+ "Configured channels satisfy policy deny rules." ,
22+ async ( ctx , findings ) => {
23+ if ( ! workspaceRepairsEnabled ( ctx ) ) {
24+ return workspaceRepairsDisabledResult ( "channel config" ) ;
25+ }
26+ const channelIds = channelIdsFromFindings ( findings ) ;
27+ if ( channelIds . length === 0 ) {
28+ return {
29+ status : "skipped" ,
30+ reason : "no channel findings matched a configurable channel" ,
31+ changes : [ ] ,
32+ } ;
33+ }
34+ const next = disableChannels ( ctx . cfg , channelIds ) ;
35+ if ( next . changed . length === 0 ) {
36+ return {
37+ status : "skipped" ,
38+ reason : "matching channels were already disabled or missing" ,
39+ changes : [ ] ,
40+ } ;
41+ }
3342 return {
34- status : "skipped" ,
35- reason : "no channel findings matched a configurable channel" ,
36- changes : [ ] ,
43+ config : next . config ,
44+ changes : next . changed . map (
45+ ( id ) => `Disabled channels.${ id } .enabled for policy conformance.` ,
46+ ) ,
3747 } ;
38- }
39- const next = disableChannels ( ctx . cfg , channelIds ) ;
40- if ( next . changed . length === 0 ) {
41- return {
42- status : "skipped" ,
43- reason : "matching channels were already disabled or missing" ,
44- changes : [ ] ,
45- } ;
46- }
47- return {
48- config : next . config ,
49- changes : next . changed . map (
50- ( id ) => `Disabled channels.${ id } .enabled for policy conformance.` ,
51- ) ,
52- } ;
53- } ,
54- } ;
55-
56- return [ policyChannelsDeniedProviderCheck ] ;
48+ } ,
49+ ] ,
50+ ] ) ;
5751}
5852
5953export function createPolicyIngressChecks ( deps : PolicyDoctorCheckDeps ) : readonly HealthCheck [ ] {
60- const { evaluatePolicy, findingsForCheck } = deps ;
61-
62- const policyIngressDmPolicyUnapprovedCheck : HealthCheck = {
63- id : CHECK_IDS . policyIngressDmPolicyUnapproved ,
64- kind : "plugin" ,
65- description : "Channel direct-message access policy matches ingress requirements." ,
66- source : "policy" ,
67- async detect ( ctx ) {
68- return findingsForCheck ( await evaluatePolicy ( ctx ) , CHECK_IDS . policyIngressDmPolicyUnapproved ) ;
69- } ,
70- } ;
71- const policyIngressDmScopeUnapprovedCheck : HealthCheck = {
72- id : CHECK_IDS . policyIngressDmScopeUnapproved ,
73- kind : "plugin" ,
74- description : "Direct-message sessions use the policy-required isolation scope." ,
75- source : "policy" ,
76- async detect ( ctx ) {
77- return findingsForCheck ( await evaluatePolicy ( ctx ) , CHECK_IDS . policyIngressDmScopeUnapproved ) ;
78- } ,
79- } ;
80- const policyIngressOpenGroupsDeniedCheck : HealthCheck = {
81- id : CHECK_IDS . policyIngressOpenGroupsDenied ,
82- kind : "plugin" ,
83- description : "Channel group access does not use open group policy when denied." ,
84- source : "policy" ,
85- async detect ( ctx ) {
86- return findingsForCheck ( await evaluatePolicy ( ctx ) , CHECK_IDS . policyIngressOpenGroupsDenied ) ;
87- } ,
88- async repair ( ctx , findings ) {
89- return repairPolicyAutomaticNarrower ( ctx , findings , CHECK_IDS . policyIngressOpenGroupsDenied ) ;
90- } ,
91- } ;
92- const policyIngressGroupMentionRequiredCheck : HealthCheck = {
93- id : CHECK_IDS . policyIngressGroupMentionRequired ,
94- kind : "plugin" ,
95- description : "Channel group access keeps mention gates enabled when required." ,
96- source : "policy" ,
97- async detect ( ctx ) {
98- return findingsForCheck (
99- await evaluatePolicy ( ctx ) ,
100- CHECK_IDS . policyIngressGroupMentionRequired ,
101- ) ;
102- } ,
103- async repair ( ctx , findings ) {
104- return repairPolicyAutomaticNarrower (
105- ctx ,
106- findings ,
107- CHECK_IDS . policyIngressGroupMentionRequired ,
108- ) ;
109- } ,
110- } ;
111-
112- return [
113- policyIngressDmPolicyUnapprovedCheck ,
114- policyIngressDmScopeUnapprovedCheck ,
115- policyIngressOpenGroupsDeniedCheck ,
116- policyIngressGroupMentionRequiredCheck ,
117- ] ;
54+ return createPolicyScopedChecks ( deps , [
55+ [
56+ CHECK_IDS . policyIngressDmPolicyUnapproved ,
57+ "Channel direct-message access policy matches ingress requirements." ,
58+ ] ,
59+ [
60+ CHECK_IDS . policyIngressDmScopeUnapproved ,
61+ "Direct-message sessions use the policy-required isolation scope." ,
62+ ] ,
63+ [
64+ CHECK_IDS . policyIngressOpenGroupsDenied ,
65+ "Channel group access does not use open group policy when denied." ,
66+ async ( ctx , findings ) =>
67+ repairPolicyAutomaticNarrower ( ctx , findings , CHECK_IDS . policyIngressOpenGroupsDenied ) ,
68+ ] ,
69+ [
70+ CHECK_IDS . policyIngressGroupMentionRequired ,
71+ "Channel group access keeps mention gates enabled when required." ,
72+ async ( ctx , findings ) =>
73+ repairPolicyAutomaticNarrower ( ctx , findings , CHECK_IDS . policyIngressGroupMentionRequired ) ,
74+ ] ,
75+ ] ) ;
11876}
0 commit comments