@omercnet/paseo-omp 5.4.0-next.410.1 → 5.4.0-next.413.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.
@@ -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,
@@ -621,6 +625,46 @@ function ProviderHealthSection({
621
625
  );
622
626
  }
623
627
 
628
+ function MagicKeywordsHelp({ styles }: { styles: OmpConfigStyles }) {
629
+ return (
630
+ <SectionCard styles={styles} title="Magic keywords">
631
+ <Text style={styles.muted}>
632
+ OMP treats a few standalone, lowercase words in a prompt as switches. Each adds a hidden
633
+ instruction for that one turn. Words inside code blocks, inline code and paths are ignored.
634
+ </Text>
635
+ <KeyValueRow
636
+ styles={styles}
637
+ label="ultrathink"
638
+ value="Careful reasoning, and maximum reasoning effort when automatic thinking is on."
639
+ />
640
+ <KeyValueRow
641
+ styles={styles}
642
+ label="orchestrate"
643
+ value="Splits the work across parallel subagents and verifies each phase. Needs the task tool."
644
+ />
645
+ <KeyValueRow
646
+ styles={styles}
647
+ label="workflowz"
648
+ value="Runs a scripted multi-subagent workflow. Needs the eval and task tools."
649
+ />
650
+ <KeyValueRow
651
+ styles={styles}
652
+ label="jevify"
653
+ value="Applies a bulk-classification contract. Needs the eval tool."
654
+ />
655
+ <Text style={styles.muted}>
656
+ Cost: orchestrate and workflowz can start extra subagents, so a turn that uses them costs
657
+ more.
658
+ </Text>
659
+ <Text style={styles.muted}>
660
+ To turn them off, set magicKeywords.enabled to false in Configuration. Each word also has
661
+ its own switch: magicKeywords.ultrathink, magicKeywords.orchestrate, magicKeywords.workflow
662
+ (this one switches workflowz) and magicKeywords.jevify.
663
+ </Text>
664
+ </SectionCard>
665
+ );
666
+ }
667
+
624
668
  function SupportDiagnosticsSection({
625
669
  theme,
626
670
  styles,
@@ -937,6 +981,7 @@ function ConfigurationCategory({
937
981
  category,
938
982
  styles,
939
983
  settings,
984
+ policySettings: allPolicySettings,
940
985
  drafts,
941
986
  theme,
942
987
  modelCatalog,
@@ -954,6 +999,8 @@ function ConfigurationCategory({
954
999
  modelRoles: Readonly<Record<string, unknown>>;
955
1000
  agentCatalog: OmpAgentCatalogState;
956
1001
  settings: readonly OmpSetting[];
1002
+ /** Every stored tool policy setting, so warnings do not depend on the search text. */
1003
+ policySettings: readonly OmpSetting[];
957
1004
  drafts: Readonly<Record<string, SettingDraft>>;
958
1005
  disabled: boolean;
959
1006
  workspaceScoped: boolean;
@@ -961,92 +1008,110 @@ function ConfigurationCategory({
961
1008
  onOpenDocumentation(link: OmpDocumentationLink): void;
962
1009
  }) {
963
1010
  const categoryDocumentation = documentationForSettingCategory(category.id);
1011
+ const visiblePolicySettings =
1012
+ category.id === "tools" ? settings.filter((setting) => isOmpToolPolicyPath(setting.path)) : [];
1013
+ const listed = settings.filter((setting) => !visiblePolicySettings.includes(setting));
964
1014
  return (
965
- <SectionCard
966
- styles={styles}
967
- title={`${category.label} · ${settings.length}`}
968
- action={
969
- categoryDocumentation ? (
970
- <DocumentationLink
971
- link={categoryDocumentation}
972
- styles={styles}
973
- onOpen={onOpenDocumentation}
974
- />
975
- ) : undefined
976
- }
977
- >
978
- {settings.map((setting) => {
979
- const complex =
980
- Array.isArray(setting.value) ||
981
- (setting.value !== null && typeof setting.value === "object");
982
- const editable =
983
- !setting.redacted && ["boolean", "number", "string", "enum"].includes(setting.type);
984
- const structuredEditable =
985
- !setting.redacted &&
986
- isOmpStructuredSettingPath(setting.path) &&
987
- setting.type === structuredSettingType(setting.path);
988
- const settingDocumentation = documentationForSettingPath(setting.path);
989
- const draft = drafts[setting.path];
990
- return (
991
- <View key={setting.path} style={styles.setting}>
992
- <View style={styles.settingHeader}>
993
- <Text style={styles.cardTitle}>{formatOmpSettingLabel(setting.path)}</Text>
994
- {setting.workspaceOverride ? (
995
- <Text style={styles.source}>Workspace override</Text>
1015
+ <>
1016
+ {visiblePolicySettings.length > 0 ? (
1017
+ <ToolPolicyCard
1018
+ settings={allPolicySettings}
1019
+ visiblePaths={visiblePolicySettings.map((setting) => setting.path)}
1020
+ drafts={drafts}
1021
+ disabled={disabled}
1022
+ workspaceScoped={workspaceScoped}
1023
+ resetLabel={workspaceScoped ? "Remove workspace override" : "Reset to default"}
1024
+ styles={styles}
1025
+ onSet={(path, value) => onDraft(path, { operation: "set", value })}
1026
+ onReset={(path) => onDraft(path, { operation: "reset" })}
1027
+ />
1028
+ ) : null}
1029
+ <SectionCard
1030
+ styles={styles}
1031
+ title={`${category.label} · ${listed.length}`}
1032
+ action={
1033
+ categoryDocumentation ? (
1034
+ <DocumentationLink
1035
+ link={categoryDocumentation}
1036
+ styles={styles}
1037
+ onOpen={onOpenDocumentation}
1038
+ />
1039
+ ) : undefined
1040
+ }
1041
+ >
1042
+ {listed.map((setting) => {
1043
+ const complex =
1044
+ Array.isArray(setting.value) ||
1045
+ (setting.value !== null && typeof setting.value === "object");
1046
+ const editable =
1047
+ !setting.redacted && ["boolean", "number", "string", "enum"].includes(setting.type);
1048
+ const structuredEditable =
1049
+ !setting.redacted &&
1050
+ isOmpStructuredSettingPath(setting.path) &&
1051
+ setting.type === structuredSettingType(setting.path);
1052
+ const settingDocumentation = documentationForSettingPath(setting.path);
1053
+ const draft = drafts[setting.path];
1054
+ return (
1055
+ <View key={setting.path} style={styles.setting}>
1056
+ <View style={styles.settingHeader}>
1057
+ <Text style={styles.cardTitle}>{formatOmpSettingLabel(setting.path)}</Text>
1058
+ {setting.workspaceOverride ? (
1059
+ <Text style={styles.source}>Workspace override</Text>
1060
+ ) : null}
1061
+ {!complex && !editable && !structuredEditable ? (
1062
+ <StructuredSettingValue setting={setting} styles={styles} />
1063
+ ) : null}
1064
+ </View>
1065
+ <Text selectable style={styles.settingPath}>
1066
+ {setting.path} · {setting.type}
1067
+ </Text>
1068
+ {settingDocumentation ? (
1069
+ <View style={styles.docsActions}>
1070
+ <DocumentationLink
1071
+ link={settingDocumentation}
1072
+ styles={styles}
1073
+ onOpen={onOpenDocumentation}
1074
+ />
1075
+ </View>
996
1076
  ) : null}
997
- {!complex && !editable && !structuredEditable ? (
1077
+ {editable ? (
1078
+ <EditableScalarValue
1079
+ setting={setting}
1080
+ draft={draft}
1081
+ disabled={disabled}
1082
+ resetLabel={workspaceScoped ? "Remove workspace override" : "Reset to default"}
1083
+ showReset={!workspaceScoped || setting.workspaceOverride === true}
1084
+ styles={styles}
1085
+ onSet={(value) => onDraft(setting.path, { operation: "set", value })}
1086
+ onReset={() => onDraft(setting.path, { operation: "reset" })}
1087
+ />
1088
+ ) : structuredEditable ? (
1089
+ <StructuredRoutingEditor
1090
+ setting={setting}
1091
+ value={draft?.operation === "set" ? draft.value : setting.value}
1092
+ disabled={disabled}
1093
+ resetLabel={workspaceScoped ? "Remove workspace override" : "Reset to default"}
1094
+ showReset={!workspaceScoped || setting.workspaceOverride === true}
1095
+ resetPending={draft?.operation === "reset"}
1096
+ styles={styles}
1097
+ theme={theme}
1098
+ modelCatalog={modelCatalog}
1099
+ modelRoles={modelRoles}
1100
+ agentCatalog={agentCatalog}
1101
+ onSet={(value) => onDraft(setting.path, { operation: "set", value })}
1102
+ onReset={() => onDraft(setting.path, { operation: "reset" })}
1103
+ />
1104
+ ) : complex ? (
998
1105
  <StructuredSettingValue setting={setting} styles={styles} />
999
1106
  ) : null}
1107
+ {setting.description ? (
1108
+ <Text style={styles.settingDescription}>{setting.description}</Text>
1109
+ ) : null}
1000
1110
  </View>
1001
- <Text selectable style={styles.settingPath}>
1002
- {setting.path} · {setting.type}
1003
- </Text>
1004
- {settingDocumentation ? (
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>
1111
+ );
1112
+ })}
1113
+ </SectionCard>
1114
+ </>
1050
1115
  );
1051
1116
  }
1052
1117
 
@@ -1208,7 +1273,7 @@ function OmpConfigContent({
1208
1273
  let value: unknown = draft.value;
1209
1274
  if (isOmpStructuredSettingPath(path)) {
1210
1275
  const parsed = parseOmpStructuredSettingValue(path, value);
1211
- if (parsed === undefined) throw new Error(`${path} contains invalid routing values.`);
1276
+ if (parsed === undefined) throw new Error(`${path} contains invalid values.`);
1212
1277
  value = parsed;
1213
1278
  } else if (setting.type === "number") {
1214
1279
  const raw = String(draft.value).trim();
@@ -1226,6 +1291,7 @@ function OmpConfigContent({
1226
1291
  queryClient.setQueryData(settingsQueryKey, result.catalog);
1227
1292
  void queryClient.invalidateQueries({ queryKey: SETTINGS_QUERY_KEY });
1228
1293
  void queryClient.invalidateQueries({ queryKey: ["paseo-omp", "config"] });
1294
+ void queryClient.invalidateQueries({ queryKey: SECURITY_QUERY_KEY });
1229
1295
  if (
1230
1296
  !result.conflict &&
1231
1297
  !result.failed &&
@@ -1350,6 +1416,9 @@ function OmpConfigContent({
1350
1416
  {view === "extensions" ? (
1351
1417
  <OmpExtensionsSection theme={theme} styles={styles} cwd={cwd} store={store} />
1352
1418
  ) : null}
1419
+ {view === "security" && cwd ? (
1420
+ <OmpSecuritySection styles={styles} cwd={cwd} store={store} />
1421
+ ) : null}
1353
1422
  {view === "composer" && !cwd && onComposerPillSettingsChange ? (
1354
1423
  <ComposerPillSettingsSection theme={theme} onChange={onComposerPillSettingsChange} />
1355
1424
  ) : null}
@@ -1359,7 +1428,10 @@ function OmpConfigContent({
1359
1428
  ) : null}
1360
1429
 
1361
1430
  {view === "help" ? (
1362
- <SupportDiagnosticsSection theme={theme} styles={styles} cwd={cwd} store={store} />
1431
+ <>
1432
+ <MagicKeywordsHelp styles={styles} />
1433
+ <SupportDiagnosticsSection theme={theme} styles={styles} cwd={cwd} store={store} />
1434
+ </>
1363
1435
  ) : null}
1364
1436
 
1365
1437
  {view === "configuration" ? (
@@ -1535,6 +1607,9 @@ function OmpConfigContent({
1535
1607
  agentCatalog={agentCatalog}
1536
1608
  styles={styles}
1537
1609
  settings={catalog.byCategory.get(selectedCategory.id) ?? []}
1610
+ policySettings={catalog.sourceSettings.filter((setting) =>
1611
+ isOmpToolPolicyPath(setting.path),
1612
+ )}
1538
1613
  drafts={drafts}
1539
1614
  disabled={!settingsQuery.data?.revision || save.isPending}
1540
1615
  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
- return workspaceScoped
35
- ? SURFACE_VIEWS.filter((candidate) => !STORE_ONLY_VIEWS.includes(candidate.id))
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
+ }