@omercnet/paseo-omp 5.4.0-next.400.1 → 5.4.0-next.402.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 +42 -16
- package/client/omp-plugin-manager.tsx +198 -3
- package/client/omp-update-row.tsx +87 -0
- package/index.server.ts +13 -0
- package/package.json +1 -1
- package/server/omp-plugins.ts +182 -0
- package/server/omp-update.ts +203 -0
- package/server/package-version.ts +1 -1
- package/shared/omp-plugins.ts +90 -0
- package/shared/omp-update.ts +27 -0
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
updateOmpSettings,
|
|
26
26
|
} from "../shared/omp-settings";
|
|
27
27
|
import { type OmpStore, storeLabel } from "../shared/omp-store";
|
|
28
|
+
import { getOmpUpdateStatus } from "../shared/omp-update";
|
|
28
29
|
import { getOmpProviderHealth, type OmpProviderHealth } from "../shared/provider-diagnostics";
|
|
29
30
|
import { getOmpSupportReport, OMP_SUPPORT_ISSUE_URL } from "../shared/support-diagnostics";
|
|
30
31
|
import { ComposerPillSettingsSection } from "./composer-pill-settings";
|
|
@@ -47,6 +48,7 @@ import { OmpRulesSection } from "./omp-rules-section";
|
|
|
47
48
|
import { OmpSkillsSection } from "./omp-skills-section";
|
|
48
49
|
import { OmpStorePicker } from "./omp-store-picker";
|
|
49
50
|
import { ompStoreKey } from "./omp-store-state";
|
|
51
|
+
import { OmpUpdateRow, UPDATE_QUERY_KEY } from "./omp-update-row";
|
|
50
52
|
import {
|
|
51
53
|
type BinaryHealthSummary,
|
|
52
54
|
loadReadyProviderSnapshot,
|
|
@@ -222,10 +224,14 @@ function BinarySection({
|
|
|
222
224
|
theme,
|
|
223
225
|
styles,
|
|
224
226
|
health,
|
|
227
|
+
workspaceScoped,
|
|
228
|
+
onUpdateInstalled,
|
|
225
229
|
}: {
|
|
226
230
|
theme: PluginSurfaceProps["theme"];
|
|
227
231
|
styles: OmpConfigStyles;
|
|
228
232
|
health: OmpProviderHealth;
|
|
233
|
+
workspaceScoped: boolean;
|
|
234
|
+
onUpdateInstalled(): void;
|
|
229
235
|
}) {
|
|
230
236
|
const summary = summarizeBinaryHealth(health.binary);
|
|
231
237
|
return (
|
|
@@ -247,6 +253,9 @@ function BinarySection({
|
|
|
247
253
|
valueColor={theme.colors.statusDanger}
|
|
248
254
|
/>
|
|
249
255
|
) : null}
|
|
256
|
+
{health.binary.installed && !workspaceScoped ? (
|
|
257
|
+
<OmpUpdateRow styles={styles} theme={theme} onInstalled={onUpdateInstalled} />
|
|
258
|
+
) : null}
|
|
250
259
|
</SectionCard>
|
|
251
260
|
);
|
|
252
261
|
}
|
|
@@ -374,8 +383,10 @@ function ProviderHealthSection({
|
|
|
374
383
|
const paseo = usePaseo();
|
|
375
384
|
const queryClient = useQueryClient();
|
|
376
385
|
const loadHealth = useRpc(getOmpProviderHealth);
|
|
386
|
+
const loadUpdateStatus = useRpc(getOmpUpdateStatus);
|
|
387
|
+
const healthKey = [...HEALTH_QUERY_KEY, ompStoreKey(store), cwd ?? "global"];
|
|
377
388
|
const health = useQuery({
|
|
378
|
-
queryKey:
|
|
389
|
+
queryKey: healthKey,
|
|
379
390
|
queryFn: () => loadHealth({ store, ...(cwd ? { cwd } : {}) }),
|
|
380
391
|
});
|
|
381
392
|
const providers = useQuery({
|
|
@@ -384,23 +395,30 @@ function ProviderHealthSection({
|
|
|
384
395
|
});
|
|
385
396
|
const refresh = useMutation({
|
|
386
397
|
mutationFn: async () => {
|
|
387
|
-
const result = await
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
),
|
|
399
|
-
|
|
400
|
-
|
|
398
|
+
const [result, update] = await Promise.all([
|
|
399
|
+
refreshProviderDiagnostics({
|
|
400
|
+
providers: paseo.providers,
|
|
401
|
+
providerIds: [
|
|
402
|
+
...selectKnownOmpProviders(providers.data?.entries ?? []).map(
|
|
403
|
+
(provider) => provider.id,
|
|
404
|
+
),
|
|
405
|
+
...(store?.profile ? [`omp-plugin-${store.profile}`] : []),
|
|
406
|
+
],
|
|
407
|
+
loadForcedHealth: () => loadHealth({ store, force: true, ...(cwd ? { cwd } : {}) }),
|
|
408
|
+
cacheHealth: (value) => queryClient.setQueryData(healthKey, value),
|
|
409
|
+
cacheProviders: (value) => queryClient.setQueryData(PROVIDERS_QUERY_KEY, value),
|
|
410
|
+
}),
|
|
411
|
+
cwd ? undefined : loadUpdateStatus({ force: true }).catch(() => undefined),
|
|
412
|
+
]);
|
|
413
|
+
if (update) queryClient.setQueryData(UPDATE_QUERY_KEY, update);
|
|
401
414
|
if (result.failed) throw new Error("Could not fully refresh OMP provider health.");
|
|
402
415
|
},
|
|
403
416
|
});
|
|
417
|
+
// After an update the version row is stale; the install already returned the fresh update status.
|
|
418
|
+
const reloadHealth = useMutation({
|
|
419
|
+
mutationFn: () => loadHealth({ store, force: true, ...(cwd ? { cwd } : {}) }),
|
|
420
|
+
onSuccess: (value) => queryClient.setQueryData(healthKey, value),
|
|
421
|
+
});
|
|
404
422
|
const isRefreshing = refresh.isPending || health.isFetching || providers.isFetching;
|
|
405
423
|
const knownProviders = providers.data ? selectKnownOmpProviders(providers.data.entries) : [];
|
|
406
424
|
|
|
@@ -434,7 +452,15 @@ function ProviderHealthSection({
|
|
|
434
452
|
{refresh.error ? (
|
|
435
453
|
<Text style={styles.error}>Could not fully refresh provider health. Try again.</Text>
|
|
436
454
|
) : null}
|
|
437
|
-
{health.data ?
|
|
455
|
+
{health.data ? (
|
|
456
|
+
<BinarySection
|
|
457
|
+
theme={theme}
|
|
458
|
+
styles={styles}
|
|
459
|
+
health={health.data}
|
|
460
|
+
workspaceScoped={cwd !== undefined}
|
|
461
|
+
onUpdateInstalled={() => reloadHealth.mutate()}
|
|
462
|
+
/>
|
|
463
|
+
) : null}
|
|
438
464
|
{health.data ? (
|
|
439
465
|
<CapabilitiesSection theme={theme} styles={styles} health={health.data} />
|
|
440
466
|
) : null}
|
|
@@ -1,30 +1,38 @@
|
|
|
1
1
|
import { type PluginSurfaceProps, useRpc } from "@getpaseo/plugin/client";
|
|
2
2
|
import { TextInput } from "@getpaseo/plugin/client/ui";
|
|
3
|
-
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { skipToken, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
4
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
5
5
|
import type { TextStyle, ViewStyle } from "react-native";
|
|
6
6
|
import { Pressable, Switch, Text, View } from "react-native";
|
|
7
7
|
import {
|
|
8
|
+
browseOmpMarketplace,
|
|
8
9
|
inspectOmpPluginConfig,
|
|
10
|
+
listOmpMarketplaces,
|
|
9
11
|
listOmpPlugins,
|
|
12
|
+
mutateOmpMarketplace,
|
|
10
13
|
mutateOmpPlugin,
|
|
11
14
|
mutateOmpPluginConfig,
|
|
12
15
|
type OmpInstalledPlugin,
|
|
16
|
+
type OmpMarketplaceMutation,
|
|
13
17
|
type OmpPluginConfigMutation,
|
|
14
18
|
OmpPluginConfigMutationSchema,
|
|
15
19
|
type OmpPluginConfigSetting,
|
|
16
20
|
type OmpPluginConfigState,
|
|
17
21
|
OmpPluginInstallSourceSchema,
|
|
18
22
|
type OmpPluginMutation,
|
|
23
|
+
redactSourceCredentials,
|
|
19
24
|
} from "../shared/omp-plugins";
|
|
20
25
|
|
|
21
26
|
import type { OmpStore } from "../shared/omp-store";
|
|
22
27
|
import { ompStoreKey } from "./omp-store-state";
|
|
23
28
|
|
|
24
29
|
const PLUGINS_QUERY_KEY = ["paseo-omp", "plugins"] as const;
|
|
30
|
+
const MARKETPLACES_QUERY_KEY = ["paseo-omp", "marketplaces"] as const;
|
|
31
|
+
const CATALOG_ROW_LIMIT = 50;
|
|
25
32
|
|
|
26
33
|
type ConfirmationOrigin =
|
|
27
34
|
| { surface: "install" }
|
|
35
|
+
| { surface: "catalog" }
|
|
28
36
|
| { surface: "plugin"; key: string }
|
|
29
37
|
| { surface: "config"; key: string };
|
|
30
38
|
|
|
@@ -42,6 +50,13 @@ type PendingConfirmation =
|
|
|
42
50
|
origin: ConfirmationOrigin;
|
|
43
51
|
title: string;
|
|
44
52
|
warning: string;
|
|
53
|
+
}
|
|
54
|
+
| {
|
|
55
|
+
kind: "marketplace";
|
|
56
|
+
input: OmpMarketplaceMutation;
|
|
57
|
+
origin: ConfirmationOrigin;
|
|
58
|
+
title: string;
|
|
59
|
+
warning: string;
|
|
45
60
|
};
|
|
46
61
|
|
|
47
62
|
type PluginManagerStyles = {
|
|
@@ -264,7 +279,7 @@ function ConfirmationPanel({
|
|
|
264
279
|
label={busy ? "Applying…" : confirmLabel}
|
|
265
280
|
disabled={busy}
|
|
266
281
|
primary
|
|
267
|
-
danger={action === "uninstall" || action === "delete"}
|
|
282
|
+
danger={action === "uninstall" || action === "delete" || action === "remove"}
|
|
268
283
|
styles={styles}
|
|
269
284
|
onPress={onConfirm}
|
|
270
285
|
/>
|
|
@@ -688,6 +703,43 @@ export function OmpPluginManagerSection({
|
|
|
688
703
|
const [inspected, setInspected] = useState<OmpPluginConfigState | null>(null);
|
|
689
704
|
const [configEditGenerations, setConfigEditGenerations] = useState<Record<string, number>>({});
|
|
690
705
|
const inspectionGeneration = useRef(0);
|
|
706
|
+
const loadMarketplaces = useRpc(listOmpMarketplaces);
|
|
707
|
+
const browseMarketplace = useRpc(browseOmpMarketplace);
|
|
708
|
+
const mutateMarketplace = useRpc(mutateOmpMarketplace);
|
|
709
|
+
const [catalogSource, setCatalogSource] = useState("");
|
|
710
|
+
const [browsing, setBrowsing] = useState<string | null>(null);
|
|
711
|
+
const marketplaces = useQuery({
|
|
712
|
+
queryKey: [...MARKETPLACES_QUERY_KEY, ompStoreKey(store)],
|
|
713
|
+
queryFn: () => loadMarketplaces({ store }),
|
|
714
|
+
staleTime: Number.POSITIVE_INFINITY,
|
|
715
|
+
});
|
|
716
|
+
const catalog = useQuery({
|
|
717
|
+
queryKey: [...MARKETPLACES_QUERY_KEY, "catalog", ompStoreKey(store), browsing],
|
|
718
|
+
queryFn:
|
|
719
|
+
browsing === null ? skipToken : () => browseMarketplace({ store, marketplace: browsing }),
|
|
720
|
+
staleTime: Number.POSITIVE_INFINITY,
|
|
721
|
+
});
|
|
722
|
+
const marketplaceMutation = useMutation({
|
|
723
|
+
mutationKey: ["paseo-omp", "marketplace", ompStoreKey(store)],
|
|
724
|
+
mutationFn: (input: OmpMarketplaceMutation) => mutateMarketplace({ ...input, store }),
|
|
725
|
+
onSuccess: (result, input) => {
|
|
726
|
+
queryClient.setQueryData([...MARKETPLACES_QUERY_KEY, ompStoreKey(store)], result.state);
|
|
727
|
+
void queryClient.invalidateQueries({
|
|
728
|
+
queryKey: [...MARKETPLACES_QUERY_KEY, "catalog", ompStoreKey(store)],
|
|
729
|
+
refetchType: "none",
|
|
730
|
+
});
|
|
731
|
+
setNotice({ tone: result.ok ? "success" : "error", text: result.message });
|
|
732
|
+
if (result.ok && input.action === "add") setCatalogSource("");
|
|
733
|
+
if (result.ok && input.action === "remove" && input.marketplace === browsing) {
|
|
734
|
+
setBrowsing(null);
|
|
735
|
+
}
|
|
736
|
+
setConfirmation(null);
|
|
737
|
+
},
|
|
738
|
+
onError: () => {
|
|
739
|
+
setNotice({ tone: "error", text: "The marketplace operation could not be completed." });
|
|
740
|
+
setConfirmation(null);
|
|
741
|
+
},
|
|
742
|
+
});
|
|
691
743
|
const plugins = useQuery({
|
|
692
744
|
queryKey: [...PLUGINS_QUERY_KEY, ompStoreKey(store), cwd ?? "global"],
|
|
693
745
|
queryFn: () => loadPlugins(context),
|
|
@@ -744,7 +796,7 @@ export function OmpPluginManagerSection({
|
|
|
744
796
|
setConfirmation(null);
|
|
745
797
|
},
|
|
746
798
|
});
|
|
747
|
-
const busy = mutation.isPending || configMutation.isPending;
|
|
799
|
+
const busy = mutation.isPending || configMutation.isPending || marketplaceMutation.isPending;
|
|
748
800
|
useEffect(() => {
|
|
749
801
|
if (!confirmation) return;
|
|
750
802
|
const { origin } = confirmation;
|
|
@@ -816,9 +868,39 @@ export function OmpPluginManagerSection({
|
|
|
816
868
|
setConfirmation(null);
|
|
817
869
|
configInspection.mutate({ plugin, generation });
|
|
818
870
|
};
|
|
871
|
+
const requestCatalogAdd = () => {
|
|
872
|
+
const parsed = OmpPluginInstallSourceSchema.safeParse(catalogSource);
|
|
873
|
+
if (!parsed.success) {
|
|
874
|
+
setNotice({
|
|
875
|
+
tone: "error",
|
|
876
|
+
text: "Enter one valid Git source, URL, or local path without options or control characters.",
|
|
877
|
+
});
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
setNotice(null);
|
|
881
|
+
setConfirmation({
|
|
882
|
+
kind: "marketplace",
|
|
883
|
+
input: { action: "add", source: parsed.data, store },
|
|
884
|
+
origin: { surface: "catalog" },
|
|
885
|
+
title: `Add marketplace ${redactSourceCredentials(parsed.data)}?`,
|
|
886
|
+
warning:
|
|
887
|
+
"Plugins from a marketplace are trusted code. Adding it fetches the catalog on the daemon host, and any plugin you install from it can run code with that host's access.",
|
|
888
|
+
});
|
|
889
|
+
};
|
|
890
|
+
const requestCatalogRemove = (name: string) => {
|
|
891
|
+
setNotice(null);
|
|
892
|
+
setConfirmation({
|
|
893
|
+
kind: "marketplace",
|
|
894
|
+
input: { action: "remove", marketplace: name, store },
|
|
895
|
+
origin: { surface: "catalog" },
|
|
896
|
+
title: `Remove marketplace ${name}?`,
|
|
897
|
+
warning: "Removes the catalog and its cached copy. Installed plugins are not uninstalled.",
|
|
898
|
+
});
|
|
899
|
+
};
|
|
819
900
|
const applyConfirmation = () => {
|
|
820
901
|
if (!confirmation) return;
|
|
821
902
|
if (confirmation.kind === "plugin") mutation.mutate(confirmation.input);
|
|
903
|
+
else if (confirmation.kind === "marketplace") marketplaceMutation.mutate(confirmation.input);
|
|
822
904
|
else configMutation.mutate(confirmation.input);
|
|
823
905
|
};
|
|
824
906
|
|
|
@@ -835,6 +917,7 @@ export function OmpPluginManagerSection({
|
|
|
835
917
|
styles={styles}
|
|
836
918
|
onPress={() => {
|
|
837
919
|
void plugins.refetch();
|
|
920
|
+
void queryClient.invalidateQueries({ queryKey: MARKETPLACES_QUERY_KEY });
|
|
838
921
|
}}
|
|
839
922
|
/>
|
|
840
923
|
</View>
|
|
@@ -877,6 +960,118 @@ export function OmpPluginManagerSection({
|
|
|
877
960
|
)}
|
|
878
961
|
</View>
|
|
879
962
|
|
|
963
|
+
<View style={styles.card}>
|
|
964
|
+
<Text style={styles.cardTitle}>Marketplaces</Text>
|
|
965
|
+
<Text style={styles.muted}>
|
|
966
|
+
Catalogs of installable OMP plugins. Browse one to fill the install box above.
|
|
967
|
+
</Text>
|
|
968
|
+
{marketplaces.isLoading ? <Text style={styles.muted}>Loading marketplaces…</Text> : null}
|
|
969
|
+
{marketplaces.error || marketplaces.data?.error ? (
|
|
970
|
+
<Text accessibilityRole="alert" style={styles.error}>
|
|
971
|
+
{marketplaces.data?.error ?? "Could not load OMP marketplaces."}
|
|
972
|
+
</Text>
|
|
973
|
+
) : null}
|
|
974
|
+
{marketplaces.data?.available && marketplaces.data.marketplaces.length === 0 ? (
|
|
975
|
+
<Text style={styles.muted}>No marketplaces configured.</Text>
|
|
976
|
+
) : null}
|
|
977
|
+
{marketplaces.data?.marketplaces.map((marketplace) => (
|
|
978
|
+
<View key={marketplace.name} style={styles.setting}>
|
|
979
|
+
<View style={styles.cardHeader}>
|
|
980
|
+
<View style={{ flexShrink: 1 }}>
|
|
981
|
+
<Text style={styles.settingName}>{marketplace.name}</Text>
|
|
982
|
+
<Text selectable style={styles.settingDescription}>
|
|
983
|
+
{marketplace.source}
|
|
984
|
+
</Text>
|
|
985
|
+
</View>
|
|
986
|
+
<View style={styles.actions}>
|
|
987
|
+
<ActionButton
|
|
988
|
+
label={browsing === marketplace.name ? "Hide" : "Browse"}
|
|
989
|
+
disabled={busy || confirmation !== null}
|
|
990
|
+
styles={styles}
|
|
991
|
+
onPress={() =>
|
|
992
|
+
setBrowsing(browsing === marketplace.name ? null : marketplace.name)
|
|
993
|
+
}
|
|
994
|
+
/>
|
|
995
|
+
<ActionButton
|
|
996
|
+
label="Remove"
|
|
997
|
+
disabled={busy || confirmation !== null}
|
|
998
|
+
danger
|
|
999
|
+
styles={styles}
|
|
1000
|
+
onPress={() => requestCatalogRemove(marketplace.name)}
|
|
1001
|
+
/>
|
|
1002
|
+
</View>
|
|
1003
|
+
</View>
|
|
1004
|
+
{browsing === marketplace.name ? (
|
|
1005
|
+
<View style={styles.settings}>
|
|
1006
|
+
{catalog.isFetching ? <Text style={styles.muted}>Loading catalog…</Text> : null}
|
|
1007
|
+
{catalog.error || catalog.data?.error ? (
|
|
1008
|
+
<Text accessibilityRole="alert" style={styles.error}>
|
|
1009
|
+
{catalog.data?.error ?? "Could not load this catalog."}
|
|
1010
|
+
</Text>
|
|
1011
|
+
) : null}
|
|
1012
|
+
{catalog.data?.available && catalog.data.plugins.length === 0 ? (
|
|
1013
|
+
<Text style={styles.muted}>This catalog lists no plugins.</Text>
|
|
1014
|
+
) : null}
|
|
1015
|
+
{catalog.data?.plugins.slice(0, CATALOG_ROW_LIMIT).map((plugin) => (
|
|
1016
|
+
<View key={plugin.id} style={styles.cardHeader}>
|
|
1017
|
+
<View style={{ flexShrink: 1 }}>
|
|
1018
|
+
<Text style={styles.settingName}>
|
|
1019
|
+
{plugin.id}
|
|
1020
|
+
{plugin.version ? ` · ${plugin.version}` : ""}
|
|
1021
|
+
</Text>
|
|
1022
|
+
{plugin.description ? (
|
|
1023
|
+
<Text style={styles.settingDescription}>{plugin.description}</Text>
|
|
1024
|
+
) : null}
|
|
1025
|
+
</View>
|
|
1026
|
+
<ActionButton
|
|
1027
|
+
label="Use"
|
|
1028
|
+
disabled={busy || confirmation !== null}
|
|
1029
|
+
styles={styles}
|
|
1030
|
+
onPress={() => setSource(plugin.id)}
|
|
1031
|
+
/>
|
|
1032
|
+
</View>
|
|
1033
|
+
))}
|
|
1034
|
+
{catalog.data && catalog.data.plugins.length > CATALOG_ROW_LIMIT ? (
|
|
1035
|
+
<Text style={styles.muted}>
|
|
1036
|
+
Showing {CATALOG_ROW_LIMIT} of {catalog.data.plugins.length} plugins.
|
|
1037
|
+
</Text>
|
|
1038
|
+
) : null}
|
|
1039
|
+
</View>
|
|
1040
|
+
) : null}
|
|
1041
|
+
</View>
|
|
1042
|
+
))}
|
|
1043
|
+
<TextInput
|
|
1044
|
+
accessibilityLabel="OMP marketplace source"
|
|
1045
|
+
editable={!busy && confirmation === null}
|
|
1046
|
+
value={catalogSource}
|
|
1047
|
+
onChangeText={setCatalogSource}
|
|
1048
|
+
placeholder="owner/repo, Git URL, or local path"
|
|
1049
|
+
placeholderTextColor={theme.colors.foregroundMuted}
|
|
1050
|
+
autoCapitalize="none"
|
|
1051
|
+
autoCorrect={false}
|
|
1052
|
+
style={styles.input}
|
|
1053
|
+
/>
|
|
1054
|
+
{confirmation?.origin.surface === "catalog" ? (
|
|
1055
|
+
<ConfirmationPanel
|
|
1056
|
+
confirmation={confirmation}
|
|
1057
|
+
busy={busy}
|
|
1058
|
+
styles={styles}
|
|
1059
|
+
onCancel={() => setConfirmation(null)}
|
|
1060
|
+
onConfirm={applyConfirmation}
|
|
1061
|
+
/>
|
|
1062
|
+
) : (
|
|
1063
|
+
<View style={styles.actions}>
|
|
1064
|
+
<ActionButton
|
|
1065
|
+
label="Review add"
|
|
1066
|
+
disabled={busy || confirmation !== null || catalogSource.length === 0}
|
|
1067
|
+
primary
|
|
1068
|
+
styles={styles}
|
|
1069
|
+
onPress={requestCatalogAdd}
|
|
1070
|
+
/>
|
|
1071
|
+
</View>
|
|
1072
|
+
)}
|
|
1073
|
+
</View>
|
|
1074
|
+
|
|
880
1075
|
{notice ? (
|
|
881
1076
|
<Text
|
|
882
1077
|
accessibilityRole="alert"
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type PluginSurfaceProps, useRpc } from "@getpaseo/plugin/client";
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Text, View } from "react-native";
|
|
5
|
+
import { getOmpUpdateStatus, installOmpUpdate, type OmpUpdateStatus } from "../shared/omp-update";
|
|
6
|
+
import { ActionButton, ConfirmModal } from "./omp-accounts-section";
|
|
7
|
+
import type { OmpConfigStyles } from "./omp-config-styles";
|
|
8
|
+
|
|
9
|
+
export const UPDATE_QUERY_KEY = ["paseo-omp", "update-status"] as const;
|
|
10
|
+
|
|
11
|
+
export function summarizeUpdateStatus(status: OmpUpdateStatus): string {
|
|
12
|
+
if (status.state === "available") return `${status.version} available`;
|
|
13
|
+
if (status.state === "up-to-date") return "Up to date";
|
|
14
|
+
return "Could not check for updates";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The "Update available" line for the omp binary card, with a confirmed Update button. */
|
|
18
|
+
export function OmpUpdateRow({
|
|
19
|
+
styles,
|
|
20
|
+
theme,
|
|
21
|
+
onInstalled,
|
|
22
|
+
}: {
|
|
23
|
+
styles: OmpConfigStyles;
|
|
24
|
+
theme: PluginSurfaceProps["theme"];
|
|
25
|
+
onInstalled(): void;
|
|
26
|
+
}) {
|
|
27
|
+
const queryClient = useQueryClient();
|
|
28
|
+
const loadStatus = useRpc(getOmpUpdateStatus);
|
|
29
|
+
const install = useRpc(installOmpUpdate);
|
|
30
|
+
const status = useQuery({ queryKey: UPDATE_QUERY_KEY, queryFn: () => loadStatus({}) });
|
|
31
|
+
const [confirming, setConfirming] = useState(false);
|
|
32
|
+
const [message, setMessage] = useState<{ ok: boolean; text: string } | null>(null);
|
|
33
|
+
const update = useMutation({
|
|
34
|
+
mutationFn: () => install({}),
|
|
35
|
+
onSuccess: async (result) => {
|
|
36
|
+
await queryClient.cancelQueries({ queryKey: UPDATE_QUERY_KEY });
|
|
37
|
+
queryClient.setQueryData(UPDATE_QUERY_KEY, result.status);
|
|
38
|
+
setMessage({ ok: result.ok, text: result.message });
|
|
39
|
+
onInstalled();
|
|
40
|
+
},
|
|
41
|
+
onError: () => setMessage({ ok: false, text: "Could not update OMP. Try again." }),
|
|
42
|
+
onSettled: () => setConfirming(false),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (status.isLoading) return <Text style={styles.muted}>Checking for an OMP update…</Text>;
|
|
46
|
+
const current = status.data ?? { state: "unknown" as const };
|
|
47
|
+
return (
|
|
48
|
+
<>
|
|
49
|
+
<View style={styles.row}>
|
|
50
|
+
<Text style={styles.rowLabel}>Update</Text>
|
|
51
|
+
<Text
|
|
52
|
+
style={[
|
|
53
|
+
styles.rowValue,
|
|
54
|
+
current.state === "available" ? { color: theme.colors.statusWarning } : null,
|
|
55
|
+
]}
|
|
56
|
+
>
|
|
57
|
+
{summarizeUpdateStatus(current)}
|
|
58
|
+
</Text>
|
|
59
|
+
{current.state === "available" ? (
|
|
60
|
+
<ActionButton
|
|
61
|
+
styles={styles}
|
|
62
|
+
theme={theme}
|
|
63
|
+
label={update.isPending ? "Updating…" : "Update"}
|
|
64
|
+
disabled={update.isPending}
|
|
65
|
+
onPress={() => setConfirming(true)}
|
|
66
|
+
/>
|
|
67
|
+
) : null}
|
|
68
|
+
</View>
|
|
69
|
+
{message ? (
|
|
70
|
+
<Text style={message.ok ? styles.muted : styles.error}>{message.text}</Text>
|
|
71
|
+
) : null}
|
|
72
|
+
{confirming ? (
|
|
73
|
+
<ConfirmModal
|
|
74
|
+
styles={styles}
|
|
75
|
+
theme={theme}
|
|
76
|
+
title="Update OMP"
|
|
77
|
+
body="Installs the newest OMP on this host. Agents that are running keep the old version until they restart."
|
|
78
|
+
confirmLabel="Update"
|
|
79
|
+
tone="primary"
|
|
80
|
+
busy={update.isPending}
|
|
81
|
+
onConfirm={() => update.mutate()}
|
|
82
|
+
onCancel={() => setConfirming(false)}
|
|
83
|
+
/>
|
|
84
|
+
) : null}
|
|
85
|
+
</>
|
|
86
|
+
);
|
|
87
|
+
}
|
package/index.server.ts
CHANGED
|
@@ -10,8 +10,11 @@ import { resolveListOmpConfig } from "./server/omp-config";
|
|
|
10
10
|
import { OmpMcps } from "./server/omp-mcps";
|
|
11
11
|
import { resolveListOmpModels } from "./server/omp-models";
|
|
12
12
|
import {
|
|
13
|
+
resolveBrowseOmpMarketplace,
|
|
13
14
|
resolveInspectOmpPluginConfig,
|
|
15
|
+
resolveListOmpMarketplaces,
|
|
14
16
|
resolveListOmpPlugins,
|
|
17
|
+
resolveMutateOmpMarketplace,
|
|
15
18
|
resolveMutateOmpPlugin,
|
|
16
19
|
resolveMutateOmpPluginConfig,
|
|
17
20
|
} from "./server/omp-plugins";
|
|
@@ -22,6 +25,7 @@ import {
|
|
|
22
25
|
resolveListOmpSkills,
|
|
23
26
|
resolveSetOmpSkillEnabled,
|
|
24
27
|
} from "./server/omp-skills";
|
|
28
|
+
import { resolveGetOmpUpdateStatus, resolveInstallOmpUpdate } from "./server/omp-update";
|
|
25
29
|
import { OmpOperationalFailureCollector } from "./server/operational-failure-diagnostics";
|
|
26
30
|
import { withOmpStore } from "./server/paths";
|
|
27
31
|
import { OmpProtocolViolationCollector } from "./server/protocol-violation-diagnostics";
|
|
@@ -69,8 +73,11 @@ import {
|
|
|
69
73
|
} from "./shared/omp-mcps";
|
|
70
74
|
import { listOmpModels } from "./shared/omp-models";
|
|
71
75
|
import {
|
|
76
|
+
browseOmpMarketplace,
|
|
72
77
|
inspectOmpPluginConfig,
|
|
78
|
+
listOmpMarketplaces,
|
|
73
79
|
listOmpPlugins,
|
|
80
|
+
mutateOmpMarketplace,
|
|
74
81
|
mutateOmpPlugin,
|
|
75
82
|
mutateOmpPluginConfig,
|
|
76
83
|
} from "./shared/omp-plugins";
|
|
@@ -78,6 +85,7 @@ import { listOmpRules } from "./shared/omp-rules";
|
|
|
78
85
|
import { listOmpSettings, updateOmpSettings } from "./shared/omp-settings";
|
|
79
86
|
import { deleteOmpManagedSkill, listOmpSkills, setOmpSkillEnabled } from "./shared/omp-skills";
|
|
80
87
|
import { listOmpStores, type OmpStore } from "./shared/omp-store";
|
|
88
|
+
import { getOmpUpdateStatus, installOmpUpdate } from "./shared/omp-update";
|
|
81
89
|
import { getOmpProviderHealth } from "./shared/provider-diagnostics";
|
|
82
90
|
import { getOmpImage } from "./shared/provider-image";
|
|
83
91
|
import { providerLaunchSettings } from "./shared/provider-launch-settings";
|
|
@@ -194,6 +202,9 @@ export default function contribute(server: PluginServerContext) {
|
|
|
194
202
|
server.handle(listOmpConfig, scoped(resolveListOmpConfig));
|
|
195
203
|
server.handle(listOmpModels, scoped(resolveListOmpModels));
|
|
196
204
|
server.handle(listOmpPlugins, scoped(resolveListOmpPlugins));
|
|
205
|
+
server.handle(listOmpMarketplaces, scoped(resolveListOmpMarketplaces));
|
|
206
|
+
server.handle(browseOmpMarketplace, scoped(resolveBrowseOmpMarketplace));
|
|
207
|
+
server.handle(mutateOmpMarketplace, scoped(resolveMutateOmpMarketplace));
|
|
197
208
|
server.handle(listOmpRules, scoped(resolveListOmpRules));
|
|
198
209
|
server.handle(listOmpSkills, scoped(resolveListOmpSkills));
|
|
199
210
|
server.handle(setOmpSkillEnabled, scoped(resolveSetOmpSkillEnabled));
|
|
@@ -204,6 +215,8 @@ export default function contribute(server: PluginServerContext) {
|
|
|
204
215
|
server.handle(listOmpSettings, scoped(resolveListOmpSettings));
|
|
205
216
|
server.handle(updateOmpSettings, scoped(resolveUpdateOmpSettings));
|
|
206
217
|
server.handle(getOmpProviderHealth, scoped(resolveGetOmpProviderHealth));
|
|
218
|
+
server.handle(getOmpUpdateStatus, resolveGetOmpUpdateStatus);
|
|
219
|
+
server.handle(installOmpUpdate, resolveInstallOmpUpdate);
|
|
207
220
|
server.handle(getOmpImage, (input) => resolveGetOmpImage(input, ompImageCache()));
|
|
208
221
|
server.handle(
|
|
209
222
|
getOmpSupportReport,
|
package/package.json
CHANGED
package/server/omp-plugins.ts
CHANGED
|
@@ -3,20 +3,28 @@ import { delimiter, isAbsolute, join } from "node:path";
|
|
|
3
3
|
import type { RpcInput } from "@getpaseo/plugin";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import {
|
|
6
|
+
type browseOmpMarketplace,
|
|
6
7
|
type inspectOmpPluginConfig,
|
|
8
|
+
type listOmpMarketplaces,
|
|
7
9
|
type listOmpPlugins,
|
|
10
|
+
type mutateOmpMarketplace,
|
|
8
11
|
type mutateOmpPlugin,
|
|
9
12
|
type mutateOmpPluginConfig,
|
|
13
|
+
OMP_CATALOG_PLUGIN_LIMIT,
|
|
10
14
|
OMP_PLUGIN_LIMIT,
|
|
15
|
+
type OmpCatalogState,
|
|
11
16
|
type OmpInstalledPlugin,
|
|
12
17
|
OmpInstalledPluginSchema,
|
|
18
|
+
OmpMarketplaceNameSchema,
|
|
13
19
|
OmpMarketplacePluginIdSchema,
|
|
20
|
+
type OmpMarketplaceState,
|
|
14
21
|
type OmpPluginConfigMutation,
|
|
15
22
|
type OmpPluginConfigSetting,
|
|
16
23
|
type OmpPluginConfigState,
|
|
17
24
|
type OmpPluginMutation,
|
|
18
25
|
OmpPluginNameSchema,
|
|
19
26
|
type OmpPluginState,
|
|
27
|
+
redactSourceCredentials,
|
|
20
28
|
} from "../shared/omp-plugins";
|
|
21
29
|
import { SerialMutationQueue } from "./mutation-queue";
|
|
22
30
|
import { currentOmpEnvironment } from "./paths";
|
|
@@ -674,3 +682,177 @@ export function resolveMutateOmpPlugin(
|
|
|
674
682
|
mutateOmpPluginWithDependencies(input, DEFAULT_DEPENDENCIES),
|
|
675
683
|
);
|
|
676
684
|
}
|
|
685
|
+
|
|
686
|
+
// OMP prints marketplace listings as text only (`--json` is ignored), so parse the stable
|
|
687
|
+
// "name source" and "name[@version]" / indented description shapes and reject anything else.
|
|
688
|
+
|
|
689
|
+
export function parseOmpMarketplaceList(stdout: string): OmpMarketplaceState["marketplaces"] {
|
|
690
|
+
const lines = stdout.split(/\r?\n/u);
|
|
691
|
+
if (!lines.some((line) => line.startsWith("Configured Marketplaces:"))) {
|
|
692
|
+
if (lines.some((line) => line.startsWith("No marketplaces configured"))) return [];
|
|
693
|
+
throw new Error("OMP returned an invalid marketplace list");
|
|
694
|
+
}
|
|
695
|
+
const marketplaces: OmpMarketplaceState["marketplaces"] = [];
|
|
696
|
+
for (const line of lines) {
|
|
697
|
+
const match = /^ {2}(\S+) {2}(\S.*)$/u.exec(line);
|
|
698
|
+
if (!match?.[1] || !match[2]) continue;
|
|
699
|
+
const name = OmpMarketplaceNameSchema.safeParse(match[1]);
|
|
700
|
+
const source = boundedText(redactSourceCredentials(match[2].trim()), 4_096);
|
|
701
|
+
if (name.success && source) marketplaces.push({ name: name.data, source });
|
|
702
|
+
if (marketplaces.length === OMP_PLUGIN_LIMIT) break;
|
|
703
|
+
}
|
|
704
|
+
return marketplaces;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
export function parseOmpCatalog(stdout: string, marketplace: string): OmpCatalogState["plugins"] {
|
|
708
|
+
const lines = stdout.split(/\r?\n/u);
|
|
709
|
+
if (!lines.some((line) => line.startsWith("Available Plugins"))) {
|
|
710
|
+
if (lines.some((line) => line.startsWith("No plugins found"))) return [];
|
|
711
|
+
throw new Error("OMP returned an invalid plugin catalog");
|
|
712
|
+
}
|
|
713
|
+
const plugins: OmpCatalogState["plugins"] = [];
|
|
714
|
+
let current: OmpCatalogState["plugins"][number] | null = null;
|
|
715
|
+
for (const line of lines) {
|
|
716
|
+
const entry = /^ {2}(\S+)$/u.exec(line);
|
|
717
|
+
if (entry?.[1]) {
|
|
718
|
+
const [name, version] = entry[1].split("@");
|
|
719
|
+
const id = `${name}@${marketplace}`;
|
|
720
|
+
// OMP allows mixed-case names and caps the assembled id at 128 characters.
|
|
721
|
+
const valid = OmpMarketplaceNameSchema.safeParse(name).success && id.length <= 128;
|
|
722
|
+
current = valid ? { id, version: boundedText(version, 128), description: null } : null;
|
|
723
|
+
if (!current) continue;
|
|
724
|
+
plugins.push(current);
|
|
725
|
+
if (plugins.length === OMP_CATALOG_PLUGIN_LIMIT) break;
|
|
726
|
+
continue;
|
|
727
|
+
}
|
|
728
|
+
const description = /^ {4}(\S.*)$/u.exec(line);
|
|
729
|
+
if (description?.[1] && current && current.description === null) {
|
|
730
|
+
current.description = boundedText(description[1].trim(), DESCRIPTION_LIMIT);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return plugins;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
async function loadMarketplaces(
|
|
737
|
+
executable: string,
|
|
738
|
+
dependencies: OmpPluginDependencies,
|
|
739
|
+
): Promise<OmpMarketplaceState> {
|
|
740
|
+
const result = await dependencies.runPlugin(
|
|
741
|
+
executable,
|
|
742
|
+
["plugin", "marketplace", "list"],
|
|
743
|
+
LIST_OUTPUT_LIMIT,
|
|
744
|
+
READ_TIMEOUT_MS,
|
|
745
|
+
);
|
|
746
|
+
if (!runSucceeded(result)) {
|
|
747
|
+
return { available: false, marketplaces: [], error: readFailure(result) };
|
|
748
|
+
}
|
|
749
|
+
try {
|
|
750
|
+
return { available: true, marketplaces: parseOmpMarketplaceList(result.stdout) };
|
|
751
|
+
} catch {
|
|
752
|
+
return {
|
|
753
|
+
available: false,
|
|
754
|
+
marketplaces: [],
|
|
755
|
+
error: "OMP returned an invalid marketplace list.",
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
export async function listOmpMarketplacesWithDependencies(
|
|
761
|
+
dependencies: OmpPluginDependencies,
|
|
762
|
+
): Promise<OmpMarketplaceState> {
|
|
763
|
+
const executable = await dependencies.resolveExecutable();
|
|
764
|
+
if (!executable) {
|
|
765
|
+
return {
|
|
766
|
+
available: false,
|
|
767
|
+
marketplaces: [],
|
|
768
|
+
error: "The OMP executable could not be resolved.",
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
return loadMarketplaces(executable, dependencies);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
export function resolveListOmpMarketplaces(
|
|
775
|
+
_input: RpcInput<typeof listOmpMarketplaces>,
|
|
776
|
+
): Promise<OmpMarketplaceState> {
|
|
777
|
+
return listOmpMarketplacesWithDependencies(DEFAULT_DEPENDENCIES);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
export async function browseOmpMarketplaceWithDependencies(
|
|
781
|
+
input: RpcInput<typeof browseOmpMarketplace>,
|
|
782
|
+
dependencies: OmpPluginDependencies,
|
|
783
|
+
): Promise<OmpCatalogState> {
|
|
784
|
+
const unavailable = (error: string): OmpCatalogState => ({
|
|
785
|
+
available: false,
|
|
786
|
+
marketplace: input.marketplace,
|
|
787
|
+
plugins: [],
|
|
788
|
+
error,
|
|
789
|
+
});
|
|
790
|
+
const executable = await dependencies.resolveExecutable();
|
|
791
|
+
if (!executable) return unavailable("The OMP executable could not be resolved.");
|
|
792
|
+
const result = await dependencies.runPlugin(
|
|
793
|
+
executable,
|
|
794
|
+
["plugin", "discover", input.marketplace],
|
|
795
|
+
LIST_OUTPUT_LIMIT,
|
|
796
|
+
READ_TIMEOUT_MS,
|
|
797
|
+
);
|
|
798
|
+
if (!runSucceeded(result)) return unavailable(readFailure(result));
|
|
799
|
+
try {
|
|
800
|
+
return {
|
|
801
|
+
available: true,
|
|
802
|
+
marketplace: input.marketplace,
|
|
803
|
+
plugins: parseOmpCatalog(result.stdout, input.marketplace),
|
|
804
|
+
};
|
|
805
|
+
} catch {
|
|
806
|
+
return unavailable("OMP returned an invalid plugin catalog.");
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
export function resolveBrowseOmpMarketplace(
|
|
811
|
+
input: RpcInput<typeof browseOmpMarketplace>,
|
|
812
|
+
): Promise<OmpCatalogState> {
|
|
813
|
+
return browseOmpMarketplaceWithDependencies(input, DEFAULT_DEPENDENCIES);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
export function buildOmpMarketplaceMutationArgs(
|
|
817
|
+
input: RpcInput<typeof mutateOmpMarketplace>,
|
|
818
|
+
): string[] {
|
|
819
|
+
return [
|
|
820
|
+
"plugin",
|
|
821
|
+
"marketplace",
|
|
822
|
+
input.action,
|
|
823
|
+
input.action === "add" ? input.source : input.marketplace,
|
|
824
|
+
];
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
export async function mutateOmpMarketplaceWithDependencies(
|
|
828
|
+
input: RpcInput<typeof mutateOmpMarketplace>,
|
|
829
|
+
dependencies: OmpPluginDependencies,
|
|
830
|
+
): Promise<{ ok: boolean; message: string; state: OmpMarketplaceState }> {
|
|
831
|
+
const executable = await dependencies.resolveExecutable();
|
|
832
|
+
if (!executable) {
|
|
833
|
+
const message = "The OMP executable could not be resolved.";
|
|
834
|
+
return { ok: false, message, state: { available: false, marketplaces: [], error: message } };
|
|
835
|
+
}
|
|
836
|
+
const mutation = await dependencies.runPlugin(
|
|
837
|
+
executable,
|
|
838
|
+
buildOmpMarketplaceMutationArgs(input),
|
|
839
|
+
MUTATION_OUTPUT_LIMIT,
|
|
840
|
+
MUTATION_TIMEOUT_MS,
|
|
841
|
+
);
|
|
842
|
+
const ok = runSucceeded(mutation);
|
|
843
|
+
const state = await loadMarketplaces(executable, dependencies);
|
|
844
|
+
if (!ok) return { ok, message: mutationFailure(mutation), state };
|
|
845
|
+
return {
|
|
846
|
+
ok,
|
|
847
|
+
message: input.action === "add" ? "Marketplace added." : "Marketplace removed.",
|
|
848
|
+
state,
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
export function resolveMutateOmpMarketplace(
|
|
853
|
+
input: RpcInput<typeof mutateOmpMarketplace>,
|
|
854
|
+
): Promise<{ ok: boolean; message: string; state: OmpMarketplaceState }> {
|
|
855
|
+
return pluginMutationQueue.run(() =>
|
|
856
|
+
mutateOmpMarketplaceWithDependencies(input, DEFAULT_DEPENDENCIES),
|
|
857
|
+
);
|
|
858
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { tmpdir } from "node:os";
|
|
2
|
+
import { delimiter, dirname, parse } from "node:path";
|
|
3
|
+
import type { RpcInput } from "@getpaseo/plugin";
|
|
4
|
+
import {
|
|
5
|
+
type getOmpUpdateStatus,
|
|
6
|
+
type installOmpUpdate,
|
|
7
|
+
type OmpUpdateStatus,
|
|
8
|
+
OmpUpdateStatusSchema,
|
|
9
|
+
} from "../shared/omp-update";
|
|
10
|
+
import { SerialMutationQueue } from "./mutation-queue";
|
|
11
|
+
import { resolveOmpExecutable } from "./omp-settings";
|
|
12
|
+
import { currentOmpEnvironment } from "./paths";
|
|
13
|
+
import {
|
|
14
|
+
type BoundedRun,
|
|
15
|
+
buildStatefulCommandEnv,
|
|
16
|
+
defaultSpawn,
|
|
17
|
+
runBounded,
|
|
18
|
+
} from "./provider-diagnostics";
|
|
19
|
+
|
|
20
|
+
const CHECK_TIMEOUT_MS = 20_000;
|
|
21
|
+
const INSTALL_TIMEOUT_MS = 5 * 60_000;
|
|
22
|
+
const KILL_GRACE_MS = 1_000;
|
|
23
|
+
const MAX_OUTPUT_BYTES = 64 * 1024;
|
|
24
|
+
const CHECK_CACHE_TTL_MS = 10 * 60_000;
|
|
25
|
+
// Network and install-root settings an npm, bun or binary self-update needs. Credentials and
|
|
26
|
+
// tokens stay excluded.
|
|
27
|
+
const UPDATE_ENV = [
|
|
28
|
+
"HTTPS_PROXY",
|
|
29
|
+
"HTTP_PROXY",
|
|
30
|
+
"NO_PROXY",
|
|
31
|
+
"https_proxy",
|
|
32
|
+
"http_proxy",
|
|
33
|
+
"no_proxy",
|
|
34
|
+
"BUN_INSTALL",
|
|
35
|
+
"NODE_EXTRA_CA_CERTS",
|
|
36
|
+
"SSL_CERT_FILE",
|
|
37
|
+
"SSL_CERT_DIR",
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
export interface OmpUpdateDependencies {
|
|
41
|
+
resolveExecutable(): Promise<string | null>;
|
|
42
|
+
run(executable: string, args: readonly string[], timeoutMs: number): Promise<BoundedRun>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface OmpInstallResult {
|
|
46
|
+
ok: boolean;
|
|
47
|
+
message: string;
|
|
48
|
+
status: OmpUpdateStatus;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* `omp update` finds the install to replace by looking up `omp` on PATH, not by its own path, so
|
|
53
|
+
* the directory of the executable we run goes first: the check and the update then act on the
|
|
54
|
+
* install the Diagnostics card shows.
|
|
55
|
+
*/
|
|
56
|
+
export function updateEnvironment(executable: string): NodeJS.ProcessEnv {
|
|
57
|
+
const source = currentOmpEnvironment();
|
|
58
|
+
const env = buildStatefulCommandEnv(source);
|
|
59
|
+
for (const name of UPDATE_ENV) {
|
|
60
|
+
const value = source[name];
|
|
61
|
+
if (value !== undefined) env[name] = value;
|
|
62
|
+
}
|
|
63
|
+
env.PATH = [dirname(executable), env.PATH].filter(Boolean).join(delimiter);
|
|
64
|
+
env.NO_COLOR = "1";
|
|
65
|
+
return env;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function runOmp(executable: string, args: readonly string[], timeoutMs: number) {
|
|
69
|
+
return runBounded(
|
|
70
|
+
defaultSpawn,
|
|
71
|
+
executable,
|
|
72
|
+
args,
|
|
73
|
+
updateEnvironment(executable),
|
|
74
|
+
timeoutMs,
|
|
75
|
+
KILL_GRACE_MS,
|
|
76
|
+
MAX_OUTPUT_BYTES,
|
|
77
|
+
tmpdir(),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** An executable under another name cannot be found by omp's PATH lookup, so it is refused. */
|
|
82
|
+
async function resolveUpdateTarget(): Promise<string | null> {
|
|
83
|
+
const executable = await resolveOmpExecutable();
|
|
84
|
+
return executable && parse(executable).name.toLowerCase() === "omp" ? executable : null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function succeeded(run: BoundedRun): boolean {
|
|
88
|
+
return (
|
|
89
|
+
run.outcome === "exited" &&
|
|
90
|
+
run.exitCode === 0 &&
|
|
91
|
+
run.signal === null &&
|
|
92
|
+
!run.truncated &&
|
|
93
|
+
!run.cleanupFailed
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Reads the two lines `omp update --check` documents: "New version available" or "Already up to date". */
|
|
98
|
+
export function parseOmpUpdateCheck(stdout: string): OmpUpdateStatus {
|
|
99
|
+
const available = /^New version available: (\S+)\s*$/m.exec(stdout);
|
|
100
|
+
if (available) {
|
|
101
|
+
const parsed = OmpUpdateStatusSchema.safeParse({ state: "available", version: available[1] });
|
|
102
|
+
return parsed.success ? parsed.data : { state: "unknown" };
|
|
103
|
+
}
|
|
104
|
+
return /Already up to date/.test(stdout) ? { state: "up-to-date" } : { state: "unknown" };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function installMessage(run: BoundedRun, status: OmpUpdateStatus): string {
|
|
108
|
+
if (run.cleanupFailed) return "OMP update process cleanup could not be confirmed.";
|
|
109
|
+
if (run.outcome === "timeout") return "OMP update timed out. The install may be incomplete.";
|
|
110
|
+
if (!succeeded(run)) return "OMP could not update itself. Update it the way it was installed.";
|
|
111
|
+
if (status.state === "available") {
|
|
112
|
+
return "OMP is still on the old version. If a package manager installed it, update it there.";
|
|
113
|
+
}
|
|
114
|
+
if (status.state === "unknown") return "OMP update finished, but the new version is unconfirmed.";
|
|
115
|
+
return "OMP updated. Running agents keep the old version until they restart.";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Owns the update check cache. `omp update --check` goes to the network, so a recent answer is
|
|
120
|
+
* reused and concurrent callers share one run. A failed check is never cached. An install
|
|
121
|
+
* invalidates every check that started before it ended, so a slow check cannot write a stale
|
|
122
|
+
* answer over the post-install one.
|
|
123
|
+
*/
|
|
124
|
+
export function createOmpUpdateService(
|
|
125
|
+
dependencies: OmpUpdateDependencies,
|
|
126
|
+
now: () => number = Date.now,
|
|
127
|
+
) {
|
|
128
|
+
let cached: { status: OmpUpdateStatus; expiresAt: number } | null = null;
|
|
129
|
+
let inFlight: Promise<OmpUpdateStatus> | null = null;
|
|
130
|
+
let generation = 0;
|
|
131
|
+
const installs = new SerialMutationQueue();
|
|
132
|
+
|
|
133
|
+
async function checkNow(): Promise<OmpUpdateStatus> {
|
|
134
|
+
const executable = await dependencies.resolveExecutable();
|
|
135
|
+
if (!executable) return { state: "unknown" };
|
|
136
|
+
const run = await dependencies.run(executable, ["update", "--check"], CHECK_TIMEOUT_MS);
|
|
137
|
+
return succeeded(run) ? parseOmpUpdateCheck(run.stdout) : { state: "unknown" };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function check(force: boolean): Promise<OmpUpdateStatus> {
|
|
141
|
+
if (!force && cached && cached.expiresAt > now()) return Promise.resolve(cached.status);
|
|
142
|
+
if (inFlight) return inFlight;
|
|
143
|
+
const started = generation;
|
|
144
|
+
const request = checkNow()
|
|
145
|
+
.then((status) => {
|
|
146
|
+
if (started === generation && status.state !== "unknown") {
|
|
147
|
+
cached = { status, expiresAt: now() + CHECK_CACHE_TTL_MS };
|
|
148
|
+
}
|
|
149
|
+
return status;
|
|
150
|
+
})
|
|
151
|
+
.finally(() => {
|
|
152
|
+
if (inFlight === request) inFlight = null;
|
|
153
|
+
});
|
|
154
|
+
inFlight = request;
|
|
155
|
+
return request;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function invalidate(): void {
|
|
159
|
+
generation += 1;
|
|
160
|
+
cached = null;
|
|
161
|
+
inFlight = null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function install(): Promise<OmpInstallResult> {
|
|
165
|
+
const executable = await dependencies.resolveExecutable();
|
|
166
|
+
if (!executable) {
|
|
167
|
+
return {
|
|
168
|
+
ok: false,
|
|
169
|
+
message: "OMP can only be updated when its executable is named omp.",
|
|
170
|
+
status: { state: "unknown" },
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
invalidate();
|
|
174
|
+
const run = await dependencies.run(executable, ["update"], INSTALL_TIMEOUT_MS);
|
|
175
|
+
invalidate();
|
|
176
|
+
const status = await check(true);
|
|
177
|
+
return {
|
|
178
|
+
ok: succeeded(run) && status.state === "up-to-date",
|
|
179
|
+
message: installMessage(run, status),
|
|
180
|
+
status,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
status: (input: RpcInput<typeof getOmpUpdateStatus>) => check(input.force === true),
|
|
186
|
+
install: () => installs.run(install),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Binary-global, so the handlers are not store-scoped: a selected profile changes nothing here.
|
|
191
|
+
const service = createOmpUpdateService({ resolveExecutable: resolveUpdateTarget, run: runOmp });
|
|
192
|
+
|
|
193
|
+
export function resolveGetOmpUpdateStatus(
|
|
194
|
+
input: RpcInput<typeof getOmpUpdateStatus>,
|
|
195
|
+
): Promise<OmpUpdateStatus> {
|
|
196
|
+
return service.status(input);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function resolveInstallOmpUpdate(
|
|
200
|
+
_input: RpcInput<typeof installOmpUpdate>,
|
|
201
|
+
): Promise<OmpInstallResult> {
|
|
202
|
+
return service.install();
|
|
203
|
+
}
|
|
@@ -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.402.1"; // x-release-please-version
|
package/shared/omp-plugins.ts
CHANGED
|
@@ -262,3 +262,93 @@ export const mutateOmpPlugin = defineRpc({
|
|
|
262
262
|
})
|
|
263
263
|
.strict(),
|
|
264
264
|
});
|
|
265
|
+
|
|
266
|
+
// OMP's own marketplace and catalog plugin name rule (marketplace/types.ts).
|
|
267
|
+
const OMP_MARKETPLACE_NAME = /^[a-zA-Z0-9](?:[a-zA-Z0-9.-]{0,62}[a-zA-Z0-9])?$/u;
|
|
268
|
+
export const OMP_CATALOG_PLUGIN_LIMIT = 1_000;
|
|
269
|
+
|
|
270
|
+
export const OmpMarketplaceNameSchema = z
|
|
271
|
+
.string()
|
|
272
|
+
.regex(OMP_MARKETPLACE_NAME, "Expected an OMP marketplace name");
|
|
273
|
+
|
|
274
|
+
export const OmpMarketplaceSchema = z
|
|
275
|
+
.object({ name: OmpMarketplaceNameSchema, source: z.string().min(1).max(4_096) })
|
|
276
|
+
.strict();
|
|
277
|
+
export type OmpMarketplace = z.infer<typeof OmpMarketplaceSchema>;
|
|
278
|
+
|
|
279
|
+
/** Drops `user:token@` from a URL source so credentials are never displayed. */
|
|
280
|
+
export function redactSourceCredentials(source: string): string {
|
|
281
|
+
return source.replace(/^([a-z][a-z0-9+.-]*:\/\/)[^/?#\s]*@/iu, "$1");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export const OmpMarketplaceStateSchema = z
|
|
285
|
+
.object({
|
|
286
|
+
available: z.boolean(),
|
|
287
|
+
marketplaces: z.array(OmpMarketplaceSchema).max(OMP_PLUGIN_LIMIT),
|
|
288
|
+
error: z.string().max(256).optional(),
|
|
289
|
+
})
|
|
290
|
+
.strict();
|
|
291
|
+
export type OmpMarketplaceState = z.infer<typeof OmpMarketplaceStateSchema>;
|
|
292
|
+
|
|
293
|
+
export const listOmpMarketplaces = defineRpc({
|
|
294
|
+
name: "paseo-omp.list-marketplaces",
|
|
295
|
+
input: z.object({ store: OmpStoreSchema.optional() }).strict(),
|
|
296
|
+
output: OmpMarketplaceStateSchema,
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
export const OmpCatalogPluginSchema = z
|
|
300
|
+
.object({
|
|
301
|
+
id: z.string().min(3).max(128),
|
|
302
|
+
version: z.string().min(1).max(128).nullable(),
|
|
303
|
+
description: z.string().max(1_024).nullable(),
|
|
304
|
+
})
|
|
305
|
+
.strict();
|
|
306
|
+
export type OmpCatalogPlugin = z.infer<typeof OmpCatalogPluginSchema>;
|
|
307
|
+
|
|
308
|
+
export const OmpCatalogStateSchema = z
|
|
309
|
+
.object({
|
|
310
|
+
available: z.boolean(),
|
|
311
|
+
marketplace: OmpMarketplaceNameSchema,
|
|
312
|
+
plugins: z.array(OmpCatalogPluginSchema).max(OMP_CATALOG_PLUGIN_LIMIT),
|
|
313
|
+
error: z.string().max(256).optional(),
|
|
314
|
+
})
|
|
315
|
+
.strict();
|
|
316
|
+
export type OmpCatalogState = z.infer<typeof OmpCatalogStateSchema>;
|
|
317
|
+
|
|
318
|
+
export const browseOmpMarketplace = defineRpc({
|
|
319
|
+
name: "paseo-omp.browse-marketplace",
|
|
320
|
+
input: z
|
|
321
|
+
.object({ store: OmpStoreSchema.optional(), marketplace: OmpMarketplaceNameSchema })
|
|
322
|
+
.strict(),
|
|
323
|
+
output: OmpCatalogStateSchema,
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
export const OmpMarketplaceMutationSchema = z.discriminatedUnion("action", [
|
|
327
|
+
z
|
|
328
|
+
.object({
|
|
329
|
+
action: z.literal("add"),
|
|
330
|
+
source: OmpPluginInstallSourceSchema,
|
|
331
|
+
store: OmpStoreSchema.optional(),
|
|
332
|
+
})
|
|
333
|
+
.strict(),
|
|
334
|
+
z
|
|
335
|
+
.object({
|
|
336
|
+
action: z.literal("remove"),
|
|
337
|
+
marketplace: OmpMarketplaceNameSchema,
|
|
338
|
+
store: OmpStoreSchema.optional(),
|
|
339
|
+
})
|
|
340
|
+
.strict(),
|
|
341
|
+
]);
|
|
342
|
+
export type OmpMarketplaceMutation = z.infer<typeof OmpMarketplaceMutationSchema>;
|
|
343
|
+
|
|
344
|
+
export const mutateOmpMarketplace = defineRpc({
|
|
345
|
+
name: "paseo-omp.mutate-marketplace",
|
|
346
|
+
input: OmpMarketplaceMutationSchema,
|
|
347
|
+
output: z
|
|
348
|
+
.object({
|
|
349
|
+
ok: z.boolean(),
|
|
350
|
+
message: z.string().min(1).max(256),
|
|
351
|
+
state: OmpMarketplaceStateSchema,
|
|
352
|
+
})
|
|
353
|
+
.strict(),
|
|
354
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineRpc } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
/** Bounded so nothing unbounded from `omp update --check` output crosses the RPC. */
|
|
5
|
+
const OmpUpdateVersionSchema = z
|
|
6
|
+
.string()
|
|
7
|
+
.regex(/^\d{1,4}\.\d{1,4}\.\d{1,4}(?:-[0-9A-Za-z.]{1,32})?$/);
|
|
8
|
+
|
|
9
|
+
/** `unknown` means the check could not run or its output was not understood: never a guess. */
|
|
10
|
+
export const OmpUpdateStatusSchema = z.discriminatedUnion("state", [
|
|
11
|
+
z.object({ state: z.literal("up-to-date") }),
|
|
12
|
+
z.object({ state: z.literal("available"), version: OmpUpdateVersionSchema }),
|
|
13
|
+
z.object({ state: z.literal("unknown") }),
|
|
14
|
+
]);
|
|
15
|
+
export type OmpUpdateStatus = z.infer<typeof OmpUpdateStatusSchema>;
|
|
16
|
+
|
|
17
|
+
export const getOmpUpdateStatus = defineRpc({
|
|
18
|
+
name: "paseo-omp.get-update-status",
|
|
19
|
+
input: z.object({ force: z.boolean().optional() }),
|
|
20
|
+
output: OmpUpdateStatusSchema,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const installOmpUpdate = defineRpc({
|
|
24
|
+
name: "paseo-omp.install-update",
|
|
25
|
+
input: z.object({}),
|
|
26
|
+
output: z.object({ ok: z.boolean(), message: z.string(), status: OmpUpdateStatusSchema }),
|
|
27
|
+
});
|