@omercnet/paseo-omp 5.4.0-next.416.1 → 5.4.0-next.417.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-rules-section.tsx +69 -10
- package/index.server.ts +3 -1
- package/package.json +1 -1
- package/server/omp-list-setting.ts +1 -1
- package/server/omp-rule-switch.ts +38 -0
- package/server/package-version.ts +1 -1
- package/shared/omp-rules.ts +17 -0
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { type PluginSurfaceProps, useRpc } from "@getpaseo/plugin/client";
|
|
2
|
-
import { copyText, Icon } from "@getpaseo/plugin/client/ui";
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { copyText, Icon, useToast } from "@getpaseo/plugin/client/ui";
|
|
3
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
4
|
import { useState } from "react";
|
|
5
|
-
import { Pressable, Text, View } from "react-native";
|
|
6
|
-
import {
|
|
5
|
+
import { Pressable, Switch, Text, View } from "react-native";
|
|
6
|
+
import {
|
|
7
|
+
listOmpRules,
|
|
8
|
+
type OmpRule,
|
|
9
|
+
type OmpRuleKind,
|
|
10
|
+
setOmpRuleEnabled,
|
|
11
|
+
} from "../shared/omp-rules";
|
|
7
12
|
import type { OmpStore } from "../shared/omp-store";
|
|
13
|
+
import { describe } from "./omp-accounts-section";
|
|
8
14
|
import type { OmpConfigStyles } from "./omp-config-styles";
|
|
9
15
|
import { ompStoreKey } from "./omp-store-state";
|
|
10
16
|
|
|
@@ -17,6 +23,8 @@ const COPY_LABELS: Record<CopyState, string> = {
|
|
|
17
23
|
failed: "Copy failed",
|
|
18
24
|
};
|
|
19
25
|
|
|
26
|
+
const RULES_KEY = ["paseo-omp", "rules"] as const;
|
|
27
|
+
|
|
20
28
|
const GROUPS: readonly { kind: OmpRuleKind; title: string; empty: string }[] = [
|
|
21
29
|
{ kind: "watch", title: "Watch", empty: "No watch rules" },
|
|
22
30
|
{ kind: "always", title: "Always applied", empty: "No always-applied rules" },
|
|
@@ -50,7 +58,20 @@ function Detail({
|
|
|
50
58
|
);
|
|
51
59
|
}
|
|
52
60
|
|
|
53
|
-
|
|
61
|
+
interface RuleSwitch {
|
|
62
|
+
busy: boolean;
|
|
63
|
+
toggle: (name: string, enabled: boolean) => void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function RuleRow({
|
|
67
|
+
styles,
|
|
68
|
+
rule,
|
|
69
|
+
rules,
|
|
70
|
+
}: {
|
|
71
|
+
styles: OmpConfigStyles;
|
|
72
|
+
rule: OmpRule;
|
|
73
|
+
rules: RuleSwitch;
|
|
74
|
+
}) {
|
|
54
75
|
const [copyState, setCopyState] = useState<CopyState>("idle");
|
|
55
76
|
async function copyPath() {
|
|
56
77
|
try {
|
|
@@ -75,6 +96,12 @@ function RuleRow({ styles, rule }: { styles: OmpConfigStyles; rule: OmpRule }) {
|
|
|
75
96
|
{rule.name}
|
|
76
97
|
</Text>
|
|
77
98
|
<Text style={styles.source}>{sourceLabel(rule)}</Text>
|
|
99
|
+
<Switch
|
|
100
|
+
accessibilityLabel={`Rule ${rule.name} is on`}
|
|
101
|
+
disabled={rules.busy}
|
|
102
|
+
value
|
|
103
|
+
onValueChange={() => rules.toggle(rule.name, false)}
|
|
104
|
+
/>
|
|
78
105
|
</View>
|
|
79
106
|
{rule.description ? <Text style={styles.settingDescription}>{rule.description}</Text> : null}
|
|
80
107
|
{details.map(([label, values]) =>
|
|
@@ -102,10 +129,12 @@ function BuiltinRules({
|
|
|
102
129
|
theme,
|
|
103
130
|
styles,
|
|
104
131
|
rules,
|
|
132
|
+
rulesSwitch,
|
|
105
133
|
}: {
|
|
106
134
|
theme: Theme;
|
|
107
135
|
styles: OmpConfigStyles;
|
|
108
136
|
rules: OmpRule[];
|
|
137
|
+
rulesSwitch: RuleSwitch;
|
|
109
138
|
}) {
|
|
110
139
|
const [expanded, setExpanded] = useState(false);
|
|
111
140
|
if (rules.length === 0) return null;
|
|
@@ -126,7 +155,9 @@ function BuiltinRules({
|
|
|
126
155
|
<Text style={styles.rowValue}>Built-in rules ({rules.length})</Text>
|
|
127
156
|
</Pressable>
|
|
128
157
|
{expanded
|
|
129
|
-
? rules.map((rule) =>
|
|
158
|
+
? rules.map((rule) => (
|
|
159
|
+
<RuleRow key={rule.name} styles={styles} rule={rule} rules={rulesSwitch} />
|
|
160
|
+
))
|
|
130
161
|
: null}
|
|
131
162
|
</>
|
|
132
163
|
);
|
|
@@ -144,10 +175,27 @@ export function OmpRulesSection({
|
|
|
144
175
|
store?: OmpStore;
|
|
145
176
|
}) {
|
|
146
177
|
const loadRules = useRpc(listOmpRules);
|
|
178
|
+
const setEnabled = useRpc(setOmpRuleEnabled);
|
|
179
|
+
const toast = useToast();
|
|
180
|
+
const queryClient = useQueryClient();
|
|
147
181
|
const rules = useQuery({
|
|
148
|
-
queryKey: [
|
|
182
|
+
queryKey: [...RULES_KEY, ompStoreKey(store), cwd ?? "global"],
|
|
149
183
|
queryFn: () => loadRules({ store, ...(cwd ? { cwd } : {}) }),
|
|
150
184
|
});
|
|
185
|
+
const toggle = useMutation({
|
|
186
|
+
mutationKey: [...RULES_KEY, "toggle"],
|
|
187
|
+
mutationFn: (change: { name: string; enabled: boolean }) =>
|
|
188
|
+
setEnabled({ store, ...(cwd ? { cwd } : {}), ...change }),
|
|
189
|
+
onSuccess: async (result) => {
|
|
190
|
+
if (result.status === "error") toast.error(result.message);
|
|
191
|
+
await queryClient.invalidateQueries({ queryKey: RULES_KEY });
|
|
192
|
+
},
|
|
193
|
+
onError: (error) => toast.error(describe(error)),
|
|
194
|
+
});
|
|
195
|
+
const rulesSwitch: RuleSwitch = {
|
|
196
|
+
busy: toggle.isPending,
|
|
197
|
+
toggle: (name, enabled) => toggle.mutate({ name, enabled }),
|
|
198
|
+
};
|
|
151
199
|
const list = rules.data;
|
|
152
200
|
return (
|
|
153
201
|
<>
|
|
@@ -186,9 +234,14 @@ export function OmpRulesSection({
|
|
|
186
234
|
<Text style={styles.cardTitle}>{group.title}</Text>
|
|
187
235
|
{members.length === 0 ? <Text style={styles.muted}>{group.empty}</Text> : null}
|
|
188
236
|
{own.map((rule) => (
|
|
189
|
-
<RuleRow key={rule.name} styles={styles} rule={rule} />
|
|
237
|
+
<RuleRow key={rule.name} styles={styles} rule={rule} rules={rulesSwitch} />
|
|
190
238
|
))}
|
|
191
|
-
<BuiltinRules
|
|
239
|
+
<BuiltinRules
|
|
240
|
+
theme={theme}
|
|
241
|
+
styles={styles}
|
|
242
|
+
rules={builtin}
|
|
243
|
+
rulesSwitch={rulesSwitch}
|
|
244
|
+
/>
|
|
192
245
|
{group.kind === "watch" && !list.builtinRules ? (
|
|
193
246
|
<Text style={styles.muted}>Built-in rules are off (ttsr.builtinRules)</Text>
|
|
194
247
|
) : null}
|
|
@@ -203,10 +256,16 @@ export function OmpRulesSection({
|
|
|
203
256
|
<>
|
|
204
257
|
<Text style={styles.muted}>Listed in ttsr.disabledRules, so OMP skips them</Text>
|
|
205
258
|
{list.disabled.map((name) => (
|
|
206
|
-
<View key={name} style={styles.setting}>
|
|
259
|
+
<View key={name} style={[styles.setting, styles.settingHeader]}>
|
|
207
260
|
<Text selectable style={styles.settingValue}>
|
|
208
261
|
{name}
|
|
209
262
|
</Text>
|
|
263
|
+
<Switch
|
|
264
|
+
accessibilityLabel={`Rule ${name} is off`}
|
|
265
|
+
disabled={rulesSwitch.busy}
|
|
266
|
+
value={false}
|
|
267
|
+
onValueChange={() => rulesSwitch.toggle(name, true)}
|
|
268
|
+
/>
|
|
210
269
|
</View>
|
|
211
270
|
))}
|
|
212
271
|
</>
|
package/index.server.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
resolveMutateOmpPluginConfig,
|
|
25
25
|
} from "./server/omp-plugins";
|
|
26
26
|
import { readHostAppendPrompt, readOmpPromptFiles } from "./server/omp-prompt-files";
|
|
27
|
+
import { resolveSetOmpRuleEnabled } from "./server/omp-rule-switch";
|
|
27
28
|
import { resolveListOmpRules } from "./server/omp-rules";
|
|
28
29
|
import { resolveListOmpSecurity } from "./server/omp-security";
|
|
29
30
|
import { resolveListOmpSettings, resolveUpdateOmpSettings } from "./server/omp-settings";
|
|
@@ -97,7 +98,7 @@ import {
|
|
|
97
98
|
mutateOmpPluginConfig,
|
|
98
99
|
} from "./shared/omp-plugins";
|
|
99
100
|
import { getOmpPromptFiles } from "./shared/omp-prompt-files";
|
|
100
|
-
import { listOmpRules } from "./shared/omp-rules";
|
|
101
|
+
import { listOmpRules, setOmpRuleEnabled } from "./shared/omp-rules";
|
|
101
102
|
import { listOmpSecurity } from "./shared/omp-security";
|
|
102
103
|
import { listOmpSettings, updateOmpSettings } from "./shared/omp-settings";
|
|
103
104
|
import { deleteOmpManagedSkill, listOmpSkills, setOmpSkillEnabled } from "./shared/omp-skills";
|
|
@@ -225,6 +226,7 @@ export default function contribute(server: PluginServerContext) {
|
|
|
225
226
|
server.handle(browseOmpMarketplace, scoped(resolveBrowseOmpMarketplace));
|
|
226
227
|
server.handle(mutateOmpMarketplace, scoped(resolveMutateOmpMarketplace));
|
|
227
228
|
server.handle(listOmpRules, scoped(resolveListOmpRules));
|
|
229
|
+
server.handle(setOmpRuleEnabled, scoped(resolveSetOmpRuleEnabled));
|
|
228
230
|
server.handle(listOmpExtensions, scoped(resolveListOmpExtensions));
|
|
229
231
|
server.handle(setOmpExtensionEnabled, scoped(resolveSetOmpExtensionEnabled));
|
|
230
232
|
server.handle(listOmpSecurity, scoped(resolveListOmpSecurity));
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from "./omp-settings";
|
|
10
10
|
import { OmpPublicError } from "./provider/security";
|
|
11
11
|
|
|
12
|
-
export type OmpListName = "skills.ignoredSkills" | "disabledExtensions";
|
|
12
|
+
export type OmpListName = "skills.ignoredSkills" | "disabledExtensions" | "ttsr.disabledRules";
|
|
13
13
|
|
|
14
14
|
export class OmpListError extends OmpPublicError {}
|
|
15
15
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { RpcInput } from "@getpaseo/plugin";
|
|
2
|
+
import type { setOmpRuleEnabled } from "../shared/omp-rules";
|
|
3
|
+
import {
|
|
4
|
+
type OmpListDependencies,
|
|
5
|
+
ompListDependencies,
|
|
6
|
+
requireOmpExecutable,
|
|
7
|
+
writeListEntry,
|
|
8
|
+
} from "./omp-list-setting";
|
|
9
|
+
import { inOmpScope } from "./omp-rules";
|
|
10
|
+
import { runSettingsMutation } from "./omp-settings";
|
|
11
|
+
import { OmpPublicError } from "./provider/security";
|
|
12
|
+
|
|
13
|
+
/** Off adds the rule to `ttsr.disabledRules`; on removes it. A workspace saves the whole project list. */
|
|
14
|
+
export async function setOmpRuleEnabledWithDependencies(
|
|
15
|
+
input: RpcInput<typeof setOmpRuleEnabled>,
|
|
16
|
+
dependencies: OmpListDependencies,
|
|
17
|
+
): Promise<{ status: "ok" } | { status: "error"; message: string }> {
|
|
18
|
+
try {
|
|
19
|
+
const executable = await requireOmpExecutable(dependencies);
|
|
20
|
+
const change = {
|
|
21
|
+
cwd: input.cwd,
|
|
22
|
+
list: "ttsr.disabledRules" as const,
|
|
23
|
+
entry: input.name,
|
|
24
|
+
enabled: input.enabled,
|
|
25
|
+
};
|
|
26
|
+
await inOmpScope(input.cwd, dependencies, (runIn) =>
|
|
27
|
+
runSettingsMutation(() => writeListEntry(change, dependencies, executable, runIn)),
|
|
28
|
+
);
|
|
29
|
+
return { status: "ok" };
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error instanceof OmpPublicError) return { status: "error", message: error.message };
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function resolveSetOmpRuleEnabled(input: RpcInput<typeof setOmpRuleEnabled>) {
|
|
37
|
+
return setOmpRuleEnabledWithDependencies(input, ompListDependencies);
|
|
38
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Release Please keeps this bundle-safe constant aligned with package.json. */
|
|
2
|
-
export const PASEO_OMP_PACKAGE_VERSION = "5.4.0-next.
|
|
2
|
+
export const PASEO_OMP_PACKAGE_VERSION = "5.4.0-next.417.1"; // x-release-please-version
|
package/shared/omp-rules.ts
CHANGED
|
@@ -47,3 +47,20 @@ export const listOmpRules = defineRpc({
|
|
|
47
47
|
.strict(),
|
|
48
48
|
output: OmpRulesListSchema,
|
|
49
49
|
});
|
|
50
|
+
|
|
51
|
+
/** Off adds `name` to `ttsr.disabledRules`; on removes it. A workspace writes its own `.omp/config.yml`. */
|
|
52
|
+
export const setOmpRuleEnabled = defineRpc({
|
|
53
|
+
name: "paseo-omp.set-rule-enabled",
|
|
54
|
+
input: z
|
|
55
|
+
.object({
|
|
56
|
+
store: OmpStoreSchema.optional(),
|
|
57
|
+
cwd: OmpWorkspaceCwdSchema.optional(),
|
|
58
|
+
name: z.string().trim().min(1).max(256),
|
|
59
|
+
enabled: z.boolean(),
|
|
60
|
+
})
|
|
61
|
+
.strict(),
|
|
62
|
+
output: z.discriminatedUnion("status", [
|
|
63
|
+
z.object({ status: z.literal("ok") }),
|
|
64
|
+
z.object({ status: z.literal("error"), message: z.string() }),
|
|
65
|
+
]),
|
|
66
|
+
});
|