@omercnet/paseo-omp 5.4.0-next.416.1 → 5.4.0-next.418.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.
@@ -0,0 +1,140 @@
1
+ import { type PluginSurfaceProps, useRpc } from "@getpaseo/plugin/client";
2
+ import { TextInput } from "@getpaseo/plugin/client/ui";
3
+ import { useMutation } from "@tanstack/react-query";
4
+ import { useState } from "react";
5
+ import { Text, View } from "react-native";
6
+ import {
7
+ MAX_RULE_TEST_CHARS,
8
+ type OmpRuleTestSource,
9
+ OmpRuleTestSourceSchema,
10
+ testOmpRules,
11
+ } from "../shared/omp-rules";
12
+ import type { OmpStore } from "../shared/omp-store";
13
+ import { describe } from "./omp-accounts-section";
14
+ import type { OmpConfigStyles } from "./omp-config-styles";
15
+ import { Choice } from "./omp-tool-config-section";
16
+
17
+ type Theme = PluginSurfaceProps["theme"];
18
+
19
+ const SOURCES = OmpRuleTestSourceSchema.options;
20
+
21
+ export function OmpRuleTest({
22
+ theme,
23
+ styles,
24
+ cwd,
25
+ store,
26
+ }: {
27
+ theme: Theme;
28
+ styles: OmpConfigStyles;
29
+ cwd?: string;
30
+ store?: OmpStore;
31
+ }) {
32
+ const test = useRpc(testOmpRules);
33
+ const [snippet, setSnippet] = useState("");
34
+ const [path, setPath] = useState("");
35
+ const [source, setSource] = useState<OmpRuleTestSource | null>(null);
36
+ const run = useMutation({
37
+ mutationFn: () =>
38
+ test({
39
+ store,
40
+ ...(cwd ? { cwd } : {}),
41
+ snippet,
42
+ ...(path.trim() ? { path: path.trim() } : {}),
43
+ ...(source ? { source } : {}),
44
+ }),
45
+ });
46
+ const result = run.data;
47
+ return (
48
+ <View style={styles.card}>
49
+ <View style={styles.cardHeader}>
50
+ <Text style={styles.cardTitle}>Test a snippet</Text>
51
+ </View>
52
+ <View style={styles.setting}>
53
+ <Text style={styles.settingDescription}>
54
+ Paste text to see which rules would fire on it, in this {cwd ? "workspace" : "user"}{" "}
55
+ scope. Nothing is sent to a model.
56
+ </Text>
57
+ <TextInput
58
+ accessibilityLabel="Snippet to test"
59
+ multiline
60
+ maxLength={MAX_RULE_TEST_CHARS}
61
+ placeholder="Text the agent might write"
62
+ placeholderTextColor={theme.colors.foregroundMuted}
63
+ value={snippet}
64
+ onChangeText={setSnippet}
65
+ style={[styles.scalarInput, { minHeight: 120, maxWidth: undefined }]}
66
+ />
67
+ <TextInput
68
+ accessibilityLabel="File path of the snippet"
69
+ autoCapitalize="none"
70
+ autoCorrect={false}
71
+ placeholder="File path, optional (src/app.ts)"
72
+ placeholderTextColor={theme.colors.foregroundMuted}
73
+ value={path}
74
+ onChangeText={setPath}
75
+ style={[styles.scalarInput, { maxWidth: undefined }]}
76
+ />
77
+ <View style={styles.editorActions}>
78
+ <Choice styles={styles} label="Auto" selected={!source} onPress={() => setSource(null)} />
79
+ {SOURCES.map((option) => (
80
+ <Choice
81
+ key={option}
82
+ styles={styles}
83
+ label={option}
84
+ selected={source === option}
85
+ onPress={() => setSource(option)}
86
+ />
87
+ ))}
88
+ </View>
89
+ <View style={styles.editorActions}>
90
+ <Choice
91
+ styles={styles}
92
+ label={run.isPending ? "Testing..." : "Test"}
93
+ selected
94
+ disabled={snippet.trim() === "" || run.isPending}
95
+ onPress={() => run.mutate()}
96
+ />
97
+ </View>
98
+ {run.error ? (
99
+ <Text accessibilityRole="alert" style={styles.error}>
100
+ {describe(run.error)}
101
+ </Text>
102
+ ) : null}
103
+ {result?.status === "error" ? (
104
+ <Text accessibilityRole="alert" style={styles.error}>
105
+ {result.message}
106
+ </Text>
107
+ ) : null}
108
+ {result?.status === "ready" ? (
109
+ <>
110
+ <Text style={styles.muted}>
111
+ {result.triggered.length === 0
112
+ ? `No rule fired, out of ${result.evaluated} checked`
113
+ : `${result.triggered.length} of ${result.evaluated} rules fired`}
114
+ </Text>
115
+ {result.triggered.map((hit) => (
116
+ <View key={hit.name} style={styles.setting}>
117
+ <Text selectable style={styles.settingValue}>
118
+ {hit.name}
119
+ </Text>
120
+ {hit.regex.length > 0 ? (
121
+ <Text selectable style={styles.settingDescription}>
122
+ Text matched: {hit.regex.join(", ")}
123
+ </Text>
124
+ ) : null}
125
+ {hit.ast.length > 0 ? (
126
+ <Text selectable style={styles.settingDescription}>
127
+ Code matched: {hit.ast.join(", ")}
128
+ </Text>
129
+ ) : null}
130
+ <Text selectable style={styles.settingPath}>
131
+ {hit.path}
132
+ </Text>
133
+ </View>
134
+ ))}
135
+ </>
136
+ ) : null}
137
+ </View>
138
+ </View>
139
+ );
140
+ }
@@ -1,11 +1,18 @@
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 { listOmpRules, type OmpRule, type OmpRuleKind } from "../shared/omp-rules";
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";
15
+ import { OmpRuleTest } from "./omp-rule-test";
9
16
  import { ompStoreKey } from "./omp-store-state";
