@omercnet/paseo-omp 5.4.0-next.408.1 → 5.4.0-next.410.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/OVERVIEW.md +1 -0
- package/client/ast-edit.tsx +53 -0
- package/client/omp-config-surface.tsx +79 -1
- package/index.client.tsx +17 -0
- package/index.server.ts +7 -0
- package/package.json +1 -1
- package/server/omp-models-file.ts +178 -0
- 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/ast-edit.ts +124 -0
- package/shared/omp-models-file.ts +30 -0
package/OVERVIEW.md
CHANGED
|
@@ -18,6 +18,7 @@ OMP adds an agent provider for the OMP coding agent, plus an OMP sidebar and wor
|
|
|
18
18
|
- When an OMP rule fires during a turn of an agent on Paseo's bundled `omp` provider, a notice under that turn names the rule and the text it matched. The plugin reads this, best effort, from the end of the agent's OMP session file, which that provider does not report.
|
|
19
19
|
- When an agent on Paseo's bundled `omp` provider calls OMP's `lsp` tool for diagnostics, the call shows as a card grouped by file with an icon per severity. Output the plugin does not recognize keeps the original row.
|
|
20
20
|
- When an agent on Paseo's bundled `omp` provider generates an image with OMP's `generate_image` tool, the row shows the image with a Download button on web and desktop. The plugin reads the saved `omp-image-*` file from the daemon host's temp directory, so the image is gone once the host cleans that directory.
|
|
21
|
+
- When an agent on Paseo's bundled `omp` provider previews an OMP `ast_edit` rewrite, the call shows as a read-only diff card per file. It is built from the preview text and does not apply or discard anything; OMP's follow-up `xd://resolve` or `xd://reject` write stays a separate row. A preview the plugin cannot parse keeps the original row.
|
|
21
22
|
- OMP agents can call Paseo's orchestration tools with the optional `serverId` argument and `list_hosts` to delegate work to other connected Paseo hosts.
|
|
22
23
|
|
|
23
24
|
## Reads and sends
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { PluginTimelineItemProps } from "@getpaseo/plugin/client";
|
|
2
|
+
import { Text, View } from "react-native";
|
|
3
|
+
import type { OmpAstEdit } from "../shared/ast-edit";
|
|
4
|
+
|
|
5
|
+
function countLabel(data: OmpAstEdit): string {
|
|
6
|
+
const total = data.files.reduce((sum, file) => sum + file.changes.length, 0);
|
|
7
|
+
const changes = total === 1 ? "1 change" : `${total} changes`;
|
|
8
|
+
const files = data.files.length === 1 ? "1 file" : `${data.files.length} files`;
|
|
9
|
+
return `AST edit preview: ${changes} in ${files}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function OmpAstEditCard({ item, theme }: PluginTimelineItemProps<OmpAstEdit>) {
|
|
13
|
+
const { foreground, foregroundMuted, border, surface1, statusDanger, statusSuccess } =
|
|
14
|
+
theme.colors;
|
|
15
|
+
const code = { fontFamily: "monospace", fontSize: 12, flexShrink: 1 } as const;
|
|
16
|
+
return (
|
|
17
|
+
<View
|
|
18
|
+
style={{
|
|
19
|
+
gap: 8,
|
|
20
|
+
padding: 10,
|
|
21
|
+
borderRadius: 8,
|
|
22
|
+
borderWidth: 1,
|
|
23
|
+
borderColor: border,
|
|
24
|
+
backgroundColor: surface1,
|
|
25
|
+
}}
|
|
26
|
+
>
|
|
27
|
+
<Text style={{ color: foregroundMuted, fontSize: 13 }}>{countLabel(item.data)}</Text>
|
|
28
|
+
{item.data.files.map((file) => (
|
|
29
|
+
<View key={file.path} style={{ gap: 2 }}>
|
|
30
|
+
<Text style={{ color: foreground, fontSize: 13, fontWeight: "500" }} selectable>
|
|
31
|
+
{file.path}
|
|
32
|
+
</Text>
|
|
33
|
+
{file.changes.map((change, index) => (
|
|
34
|
+
<View key={`${index}:${change.line}`} style={{ gap: 1 }}>
|
|
35
|
+
<View style={{ flexDirection: "row", gap: 8 }}>
|
|
36
|
+
<Text style={{ ...code, color: foregroundMuted, minWidth: 28 }}>{change.line}</Text>
|
|
37
|
+
<Text style={{ ...code, color: statusDanger }} selectable>
|
|
38
|
+
{`- ${change.before}`}
|
|
39
|
+
</Text>
|
|
40
|
+
</View>
|
|
41
|
+
<View style={{ flexDirection: "row", gap: 8 }}>
|
|
42
|
+
<Text style={{ ...code, minWidth: 28 }}> </Text>
|
|
43
|
+
<Text style={{ ...code, color: statusSuccess }} selectable>
|
|
44
|
+
{`+ ${change.after}`}
|
|
45
|
+
</Text>
|
|
46
|
+
</View>
|
|
47
|
+
</View>
|
|
48
|
+
))}
|
|
49
|
+
</View>
|
|
50
|
+
))}
|
|
51
|
+
</View>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -14,6 +14,7 @@ import type { ComposerPillSettings } from "../shared/composer-pill-settings";
|
|
|
14
14
|
import { listOmpAgents } from "../shared/omp-agents";
|
|
15
15
|
import { listOmpConfig, type OmpConfig } from "../shared/omp-config";
|
|
16
16
|
import { listOmpModels } from "../shared/omp-models";
|
|
17
|
+
import { getOmpModelsFileStatus, refreshOmpModels } from "../shared/omp-models-file";
|
|
17
18
|
import { getOmpPromptFiles } from "../shared/omp-prompt-files";
|
|
18
19
|
import {
|
|
19
20
|
categorizeOmpSetting,
|
|
@@ -34,7 +35,7 @@ import { getOmpProviderHealth, type OmpProviderHealth } from "../shared/provider
|
|
|
34
35
|
import { getOmpSupportReport, OMP_SUPPORT_ISSUE_URL } from "../shared/support-diagnostics";
|
|
35
36
|
import { ComposerPillSettingsSection } from "./composer-pill-settings";
|
|
36
37
|
import { openOmpExternalUrl } from "./external-url";
|
|
37
|
-
import { OmpAccountsSection } from "./omp-accounts-section";
|
|
38
|
+
import { ActionButton, OmpAccountsSection } from "./omp-accounts-section";
|
|
38
39
|
import { type OmpConfigStyles, useConfigStyles } from "./omp-config-styles";
|
|
39
40
|
import { type OmpConfigSurfaceView as SurfaceView, surfaceViewsForScope } from "./omp-config-views";
|
|
40
41
|
import {
|
|
@@ -89,6 +90,7 @@ const SETTINGS_QUERY_KEY = ["paseo-omp", "settings"] as const;
|
|
|
89
90
|
const CONFIG_POLL_MS = 30_000;
|
|
90
91
|
const HEALTH_QUERY_KEY = ["paseo-omp", "provider-health"] as const;
|
|
91
92
|
const PROMPT_FILES_QUERY_KEY = ["paseo-omp", "prompt-files"] as const;
|
|
93
|
+
const MODELS_FILE_QUERY_KEY = ["paseo-omp", "models-file"] as const;
|
|
92
94
|
const PROVIDERS_QUERY_KEY = ["paseo-omp", "provider-snapshot"] as const;
|
|
93
95
|
|
|
94
96
|
function KeyValueRow({
|
|
@@ -416,6 +418,72 @@ function PromptFilesSection({
|
|
|
416
418
|
);
|
|
417
419
|
}
|
|
418
420
|
|
|
421
|
+
function ModelsSection({
|
|
422
|
+
theme,
|
|
423
|
+
styles,
|
|
424
|
+
store,
|
|
425
|
+
onRefreshed,
|
|
426
|
+
}: {
|
|
427
|
+
theme: PluginSurfaceProps["theme"];
|
|
428
|
+
styles: OmpConfigStyles;
|
|
429
|
+
store?: OmpStore;
|
|
430
|
+
onRefreshed(): void;
|
|
431
|
+
}) {
|
|
432
|
+
const loadStatus = useRpc(getOmpModelsFileStatus);
|
|
433
|
+
const refreshModels = useRpc(refreshOmpModels);
|
|
434
|
+
const status = useQuery({
|
|
435
|
+
queryKey: [...MODELS_FILE_QUERY_KEY, ompStoreKey(store)],
|
|
436
|
+
queryFn: () => loadStatus({ store }),
|
|
437
|
+
});
|
|
438
|
+
const [message, setMessage] = useState<{ ok: boolean; text: string } | null>(null);
|
|
439
|
+
const refresh = useMutation({
|
|
440
|
+
mutationFn: () => refreshModels({ store }),
|
|
441
|
+
onSuccess: (result) => {
|
|
442
|
+
setMessage({
|
|
443
|
+
ok: result.ok,
|
|
444
|
+
text: result.ok
|
|
445
|
+
? "OMP refreshed its model lists. Paseo's list updates next."
|
|
446
|
+
: result.message,
|
|
447
|
+
});
|
|
448
|
+
if (result.ok) onRefreshed();
|
|
449
|
+
},
|
|
450
|
+
onError: () => setMessage({ ok: false, text: "Could not refresh models. Try again." }),
|
|
451
|
+
});
|
|
452
|
+
const current = status.data;
|
|
453
|
+
return (
|
|
454
|
+
<SectionCard styles={styles} title="Models">
|
|
455
|
+
{status.isLoading ? <Text style={styles.muted}>Checking models.yml…</Text> : null}
|
|
456
|
+
{current?.state === "ok" ? (
|
|
457
|
+
<KeyValueRow styles={styles} label="models.yml" value="No errors reported" />
|
|
458
|
+
) : null}
|
|
459
|
+
{current?.state === "invalid" ? (
|
|
460
|
+
<KeyValueRow
|
|
461
|
+
styles={styles}
|
|
462
|
+
label="models.yml"
|
|
463
|
+
value={`OMP dropped your custom providers: ${current.detail}`}
|
|
464
|
+
valueColor={theme.colors.statusDanger}
|
|
465
|
+
/>
|
|
466
|
+
) : null}
|
|
467
|
+
{current?.state === "unknown" || status.error ? (
|
|
468
|
+
<KeyValueRow styles={styles} label="models.yml" value="Could not check" />
|
|
469
|
+
) : null}
|
|
470
|
+
<View style={styles.row}>
|
|
471
|
+
<Text style={styles.rowLabel}>Model lists</Text>
|
|
472
|
+
<ActionButton
|
|
473
|
+
styles={styles}
|
|
474
|
+
theme={theme}
|
|
475
|
+
label={refresh.isPending ? "Refreshing models…" : "Refresh models"}
|
|
476
|
+
disabled={refresh.isPending}
|
|
477
|
+
onPress={() => refresh.mutate()}
|
|
478
|
+
/>
|
|
479
|
+
</View>
|
|
480
|
+
{message ? (
|
|
481
|
+
<Text style={message.ok ? styles.muted : styles.error}>{message.text}</Text>
|
|
482
|
+
) : null}
|
|
483
|
+
</SectionCard>
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
|
|
419
487
|
function ProviderHealthSection({
|
|
420
488
|
theme,
|
|
421
489
|
styles,
|
|
@@ -459,6 +527,7 @@ function ProviderHealthSection({
|
|
|
459
527
|
]);
|
|
460
528
|
if (update) queryClient.setQueryData(UPDATE_QUERY_KEY, update);
|
|
461
529
|
await queryClient.invalidateQueries({ queryKey: PROMPT_FILES_QUERY_KEY });
|
|
530
|
+
await queryClient.invalidateQueries({ queryKey: MODELS_FILE_QUERY_KEY });
|
|
462
531
|
if (result.failed) throw new Error("Could not fully refresh OMP provider health.");
|
|
463
532
|
},
|
|
464
533
|
});
|
|
@@ -515,6 +584,15 @@ function ProviderHealthSection({
|
|
|
515
584
|
{health.data ? <StorageSection theme={theme} styles={styles} health={health.data} /> : null}
|
|
516
585
|
{health.data ? <ProcessSection theme={theme} styles={styles} health={health.data} /> : null}
|
|
517
586
|
<PromptFilesSection theme={theme} styles={styles} cwd={cwd} store={store} />
|
|
587
|
+
<ModelsSection
|
|
588
|
+
theme={theme}
|
|
589
|
+
styles={styles}
|
|
590
|
+
store={store}
|
|
591
|
+
onRefreshed={() => {
|
|
592
|
+
void queryClient.invalidateQueries({ queryKey: ["paseo-omp", "models"] });
|
|
593
|
+
refresh.mutate();
|
|
594
|
+
}}
|
|
595
|
+
/>
|
|
518
596
|
|
|
519
597
|
{providers.isLoading ? <Text style={styles.muted}>Loading provider status…</Text> : null}
|
|
520
598
|
{providers.error ? (
|
package/index.client.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
PluginClientContext,
|
|
5
5
|
PluginSurfaceProps,
|
|
6
6
|
} from "@getpaseo/plugin/client";
|
|
7
|
+
import { OmpAstEditCard } from "./client/ast-edit";
|
|
7
8
|
import { ConfigSidebarItem } from "./client/config-sidebar";
|
|
8
9
|
import { OmpGeneratedImagesRow } from "./client/generated-image";
|
|
9
10
|
import { OMP_ICON } from "./client/hub-icon";
|
|
@@ -39,6 +40,7 @@ import {
|
|
|
39
40
|
configStoreFromParams,
|
|
40
41
|
} from "./client/sidebar-compat";
|
|
41
42
|
import { OmpSubagentStrip } from "./client/subagents-strip";
|
|
43
|
+
import { OMP_AST_EDIT_KIND, ompAstEditSchema, transformOmpAstEditItem } from "./shared/ast-edit";
|
|
42
44
|
import {
|
|
43
45
|
type ComposerPillSettings,
|
|
44
46
|
composerPillSettings,
|
|
@@ -274,6 +276,19 @@ export default function contribute(client: PluginClientContext) {
|
|
|
274
276
|
return transformOmpGeneratedImageItem(item);
|
|
275
277
|
},
|
|
276
278
|
});
|
|
279
|
+
const removeAstEditRenderer = client.addTimelineRenderer({
|
|
280
|
+
kind: OMP_AST_EDIT_KIND,
|
|
281
|
+
version: 1,
|
|
282
|
+
schema: ompAstEditSchema,
|
|
283
|
+
Component: OmpAstEditCard,
|
|
284
|
+
});
|
|
285
|
+
const removeAstEditTransformer = client.addTimelineTransformer({
|
|
286
|
+
id: "omp-ast-edit",
|
|
287
|
+
query: { itemType: "tool_call" },
|
|
288
|
+
transform({ item }) {
|
|
289
|
+
return transformOmpAstEditItem(item);
|
|
290
|
+
},
|
|
291
|
+
});
|
|
277
292
|
const loadStoreQuotas = createStoreQuotaLoader(
|
|
278
293
|
(input) => client.rpc(listOmpQuotas, input),
|
|
279
294
|
QUOTA_POLL_MS,
|
|
@@ -564,6 +579,8 @@ export default function contribute(client: PluginClientContext) {
|
|
|
564
579
|
removeImageTransformer();
|
|
565
580
|
removeGeneratedImageRenderer();
|
|
566
581
|
removeGeneratedImageTransformer();
|
|
582
|
+
removeAstEditRenderer();
|
|
583
|
+
removeAstEditTransformer();
|
|
567
584
|
removeOpenConfig();
|
|
568
585
|
removeConfigEntry();
|
|
569
586
|
removeOpenWorkspace();
|
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,
|
|
@@ -79,6 +80,7 @@ import {
|
|
|
79
80
|
submitOmpMcpAuthCode,
|
|
80
81
|
} from "./shared/omp-mcps";
|
|
81
82
|
import { listOmpModels } from "./shared/omp-models";
|
|
83
|
+
import { getOmpModelsFileStatus, refreshOmpModels } from "./shared/omp-models-file";
|
|
82
84
|
import {
|
|
83
85
|
browseOmpMarketplace,
|
|
84
86
|
inspectOmpPluginConfig,
|
|
@@ -230,6 +232,11 @@ export default function contribute(server: PluginServerContext) {
|
|
|
230
232
|
server.handle(getOmpPromptFiles, ({ store, cwd }, { paseo }) =>
|
|
231
233
|
withOmpStore(store, async () => readOmpPromptFiles(cwd, await readHostAppendPrompt(paseo))),
|
|
232
234
|
);
|
|
235
|
+
server.handle(getOmpModelsFileStatus, scoped(resolveGetOmpModelsFileStatus));
|
|
236
|
+
server.handle(
|
|
237
|
+
refreshOmpModels,
|
|
238
|
+
scoped(async (input) => resolveRefreshOmpModels(input, await resolveHostInheritEnv())),
|
|
239
|
+
);
|
|
233
240
|
server.handle(getOmpUpdateStatus, resolveGetOmpUpdateStatus);
|
|
234
241
|
server.handle(installOmpUpdate, resolveInstallOmpUpdate);
|
|
235
242
|
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
|
+
}
|
|
@@ -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.410.1"; // x-release-please-version
|
|
@@ -200,7 +200,7 @@ function inheritedEnvironmentNames(inheritEnv: readonly string[] | undefined): R
|
|
|
200
200
|
return names;
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
function buildOmpEnvironment(
|
|
203
|
+
export function buildOmpEnvironment(
|
|
204
204
|
sessionEnv: Readonly<Record<string, string>> | undefined,
|
|
205
205
|
inheritEnv: readonly string[] | undefined,
|
|
206
206
|
sourceEnv: NodeJS.ProcessEnv,
|
|
@@ -356,6 +356,8 @@ export interface BoundedRun {
|
|
|
356
356
|
spawnErrorCode: string | null;
|
|
357
357
|
/** True when tree termination/verification failed or the leader missed its final close bound. */
|
|
358
358
|
cleanupFailed: boolean;
|
|
359
|
+
/** Only present when the caller asked for it with `stderrLimit`. Never forwarded across RPC. */
|
|
360
|
+
stderr?: string;
|
|
359
361
|
}
|
|
360
362
|
|
|
361
363
|
/**
|
|
@@ -375,6 +377,7 @@ export function runBounded(
|
|
|
375
377
|
killGraceMs: number,
|
|
376
378
|
maxBytes: number,
|
|
377
379
|
cwd?: string,
|
|
380
|
+
stderrLimit = 0,
|
|
378
381
|
): Promise<BoundedRun> {
|
|
379
382
|
const { promise, resolve } = Promise.withResolvers<BoundedRun>();
|
|
380
383
|
let child: ProbeChildProcess;
|
|
@@ -397,6 +400,8 @@ export function runBounded(
|
|
|
397
400
|
const stdoutChunks: Buffer[] = [];
|
|
398
401
|
let stdoutBytes = 0;
|
|
399
402
|
let truncated = false;
|
|
403
|
+
const stderrChunks: Buffer[] = [];
|
|
404
|
+
let stderrBytes = 0;
|
|
400
405
|
let timedOut = false;
|
|
401
406
|
let leaderClosed = false;
|
|
402
407
|
let leaderExitCode: number | null = null;
|
|
@@ -405,6 +410,7 @@ export function runBounded(
|
|
|
405
410
|
let treeCleanupSucceeded = false;
|
|
406
411
|
let finalLeaderTimer: ReturnType<typeof setTimeout> | undefined;
|
|
407
412
|
const getStdout = () => Buffer.concat(stdoutChunks, stdoutBytes).toString("utf8");
|
|
413
|
+
const getStderr = () => Buffer.concat(stderrChunks, stderrBytes).toString("utf8");
|
|
408
414
|
|
|
409
415
|
const cleanupListeners = () => {
|
|
410
416
|
child.stdout.removeAllListeners();
|
|
@@ -428,6 +434,7 @@ export function runBounded(
|
|
|
428
434
|
signal: leaderSignal,
|
|
429
435
|
spawnErrorCode: null,
|
|
430
436
|
cleanupFailed,
|
|
437
|
+
...(stderrLimit > 0 ? { stderr: getStderr() } : {}),
|
|
431
438
|
});
|
|
432
439
|
};
|
|
433
440
|
const settleAfterCleanup = () => {
|
|
@@ -482,8 +489,14 @@ export function runBounded(
|
|
|
482
489
|
stdoutChunks.push(accepted);
|
|
483
490
|
stdoutBytes += accepted.length;
|
|
484
491
|
});
|
|
485
|
-
child.stderr.on("data", () => {
|
|
486
|
-
//
|
|
492
|
+
child.stderr.on("data", (chunk: Buffer) => {
|
|
493
|
+
// Discarded unless the caller opted in with `stderrLimit`; then kept, bounded, for that
|
|
494
|
+
// caller to parse. It is never forwarded across the RPC boundary as-is.
|
|
495
|
+
const remaining = stderrLimit - stderrBytes;
|
|
496
|
+
if (remaining <= 0) return;
|
|
497
|
+
const accepted = chunk.subarray(0, remaining);
|
|
498
|
+
stderrChunks.push(accepted);
|
|
499
|
+
stderrBytes += accepted.length;
|
|
487
500
|
});
|
|
488
501
|
child.onClose((code, signal) => {
|
|
489
502
|
leaderClosed = true;
|
|
@@ -501,6 +514,7 @@ export function runBounded(
|
|
|
501
514
|
signal,
|
|
502
515
|
spawnErrorCode: null,
|
|
503
516
|
cleanupFailed: false,
|
|
517
|
+
...(stderrLimit > 0 ? { stderr: getStderr() } : {}),
|
|
504
518
|
});
|
|
505
519
|
});
|
|
506
520
|
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const OMP_AST_EDIT_KIND = "omp-ast-edit";
|
|
4
|
+
|
|
5
|
+
export const ompAstEditSchema = z.object({
|
|
6
|
+
files: z
|
|
7
|
+
.array(
|
|
8
|
+
z.object({
|
|
9
|
+
path: z.string().min(1),
|
|
10
|
+
changes: z
|
|
11
|
+
.array(
|
|
12
|
+
z.object({
|
|
13
|
+
line: z.number().int().positive(),
|
|
14
|
+
before: z.string(),
|
|
15
|
+
after: z.string(),
|
|
16
|
+
}),
|
|
17
|
+
)
|
|
18
|
+
.min(1),
|
|
19
|
+
}),
|
|
20
|
+
)
|
|
21
|
+
.min(1),
|
|
22
|
+
});
|
|
23
|
+
export type OmpAstEdit = z.infer<typeof ompAstEditSchema>;
|
|
24
|
+
|
|
25
|
+
const PROPOSAL = /^Staged as a proposal\b/u;
|
|
26
|
+
const TAG = "#[0-9A-Fa-f]{2,8}";
|
|
27
|
+
/** `[a.ts#387A]` heads a single-file preview. */
|
|
28
|
+
const SINGLE_FILE = new RegExp(`^\\[(.+)${TAG}\\]$`, "u");
|
|
29
|
+
/** `## b.ts#D8CE (1 replacement)` is a file in a directory preview; `# sub/` is a directory. */
|
|
30
|
+
const TREE_FILE = new RegExp(`^(#+) (.+)${TAG} \\(\\d+ replacements?\\)$`, "u");
|
|
31
|
+
const TREE_DIRECTORY = /^(#+) (.+\/)$/u;
|
|
32
|
+
const CHANGE = /^([-+])(\d+):(.*)$/u;
|
|
33
|
+
|
|
34
|
+
type FileChanges = OmpAstEdit["files"][number]["changes"];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Parses the preview text OMP's `ast_edit` returns in its default hashline mode: a header per file
|
|
38
|
+
* (`[path#TAG]`, or a `#` tree for several files) followed by `-LINE:before` / `+LINE:after`
|
|
39
|
+
* pairs. Returns `undefined` unless every line is recognized, so any other output (plain
|
|
40
|
+
* line/column mode, no matches, parse issues, a truncation notice) keeps its original row.
|
|
41
|
+
*/
|
|
42
|
+
export function parseOmpAstEdit(text: string): OmpAstEdit | undefined {
|
|
43
|
+
const files = new Map<string, FileChanges>();
|
|
44
|
+
const directories: string[] = [];
|
|
45
|
+
let current: FileChanges | undefined;
|
|
46
|
+
let removed: { line: number; before: string } | undefined;
|
|
47
|
+
for (const line of text.split(/\r?\n/u)) {
|
|
48
|
+
if (line.trim() === "" || PROPOSAL.test(line)) continue;
|
|
49
|
+
const change = CHANGE.exec(line);
|
|
50
|
+
if (change) {
|
|
51
|
+
const number = Number(change[2]);
|
|
52
|
+
const content = change[3] ?? "";
|
|
53
|
+
if (!current) return undefined;
|
|
54
|
+
if (change[1] === "-") {
|
|
55
|
+
if (removed) return undefined;
|
|
56
|
+
removed = { line: number, before: content };
|
|
57
|
+
} else {
|
|
58
|
+
if (removed?.line !== number) return undefined;
|
|
59
|
+
current.push({ line: number, before: removed.before, after: content });
|
|
60
|
+
removed = undefined;
|
|
61
|
+
}
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (removed) return undefined;
|
|
65
|
+
const file = SINGLE_FILE.exec(line) ?? TREE_FILE.exec(line);
|
|
66
|
+
if (file) {
|
|
67
|
+
const depth = file.length === 3 ? (file[1] ?? "").length - 1 : 0;
|
|
68
|
+
directories.length = depth;
|
|
69
|
+
const path = directories.join("") + (file.at(-1) ?? "");
|
|
70
|
+
current = files.get(path) ?? [];
|
|
71
|
+
files.set(path, current);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const directory = TREE_DIRECTORY.exec(line);
|
|
75
|
+
if (!directory) return undefined;
|
|
76
|
+
const depth = (directory[1] ?? "").length - 1;
|
|
77
|
+
directories.length = depth;
|
|
78
|
+
directories[depth] = directory[2] ?? "";
|
|
79
|
+
current = undefined;
|
|
80
|
+
}
|
|
81
|
+
if (removed) return undefined;
|
|
82
|
+
const parsed = ompAstEditSchema.safeParse({
|
|
83
|
+
files: [...files].map(([path, changes]) => ({ path, changes })),
|
|
84
|
+
});
|
|
85
|
+
return parsed.success ? parsed.data : undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const textBlockSchema = z.looseObject({ type: z.string(), text: z.string().optional() });
|
|
89
|
+
const astEditRowSchema = z.object({
|
|
90
|
+
name: z.literal("ast_edit"),
|
|
91
|
+
callId: z.string(),
|
|
92
|
+
status: z.literal("completed"),
|
|
93
|
+
detail: z.union([
|
|
94
|
+
z.object({ type: z.literal("plain_text"), text: z.string() }),
|
|
95
|
+
z.object({
|
|
96
|
+
type: z.literal("unknown"),
|
|
97
|
+
output: z.looseObject({ content: z.array(textBlockSchema) }),
|
|
98
|
+
}),
|
|
99
|
+
]),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Replaces a completed built-in `ast_edit` row with a read-only diff card. The built-in provider
|
|
104
|
+
* passes only the result text (as a plain text row, or as the raw result for an unmapped tool), so
|
|
105
|
+
* a row whose text does not parse stays as is.
|
|
106
|
+
*/
|
|
107
|
+
export function transformOmpAstEditItem(item: unknown) {
|
|
108
|
+
const row = astEditRowSchema.safeParse(item);
|
|
109
|
+
if (!row.success) return undefined;
|
|
110
|
+
const { detail } = row.data;
|
|
111
|
+
const text =
|
|
112
|
+
detail.type === "plain_text"
|
|
113
|
+
? detail.text
|
|
114
|
+
: detail.output.content
|
|
115
|
+
.flatMap((block) => (block.text === undefined ? [] : [block.text]))
|
|
116
|
+
.join("\n");
|
|
117
|
+
const data = parseOmpAstEdit(text);
|
|
118
|
+
if (!data) return undefined;
|
|
119
|
+
return {
|
|
120
|
+
items: [
|
|
121
|
+
{ type: "plugin" as const, kind: OMP_AST_EDIT_KIND, id: row.data.callId, version: 1, data },
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineRpc } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { OmpStoreSchema } from "./omp-store";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Whether OMP loaded `models.yml`. A typo makes OMP drop every custom provider with only a
|
|
7
|
+
* warning, so the card says so. `unknown` means the check could not run: never a guess.
|
|
8
|
+
*/
|
|
9
|
+
export const OmpModelsFileStatusSchema = z.discriminatedUnion("state", [
|
|
10
|
+
z.object({ state: z.literal("ok") }),
|
|
11
|
+
/**
|
|
12
|
+
* OMP's own validation message, control characters stripped and bounded. Values OMP echoes as
|
|
13
|
+
* "(was ...)" are removed; field paths and the provider and model names from the file remain.
|
|
14
|
+
*/
|
|
15
|
+
z.object({ state: z.literal("invalid"), detail: z.string().max(400) }),
|
|
16
|
+
z.object({ state: z.literal("unknown") }),
|
|
17
|
+
]);
|
|
18
|
+
export type OmpModelsFileStatus = z.infer<typeof OmpModelsFileStatusSchema>;
|
|
19
|
+
|
|
20
|
+
export const getOmpModelsFileStatus = defineRpc({
|
|
21
|
+
name: "paseo-omp.get-models-file-status",
|
|
22
|
+
input: z.object({ store: OmpStoreSchema.optional() }),
|
|
23
|
+
output: OmpModelsFileStatusSchema,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const refreshOmpModels = defineRpc({
|
|
27
|
+
name: "paseo-omp.refresh-models",
|
|
28
|
+
input: z.object({ store: OmpStoreSchema.optional() }),
|
|
29
|
+
output: z.object({ ok: z.boolean(), message: z.string() }),
|
|
30
|
+
});
|