@omercnet/paseo-omp 5.4.0-next.404.1 → 5.4.0-next.406.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/generated-image.tsx +79 -0
- package/client/omp-config-surface.tsx +41 -0
- package/client/provider-diagnostics-state.ts +28 -0
- package/client/provider-image.tsx +1 -1
- package/client/web.ts +34 -0
- package/index.client.tsx +21 -0
- package/index.server.ts +11 -0
- package/package.json +1 -1
- package/server/generated-images.ts +57 -0
- package/server/omp-prompt-files.ts +41 -0
- package/server/package-version.ts +1 -1
- package/server/provider/image-cache.ts +1 -1
- package/server/regular-file.ts +30 -0
- package/shared/generated-image.ts +68 -0
- package/shared/omp-prompt-files.ts +24 -0
- package/shared/provider-image.ts +7 -2
package/OVERVIEW.md
CHANGED
|
@@ -17,6 +17,7 @@ OMP adds an agent provider for the OMP coding agent, plus an OMP sidebar and wor
|
|
|
17
17
|
- While OMP subagents run, a row under each `task` card in the conversation lets you steer one with a message or stop it after confirmation. It needs OMP 18.4.9 or newer.
|
|
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
|
+
- 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.
|
|
20
21
|
- OMP agents can call Paseo's orchestration tools with the optional `serverId` argument and `list_hosts` to delegate work to other connected Paseo hosts.
|
|
21
22
|
|
|
22
23
|
## Reads and sends
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type PluginTimelineItemProps, useRpc } from "@getpaseo/plugin/client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { Pressable, Text, View } from "react-native";
|
|
4
|
+
import { type OmpGeneratedImages, resolveOmpGeneratedImages } from "../shared/generated-image";
|
|
5
|
+
import type { OmpImage } from "../shared/provider-image";
|
|
6
|
+
import { OmpImageTimeline, useOmpImageSource } from "./provider-image";
|
|
7
|
+
import { canDownloadFiles, downloadDataUri } from "./web";
|
|
8
|
+
|
|
9
|
+
const LABEL = "Generated image";
|
|
10
|
+
|
|
11
|
+
function DownloadButton({
|
|
12
|
+
image,
|
|
13
|
+
hostId,
|
|
14
|
+
color,
|
|
15
|
+
}: {
|
|
16
|
+
image: OmpImage;
|
|
17
|
+
hostId: string;
|
|
18
|
+
color: string;
|
|
19
|
+
}) {
|
|
20
|
+
const source = useOmpImageSource(image, hostId);
|
|
21
|
+
if (source.status !== "ready") return null;
|
|
22
|
+
const extension = image.mimeType === "image/jpeg" ? "jpg" : image.mimeType.slice("image/".length);
|
|
23
|
+
return (
|
|
24
|
+
<Pressable
|
|
25
|
+
accessibilityRole="button"
|
|
26
|
+
accessibilityLabel="Download generated image"
|
|
27
|
+
onPress={() => downloadDataUri(source.uri, `generated-image-${image.id}.${extension}`)}
|
|
28
|
+
>
|
|
29
|
+
<Text style={{ color, fontSize: 12, fontWeight: "600" }}>Download</Text>
|
|
30
|
+
</Pressable>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function OmpGeneratedImagesRow(props: PluginTimelineItemProps<OmpGeneratedImages>) {
|
|
35
|
+
const { item, theme, host } = props;
|
|
36
|
+
const resolve = useRpc(resolveOmpGeneratedImages);
|
|
37
|
+
const query = useQuery({
|
|
38
|
+
queryKey: ["omp-generated-images", host.id, item.data.paths],
|
|
39
|
+
queryFn: () => resolve({ paths: item.data.paths }),
|
|
40
|
+
staleTime: (current) =>
|
|
41
|
+
current.state.data?.images.every((result) => result.status === "available")
|
|
42
|
+
? Number.POSITIVE_INFINITY
|
|
43
|
+
: 0,
|
|
44
|
+
retry: 1,
|
|
45
|
+
});
|
|
46
|
+
const muted = { color: theme.colors.foregroundMuted, fontSize: 12 };
|
|
47
|
+
if (query.isError)
|
|
48
|
+
return <Text style={muted}>Unable to load generated images from the host.</Text>;
|
|
49
|
+
if (!query.data) return <Text style={muted}>Loading image...</Text>;
|
|
50
|
+
const images: OmpImage[] = [];
|
|
51
|
+
for (const result of query.data.images) {
|
|
52
|
+
if (result.status === "available") {
|
|
53
|
+
images.push({ id: result.ref.slice(0, 16), ref: result.ref, mimeType: result.mimeType });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return (
|
|
57
|
+
<View style={{ gap: 8 }}>
|
|
58
|
+
{images.length > 0 ? (
|
|
59
|
+
<OmpImageTimeline
|
|
60
|
+
{...props}
|
|
61
|
+
item={{ ...item, kind: "omp-images", data: { label: LABEL, images } }}
|
|
62
|
+
/>
|
|
63
|
+
) : null}
|
|
64
|
+
{canDownloadFiles
|
|
65
|
+
? images.map((image, index) => (
|
|
66
|
+
<DownloadButton
|
|
67
|
+
key={`${index}:${image.id}`}
|
|
68
|
+
image={image}
|
|
69
|
+
hostId={host.id}
|
|
70
|
+
color={theme.colors.accent}
|
|
71
|
+
/>
|
|
72
|
+
))
|
|
73
|
+
: null}
|
|
74
|
+
{images.length < query.data.images.length ? (
|
|
75
|
+
<Text style={muted}>Some generated images are no longer available on the host.</Text>
|
|
76
|
+
) : null}
|
|
77
|
+
</View>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -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 { getOmpPromptFiles } from "../shared/omp-prompt-files";
|
|
17
18
|
import {
|
|
18
19
|
categorizeOmpSetting,
|
|
19
20
|
formatOmpSettingLabel,
|
|
@@ -63,6 +64,7 @@ import {
|
|
|
63
64
|
mcpTone,
|
|
64
65
|
type PathStateSummary,
|
|
65
66
|
processTone,
|
|
67
|
+
promptFileNotices,
|
|
66
68
|
refreshProviderDiagnostics,
|
|
67
69
|
rpcUiTone,
|
|
68
70
|
selectKnownOmpProviders,
|
|
@@ -85,6 +87,7 @@ import {
|
|
|
85
87
|
const SETTINGS_QUERY_KEY = ["paseo-omp", "settings"] as const;
|
|
86
88
|
const CONFIG_POLL_MS = 30_000;
|
|
87
89
|
const HEALTH_QUERY_KEY = ["paseo-omp", "provider-health"] as const;
|
|
90
|
+
const PROMPT_FILES_QUERY_KEY = ["paseo-omp", "prompt-files"] as const;
|
|
88
91
|
const PROVIDERS_QUERY_KEY = ["paseo-omp", "provider-snapshot"] as const;
|
|
89
92
|
|
|
90
93
|
function KeyValueRow({
|
|
@@ -376,6 +379,42 @@ function ProcessSection({
|
|
|
376
379
|
);
|
|
377
380
|
}
|
|
378
381
|
|
|
382
|
+
function PromptFilesSection({
|
|
383
|
+
theme,
|
|
384
|
+
styles,
|
|
385
|
+
cwd,
|
|
386
|
+
store,
|
|
387
|
+
}: {
|
|
388
|
+
theme: PluginSurfaceProps["theme"];
|
|
389
|
+
styles: OmpConfigStyles;
|
|
390
|
+
cwd?: string;
|
|
391
|
+
store?: OmpStore;
|
|
392
|
+
}) {
|
|
393
|
+
const loadPromptFiles = useRpc(getOmpPromptFiles);
|
|
394
|
+
const files = useQuery({
|
|
395
|
+
queryKey: [...PROMPT_FILES_QUERY_KEY, ompStoreKey(store), cwd ?? "global"],
|
|
396
|
+
queryFn: () => loadPromptFiles({ store, ...(cwd ? { cwd } : {}) }),
|
|
397
|
+
});
|
|
398
|
+
if (files.error) {
|
|
399
|
+
return <Text style={styles.error}>Could not read the OMP prompt files. Try refreshing.</Text>;
|
|
400
|
+
}
|
|
401
|
+
const notices = files.data ? promptFileNotices(files.data) : [];
|
|
402
|
+
if (notices.length === 0) return null;
|
|
403
|
+
return (
|
|
404
|
+
<SectionCard styles={styles} title="Prompt files">
|
|
405
|
+
{notices.map((notice) => (
|
|
406
|
+
<KeyValueRow
|
|
407
|
+
key={notice.file}
|
|
408
|
+
styles={styles}
|
|
409
|
+
label={notice.file}
|
|
410
|
+
value={notice.text}
|
|
411
|
+
valueColor={theme.colors.statusWarning}
|
|
412
|
+
/>
|
|
413
|
+
))}
|
|
414
|
+
</SectionCard>
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
|
|
379
418
|
function ProviderHealthSection({
|
|
380
419
|
theme,
|
|
381
420
|
styles,
|
|
@@ -418,6 +457,7 @@ function ProviderHealthSection({
|
|
|
418
457
|
cwd ? undefined : loadUpdateStatus({ force: true }).catch(() => undefined),
|
|
419
458
|
]);
|
|
420
459
|
if (update) queryClient.setQueryData(UPDATE_QUERY_KEY, update);
|
|
460
|
+
await queryClient.invalidateQueries({ queryKey: PROMPT_FILES_QUERY_KEY });
|
|
421
461
|
if (result.failed) throw new Error("Could not fully refresh OMP provider health.");
|
|
422
462
|
},
|
|
423
463
|
});
|
|
@@ -473,6 +513,7 @@ function ProviderHealthSection({
|
|
|
473
513
|
) : null}
|
|
474
514
|
{health.data ? <StorageSection theme={theme} styles={styles} health={health.data} /> : null}
|
|
475
515
|
{health.data ? <ProcessSection theme={theme} styles={styles} health={health.data} /> : null}
|
|
516
|
+
<PromptFilesSection theme={theme} styles={styles} cwd={cwd} store={store} />
|
|
476
517
|
|
|
477
518
|
{providers.isLoading ? <Text style={styles.muted}>Loading provider status…</Text> : null}
|
|
478
519
|
{providers.error ? (
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OmpPromptFiles } from "../shared/omp-prompt-files";
|
|
1
2
|
import type {
|
|
2
3
|
OmpLspDiagnostics,
|
|
3
4
|
OmpMcpDiagnostics,
|
|
@@ -259,3 +260,30 @@ export function selectKnownOmpProviders(
|
|
|
259
260
|
: [],
|
|
260
261
|
);
|
|
261
262
|
}
|
|
263
|
+
|
|
264
|
+
export interface PromptFileNotice {
|
|
265
|
+
file: "APPEND_SYSTEM.md" | "SYSTEM.md";
|
|
266
|
+
text: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Paseo's built-in omp provider passes the host Append system prompt as `--append-system-prompt`
|
|
271
|
+
* on create and resume, which makes OMP skip a discovered APPEND_SYSTEM.md. With no host prompt
|
|
272
|
+
* there is no APPEND_SYSTEM.md notice; per-agent prompts are not visible to a plugin.
|
|
273
|
+
*/
|
|
274
|
+
export function promptFileNotices(files: OmpPromptFiles): PromptFileNotice[] {
|
|
275
|
+
const notices: PromptFileNotice[] = [];
|
|
276
|
+
if (files.appendSystemFile && files.hostAppendPrompt) {
|
|
277
|
+
notices.push({
|
|
278
|
+
file: "APPEND_SYSTEM.md",
|
|
279
|
+
text: "Paseo's Append system prompt is set, so agents on the built-in omp provider and newly created agents on the omp-plugin provider ignore this file.",
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
if (files.systemFile) {
|
|
283
|
+
notices.push({
|
|
284
|
+
file: "SYSTEM.md",
|
|
285
|
+
text: "Active. It replaces OMP's default prompt, so OMP's default tool policy is off.",
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return notices;
|
|
289
|
+
}
|
|
@@ -21,7 +21,7 @@ type OmpImageSource =
|
|
|
21
21
|
/** A decoded screenshot can hold several MB, so drop it soon after nothing shows it. */
|
|
22
22
|
const IMAGE_QUERY_GC_MS = 60_000;
|
|
23
23
|
|
|
24
|
-
function useOmpImageSource(image: OmpImage, hostId: string): OmpImageSource {
|
|
24
|
+
export function useOmpImageSource(image: OmpImage, hostId: string): OmpImageSource {
|
|
25
25
|
const fetchImage = useRpc(getOmpImage);
|
|
26
26
|
const ref = "ref" in image ? image.ref : null;
|
|
27
27
|
const query = useQuery({
|
package/client/web.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
|
|
3
|
+
declare const document: {
|
|
4
|
+
createElement(tag: "a"): { href: string; download: string; click(): void };
|
|
5
|
+
};
|
|
6
|
+
declare function atob(data: string): string;
|
|
7
|
+
declare class Blob {
|
|
8
|
+
constructor(parts: Uint8Array[], options: { type: string });
|
|
9
|
+
}
|
|
10
|
+
declare const URL: { createObjectURL(blob: Blob): string; revokeObjectURL(url: string): void };
|
|
11
|
+
|
|
12
|
+
/** Saving a file needs the browser; the desktop app and the web client both run it. */
|
|
13
|
+
export const canDownloadFiles = Platform.OS === "web";
|
|
14
|
+
|
|
15
|
+
const BASE64_DATA_URI = /^data:([^;,]+);base64,(.*)$/su;
|
|
16
|
+
const REVOKE_DELAY_MS = 60_000;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Saves a `data:` URI. Browsers refuse to download a data URL past about 2 MiB, so the bytes go
|
|
20
|
+
* through a Blob and an object URL instead.
|
|
21
|
+
*/
|
|
22
|
+
export function downloadDataUri(uri: string, fileName: string): void {
|
|
23
|
+
if (!canDownloadFiles) return;
|
|
24
|
+
const match = BASE64_DATA_URI.exec(uri);
|
|
25
|
+
const bytes = match ? Uint8Array.from(atob(match[2] ?? ""), (char) => char.charCodeAt(0)) : null;
|
|
26
|
+
const objectUrl =
|
|
27
|
+
match && bytes ? URL.createObjectURL(new Blob([bytes], { type: match[1] ?? "" })) : null;
|
|
28
|
+
const link = document.createElement("a");
|
|
29
|
+
link.href = objectUrl ?? uri;
|
|
30
|
+
link.download = fileName;
|
|
31
|
+
link.click();
|
|
32
|
+
// Safari and Firefox can start the download after the click returns, so revoke late.
|
|
33
|
+
if (objectUrl) setTimeout(() => URL.revokeObjectURL(objectUrl), REVOKE_DELAY_MS);
|
|
34
|
+
}
|
package/index.client.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
PluginSurfaceProps,
|
|
6
6
|
} from "@getpaseo/plugin/client";
|
|
7
7
|
import { ConfigSidebarItem } from "./client/config-sidebar";
|
|
8
|
+
import { OmpGeneratedImagesRow } from "./client/generated-image";
|
|
8
9
|
import { OMP_ICON } from "./client/hub-icon";
|
|
9
10
|
import { HubPopover } from "./client/hub-popover";
|
|
10
11
|
import { summarizeHubProcesses } from "./client/hub-status";
|
|
@@ -43,6 +44,11 @@ import {
|
|
|
43
44
|
composerPillSettings,
|
|
44
45
|
composerPillSettingsSchema,
|
|
45
46
|
} from "./shared/composer-pill-settings";
|
|
47
|
+
import {
|
|
48
|
+
OMP_GENERATED_IMAGE_KIND,
|
|
49
|
+
ompGeneratedImagesSchema,
|
|
50
|
+
transformOmpGeneratedImageItem,
|
|
51
|
+
} from "./shared/generated-image";
|
|
46
52
|
import { listHubProcesses } from "./shared/hub";
|
|
47
53
|
import {
|
|
48
54
|
OMP_LSP_DIAGNOSTICS_KIND,
|
|
@@ -255,6 +261,19 @@ export default function contribute(client: PluginClientContext) {
|
|
|
255
261
|
return transformOmpImageToolItem(item);
|
|
256
262
|
},
|
|
257
263
|
});
|
|
264
|
+
const removeGeneratedImageRenderer = client.addTimelineRenderer({
|
|
265
|
+
kind: OMP_GENERATED_IMAGE_KIND,
|
|
266
|
+
version: 1,
|
|
267
|
+
schema: ompGeneratedImagesSchema,
|
|
268
|
+
Component: OmpGeneratedImagesRow,
|
|
269
|
+
});
|
|
270
|
+
const removeGeneratedImageTransformer = client.addTimelineTransformer({
|
|
271
|
+
id: "omp-generated-images",
|
|
272
|
+
query: { itemType: "tool_call" },
|
|
273
|
+
transform({ item }) {
|
|
274
|
+
return transformOmpGeneratedImageItem(item);
|
|
275
|
+
},
|
|
276
|
+
});
|
|
258
277
|
const loadStoreQuotas = createStoreQuotaLoader(
|
|
259
278
|
(input) => client.rpc(listOmpQuotas, input),
|
|
260
279
|
QUOTA_POLL_MS,
|
|
@@ -543,6 +562,8 @@ export default function contribute(client: PluginClientContext) {
|
|
|
543
562
|
removeLspDiagnosticsRenderer();
|
|
544
563
|
removeLspTransformer();
|
|
545
564
|
removeImageTransformer();
|
|
565
|
+
removeGeneratedImageRenderer();
|
|
566
|
+
removeGeneratedImageTransformer();
|
|
546
567
|
removeOpenConfig();
|
|
547
568
|
removeConfigEntry();
|
|
548
569
|
removeOpenWorkspace();
|
package/index.server.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
2
|
+
import { resolveGeneratedImages } from "./server/generated-images";
|
|
2
3
|
import { resolveListHubProcesses, resolveTailHubLog } from "./server/hub";
|
|
3
4
|
import {
|
|
4
5
|
OmpBrowserAuthorizationRegistry,
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
resolveMutateOmpPlugin,
|
|
20
21
|
resolveMutateOmpPluginConfig,
|
|
21
22
|
} from "./server/omp-plugins";
|
|
23
|
+
import { readHostAppendPrompt, readOmpPromptFiles } from "./server/omp-prompt-files";
|
|
22
24
|
import { resolveListOmpRules } from "./server/omp-rules";
|
|
23
25
|
import { resolveListOmpSettings, resolveUpdateOmpSettings } from "./server/omp-settings";
|
|
24
26
|
import {
|
|
@@ -50,6 +52,7 @@ import {
|
|
|
50
52
|
} from "./server/subagents";
|
|
51
53
|
import { resolveGetOmpSupportReport } from "./server/support-diagnostics";
|
|
52
54
|
import { composerPillSettings } from "./shared/composer-pill-settings";
|
|
55
|
+
import { resolveOmpGeneratedImages } from "./shared/generated-image";
|
|
53
56
|
import { listHubProcesses, tailHubLog } from "./shared/hub";
|
|
54
57
|
import { openOmpMcpAuthorizationInPaseoBrowser } from "./shared/mcp";
|
|
55
58
|
import { listOmpMemory } from "./shared/memory";
|
|
@@ -83,6 +86,7 @@ import {
|
|
|
83
86
|
mutateOmpPlugin,
|
|
84
87
|
mutateOmpPluginConfig,
|
|
85
88
|
} from "./shared/omp-plugins";
|
|
89
|
+
import { getOmpPromptFiles } from "./shared/omp-prompt-files";
|
|
86
90
|
import { listOmpRules } from "./shared/omp-rules";
|
|
87
91
|
import { listOmpSettings, updateOmpSettings } from "./shared/omp-settings";
|
|
88
92
|
import { deleteOmpManagedSkill, listOmpSkills, setOmpSkillEnabled } from "./shared/omp-skills";
|
|
@@ -218,9 +222,16 @@ export default function contribute(server: PluginServerContext) {
|
|
|
218
222
|
server.handle(listOmpSettings, scoped(resolveListOmpSettings));
|
|
219
223
|
server.handle(updateOmpSettings, scoped(resolveUpdateOmpSettings));
|
|
220
224
|
server.handle(getOmpProviderHealth, scoped(resolveGetOmpProviderHealth));
|
|
225
|
+
// Not `scoped`: the handler also needs the host context to read Paseo's Append system prompt.
|
|
226
|
+
server.handle(getOmpPromptFiles, ({ store, cwd }, { paseo }) =>
|
|
227
|
+
withOmpStore(store, async () => readOmpPromptFiles(cwd, await readHostAppendPrompt(paseo))),
|
|
228
|
+
);
|
|
221
229
|
server.handle(getOmpUpdateStatus, resolveGetOmpUpdateStatus);
|
|
222
230
|
server.handle(installOmpUpdate, resolveInstallOmpUpdate);
|
|
223
231
|
server.handle(getOmpImage, (input) => resolveGetOmpImage(input, ompImageCache()));
|
|
232
|
+
server.handle(resolveOmpGeneratedImages, (input) =>
|
|
233
|
+
resolveGeneratedImages(input, ompImageCache()),
|
|
234
|
+
);
|
|
224
235
|
server.handle(
|
|
225
236
|
getOmpSupportReport,
|
|
226
237
|
scoped((input) => resolveGetOmpSupportReport(input, protocolViolations, operationalFailures)),
|
package/package.json
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { basename, dirname, extname, isAbsolute, join } from "node:path";
|
|
4
|
+
import type { RpcInput, RpcOutput } from "@getpaseo/plugin";
|
|
5
|
+
import type { resolveOmpGeneratedImages } from "../shared/generated-image";
|
|
6
|
+
import { isValidImagePayload, type OmpImageMimeType } from "./provider/image";
|
|
7
|
+
import { MAX_CACHED_IMAGE_BYTES, type OmpImageCache } from "./provider/image-cache";
|
|
8
|
+
import { readRegularFile } from "./regular-file";
|
|
9
|
+
|
|
10
|
+
/** The name OMP's `generate_image` gives its output files, written to the OS temp directory. */
|
|
11
|
+
const GENERATED_FILE_NAME = /^omp-image-[A-Za-z0-9_-]+\.(?:gif|jpe?g|png|webp)$/u;
|
|
12
|
+
const MIME_BY_EXTENSION: Readonly<Record<string, OmpImageMimeType>> = {
|
|
13
|
+
".gif": "image/gif",
|
|
14
|
+
".jpg": "image/jpeg",
|
|
15
|
+
".jpeg": "image/jpeg",
|
|
16
|
+
".png": "image/png",
|
|
17
|
+
".webp": "image/webp",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Only `omp-image-*` files directly in the temp directory are read; any other path is refused. */
|
|
21
|
+
function readGeneratedImage(
|
|
22
|
+
path: string,
|
|
23
|
+
): { bytes: Buffer; mimeType: OmpImageMimeType } | undefined {
|
|
24
|
+
const name = basename(path);
|
|
25
|
+
const mimeType = MIME_BY_EXTENSION[extname(name).toLowerCase()];
|
|
26
|
+
if (!isAbsolute(path) || !GENERATED_FILE_NAME.test(name) || !mimeType) return undefined;
|
|
27
|
+
let directory: string;
|
|
28
|
+
try {
|
|
29
|
+
directory = realpathSync(dirname(path));
|
|
30
|
+
if (directory !== realpathSync(tmpdir())) return undefined;
|
|
31
|
+
} catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const bytes = readRegularFile(join(directory, name), MAX_CACHED_IMAGE_BYTES);
|
|
35
|
+
// Only the magic bytes are checked, so encode only the header (12 bytes are 16 characters).
|
|
36
|
+
if (!bytes || !isValidImagePayload(bytes.subarray(0, 12).toString("base64"), mimeType, 16)) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return { bytes, mimeType };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function resolveGeneratedImages(
|
|
43
|
+
input: RpcInput<typeof resolveOmpGeneratedImages>,
|
|
44
|
+
cache: OmpImageCache,
|
|
45
|
+
): RpcOutput<typeof resolveOmpGeneratedImages> {
|
|
46
|
+
return {
|
|
47
|
+
images: input.paths.map((path) => {
|
|
48
|
+
const image = readGeneratedImage(path);
|
|
49
|
+
if (!image) return { status: "missing" as const };
|
|
50
|
+
return {
|
|
51
|
+
status: "available" as const,
|
|
52
|
+
ref: cache.store(image.bytes, image.mimeType),
|
|
53
|
+
mimeType: image.mimeType,
|
|
54
|
+
};
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
4
|
+
import type { OmpPromptFiles } from "../shared/omp-prompt-files";
|
|
5
|
+
import { ompAgentDir } from "./paths";
|
|
6
|
+
|
|
7
|
+
// OMP checks for the file's existence, so an empty file still counts. A `.omp` that is a file
|
|
8
|
+
// (ENOTDIR) simply has no prompt files in it.
|
|
9
|
+
async function hasFile(path: string): Promise<boolean> {
|
|
10
|
+
try {
|
|
11
|
+
return (await stat(path)).isFile();
|
|
12
|
+
} catch (error) {
|
|
13
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
14
|
+
if (code === "ENOENT" || code === "ENOTDIR") return false;
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function hasPromptFile(directories: readonly string[], name: string): Promise<boolean> {
|
|
20
|
+
const found = await Promise.all(directories.map((directory) => hasFile(join(directory, name))));
|
|
21
|
+
return found.some(Boolean);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Paseo's host Append system prompt as a yes/no; the text never leaves this function. */
|
|
25
|
+
export async function readHostAppendPrompt(paseo: PluginHandlerContext["paseo"]): Promise<boolean> {
|
|
26
|
+
const { config } = await paseo.config.get();
|
|
27
|
+
return config.appendSystemPrompt.trim() !== "";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Where OMP looks: the agent directory, plus the workspace's `.omp/` for a project view. */
|
|
31
|
+
export async function readOmpPromptFiles(
|
|
32
|
+
cwd: string | undefined,
|
|
33
|
+
hostAppendPrompt: boolean,
|
|
34
|
+
): Promise<OmpPromptFiles> {
|
|
35
|
+
const directories = [ompAgentDir(), ...(cwd ? [join(cwd, ".omp")] : [])];
|
|
36
|
+
const [appendSystemFile, systemFile] = await Promise.all([
|
|
37
|
+
hasPromptFile(directories, "APPEND_SYSTEM.md"),
|
|
38
|
+
hasPromptFile(directories, "SYSTEM.md"),
|
|
39
|
+
]);
|
|
40
|
+
return { appendSystemFile, systemFile, hostAppendPrompt };
|
|
41
|
+
}
|
|
@@ -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.406.1"; // x-release-please-version
|
|
@@ -23,7 +23,7 @@ import type { getOmpImage } from "../../shared/provider-image";
|
|
|
23
23
|
import type { OmpImageMimeType } from "./image";
|
|
24
24
|
|
|
25
25
|
/** Matches the projector's 8 MiB encoded image bound. */
|
|
26
|
-
const MAX_CACHED_IMAGE_BYTES = 6 * 1024 * 1024;
|
|
26
|
+
export const MAX_CACHED_IMAGE_BYTES = 6 * 1024 * 1024;
|
|
27
27
|
const MAX_CACHE_BYTES = 256 * 1024 * 1024;
|
|
28
28
|
const MAX_CACHE_FILES = 1_024;
|
|
29
29
|
const PRIVATE_DIRECTORY_MODE = 0o700;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
/** The bytes of a regular file of at most `maxBytes`; a symlink, FIFO, directory or larger file reads as nothing. */
|
|
4
|
+
export function readRegularFile(path: string, maxBytes: number): Buffer | undefined {
|
|
5
|
+
// O_NONBLOCK keeps a FIFO planted under the file's name from hanging the worker.
|
|
6
|
+
const flags = constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0);
|
|
7
|
+
let descriptor: number;
|
|
8
|
+
try {
|
|
9
|
+
if (lstatSync(path).isSymbolicLink()) return undefined;
|
|
10
|
+
descriptor = openSync(path, flags);
|
|
11
|
+
} catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const stat = fstatSync(descriptor);
|
|
16
|
+
if (!stat.isFile() || stat.size > maxBytes) return undefined;
|
|
17
|
+
// A file another user planted in a shared directory is not ours to read.
|
|
18
|
+
if (process.getuid !== undefined && stat.uid !== process.getuid()) return undefined;
|
|
19
|
+
const bytes = Buffer.alloc(stat.size);
|
|
20
|
+
let offset = 0;
|
|
21
|
+
while (offset < bytes.length) {
|
|
22
|
+
const read = readSync(descriptor, bytes, offset, bytes.length - offset, offset);
|
|
23
|
+
if (read === 0) return undefined;
|
|
24
|
+
offset += read;
|
|
25
|
+
}
|
|
26
|
+
return bytes;
|
|
27
|
+
} finally {
|
|
28
|
+
closeSync(descriptor);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { defineRpc } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { ompImageMimeTypeSchema, ompImageRefSchema } from "./provider-image";
|
|
4
|
+
|
|
5
|
+
export const OMP_GENERATED_IMAGE_KIND = "omp-generated-images";
|
|
6
|
+
|
|
7
|
+
const MAX_GENERATED_IMAGES = 8;
|
|
8
|
+
const MAX_PATH_LENGTH = 1024;
|
|
9
|
+
const pathSchema = z.string().min(1).max(MAX_PATH_LENGTH);
|
|
10
|
+
const pathsSchema = z.array(pathSchema).min(1).max(MAX_GENERATED_IMAGES);
|
|
11
|
+
|
|
12
|
+
/** Files OMP's `generate_image` tool saved on the daemon host; the row itself carries no usable bytes. */
|
|
13
|
+
export const ompGeneratedImagesSchema = z.object({ paths: pathsSchema });
|
|
14
|
+
export type OmpGeneratedImages = z.infer<typeof ompGeneratedImagesSchema>;
|
|
15
|
+
|
|
16
|
+
/** Copies each file into the image cache and returns its reference, so the stock image viewer can show it. */
|
|
17
|
+
export const resolveOmpGeneratedImages = defineRpc({
|
|
18
|
+
name: "paseo-omp.resolve-generated-images",
|
|
19
|
+
input: z.strictObject({ paths: pathsSchema }),
|
|
20
|
+
output: z.object({
|
|
21
|
+
images: z.array(
|
|
22
|
+
z.discriminatedUnion("status", [
|
|
23
|
+
z.object({
|
|
24
|
+
status: z.literal("available"),
|
|
25
|
+
ref: ompImageRefSchema,
|
|
26
|
+
mimeType: ompImageMimeTypeSchema,
|
|
27
|
+
}),
|
|
28
|
+
z.object({ status: z.literal("missing") }),
|
|
29
|
+
]),
|
|
30
|
+
),
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const generateImageRowSchema = z.object({
|
|
35
|
+
name: z.literal("generate_image"),
|
|
36
|
+
callId: z.string(),
|
|
37
|
+
status: z.literal("completed"),
|
|
38
|
+
detail: z.object({
|
|
39
|
+
type: z.literal("unknown"),
|
|
40
|
+
output: z.object({
|
|
41
|
+
details: z.object({ imagePaths: z.array(z.string()) }).loose(),
|
|
42
|
+
}),
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Replaces a completed built-in `generate_image` row with the images it saved. The provider cuts
|
|
48
|
+
* the row's base64 at 64 KiB, but keeps `details.imagePaths`; a row without paths stays as is.
|
|
49
|
+
*/
|
|
50
|
+
export function transformOmpGeneratedImageItem(item: unknown) {
|
|
51
|
+
const row = generateImageRowSchema.safeParse(item);
|
|
52
|
+
if (!row.success) return undefined;
|
|
53
|
+
const paths = row.data.detail.output.details.imagePaths
|
|
54
|
+
.filter((path) => path.length > 0 && path.length <= MAX_PATH_LENGTH)
|
|
55
|
+
.slice(0, MAX_GENERATED_IMAGES);
|
|
56
|
+
if (paths.length === 0) return undefined;
|
|
57
|
+
return {
|
|
58
|
+
items: [
|
|
59
|
+
{
|
|
60
|
+
type: "plugin" as const,
|
|
61
|
+
kind: OMP_GENERATED_IMAGE_KIND,
|
|
62
|
+
id: row.data.callId,
|
|
63
|
+
version: 1,
|
|
64
|
+
data: { paths },
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineRpc } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { OmpWorkspaceCwdSchema } from "./hub";
|
|
4
|
+
import { OmpStoreSchema } from "./omp-store";
|
|
5
|
+
|
|
6
|
+
/** Facts only: never the text of a prompt file or of Paseo's Append system prompt. */
|
|
7
|
+
export const OmpPromptFilesSchema = z.object({
|
|
8
|
+
/** An APPEND_SYSTEM.md exists in the agent directory (or the workspace's `.omp/`). */
|
|
9
|
+
appendSystemFile: z.boolean(),
|
|
10
|
+
/** A SYSTEM.md exists there: it replaces OMP's default instruction template. */
|
|
11
|
+
systemFile: z.boolean(),
|
|
12
|
+
/** Whether Paseo has an Append system prompt set. */
|
|
13
|
+
hostAppendPrompt: z.boolean(),
|
|
14
|
+
});
|
|
15
|
+
export type OmpPromptFiles = z.infer<typeof OmpPromptFilesSchema>;
|
|
16
|
+
|
|
17
|
+
export const getOmpPromptFiles = defineRpc({
|
|
18
|
+
name: "paseo-omp.get-prompt-files",
|
|
19
|
+
input: z.object({
|
|
20
|
+
store: OmpStoreSchema.optional(),
|
|
21
|
+
cwd: OmpWorkspaceCwdSchema.optional(),
|
|
22
|
+
}),
|
|
23
|
+
output: OmpPromptFilesSchema,
|
|
24
|
+
});
|
package/shared/provider-image.ts
CHANGED
|
@@ -83,10 +83,15 @@ function hasExpectedHeader(mimeType: string, bytes: readonly number[]): boolean
|
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
const ompImageMimeTypeSchema = z.enum([
|
|
86
|
+
export const ompImageMimeTypeSchema = z.enum([
|
|
87
|
+
"image/gif",
|
|
88
|
+
"image/jpeg",
|
|
89
|
+
"image/png",
|
|
90
|
+
"image/webp",
|
|
91
|
+
]);
|
|
87
92
|
const ompImageIdSchema = z.string().regex(/^[A-Za-z0-9_-]{16}$/u);
|
|
88
93
|
/** SHA-256 of the image bytes, naming the file in the server's image cache. */
|
|
89
|
-
const ompImageRefSchema = z.string().regex(/^[0-9a-f]{64}$/u);
|
|
94
|
+
export const ompImageRefSchema = z.string().regex(/^[0-9a-f]{64}$/u);
|
|
90
95
|
|
|
91
96
|
const cachedOmpImageSchema = z.object({
|
|
92
97
|
id: ompImageIdSchema,
|