10
17
 
11
18
  type Theme = PluginSurfaceProps["theme"];
@@ -17,6 +24,8 @@ const COPY_LABELS: Record<CopyState, string> = {
17
24
  failed: "Copy failed",
18
25
  };
19
26
 
27
+ const RULES_KEY = ["paseo-omp", "rules"] as const;
28
+
20
29
  const GROUPS: readonly { kind: OmpRuleKind; title: string; empty: string }[] = [
21
30
  { kind: "watch", title: "Watch", empty: "No watch rules" },
22
31
  { kind: "always", title: "Always applied", empty: "No always-applied rules" },
@@ -50,7 +59,20 @@ function Detail({
50
59
  );
51
60
  }
52
61
 
53
- function RuleRow({ styles, rule }: { styles: OmpConfigStyles; rule: OmpRule }) {
62
+ interface RuleSwitch {
63
+ busy: boolean;
64
+ toggle: (name: string, enabled: boolean) => void;
65
+ }
66
+
67
+ function RuleRow({
68
+ styles,
69
+ rule,
70
+ rules,
71
+ }: {
72
+ styles: OmpConfigStyles;
73
+ rule: OmpRule;
74
+ rules: RuleSwitch;
75
+ }) {
54
76
  const [copyState, setCopyState] = useState<CopyState>("idle");
55
77
  async function copyPath() {
56
78
  try {
@@ -75,6 +97,12 @@ function RuleRow({ styles, rule }: { styles: OmpConfigStyles; rule: OmpRule }) {
75
97
  {rule.name}
76
98
  </Text>
77
99
  <Text style={styles.source}>{sourceLabel(rule)}</Text>
100
+ <Switch
101
+ accessibilityLabel={`Rule ${rule.name} is on`}
102
+ disabled={rules.busy}
103
+ value
104
+ onValueChange={() => rules.toggle(rule.name, false)}
105
+ />
78
106
  </View>
79
107
  {rule.description ? <Text style={styles.settingDescription}>{rule.description}</Text> : null}
80
108
  {details.map(([label, values]) =>
@@ -102,10 +130,12 @@ function BuiltinRules({
102
130
  theme,
103
131
  styles,
104
132
  rules,
133
+ rulesSwitch,
105
134
  }: {
106
135
  theme: Theme;
107
136
  styles: OmpConfigStyles;
108
137
  rules: OmpRule[];
138
+ rulesSwitch: RuleSwitch;
109
139
  }) {
110
140
  const [expanded, setExpanded] = useState(false);
111
141
  if (rules.length === 0) return null;
@@ -126,7 +156,9 @@ function BuiltinRules({
126
156
  <Text style={styles.rowValue}>Built-in rules ({rules.length})</Text>
127
157
  </Pressable>
128
158
  {expanded
129
- ? rules.map((rule) => <RuleRow key={rule.name} styles={styles} rule={rule} />)
159
+ ? rules.map((rule) => (
160
+ <RuleRow key={rule.name} styles={styles} rule={rule} rules={rulesSwitch} />
161
+ ))
130
162
  : null}
131
163
  </>
132
164
  );
@@ -144,10 +176,27 @@ export function OmpRulesSection({
144
176
  store?: OmpStore;
145
177
  }) {
146
178
  const loadRules = useRpc(listOmpRules);
179
+ const setEnabled = useRpc(setOmpRuleEnabled);
180
+ const toast = useToast();
181
+ const queryClient = useQueryClient();
147
182
  const rules = useQuery({
148
- queryKey: ["paseo-omp", "rules", ompStoreKey(store), cwd ?? "global"],
183
+ queryKey: [...RULES_KEY, ompStoreKey(store), cwd ?? "global"],
149
184
  queryFn: () => loadRules({ store, ...(cwd ? { cwd } : {}) }),
150
185
  });
186
+ const toggle = useMutation({
187
+ mutationKey: [...RULES_KEY, "toggle"],
188
+ mutationFn: (change: { name: string; enabled: boolean }) =>
189
+ setEnabled({ store, ...(cwd ? { cwd } : {}), ...change }),
190
+ onSuccess: async (result) => {
191
+ if (result.status === "error") toast.error(result.message);
192
+ await queryClient.invalidateQueries({ queryKey: RULES_KEY });
193
+ },
194
+ onError: (error) => toast.error(describe(error)),
195
+ });
196
+ const rulesSwitch: RuleSwitch = {
197
+ busy: toggle.isPending,
198
+ toggle: (name, enabled) => toggle.mutate({ name, enabled }),
199
+ };
151
200
  const list = rules.data;
152
201
  return (
153
202
  <>
@@ -164,6 +213,7 @@ export function OmpRulesSection({
164
213
  </Text>
165
214
  <Text style={styles.muted}>Rule settings (ttsr.*) are in the Configuration tab.</Text>
166
215
  </View>
216
+ <OmpRuleTest theme={theme} styles={styles} cwd={cwd} store={store} />
167
217
  {rules.isLoading ? <Text style={styles.muted}>Loading rules...</Text> : null}
168
218
  {rules.error ? (
169
219
  <Text accessibilityRole="alert" style={styles.error}>
@@ -186,9 +236,14 @@ export function OmpRulesSection({
186
236
  <Text style={styles.cardTitle}>{group.title}</Text>
187
237
  {members.length === 0 ? <Text style={styles.muted}>{group.empty}</Text> : null}
188
238
  {own.map((rule) => (
189
- <RuleRow key={rule.name} styles={styles} rule={rule} />
239
+ <RuleRow key={rule.name} styles={styles} rule={rule} rules={rulesSwitch} />
190
240
  ))}
191
- <BuiltinRules theme={theme} styles={styles} rules={builtin} />
241
+ <BuiltinRules
242
+ theme={theme}
243
+ styles={styles}
244
+ rules={builtin}
245
+ rulesSwitch={rulesSwitch}
246
+ />
192
247
  {group.kind === "watch" && !list.builtinRules ? (
193
248
  <Text style={styles.muted}>Built-in rules are off (ttsr.builtinRules)</Text>
194
249
  ) : null}
@@ -203,10 +258,16 @@ export function OmpRulesSection({
203
258
  <>
204
259
  <Text style={styles.muted}>Listed in ttsr.disabledRules, so OMP skips them</Text>
205
260
  {list.disabled.map((name) => (
206
- <View key={name} style={styles.setting}>
261
+ <View key={name} style={[styles.setting, styles.settingHeader]}>
207
262
  <Text selectable style={styles.settingValue}>
208
263
  {name}
209
264
  </Text>
265
+ <Switch
266
+ accessibilityLabel={`Rule ${name} is off`}
267
+ disabled={rulesSwitch.busy}
268
+ value={false}
269
+ onValueChange={() => rulesSwitch.toggle(name, true)}
270
+ />
210
271
  </View>
211
272
  ))}
212
273
  </>
@@ -28,7 +28,7 @@ const KINDS: readonly { kind: OmpToolConfigKind; label: string; example: string
28
28
  },
29
29
  ];
30
30
 
31
- function Choice({
31
+ export function Choice({
32
32
  styles,
33
33
  label,
34
34
  selected,
package/index.server.ts CHANGED
@@ -24,6 +24,8 @@ 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";
28
+ import { resolveTestOmpRules } from "./server/omp-rule-test";
27
29
  import { resolveListOmpRules } from "./server/omp-rules";
28
30
  import { resolveListOmpSecurity } from "./server/omp-security";
29
31
  import { resolveListOmpSettings, resolveUpdateOmpSettings } from "./server/omp-settings";
@@ -97,7 +99,7 @@ import {
97
99
  mutateOmpPluginConfig,
98
100
  } from "./shared/omp-plugins";
99
101
  import { getOmpPromptFiles } from "./shared/omp-prompt-files";
100
- import { listOmpRules } from "./shared/omp-rules";
102
+ import { listOmpRules, setOmpRuleEnabled, testOmpRules } from "./shared/omp-rules";
101
103
  import { listOmpSecurity } from "./shared/omp-security";
102
104
  import { listOmpSettings, updateOmpSettings } from "./shared/omp-settings";
103
105
  import { deleteOmpManagedSkill, listOmpSkills, setOmpSkillEnabled } from "./shared/omp-skills";
@@ -225,6 +227,8 @@ export default function contribute(server: PluginServerContext) {
225
227
  server.handle(browseOmpMarketplace, scoped(resolveBrowseOmpMarketplace));
226
228
  server.handle(mutateOmpMarketplace, scoped(resolveMutateOmpMarketplace));
227
229
  server.handle(listOmpRules, scoped(resolveListOmpRules));
230
+ server.handle(setOmpRuleEnabled, scoped(resolveSetOmpRuleEnabled));
231
+ server.handle(testOmpRules, scoped(resolveTestOmpRules));
228
232
  server.handle(listOmpExtensions, scoped(resolveListOmpExtensions));
229
233
  server.handle(setOmpExtensionEnabled, scoped(resolveSetOmpExtensionEnabled));
230
234
  server.handle(listOmpSecurity, scoped(resolveListOmpSecurity));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omercnet/paseo-omp",
3
- "version": "5.4.0-next.416.1",
3
+ "version": "5.4.0-next.418.1",
4
4
  "type": "module",
5
5
  "description": "Paseo integration for OMP, including its direct provider and workspace tooling.",
6
6
  "license": "MIT",
@@ -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
+ }
@@ -0,0 +1,82 @@
1
+ import type { RpcInput } from "@getpaseo/plugin";
2
+ import { z } from "zod";
3
+ import type { OmpRuleTestHit, testOmpRules } from "../shared/omp-rules";
4
+ import {
5
+ inOmpScope,
6
+ type OmpRulesDependencies,
7
+ OmpRulesError,
8
+ ompCommandDependencies,
9
+ runJson,
10
+ } from "./omp-rules";
11
+ import { OmpPublicError } from "./provider/security";
12
+
13
+ const MAX_HITS = 100;
14
+ const MAX_TEXT_CHARS = 2_000;
15
+ const MAX_PATTERNS = 20;
16
+
17
+ const Patterns = z
18
+ .array(z.string())
19
+ .default([])
20
+ .transform((list) => list.slice(0, MAX_PATTERNS).map((text) => text.slice(0, MAX_TEXT_CHARS)));
21
+
22
+ /** `omp ttsr test --json`: the rules that fired are `triggered`; `notTriggered` is not needed. */
23
+ const TestOutputSchema = z.object({
24
+ evaluated: z.number().int().nonnegative(),
25
+ triggered: z.array(z.unknown()),
26
+ });
27
+
28
+ const TriggeredSchema = z.object({
29
+ name: z.string().min(1).max(256),
30
+ path: z.string().max(4_096),
31
+ sourceProvider: z.string().max(128),
32
+ matched: z.object({ regex: Patterns, ast: Patterns }),
33
+ });
34
+
35
+ export async function testOmpRulesWithDependencies(
36
+ input: RpcInput<typeof testOmpRules>,
37
+ dependencies: OmpRulesDependencies,
38
+ ): Promise<
39
+ | { status: "ready"; evaluated: number; triggered: OmpRuleTestHit[] }
40
+ | { status: "error"; message: string }
41
+ > {
42
+ try {
43
+ const executable = await dependencies.resolveExecutable();
44
+ if (!executable) throw new OmpRulesError("The omp command was not found on this host");
45
+ // The snippet goes over stdin and the optional values are `--flag=value`, so neither can be
46
+ // read as another option. No shell is involved.
47
+ const args = [
48
+ "ttsr",
49
+ "test",
50
+ "--json",
51
+ "--file",
52
+ "-",
53
+ ...(input.source ? [`--source=${input.source}`] : []),
54
+ ...(input.path ? [`--path=${input.path}`] : []),
55
+ ];
56
+ const raw = await inOmpScope(input.cwd, dependencies, (runIn) =>
57
+ runJson(dependencies, executable, args, runIn, input.snippet),
58
+ );
59
+ const output = TestOutputSchema.safeParse(raw);
60
+ if (!output.success) throw new OmpRulesError("omp ttsr test gave output the plugin can't read");
61
+ const triggered = output.data.triggered
62
+ .flatMap((entry): OmpRuleTestHit[] => {
63
+ const parsed = TriggeredSchema.safeParse(entry);
64
+ if (!parsed.success) return [];
65
+ const { name, path, sourceProvider, matched } = parsed.data;
66
+ return [{ name, provider: sourceProvider, path, regex: matched.regex, ast: matched.ast }];
67
+ })
68
+ .slice(0, MAX_HITS);
69
+ // Fired rules that all fail to parse mean the output changed shape; "none fired" would be false.
70
+ if (output.data.triggered.length > 0 && triggered.length === 0) {
71
+ throw new OmpRulesError("omp ttsr test gave output the plugin can't read");
72
+ }
73
+ return { status: "ready", evaluated: output.data.evaluated, triggered };
74
+ } catch (error) {
75
+ if (error instanceof OmpPublicError) return { status: "error", message: error.message };
76
+ throw error;
77
+ }
78
+ }
79
+
80
+ export function resolveTestOmpRules(input: RpcInput<typeof testOmpRules>) {
81
+ return testOmpRulesWithDependencies(input, ompCommandDependencies);
82
+ }
@@ -29,7 +29,12 @@ export class OmpRulesError extends OmpPublicError {}
29
29
 
30
30
  export interface OmpRulesDependencies {
31
31
  resolveExecutable(): Promise<string | null>;
32
- run(executable: string, args: readonly string[], cwd: string): Promise<BoundedRun>;
32
+ run(
33
+ executable: string,
34
+ args: readonly string[],
35
+ cwd: string,
36
+ input?: string,
37
+ ): Promise<BoundedRun>;
33
38
  makeScratchDir(prefix: string): Promise<string>;
34
39
  removeDir(path: string): Promise<void>;
35
40
  }
@@ -111,9 +116,10 @@ export async function runJson(
111
116
  executable: string,
112
117
  args: readonly string[],
113
118
  cwd: string,
119
+ input?: string,
114
120
  ): Promise<unknown> {
115
121
  const label = `omp ${args.join(" ")}`;
116
- const run = await dependencies.run(executable, args, cwd);
122
+ const run = await dependencies.run(executable, args, cwd, input);
117
123
  if (run.outcome === "timeout") throw new OmpRulesError(`${label} timed out`);
118
124
  if (run.outcome !== "exited" || run.exitCode !== 0 || run.truncated) {
119
125
  throw new OmpRulesError(`${label} failed`);
@@ -424,7 +430,7 @@ export async function listOmpRulesWithDependencies(
424
430
 
425
431
  export const ompCommandDependencies: OmpRulesDependencies = {
426
432
  resolveExecutable: resolveOmpExecutable,
427
- run: (executable, args, cwd) =>
433
+ run: (executable, args, cwd, input) =>
428
434
  runBounded(
429
435
  defaultSpawn,
430
436
  executable,
@@ -434,6 +440,8 @@ export const ompCommandDependencies: OmpRulesDependencies = {
434
440
  KILL_GRACE_MS,
435
441
  MAX_OUTPUT_BYTES,
436
442
  cwd,
443
+ 0,
444
+ input,
437
445
  ),
438
446
  makeScratchDir: (prefix) => mkdtemp(prefix),
439
447
  removeDir: (path) => rm(path, { recursive: true, force: true }),
@@ -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.416.1"; // x-release-please-version
2
+ export const PASEO_OMP_PACKAGE_VERSION = "5.4.0-next.418.1"; // x-release-please-version
@@ -118,6 +118,8 @@ export type SpawnFn = (
118
118
  args: readonly string[],
119
119
  env: NodeJS.ProcessEnv,
120
120
  cwd?: string,
121
+ /** Written to the child's stdin, which is closed afterwards. Without it stdin closes at once. */
122
+ input?: string,
121
123
  ) => ProbeChildProcess;
122
124
 
123
125
  export type SignalProcess = (pid: number, signal: NodeJS.Signals | 0) => void;
@@ -234,13 +236,18 @@ export function defaultSpawn(
234
236
  args: readonly string[],
235
237
  env: NodeJS.ProcessEnv,
236
238
  cwd?: string,
239
+ input?: string,
237
240
  ): ProbeChildProcess {
238
241
  const child = spawn(command, args, {
239
242
  cwd,
240
- stdio: ["ignore", "pipe", "pipe"],
243
+ stdio: ["pipe", "pipe", "pipe"],
241
244
  env,
242
245
  detached: process.platform !== "win32",
243
246
  });
247
+ // A child that exits without reading closes the pipe; that is not an error here. Without
248
+ // input, stdin closes at once, so a child that reads it sees end of input.
249
+ child.stdin.on("error", () => {});
250
+ child.stdin.end(input);
244
251
  return {
245
252
  pid: child.pid,
246
253
  stdout: child.stdout,
@@ -378,11 +385,12 @@ export function runBounded(
378
385
  maxBytes: number,
379
386
  cwd?: string,
380
387
  stderrLimit = 0,
388
+ input?: string,
381
389
  ): Promise<BoundedRun> {
382
390
  const { promise, resolve } = Promise.withResolvers<BoundedRun>();
383
391
  let child: ProbeChildProcess;
384
392
  try {
385
- child = spawnFn(command, args, env, cwd);
393
+ child = spawnFn(command, args, env, cwd, input);
386
394
  } catch (error) {
387
395
  resolve({
388
396
  outcome: "spawn-error",
@@ -47,3 +47,65 @@ 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
+ });
67
+
68
+ export const MAX_RULE_TEST_CHARS = 20_000;
69
+
70
+ export const OmpRuleTestSourceSchema = z.enum(["text", "thinking", "tool"]);
71
+ export type OmpRuleTestSource = z.infer<typeof OmpRuleTestSourceSchema>;
72
+
73
+ export const OmpRuleTestHitSchema = z.object({
74
+ name: z.string(),
75
+ provider: z.string(),
76
+ path: z.string(),
77
+ /** The rule's own patterns that matched the snippet. */
78
+ regex: z.array(z.string()),
79
+ ast: z.array(z.string()),
80
+ });
81
+ export type OmpRuleTestHit = z.infer<typeof OmpRuleTestHitSchema>;
82
+
83
+ /** Runs `omp ttsr test`: which rules would fire on a snippet, in this workspace or the user scope. */
84
+ export const testOmpRules = defineRpc({
85
+ name: "paseo-omp.test-rules",
86
+ input: z
87
+ .object({
88
+ store: OmpStoreSchema.optional(),
89
+ cwd: OmpWorkspaceCwdSchema.optional(),
90
+ snippet: z.string().min(1).max(MAX_RULE_TEST_CHARS),
91
+ /** The file the snippet pretends to come from, for scope and glob matching. */
92
+ path: z
93
+ .string()
94
+ .trim()
95
+ .min(1)
96
+ .max(1_024)
97
+ .refine((path) => !path.includes("\0"), "The path cannot hold a null character")
98
+ .optional(),
99
+ source: OmpRuleTestSourceSchema.optional(),
100
+ })
101
+ .strict(),
102
+ output: z.discriminatedUnion("status", [
103
+ z.object({
104
+ status: z.literal("ready"),
105
+ /** How many rules OMP checked. */
106
+ evaluated: z.number().int().nonnegative(),
107
+ triggered: z.array(OmpRuleTestHitSchema),
108
+ }),
109
+ z.object({ status: z.literal("error"), message: z.string() }),
110
+ ]),
111
+ });