@omercnet/paseo-omp 5.4.0-next.409.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 +193 -83
- 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 +10 -0
- package/package.json +1 -1
- package/server/omp-models-file.ts +178 -0
- package/server/omp-security.ts +169 -0
- package/server/omp-settings.ts +68 -4
- package/server/package-version.ts +1 -1
- package/server/provider/omp-rpc-environment.ts +1 -1
- package/server/provider-diagnostics.ts +16 -2
- package/shared/omp-models-file.ts +30 -0
- package/shared/omp-security.ts +50 -0
- package/shared/omp-settings.ts +99 -4
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { TextInput } from "@getpaseo/plugin/client/ui";
|
|
2
|
+
import { type ReactNode, useRef, useState } from "react";
|
|
3
|
+
import { Pressable, Text, View } from "react-native";
|
|
4
|
+
import {
|
|
5
|
+
type OmpBashRule,
|
|
6
|
+
OmpBashRuleSchema,
|
|
7
|
+
OmpRestrictedFoldersSchema,
|
|
8
|
+
type OmpSetting,
|
|
9
|
+
type OmpToolApproval,
|
|
10
|
+
} from "../shared/omp-settings";
|
|
11
|
+
import type { OmpConfigStyles } from "./omp-config-styles";
|
|
12
|
+
import {
|
|
13
|
+
canAddBashRule,
|
|
14
|
+
canAddToolRule,
|
|
15
|
+
moveRule,
|
|
16
|
+
policyWarnings,
|
|
17
|
+
readBashRuleDraft,
|
|
18
|
+
readBashRules,
|
|
19
|
+
readFolders,
|
|
20
|
+
readToolPolicies,
|
|
21
|
+
} from "./omp-tool-policy-state";
|
|
22
|
+
|
|
23
|
+
type PolicyDraft = { operation: "set"; value: unknown } | { operation: "reset" };
|
|
24
|
+
|
|
25
|
+
const APPROVALS: readonly { value: OmpToolApproval; label: string }[] = [
|
|
26
|
+
{ value: "allow", label: "Allow" },
|
|
27
|
+
{ value: "prompt", label: "Ask" },
|
|
28
|
+
{ value: "deny", label: "Deny" },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const CAVEATS = [
|
|
32
|
+
"Deny, Ask and restricted-folder rules also apply in Full Access.",
|
|
33
|
+
"A new Deny rule may not guard an agent that is already running until it is reloaded.",
|
|
34
|
+
"Bash rules do not cover commands run through eval, are not a sandbox, and only support * wildcards. The first matching rule wins.",
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
interface ToolPolicyCardProps {
|
|
38
|
+
settings: readonly OmpSetting[];
|
|
39
|
+
visiblePaths: readonly string[];
|
|
40
|
+
drafts: Readonly<Record<string, PolicyDraft>>;
|
|
41
|
+
disabled: boolean;
|
|
42
|
+
workspaceScoped: boolean;
|
|
43
|
+
resetLabel: string;
|
|
44
|
+
styles: OmpConfigStyles;
|
|
45
|
+
onSet(path: string, value: unknown): void;
|
|
46
|
+
onReset(path: string): void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const ACTION_GROUP = { flexDirection: "row", flexWrap: "wrap", gap: 8 } as const;
|
|
50
|
+
|
|
51
|
+
function Action({
|
|
52
|
+
label,
|
|
53
|
+
text,
|
|
54
|
+
disabled,
|
|
55
|
+
selected,
|
|
56
|
+
styles,
|
|
57
|
+
onPress,
|
|
58
|
+
}: {
|
|
59
|
+
label: string;
|
|
60
|
+
text: string;
|
|
61
|
+
disabled: boolean;
|
|
62
|
+
selected?: boolean;
|
|
63
|
+
styles: OmpConfigStyles;
|
|
64
|
+
onPress(): void;
|
|
65
|
+
}) {
|
|
66
|
+
return (
|
|
67
|
+
<Pressable
|
|
68
|
+
accessibilityRole="button"
|
|
69
|
+
accessibilityLabel={label}
|
|
70
|
+
accessibilityState={{ selected: selected === true }}
|
|
71
|
+
disabled={disabled}
|
|
72
|
+
onPress={onPress}
|
|
73
|
+
style={[styles.editorAction, selected ? styles.editorActionPrimary : null]}
|
|
74
|
+
>
|
|
75
|
+
<Text style={[styles.editorActionText, selected ? styles.editorActionTextPrimary : null]}>
|
|
76
|
+
{text}
|
|
77
|
+
</Text>
|
|
78
|
+
</Pressable>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function ApprovalChoice({
|
|
83
|
+
subject,
|
|
84
|
+
value,
|
|
85
|
+
disabled,
|
|
86
|
+
styles,
|
|
87
|
+
onChange,
|
|
88
|
+
}: {
|
|
89
|
+
subject: string;
|
|
90
|
+
value: OmpToolApproval;
|
|
91
|
+
disabled: boolean;
|
|
92
|
+
styles: OmpConfigStyles;
|
|
93
|
+
onChange(value: OmpToolApproval): void;
|
|
94
|
+
}) {
|
|
95
|
+
return (
|
|
96
|
+
<>
|
|
97
|
+
{APPROVALS.map((choice) => (
|
|
98
|
+
<Action
|
|
99
|
+
key={choice.value}
|
|
100
|
+
label={`${choice.label} ${subject}`}
|
|
101
|
+
text={choice.label}
|
|
102
|
+
disabled={disabled}
|
|
103
|
+
selected={value === choice.value}
|
|
104
|
+
styles={styles}
|
|
105
|
+
onPress={() => onChange(choice.value)}
|
|
106
|
+
/>
|
|
107
|
+
))}
|
|
108
|
+
</>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function PolicySection({
|
|
113
|
+
title,
|
|
114
|
+
description,
|
|
115
|
+
pending,
|
|
116
|
+
showReset,
|
|
117
|
+
resetLabel,
|
|
118
|
+
disabled,
|
|
119
|
+
styles,
|
|
120
|
+
onReset,
|
|
121
|
+
children,
|
|
122
|
+
}: {
|
|
123
|
+
title: string;
|
|
124
|
+
description: string;
|
|
125
|
+
pending: boolean;
|
|
126
|
+
showReset: boolean;
|
|
127
|
+
resetLabel: string;
|
|
128
|
+
disabled: boolean;
|
|
129
|
+
styles: OmpConfigStyles;
|
|
130
|
+
onReset(): void;
|
|
131
|
+
children: ReactNode;
|
|
132
|
+
}) {
|
|
133
|
+
return (
|
|
134
|
+
<View style={styles.setting}>
|
|
135
|
+
<Text style={styles.cardTitle}>{title}</Text>
|
|
136
|
+
<Text style={styles.settingDescription}>{description}</Text>
|
|
137
|
+
{pending ? (
|
|
138
|
+
<Text style={styles.muted}>{resetLabel} when changes are applied</Text>
|
|
139
|
+
) : (
|
|
140
|
+
<View style={styles.recordList}>{children}</View>
|
|
141
|
+
)}
|
|
142
|
+
{showReset ? (
|
|
143
|
+
<Pressable accessibilityRole="button" disabled={disabled} onPress={onReset}>
|
|
144
|
+
<Text style={styles.resetAction}>{resetLabel}</Text>
|
|
145
|
+
</Pressable>
|
|
146
|
+
) : null}
|
|
147
|
+
</View>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function AddRow({
|
|
152
|
+
label,
|
|
153
|
+
inputLabel,
|
|
154
|
+
placeholder,
|
|
155
|
+
valid,
|
|
156
|
+
disabled,
|
|
157
|
+
styles,
|
|
158
|
+
onAdd,
|
|
159
|
+
}: {
|
|
160
|
+
label: string;
|
|
161
|
+
inputLabel: string;
|
|
162
|
+
placeholder: string;
|
|
163
|
+
valid(text: string): boolean;
|
|
164
|
+
disabled: boolean;
|
|
165
|
+
styles: OmpConfigStyles;
|
|
166
|
+
onAdd(text: string): void;
|
|
167
|
+
}) {
|
|
168
|
+
const [text, setText] = useState("");
|
|
169
|
+
const trimmed = text.trim();
|
|
170
|
+
return (
|
|
171
|
+
<View style={styles.recordRow}>
|
|
172
|
+
<TextInput
|
|
173
|
+
accessibilityLabel={inputLabel}
|
|
174
|
+
editable={!disabled}
|
|
175
|
+
placeholder={placeholder}
|
|
176
|
+
value={text}
|
|
177
|
+
onChangeText={setText}
|
|
178
|
+
style={styles.scalarInput}
|
|
179
|
+
/>
|
|
180
|
+
<Action
|
|
181
|
+
label={label}
|
|
182
|
+
text="Add"
|
|
183
|
+
disabled={disabled || !valid(trimmed)}
|
|
184
|
+
styles={styles}
|
|
185
|
+
onPress={() => {
|
|
186
|
+
onAdd(trimmed);
|
|
187
|
+
setText("");
|
|
188
|
+
}}
|
|
189
|
+
/>
|
|
190
|
+
</View>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Rules have no identity of their own and their order is the data, so each row carries an id that follows it through moves and removals. */
|
|
195
|
+
function useRuleIds(length: number) {
|
|
196
|
+
const ids = useRef<number[]>([]);
|
|
197
|
+
const nextId = useRef(0);
|
|
198
|
+
while (ids.current.length < length) ids.current.push(nextId.current++);
|
|
199
|
+
ids.current.length = length;
|
|
200
|
+
return ids;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function ToolPolicyCard({
|
|
204
|
+
settings,
|
|
205
|
+
visiblePaths,
|
|
206
|
+
drafts,
|
|
207
|
+
disabled,
|
|
208
|
+
workspaceScoped,
|
|
209
|
+
resetLabel,
|
|
210
|
+
styles,
|
|
211
|
+
onSet,
|
|
212
|
+
onReset,
|
|
213
|
+
}: ToolPolicyCardProps) {
|
|
214
|
+
const byPath = new Map(settings.map((setting) => [setting.path, setting]));
|
|
215
|
+
const current = (path: string): unknown => {
|
|
216
|
+
const draft = drafts[path];
|
|
217
|
+
return draft?.operation === "set" ? draft.value : byPath.get(path)?.value;
|
|
218
|
+
};
|
|
219
|
+
const resetting = (path: string) => drafts[path]?.operation === "reset";
|
|
220
|
+
const canReset = (path: string) =>
|
|
221
|
+
!workspaceScoped || byPath.get(path)?.workspaceOverride === true;
|
|
222
|
+
const inheritedPolicies = readToolPolicies(
|
|
223
|
+
workspaceScoped ? byPath.get("tools.approval")?.userValue : undefined,
|
|
224
|
+
);
|
|
225
|
+
const policies = readToolPolicies(current("tools.approval"));
|
|
226
|
+
const bashDraft = drafts["bash.patterns"];
|
|
227
|
+
const rules =
|
|
228
|
+
bashDraft?.operation === "set"
|
|
229
|
+
? readBashRuleDraft(bashDraft.value)
|
|
230
|
+
: readBashRules(byPath.get("bash.patterns")?.value);
|
|
231
|
+
const folders = readFolders(current("tools.restrictedFolders"));
|
|
232
|
+
const ruleIds = useRuleIds(rules.length);
|
|
233
|
+
const warnings = policyWarnings({ policies, rules });
|
|
234
|
+
const setRule = (index: number, rule: OmpBashRule) =>
|
|
235
|
+
onSet(
|
|
236
|
+
"bash.patterns",
|
|
237
|
+
rules.map((existing, position) => (position === index ? rule : existing)),
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
return (
|
|
241
|
+
<View style={styles.card}>
|
|
242
|
+
<View style={styles.cardHeader}>
|
|
243
|
+
<Text style={styles.cardTitle}>Tool policy</Text>
|
|
244
|
+
</View>
|
|
245
|
+
{visiblePaths.includes("tools.approval") ? (
|
|
246
|
+
<PolicySection
|
|
247
|
+
title="Per-tool approval"
|
|
248
|
+
description="Allow runs a tool without asking, Ask requires confirmation and Deny blocks it. These rules win over the approval mode."
|
|
249
|
+
pending={resetting("tools.approval")}
|
|
250
|
+
showReset={canReset("tools.approval")}
|
|
251
|
+
resetLabel={resetLabel}
|
|
252
|
+
disabled={disabled}
|
|
253
|
+
styles={styles}
|
|
254
|
+
onReset={() => onReset("tools.approval")}
|
|
255
|
+
>
|
|
256
|
+
{Object.entries(policies).map(([tool, approval]) => (
|
|
257
|
+
<View key={tool} style={styles.recordRow}>
|
|
258
|
+
<Text selectable style={styles.recordKey}>
|
|
259
|
+
{tool}
|
|
260
|
+
</Text>
|
|
261
|
+
<View style={ACTION_GROUP}>
|
|
262
|
+
<ApprovalChoice
|
|
263
|
+
subject={tool}
|
|
264
|
+
value={approval}
|
|
265
|
+
disabled={disabled}
|
|
266
|
+
styles={styles}
|
|
267
|
+
onChange={(next) => onSet("tools.approval", { ...policies, [tool]: next })}
|
|
268
|
+
/>
|
|
269
|
+
{inheritedPolicies[tool] === approval ? (
|
|
270
|
+
<Text style={styles.muted}>From user config</Text>
|
|
271
|
+
) : (
|
|
272
|
+
<Action
|
|
273
|
+
label={`Remove ${tool}`}
|
|
274
|
+
text="Remove"
|
|
275
|
+
disabled={disabled}
|
|
276
|
+
styles={styles}
|
|
277
|
+
onPress={() =>
|
|
278
|
+
onSet(
|
|
279
|
+
"tools.approval",
|
|
280
|
+
Object.fromEntries(
|
|
281
|
+
Object.entries(policies).filter(([name]) => name !== tool),
|
|
282
|
+
),
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
/>
|
|
286
|
+
)}
|
|
287
|
+
</View>
|
|
288
|
+
</View>
|
|
289
|
+
))}
|
|
290
|
+
<AddRow
|
|
291
|
+
label="Add tool rule"
|
|
292
|
+
inputLabel="Tool name"
|
|
293
|
+
placeholder="Tool, e.g. eval"
|
|
294
|
+
valid={(text) => canAddToolRule(policies, text)}
|
|
295
|
+
disabled={disabled}
|
|
296
|
+
styles={styles}
|
|
297
|
+
onAdd={(tool) => onSet("tools.approval", { ...policies, [tool]: "prompt" })}
|
|
298
|
+
/>
|
|
299
|
+
</PolicySection>
|
|
300
|
+
) : null}
|
|
301
|
+
{visiblePaths.includes("bash.patterns") ? (
|
|
302
|
+
<PolicySection
|
|
303
|
+
title="Bash command rules"
|
|
304
|
+
description="Matched top to bottom against each bash command; the first match decides. Use * as a wildcard, for example npm test* or git push --force*."
|
|
305
|
+
pending={resetting("bash.patterns")}
|
|
306
|
+
showReset={canReset("bash.patterns")}
|
|
307
|
+
resetLabel={resetLabel}
|
|
308
|
+
disabled={disabled}
|
|
309
|
+
styles={styles}
|
|
310
|
+
onReset={() => onReset("bash.patterns")}
|
|
311
|
+
>
|
|
312
|
+
{rules.map((rule, index) => (
|
|
313
|
+
<View key={ruleIds.current[index]} style={styles.recordRow}>
|
|
314
|
+
<Text style={styles.recordKey}>{index + 1}</Text>
|
|
315
|
+
<TextInput
|
|
316
|
+
accessibilityLabel={`Bash rule ${index + 1} pattern`}
|
|
317
|
+
editable={!disabled}
|
|
318
|
+
value={rule.match}
|
|
319
|
+
onChangeText={(match) => setRule(index, { ...rule, match })}
|
|
320
|
+
style={styles.scalarInput}
|
|
321
|
+
/>
|
|
322
|
+
{OmpBashRuleSchema.safeParse(rule).success ? null : (
|
|
323
|
+
<Text style={styles.error}>Enter a pattern of 1 to 512 characters.</Text>
|
|
324
|
+
)}
|
|
325
|
+
<View style={ACTION_GROUP}>
|
|
326
|
+
<ApprovalChoice
|
|
327
|
+
subject={`for bash rule ${index + 1}`}
|
|
328
|
+
value={rule.approval}
|
|
329
|
+
disabled={disabled}
|
|
330
|
+
styles={styles}
|
|
331
|
+
onChange={(approval) => setRule(index, { ...rule, approval })}
|
|
332
|
+
/>
|
|
333
|
+
<Action
|
|
334
|
+
label={`Move bash rule ${index + 1} up`}
|
|
335
|
+
text="Up"
|
|
336
|
+
disabled={disabled || index === 0}
|
|
337
|
+
styles={styles}
|
|
338
|
+
onPress={() => {
|
|
339
|
+
ruleIds.current = moveRule(ruleIds.current, index, -1);
|
|
340
|
+
onSet("bash.patterns", moveRule(rules, index, -1));
|
|
341
|
+
}}
|
|
342
|
+
/>
|
|
343
|
+
<Action
|
|
344
|
+
label={`Move bash rule ${index + 1} down`}
|
|
345
|
+
text="Down"
|
|
346
|
+
disabled={disabled || index === rules.length - 1}
|
|
347
|
+
styles={styles}
|
|
348
|
+
onPress={() => {
|
|
349
|
+
ruleIds.current = moveRule(ruleIds.current, index, 1);
|
|
350
|
+
onSet("bash.patterns", moveRule(rules, index, 1));
|
|
351
|
+
}}
|
|
352
|
+
/>
|
|
353
|
+
<Action
|
|
354
|
+
label={`Remove bash rule ${index + 1}`}
|
|
355
|
+
text="Remove"
|
|
356
|
+
disabled={disabled}
|
|
357
|
+
styles={styles}
|
|
358
|
+
onPress={() => {
|
|
359
|
+
ruleIds.current = ruleIds.current.filter((_, position) => position !== index);
|
|
360
|
+
onSet(
|
|
361
|
+
"bash.patterns",
|
|
362
|
+
rules.filter((_, position) => position !== index),
|
|
363
|
+
);
|
|
364
|
+
}}
|
|
365
|
+
/>
|
|
366
|
+
</View>
|
|
367
|
+
</View>
|
|
368
|
+
))}
|
|
369
|
+
<AddRow
|
|
370
|
+
label="Add bash rule"
|
|
371
|
+
inputLabel="Bash command pattern"
|
|
372
|
+
placeholder="Pattern, e.g. npm test*"
|
|
373
|
+
valid={(text) => canAddBashRule(rules, text)}
|
|
374
|
+
disabled={disabled}
|
|
375
|
+
styles={styles}
|
|
376
|
+
onAdd={(match) => onSet("bash.patterns", [...rules, { match, approval: "prompt" }])}
|
|
377
|
+
/>
|
|
378
|
+
</PolicySection>
|
|
379
|
+
) : null}
|
|
380
|
+
{visiblePaths.includes("tools.restrictedFolders") ? (
|
|
381
|
+
<PolicySection
|
|
382
|
+
title="Restricted folders"
|
|
383
|
+
description="Every read, write, edit, search or command in these folders, and everything under them, needs an explicit approval in every mode."
|
|
384
|
+
pending={resetting("tools.restrictedFolders")}
|
|
385
|
+
showReset={canReset("tools.restrictedFolders")}
|
|
386
|
+
resetLabel={resetLabel}
|
|
387
|
+
disabled={disabled}
|
|
388
|
+
styles={styles}
|
|
389
|
+
onReset={() => onReset("tools.restrictedFolders")}
|
|
390
|
+
>
|
|
391
|
+
{folders.map((folder, index) => (
|
|
392
|
+
<View key={folder} style={styles.recordRow}>
|
|
393
|
+
<Text selectable style={styles.recordValue}>
|
|
394
|
+
{folder}
|
|
395
|
+
</Text>
|
|
396
|
+
<Action
|
|
397
|
+
label={`Remove ${folder}`}
|
|
398
|
+
text="Remove"
|
|
399
|
+
disabled={disabled}
|
|
400
|
+
styles={styles}
|
|
401
|
+
onPress={() =>
|
|
402
|
+
onSet(
|
|
403
|
+
"tools.restrictedFolders",
|
|
404
|
+
folders.filter((_, position) => position !== index),
|
|
405
|
+
)
|
|
406
|
+
}
|
|
407
|
+
/>
|
|
408
|
+
</View>
|
|
409
|
+
))}
|
|
410
|
+
<AddRow
|
|
411
|
+
label="Add restricted folder"
|
|
412
|
+
inputLabel="Restricted folder path"
|
|
413
|
+
placeholder="Path, e.g. ~/secrets"
|
|
414
|
+
valid={(text) => OmpRestrictedFoldersSchema.safeParse([...folders, text]).success}
|
|
415
|
+
disabled={disabled}
|
|
416
|
+
styles={styles}
|
|
417
|
+
onAdd={(folder) => onSet("tools.restrictedFolders", [...folders, folder])}
|
|
418
|
+
/>
|
|
419
|
+
</PolicySection>
|
|
420
|
+
) : null}
|
|
421
|
+
<View style={styles.setting}>
|
|
422
|
+
{warnings.map((warning) => (
|
|
423
|
+
<Text key={warning} style={styles.error}>
|
|
424
|
+
{warning}
|
|
425
|
+
</Text>
|
|
426
|
+
))}
|
|
427
|
+
{CAVEATS.map((caveat) => (
|
|
428
|
+
<Text key={caveat} style={styles.settingDescription}>
|
|
429
|
+
{caveat}
|
|
430
|
+
</Text>
|
|
431
|
+
))}
|
|
432
|
+
</View>
|
|
433
|
+
</View>
|
|
434
|
+
);
|
|
435
|
+
}
|
package/index.server.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { resolveListOmpConfig } from "./server/omp-config";
|
|
|
12
12
|
import { resolveListOmpExtensions, resolveSetOmpExtensionEnabled } from "./server/omp-extensions";
|
|
13
13
|
import { OmpMcps } from "./server/omp-mcps";
|
|
14
14
|
import { resolveListOmpModels } from "./server/omp-models";
|
|
15
|
+
import { resolveGetOmpModelsFileStatus, resolveRefreshOmpModels } from "./server/omp-models-file";
|
|
15
16
|
import {
|
|
16
17
|
resolveBrowseOmpMarketplace,
|
|
17
18
|
resolveInspectOmpPluginConfig,
|
|
@@ -23,6 +24,7 @@ import {
|
|
|
23
24
|
} from "./server/omp-plugins";
|
|
24
25
|
import { readHostAppendPrompt, readOmpPromptFiles } from "./server/omp-prompt-files";
|
|
25
26
|
import { resolveListOmpRules } from "./server/omp-rules";
|
|
27
|
+
import { resolveListOmpSecurity } from "./server/omp-security";
|
|
26
28
|
import { resolveListOmpSettings, resolveUpdateOmpSettings } from "./server/omp-settings";
|
|
27
29
|
import {
|
|
28
30
|
resolveDeleteOmpManagedSkill,
|
|
@@ -79,6 +81,7 @@ import {
|
|
|
79
81
|
submitOmpMcpAuthCode,
|
|
80
82
|
} from "./shared/omp-mcps";
|
|
81
83
|
import { listOmpModels } from "./shared/omp-models";
|
|
84
|
+
import { getOmpModelsFileStatus, refreshOmpModels } from "./shared/omp-models-file";
|
|
82
85
|
import {
|
|
83
86
|
browseOmpMarketplace,
|
|
84
87
|
inspectOmpPluginConfig,
|
|
@@ -90,6 +93,7 @@ import {
|
|
|
90
93
|
} from "./shared/omp-plugins";
|
|
91
94
|
import { getOmpPromptFiles } from "./shared/omp-prompt-files";
|
|
92
95
|
import { listOmpRules } from "./shared/omp-rules";
|
|
96
|
+
import { listOmpSecurity } from "./shared/omp-security";
|
|
93
97
|
import { listOmpSettings, updateOmpSettings } from "./shared/omp-settings";
|
|
94
98
|
import { deleteOmpManagedSkill, listOmpSkills, setOmpSkillEnabled } from "./shared/omp-skills";
|
|
95
99
|
import { listOmpStores, type OmpStore } from "./shared/omp-store";
|
|
@@ -217,6 +221,7 @@ export default function contribute(server: PluginServerContext) {
|
|
|
217
221
|
server.handle(listOmpRules, scoped(resolveListOmpRules));
|
|
218
222
|
server.handle(listOmpExtensions, scoped(resolveListOmpExtensions));
|
|
219
223
|
server.handle(setOmpExtensionEnabled, scoped(resolveSetOmpExtensionEnabled));
|
|
224
|
+
server.handle(listOmpSecurity, scoped(resolveListOmpSecurity));
|
|
220
225
|
server.handle(listOmpSkills, scoped(resolveListOmpSkills));
|
|
221
226
|
server.handle(setOmpSkillEnabled, scoped(resolveSetOmpSkillEnabled));
|
|
222
227
|
server.handle(deleteOmpManagedSkill, scoped(resolveDeleteOmpManagedSkill));
|
|
@@ -230,6 +235,11 @@ export default function contribute(server: PluginServerContext) {
|
|
|
230
235
|
server.handle(getOmpPromptFiles, ({ store, cwd }, { paseo }) =>
|
|
231
236
|
withOmpStore(store, async () => readOmpPromptFiles(cwd, await readHostAppendPrompt(paseo))),
|
|
232
237
|
);
|
|
238
|
+
server.handle(getOmpModelsFileStatus, scoped(resolveGetOmpModelsFileStatus));
|
|
239
|
+
server.handle(
|
|
240
|
+
refreshOmpModels,
|
|
241
|
+
scoped(async (input) => resolveRefreshOmpModels(input, await resolveHostInheritEnv())),
|
|
242
|
+
);
|
|
233
243
|
server.handle(getOmpUpdateStatus, resolveGetOmpUpdateStatus);
|
|
234
244
|
server.handle(installOmpUpdate, resolveInstallOmpUpdate);
|
|
235
245
|
server.handle(getOmpImage, (input) => resolveGetOmpImage(input, ompImageCache()));
|
package/package.json
CHANGED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { tmpdir } from "node:os";
|
|
2
|
+
import type { RpcInput } from "@getpaseo/plugin";
|
|
3
|
+
import type {
|
|
4
|
+
getOmpModelsFileStatus,
|
|
5
|
+
OmpModelsFileStatus,
|
|
6
|
+
refreshOmpModels,
|
|
7
|
+
} from "../shared/omp-models-file";
|
|
8
|
+
import { SerialMutationQueue } from "./mutation-queue";
|
|
9
|
+
import { resolveOmpExecutable } from "./omp-settings";
|
|
10
|
+
import { currentOmpEnvironment } from "./paths";
|
|
11
|
+
import { buildOmpEnvironment } from "./provider/omp-rpc-environment";
|
|
12
|
+
import {
|
|
13
|
+
type BoundedRun,
|
|
14
|
+
buildStatefulCommandEnv,
|
|
15
|
+
defaultSpawn,
|
|
16
|
+
runBounded,
|
|
17
|
+
} from "./provider-diagnostics";
|
|
18
|
+
|
|
19
|
+
const CHECK_TIMEOUT_MS = 30_000;
|
|
20
|
+
const REFRESH_TIMEOUT_MS = 90_000;
|
|
21
|
+
const KILL_GRACE_MS = 1_000;
|
|
22
|
+
const MAX_OUTPUT_BYTES = 2 * 1024 * 1024;
|
|
23
|
+
const MAX_STDERR_BYTES = 16 * 1024;
|
|
24
|
+
const MAX_DETAIL_CHARS = 300;
|
|
25
|
+
|
|
26
|
+
export interface OmpModelsDependencies {
|
|
27
|
+
resolveExecutable(): Promise<string | null>;
|
|
28
|
+
run(
|
|
29
|
+
executable: string,
|
|
30
|
+
args: readonly string[],
|
|
31
|
+
timeoutMs: number,
|
|
32
|
+
stderrLimit: number,
|
|
33
|
+
providerEnvironment: boolean,
|
|
34
|
+
): Promise<BoundedRun>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A refresh asks hosted catalogs for their lists with the API keys Paseo's own omp provider
|
|
39
|
+
* would hand OMP, so it gets that launch environment (runtime variables, provider-auth families
|
|
40
|
+
* and the host's inherited names; loader controls and other daemon secrets stay out). The
|
|
41
|
+
* models.yml check only needs the stateful probe environment.
|
|
42
|
+
*/
|
|
43
|
+
export function modelsEnvironment(
|
|
44
|
+
providerEnvironment: boolean,
|
|
45
|
+
inheritEnv: readonly string[] = [],
|
|
46
|
+
): NodeJS.ProcessEnv {
|
|
47
|
+
const source = currentOmpEnvironment();
|
|
48
|
+
if (!providerEnvironment) return buildStatefulCommandEnv(source);
|
|
49
|
+
const { env } = buildOmpEnvironment(undefined, inheritEnv, source);
|
|
50
|
+
env.NO_COLOR = "1";
|
|
51
|
+
return env;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function runOmp(
|
|
55
|
+
executable: string,
|
|
56
|
+
args: readonly string[],
|
|
57
|
+
timeoutMs: number,
|
|
58
|
+
stderrLimit: number,
|
|
59
|
+
providerEnvironment: boolean,
|
|
60
|
+
inheritEnv: readonly string[],
|
|
61
|
+
): Promise<BoundedRun> {
|
|
62
|
+
return runBounded(
|
|
63
|
+
defaultSpawn,
|
|
64
|
+
executable,
|
|
65
|
+
args,
|
|
66
|
+
modelsEnvironment(providerEnvironment, inheritEnv),
|
|
67
|
+
timeoutMs,
|
|
68
|
+
KILL_GRACE_MS,
|
|
69
|
+
MAX_OUTPUT_BYTES,
|
|
70
|
+
tmpdir(),
|
|
71
|
+
stderrLimit,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function dependenciesFor(inheritEnv: readonly string[]): OmpModelsDependencies {
|
|
76
|
+
return {
|
|
77
|
+
resolveExecutable: resolveOmpExecutable,
|
|
78
|
+
run: (executable, args, timeoutMs, stderrLimit, providerEnvironment) =>
|
|
79
|
+
runOmp(executable, args, timeoutMs, stderrLimit, providerEnvironment, inheritEnv),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function succeeded(run: BoundedRun): boolean {
|
|
84
|
+
return (
|
|
85
|
+
run.outcome === "exited" &&
|
|
86
|
+
run.exitCode === 0 &&
|
|
87
|
+
run.signal === null &&
|
|
88
|
+
!run.truncated &&
|
|
89
|
+
!run.cleanupFailed
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// OMP prints these lines to stderr and exits 0 when it drops a bad models.yml:
|
|
94
|
+
// Warning: models.yml validation failed ...
|
|
95
|
+
// Failed to load config file models, <label>: <message>
|
|
96
|
+
// and a schema error may continue with indented " - <path>: <message>" lines.
|
|
97
|
+
const WARNING_LINE = /^Warning: models\.yml validation failed/m;
|
|
98
|
+
const FAILURE_PREFIX = /^Failed to load config file models, [^:]*:\s*/;
|
|
99
|
+
const BULLET = /^\s+- /;
|
|
100
|
+
// Schema errors echo the offending value as "(was ...)": a key in the wrong field would leak.
|
|
101
|
+
const ECHOED_VALUE = /\s*\(was .*\)\s*$/;
|
|
102
|
+
|
|
103
|
+
/** Reads OMP's models.yml warning. The detail is bounded, free of control characters and values. */
|
|
104
|
+
export function parseOmpModelsWarning(stderr: string): OmpModelsFileStatus {
|
|
105
|
+
if (!WARNING_LINE.test(stderr)) return { state: "ok" };
|
|
106
|
+
const lines = stderr.split(/\r?\n/);
|
|
107
|
+
const start = lines.findIndex((line) => FAILURE_PREFIX.test(line));
|
|
108
|
+
const pieces: string[] = [];
|
|
109
|
+
if (start >= 0) {
|
|
110
|
+
pieces.push((lines[start] ?? "").replace(FAILURE_PREFIX, ""));
|
|
111
|
+
for (const line of lines.slice(start + 1)) {
|
|
112
|
+
if (!BULLET.test(line)) break;
|
|
113
|
+
pieces.push(line.replace(BULLET, ""));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const detail = pieces
|
|
117
|
+
.map((piece) => piece.replace(ECHOED_VALUE, "").trim())
|
|
118
|
+
.filter((piece) => piece !== "")
|
|
119
|
+
.join("; ");
|
|
120
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: strips terminal control characters
|
|
121
|
+
const clean = detail.replace(/[\u0000-\u001f\u007f]/g, " ");
|
|
122
|
+
return {
|
|
123
|
+
state: "invalid",
|
|
124
|
+
detail: (clean || "OMP could not load it").slice(0, MAX_DETAIL_CHARS),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function getOmpModelsFileStatusWithDependencies(
|
|
129
|
+
dependencies: OmpModelsDependencies,
|
|
130
|
+
): Promise<OmpModelsFileStatus> {
|
|
131
|
+
const executable = await dependencies.resolveExecutable();
|
|
132
|
+
if (!executable) return { state: "unknown" };
|
|
133
|
+
const run = await dependencies.run(
|
|
134
|
+
executable,
|
|
135
|
+
["models", "--json", "--no-extensions"],
|
|
136
|
+
CHECK_TIMEOUT_MS,
|
|
137
|
+
MAX_STDERR_BYTES,
|
|
138
|
+
false,
|
|
139
|
+
);
|
|
140
|
+
return succeeded(run) ? parseOmpModelsWarning(run.stderr ?? "") : { state: "unknown" };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function refreshMessage(run: BoundedRun): string {
|
|
144
|
+
if (run.cleanupFailed) return "OMP models process cleanup could not be confirmed.";
|
|
145
|
+
if (run.outcome === "timeout") return "OMP took too long to refresh its model lists.";
|
|
146
|
+
if (!succeeded(run)) return "OMP could not refresh its model lists.";
|
|
147
|
+
return "OMP refreshed its model lists.";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function refreshOmpModelsWithDependencies(
|
|
151
|
+
dependencies: OmpModelsDependencies,
|
|
152
|
+
): Promise<{ ok: boolean; message: string }> {
|
|
153
|
+
const executable = await dependencies.resolveExecutable();
|
|
154
|
+
if (!executable) return { ok: false, message: "The OMP executable could not be resolved." };
|
|
155
|
+
const run = await dependencies.run(
|
|
156
|
+
executable,
|
|
157
|
+
["models", "refresh", "--no-extensions"],
|
|
158
|
+
REFRESH_TIMEOUT_MS,
|
|
159
|
+
0,
|
|
160
|
+
true,
|
|
161
|
+
);
|
|
162
|
+
return { ok: succeeded(run), message: refreshMessage(run) };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const refreshQueue = new SerialMutationQueue();
|
|
166
|
+
|
|
167
|
+
export function resolveGetOmpModelsFileStatus(
|
|
168
|
+
_input: RpcInput<typeof getOmpModelsFileStatus>,
|
|
169
|
+
): Promise<OmpModelsFileStatus> {
|
|
170
|
+
return getOmpModelsFileStatusWithDependencies(dependenciesFor([]));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function resolveRefreshOmpModels(
|
|
174
|
+
_input: RpcInput<typeof refreshOmpModels>,
|
|
175
|
+
hostInheritEnv: readonly string[],
|
|
176
|
+
): Promise<{ ok: boolean; message: string }> {
|
|
177
|
+
return refreshQueue.run(() => refreshOmpModelsWithDependencies(dependenciesFor(hostInheritEnv)));
|
|
178
|
+
}
|