@omercnet/paseo-omp 5.4.0-next.410.1 → 5.4.0-next.412.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/omp-config-surface.tsx +114 -82
- package/client/omp-config-views.ts +7 -3
- package/client/omp-security-section.tsx +99 -0
- package/client/omp-security-state.ts +14 -0
- package/client/omp-tool-policy-state.ts +101 -0
- package/client/omp-tool-policy.tsx +435 -0
- package/index.server.ts +3 -0
- package/package.json +1 -1
- package/server/omp-security.ts +169 -0
- package/server/omp-settings.ts +68 -4
- package/server/package-version.ts +1 -1
- package/shared/omp-security.ts +50 -0
- package/shared/omp-settings.ts +99 -4
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
categorizeOmpSetting,
|
|
21
21
|
formatOmpSettingLabel,
|
|
22
22
|
isOmpStructuredSettingPath,
|
|
23
|
+
isOmpToolPolicyPath,
|
|
23
24
|
listOmpSettings,
|
|
24
25
|
OMP_SETTING_CATEGORIES,
|
|
25
26
|
type OmpSetting,
|
|
@@ -55,9 +56,12 @@ import {
|
|
|
55
56
|
StructuredRoutingEditor,
|
|
56
57
|
} from "./omp-routing-editor";
|
|
57
58
|
import { OmpRulesSection } from "./omp-rules-section";
|
|
59
|
+
import { OmpSecuritySection } from "./omp-security-section";
|
|
60
|
+
import { SECURITY_QUERY_KEY } from "./omp-security-state";
|
|
58
61
|
import { OmpSkillsSection } from "./omp-skills-section";
|
|
59
62
|
import { OmpStorePicker } from "./omp-store-picker";
|
|
60
63
|
import { ompStoreKey } from "./omp-store-state";
|
|
64
|
+
import { ToolPolicyCard } from "./omp-tool-policy";
|
|
61
65
|
import { OmpUpdateRow, UPDATE_QUERY_KEY } from "./omp-update-row";
|
|
62
66
|
import {
|
|
63
67
|
type BinaryHealthSummary,
|
|
@@ -937,6 +941,7 @@ function ConfigurationCategory({
|
|
|
937
941
|
category,
|
|
938
942
|
styles,
|
|
939
943
|
settings,
|
|
944
|
+
policySettings: allPolicySettings,
|
|
940
945
|
drafts,
|
|
941
946
|
theme,
|
|
942
947
|
modelCatalog,
|
|
@@ -954,6 +959,8 @@ function ConfigurationCategory({
|
|
|
954
959
|
modelRoles: Readonly<Record<string, unknown>>;
|
|
955
960
|
agentCatalog: OmpAgentCatalogState;
|
|
956
961
|
settings: readonly OmpSetting[];
|
|
962
|
+
/** Every stored tool policy setting, so warnings do not depend on the search text. */
|
|
963
|
+
policySettings: readonly OmpSetting[];
|
|
957
964
|
drafts: Readonly<Record<string, SettingDraft>>;
|
|
958
965
|
disabled: boolean;
|
|
959
966
|
workspaceScoped: boolean;
|
|
@@ -961,92 +968,110 @@ function ConfigurationCategory({
|
|
|
961
968
|
onOpenDocumentation(link: OmpDocumentationLink): void;
|
|
962
969
|
}) {
|
|
963
970
|
const categoryDocumentation = documentationForSettingCategory(category.id);
|
|
971
|
+
const visiblePolicySettings =
|
|
972
|
+
category.id === "tools" ? settings.filter((setting) => isOmpToolPolicyPath(setting.path)) : [];
|
|
973
|
+
const listed = settings.filter((setting) => !visiblePolicySettings.includes(setting));
|
|
964
974
|
return (
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
975
|
+
<>
|
|
976
|
+
{visiblePolicySettings.length > 0 ? (
|
|
977
|
+
<ToolPolicyCard
|
|
978
|
+
settings={allPolicySettings}
|
|
979
|
+
visiblePaths={visiblePolicySettings.map((setting) => setting.path)}
|
|
980
|
+
drafts={drafts}
|
|
981
|
+
disabled={disabled}
|
|
982
|
+
workspaceScoped={workspaceScoped}
|
|
983
|
+
resetLabel={workspaceScoped ? "Remove workspace override" : "Reset to default"}
|
|
984
|
+
styles={styles}
|
|
985
|
+
onSet={(path, value) => onDraft(path, { operation: "set", value })}
|
|
986
|
+
onReset={(path) => onDraft(path, { operation: "reset" })}
|
|
987
|
+
/>
|
|
988
|
+
) : null}
|
|
989
|
+
<SectionCard
|
|
990
|
+
styles={styles}
|
|
991
|
+
title={`${category.label} · ${listed.length}`}
|
|
992
|
+
action={
|
|
993
|
+
categoryDocumentation ? (
|
|
994
|
+
<DocumentationLink
|
|
995
|
+
link={categoryDocumentation}
|
|
996
|
+
styles={styles}
|
|
997
|
+
onOpen={onOpenDocumentation}
|
|
998
|
+
/>
|
|
999
|
+
) : undefined
|
|
1000
|
+
}
|
|
1001
|
+
>
|
|
1002
|
+
{listed.map((setting) => {
|
|
1003
|
+
const complex =
|
|
1004
|
+
Array.isArray(setting.value) ||
|
|
1005
|
+
(setting.value !== null && typeof setting.value === "object");
|
|
1006
|
+
const editable =
|
|
1007
|
+
!setting.redacted && ["boolean", "number", "string", "enum"].includes(setting.type);
|
|
1008
|
+
const structuredEditable =
|
|
1009
|
+
!setting.redacted &&
|
|
1010
|
+
isOmpStructuredSettingPath(setting.path) &&
|
|
1011
|
+
setting.type === structuredSettingType(setting.path);
|
|
1012
|
+
const settingDocumentation = documentationForSettingPath(setting.path);
|
|
1013
|
+
const draft = drafts[setting.path];
|
|
1014
|
+
return (
|
|
1015
|
+
<View key={setting.path} style={styles.setting}>
|
|
1016
|
+
<View style={styles.settingHeader}>
|
|
1017
|
+
<Text style={styles.cardTitle}>{formatOmpSettingLabel(setting.path)}</Text>
|
|
1018
|
+
{setting.workspaceOverride ? (
|
|
1019
|
+
<Text style={styles.source}>Workspace override</Text>
|
|
1020
|
+
) : null}
|
|
1021
|
+
{!complex && !editable && !structuredEditable ? (
|
|
1022
|
+
<StructuredSettingValue setting={setting} styles={styles} />
|
|
1023
|
+
) : null}
|
|
1024
|
+
</View>
|
|
1025
|
+
<Text selectable style={styles.settingPath}>
|
|
1026
|
+
{setting.path} · {setting.type}
|
|
1027
|
+
</Text>
|
|
1028
|
+
{settingDocumentation ? (
|
|
1029
|
+
<View style={styles.docsActions}>
|
|
1030
|
+
<DocumentationLink
|
|
1031
|
+
link={settingDocumentation}
|
|
1032
|
+
styles={styles}
|
|
1033
|
+
onOpen={onOpenDocumentation}
|
|
1034
|
+
/>
|
|
1035
|
+
</View>
|
|
996
1036
|
) : null}
|
|
997
|
-
{
|
|
1037
|
+
{editable ? (
|
|
1038
|
+
<EditableScalarValue
|
|
1039
|
+
setting={setting}
|
|
1040
|
+
draft={draft}
|
|
1041
|
+
disabled={disabled}
|
|
1042
|
+
resetLabel={workspaceScoped ? "Remove workspace override" : "Reset to default"}
|
|
1043
|
+
showReset={!workspaceScoped || setting.workspaceOverride === true}
|
|
1044
|
+
styles={styles}
|
|
1045
|
+
onSet={(value) => onDraft(setting.path, { operation: "set", value })}
|
|
1046
|
+
onReset={() => onDraft(setting.path, { operation: "reset" })}
|
|
1047
|
+
/>
|
|
1048
|
+
) : structuredEditable ? (
|
|
1049
|
+
<StructuredRoutingEditor
|
|
1050
|
+
setting={setting}
|
|
1051
|
+
value={draft?.operation === "set" ? draft.value : setting.value}
|
|
1052
|
+
disabled={disabled}
|
|
1053
|
+
resetLabel={workspaceScoped ? "Remove workspace override" : "Reset to default"}
|
|
1054
|
+
showReset={!workspaceScoped || setting.workspaceOverride === true}
|
|
1055
|
+
resetPending={draft?.operation === "reset"}
|
|
1056
|
+
styles={styles}
|
|
1057
|
+
theme={theme}
|
|
1058
|
+
modelCatalog={modelCatalog}
|
|
1059
|
+
modelRoles={modelRoles}
|
|
1060
|
+
agentCatalog={agentCatalog}
|
|
1061
|
+
onSet={(value) => onDraft(setting.path, { operation: "set", value })}
|
|
1062
|
+
onReset={() => onDraft(setting.path, { operation: "reset" })}
|
|
1063
|
+
/>
|
|
1064
|
+
) : complex ? (
|
|
998
1065
|
<StructuredSettingValue setting={setting} styles={styles} />
|
|
999
1066
|
) : null}
|
|
1067
|
+
{setting.description ? (
|
|
1068
|
+
<Text style={styles.settingDescription}>{setting.description}</Text>
|
|
1069
|
+
) : null}
|
|
1000
1070
|
</View>
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
<View style={styles.docsActions}>
|
|
1006
|
-
<DocumentationLink
|
|
1007
|
-
link={settingDocumentation}
|
|
1008
|
-
styles={styles}
|
|
1009
|
-
onOpen={onOpenDocumentation}
|
|
1010
|
-
/>
|
|
1011
|
-
</View>
|
|
1012
|
-
) : null}
|
|
1013
|
-
{editable ? (
|
|
1014
|
-
<EditableScalarValue
|
|
1015
|
-
setting={setting}
|
|
1016
|
-
draft={draft}
|
|
1017
|
-
disabled={disabled}
|
|
1018
|
-
resetLabel={workspaceScoped ? "Remove workspace override" : "Reset to default"}
|
|
1019
|
-
showReset={!workspaceScoped || setting.workspaceOverride === true}
|
|
1020
|
-
styles={styles}
|
|
1021
|
-
onSet={(value) => onDraft(setting.path, { operation: "set", value })}
|
|
1022
|
-
onReset={() => onDraft(setting.path, { operation: "reset" })}
|
|
1023
|
-
/>
|
|
1024
|
-
) : structuredEditable ? (
|
|
1025
|
-
<StructuredRoutingEditor
|
|
1026
|
-
setting={setting}
|
|
1027
|
-
value={draft?.operation === "set" ? draft.value : setting.value}
|
|
1028
|
-
disabled={disabled}
|
|
1029
|
-
resetLabel={workspaceScoped ? "Remove workspace override" : "Reset to default"}
|
|
1030
|
-
showReset={!workspaceScoped || setting.workspaceOverride === true}
|
|
1031
|
-
resetPending={draft?.operation === "reset"}
|
|
1032
|
-
styles={styles}
|
|
1033
|
-
theme={theme}
|
|
1034
|
-
modelCatalog={modelCatalog}
|
|
1035
|
-
modelRoles={modelRoles}
|
|
1036
|
-
agentCatalog={agentCatalog}
|
|
1037
|
-
onSet={(value) => onDraft(setting.path, { operation: "set", value })}
|
|
1038
|
-
onReset={() => onDraft(setting.path, { operation: "reset" })}
|
|
1039
|
-
/>
|
|
1040
|
-
) : complex ? (
|
|
1041
|
-
<StructuredSettingValue setting={setting} styles={styles} />
|
|
1042
|
-
) : null}
|
|
1043
|
-
{setting.description ? (
|
|
1044
|
-
<Text style={styles.settingDescription}>{setting.description}</Text>
|
|
1045
|
-
) : null}
|
|
1046
|
-
</View>
|
|
1047
|
-
);
|
|
1048
|
-
})}
|
|
1049
|
-
</SectionCard>
|
|
1071
|
+
);
|
|
1072
|
+
})}
|
|
1073
|
+
</SectionCard>
|
|
1074
|
+
</>
|
|
1050
1075
|
);
|
|
1051
1076
|
}
|
|
1052
1077
|
|
|
@@ -1208,7 +1233,7 @@ function OmpConfigContent({
|
|
|
1208
1233
|
let value: unknown = draft.value;
|
|
1209
1234
|
if (isOmpStructuredSettingPath(path)) {
|
|
1210
1235
|
const parsed = parseOmpStructuredSettingValue(path, value);
|
|
1211
|
-
if (parsed === undefined) throw new Error(`${path} contains invalid
|
|
1236
|
+
if (parsed === undefined) throw new Error(`${path} contains invalid values.`);
|
|
1212
1237
|
value = parsed;
|
|
1213
1238
|
} else if (setting.type === "number") {
|
|
1214
1239
|
const raw = String(draft.value).trim();
|
|
@@ -1226,6 +1251,7 @@ function OmpConfigContent({
|
|
|
1226
1251
|
queryClient.setQueryData(settingsQueryKey, result.catalog);
|
|
1227
1252
|
void queryClient.invalidateQueries({ queryKey: SETTINGS_QUERY_KEY });
|
|
1228
1253
|
void queryClient.invalidateQueries({ queryKey: ["paseo-omp", "config"] });
|
|
1254
|
+
void queryClient.invalidateQueries({ queryKey: SECURITY_QUERY_KEY });
|
|
1229
1255
|
if (
|
|
1230
1256
|
!result.conflict &&
|
|
1231
1257
|
!result.failed &&
|
|
@@ -1350,6 +1376,9 @@ function OmpConfigContent({
|
|
|
1350
1376
|
{view === "extensions" ? (
|
|
1351
1377
|
<OmpExtensionsSection theme={theme} styles={styles} cwd={cwd} store={store} />
|
|
1352
1378
|
) : null}
|
|
1379
|
+
{view === "security" && cwd ? (
|
|
1380
|
+
<OmpSecuritySection styles={styles} cwd={cwd} store={store} />
|
|
1381
|
+
) : null}
|
|
1353
1382
|
{view === "composer" && !cwd && onComposerPillSettingsChange ? (
|
|
1354
1383
|
<ComposerPillSettingsSection theme={theme} onChange={onComposerPillSettingsChange} />
|
|
1355
1384
|
) : null}
|
|
@@ -1535,6 +1564,9 @@ function OmpConfigContent({
|
|
|
1535
1564
|
agentCatalog={agentCatalog}
|
|
1536
1565
|
styles={styles}
|
|
1537
1566
|
settings={catalog.byCategory.get(selectedCategory.id) ?? []}
|
|
1567
|
+
policySettings={catalog.sourceSettings.filter((setting) =>
|
|
1568
|
+
isOmpToolPolicyPath(setting.path),
|
|
1569
|
+
)}
|
|
1538
1570
|
drafts={drafts}
|
|
1539
1571
|
disabled={!settingsQuery.data?.revision || save.isPending}
|
|
1540
1572
|
workspaceScoped={cwd !== undefined}
|
|
@@ -7,6 +7,7 @@ export type OmpConfigSurfaceView =
|
|
|
7
7
|
| "rules"
|
|
8
8
|
| "skills"
|
|
9
9
|
| "extensions"
|
|
10
|
+
| "security"
|
|
10
11
|
| "composer"
|
|
11
12
|
| "configuration"
|
|
12
13
|
| "diagnostics"
|
|
@@ -21,6 +22,7 @@ const SURFACE_VIEWS: readonly { id: OmpConfigSurfaceView; label: string }[] = [
|
|
|
21
22
|
{ id: "rules", label: "Rules" },
|
|
22
23
|
{ id: "skills", label: "Skills" },
|
|
23
24
|
{ id: "extensions", label: "Extensions" },
|
|
25
|
+
{ id: "security", label: "Security" },
|
|
24
26
|
{ id: "composer", label: "Composer" },
|
|
25
27
|
{ id: "configuration", label: "Configuration" },
|
|
26
28
|
{ id: "diagnostics", label: "Diagnostics" },
|
|
@@ -30,8 +32,10 @@ const SURFACE_VIEWS: readonly { id: OmpConfigSurfaceView; label: string }[] = [
|
|
|
30
32
|
/** Views that belong to the OMP store, not to a workspace's project settings. */
|
|
31
33
|
const STORE_ONLY_VIEWS: readonly OmpConfigSurfaceView[] = ["composer", "accounts", "mcps"];
|
|
32
34
|
|
|
35
|
+
/** Views about one project, which the global OMP screen has no project for. */
|
|
36
|
+
const WORKSPACE_ONLY_VIEWS: readonly OmpConfigSurfaceView[] = ["security"];
|
|
37
|
+
|
|
33
38
|
export function surfaceViewsForScope(workspaceScoped: boolean) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
: SURFACE_VIEWS;
|
|
39
|
+
const hidden = workspaceScoped ? STORE_ONLY_VIEWS : WORKSPACE_ONLY_VIEWS;
|
|
40
|
+
return SURFACE_VIEWS.filter((candidate) => !hidden.includes(candidate.id));
|
|
37
41
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useRpc } from "@getpaseo/plugin/client";
|
|
2
|
+
import {
|
|
3
|
+
SettingsAction,
|
|
4
|
+
SettingsCard,
|
|
5
|
+
SettingsRow,
|
|
6
|
+
SettingsSection,
|
|
7
|
+
} from "@getpaseo/plugin/client/ui";
|
|
8
|
+
import { useQuery } from "@tanstack/react-query";
|
|
9
|
+
import { Text, View } from "react-native";
|
|
10
|
+
import { listOmpSecurity, type OmpSecurityScan } from "../shared/omp-security";
|
|
11
|
+
import type { OmpStore } from "../shared/omp-store";
|
|
12
|
+
import type { OmpConfigStyles } from "./omp-config-styles";
|
|
13
|
+
import { SECURITY_QUERY_KEY, severityText } from "./omp-security-state";
|
|
14
|
+
import { ompStoreKey } from "./omp-store-state";
|
|
15
|
+
|
|
16
|
+
const INFO =
|
|
17
|
+
"Scans the agent ran with OMP's security_scan tool for this project, read through omp itself. Only each scan's phase and finding counts are shown: findings are private, so titles, locations and reports stay in OMP. Starting, cancelling or validating a scan happens inside an agent session; ask the agent. Opening this tab makes OMP create an empty store entry for the project.";
|
|
18
|
+
|
|
19
|
+
/** A refetch runs up to 22 omp processes, so it is manual or at most once a minute. */
|
|
20
|
+
const STALE_MS = 60_000;
|
|
21
|
+
|
|
22
|
+
function rowLabel(scan: OmpSecurityScan): string {
|
|
23
|
+
const noun = scan.findingCount === 1 ? "finding" : "findings";
|
|
24
|
+
return `${scan.phase} · ${scan.findingCount} ${noun}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function OmpSecuritySection({
|
|
28
|
+
styles,
|
|
29
|
+
cwd,
|
|
30
|
+
store,
|
|
31
|
+
}: {
|
|
32
|
+
styles: OmpConfigStyles;
|
|
33
|
+
cwd: string;
|
|
34
|
+
store?: OmpStore;
|
|
35
|
+
}) {
|
|
36
|
+
const load = useRpc(listOmpSecurity);
|
|
37
|
+
const security = useQuery({
|
|
38
|
+
queryKey: [...SECURITY_QUERY_KEY, ompStoreKey(store), cwd],
|
|
39
|
+
queryFn: () => load({ store, cwd }),
|
|
40
|
+
staleTime: STALE_MS,
|
|
41
|
+
refetchOnWindowFocus: false,
|
|
42
|
+
});
|
|
43
|
+
const list = security.data;
|
|
44
|
+
return (
|
|
45
|
+
<View style={{ gap: 12 }}>
|
|
46
|
+
<SettingsSection title="Security scans" info={INFO}>
|
|
47
|
+
<SettingsCard>
|
|
48
|
+
<SettingsAction
|
|
49
|
+
label="Refresh list"
|
|
50
|
+
hint="Read the scans from omp again"
|
|
51
|
+
actionLabel={security.isFetching ? "Refreshing..." : "Refresh"}
|
|
52
|
+
disabled={security.isFetching}
|
|
53
|
+
onPress={() => void security.refetch()}
|
|
54
|
+
/>
|
|
55
|
+
</SettingsCard>
|
|
56
|
+
</SettingsSection>
|
|
57
|
+
{security.isLoading ? <Text style={styles.muted}>Loading security scans...</Text> : null}
|
|
58
|
+
{security.error ? (
|
|
59
|
+
<Text accessibilityRole="alert" style={styles.error}>
|
|
60
|
+
Could not read OMP's security scans.
|
|
61
|
+
</Text>
|
|
62
|
+
) : null}
|
|
63
|
+
{list?.status === "error" ? (
|
|
64
|
+
<Text accessibilityRole="alert" style={styles.error}>
|
|
65
|
+
{list.message}
|
|
66
|
+
</Text>
|
|
67
|
+
) : null}
|
|
68
|
+
{list?.status === "off" ? (
|
|
69
|
+
<Text style={styles.muted}>
|
|
70
|
+
Security scans are off. Turn on security.enabled in the Configuration tab to use them.
|
|
71
|
+
</Text>
|
|
72
|
+
) : null}
|
|
73
|
+
{list?.status === "ready" && list.scans.length === 0 ? (
|
|
74
|
+
<Text style={styles.muted}>No scans are stored for this project</Text>
|
|
75
|
+
) : null}
|
|
76
|
+
{list?.status === "ready" && list.skipped > 0 ? (
|
|
77
|
+
<Text style={styles.muted}>
|
|
78
|
+
{`${list.skipped} ${list.skipped === 1 ? "entry" : "entries"} in OMP's scan list could not be read`}
|
|
79
|
+
</Text>
|
|
80
|
+
) : null}
|
|
81
|
+
{list?.status === "ready" && list.scans.length > 0 ? (
|
|
82
|
+
<SettingsSection title="Scans">
|
|
83
|
+
<SettingsCard>
|
|
84
|
+
{list.scans.map((scan) => (
|
|
85
|
+
<SettingsRow
|
|
86
|
+
key={scan.id}
|
|
87
|
+
label={rowLabel(scan)}
|
|
88
|
+
hint={`${severityText(scan)} · ${scan.producer} · ${scan.createdAt}`}
|
|
89
|
+
/>
|
|
90
|
+
))}
|
|
91
|
+
</SettingsCard>
|
|
92
|
+
{list.truncated ? (
|
|
93
|
+
<Text style={styles.muted}>Only the first scans OMP lists are shown</Text>
|
|
94
|
+
) : null}
|
|
95
|
+
</SettingsSection>
|
|
96
|
+
) : null}
|
|
97
|
+
</View>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OMP_SECURITY_SEVERITIES, type OmpSecurityScan } from "../shared/omp-security";
|
|
2
|
+
|
|
3
|
+
/** The security tab's query key prefix, invalidated when a setting such as security.enabled is saved. */
|
|
4
|
+
export const SECURITY_QUERY_KEY = ["paseo-omp", "security"] as const;
|
|
5
|
+
|
|
6
|
+
/** The per-severity counts of one scan, worded for both a cut-short list and a failed read. */
|
|
7
|
+
export function severityText(scan: OmpSecurityScan): string {
|
|
8
|
+
if (scan.findingCount === 0) return "No findings";
|
|
9
|
+
const listed = OMP_SECURITY_SEVERITIES.flatMap((level) =>
|
|
10
|
+
scan.severities[level] ? [`${scan.severities[level]} ${level}`] : [],
|
|
11
|
+
).join(", ");
|
|
12
|
+
if (scan.severitiesComplete) return listed;
|
|
13
|
+
return listed === "" ? "Severity counts unavailable" : `${listed} (counts may be incomplete)`;
|
|
14
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type OmpBashRule,
|
|
3
|
+
OmpBashRuleSchema,
|
|
4
|
+
OmpBashRulesSchema,
|
|
5
|
+
OmpRestrictedFoldersSchema,
|
|
6
|
+
type OmpToolApproval,
|
|
7
|
+
OmpToolApprovalSchema,
|
|
8
|
+
OmpToolPoliciesSchema,
|
|
9
|
+
} from "../shared/omp-settings";
|
|
10
|
+
|
|
11
|
+
export type ToolPolicies = Record<string, OmpToolApproval>;
|
|
12
|
+
|
|
13
|
+
export interface ToolPolicyState {
|
|
14
|
+
policies: ToolPolicies;
|
|
15
|
+
rules: OmpBashRule[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* OMP does not validate these values when it stores them. Keep only entries Apply would accept,
|
|
20
|
+
* so one stored bad entry cannot make every later save fail.
|
|
21
|
+
*/
|
|
22
|
+
export function readToolPolicies(value: unknown): ToolPolicies {
|
|
23
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return {};
|
|
24
|
+
const policies: ToolPolicies = {};
|
|
25
|
+
for (const [tool, approval] of Object.entries(value)) {
|
|
26
|
+
const parsed = OmpToolPoliciesSchema.safeParse({ [tool]: approval });
|
|
27
|
+
if (parsed.success) Object.assign(policies, parsed.data);
|
|
28
|
+
}
|
|
29
|
+
return policies;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function readBashRules(value: unknown): OmpBashRule[] {
|
|
33
|
+
if (!Array.isArray(value)) return [];
|
|
34
|
+
return value.flatMap((entry): OmpBashRule[] => {
|
|
35
|
+
if (entry === null || typeof entry !== "object") return [];
|
|
36
|
+
const { match, approval } = entry as { match?: unknown; approval?: unknown };
|
|
37
|
+
const parsed = OmpBashRuleSchema.safeParse({ match, approval });
|
|
38
|
+
return parsed.success ? [parsed.data] : [];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** A rule being edited can be momentarily invalid, for example an emptied pattern, and must stay on screen. */
|
|
43
|
+
export function readBashRuleDraft(value: unknown): OmpBashRule[] {
|
|
44
|
+
if (!Array.isArray(value)) return [];
|
|
45
|
+
return value.flatMap((entry): OmpBashRule[] => {
|
|
46
|
+
if (entry === null || typeof entry !== "object") return [];
|
|
47
|
+
const { match, approval } = entry as { match?: unknown; approval?: unknown };
|
|
48
|
+
const parsed = OmpToolApprovalSchema.safeParse(approval);
|
|
49
|
+
return typeof match === "string" && parsed.success ? [{ match, approval: parsed.data }] : [];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function readFolders(value: unknown): string[] {
|
|
54
|
+
if (!Array.isArray(value)) return [];
|
|
55
|
+
const folders = value.filter((item) => OmpRestrictedFoldersSchema.safeParse([item]).success);
|
|
56
|
+
return [...new Set(folders as string[])];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Rules are first match wins, so moving a rule changes which one applies. */
|
|
60
|
+
export function moveRule<T>(rules: readonly T[], index: number, offset: -1 | 1): T[] {
|
|
61
|
+
const target = index + offset;
|
|
62
|
+
if (target < 0 || target >= rules.length) return [...rules];
|
|
63
|
+
const next = [...rules];
|
|
64
|
+
const [moved] = next.splice(index, 1);
|
|
65
|
+
if (moved === undefined) return next;
|
|
66
|
+
next.splice(target, 0, moved);
|
|
67
|
+
return next;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Effects of the saved policy that a user would not guess from the approval mode picker. */
|
|
71
|
+
export function policyWarnings({ policies, rules }: ToolPolicyState): string[] {
|
|
72
|
+
const warnings: string[] = [];
|
|
73
|
+
if (policies.bash === "allow") {
|
|
74
|
+
warnings.push(
|
|
75
|
+
"Bash is set to Allow, so it runs without asking in every mode, including Always Ask.",
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (rules.some((rule) => rule.approval === "allow")) {
|
|
79
|
+
warnings.push("Commands matching an Allow rule run without asking, even in Always Ask.");
|
|
80
|
+
}
|
|
81
|
+
const asks =
|
|
82
|
+
Object.values(policies).includes("prompt") || rules.some((rule) => rule.approval === "prompt");
|
|
83
|
+
if (asks) {
|
|
84
|
+
warnings.push(
|
|
85
|
+
"Subagents cannot answer prompts, so a call that matches an Ask rule fails there.",
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return warnings;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Add is offered only when the whole resulting list would pass the schema Apply uses. */
|
|
92
|
+
export function canAddToolRule(policies: ToolPolicies, tool: string): boolean {
|
|
93
|
+
return (
|
|
94
|
+
!Object.hasOwn(policies, tool) &&
|
|
95
|
+
OmpToolPoliciesSchema.safeParse({ ...policies, [tool]: "prompt" }).success
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function canAddBashRule(rules: readonly OmpBashRule[], match: string): boolean {
|
|
100
|
+
return OmpBashRulesSchema.safeParse([...rules, { match, approval: "prompt" }]).success;
|
|
101
|
+
}
|