@omercnet/paseo-omp 5.4.0-next.404.1 → 5.4.0-next.405.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 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
+ }
@@ -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,
@@ -50,6 +51,7 @@ import {
50
51
  } from "./server/subagents";
51
52
  import { resolveGetOmpSupportReport } from "./server/support-diagnostics";
52
53
  import { composerPillSettings } from "./shared/composer-pill-settings";
54
+ import { resolveOmpGeneratedImages } from "./shared/generated-image";
53
55
  import { listHubProcesses, tailHubLog } from "./shared/hub";
54
56
  import { openOmpMcpAuthorizationInPaseoBrowser } from "./shared/mcp";
55
57
  import { listOmpMemory } from "./shared/memory";
@@ -221,6 +223,9 @@ export default function contribute(server: PluginServerContext) {
221
223
  server.handle(getOmpUpdateStatus, resolveGetOmpUpdateStatus);
222
224
  server.handle(installOmpUpdate, resolveInstallOmpUpdate);
223
225
  server.handle(getOmpImage, (input) => resolveGetOmpImage(input, ompImageCache()));
226
+ server.handle(resolveOmpGeneratedImages, (input) =>
227
+ resolveGeneratedImages(input, ompImageCache()),
228
+ );
224
229
  server.handle(
225
230
  getOmpSupportReport,
226
231
  scoped((input) => resolveGetOmpSupportReport(input, protocolViolations, operationalFailures)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omercnet/paseo-omp",
3
- "version": "5.4.0-next.404.1",
3
+ "version": "5.4.0-next.405.1",
4
4
  "type": "module",
5
5
  "description": "Paseo integration for OMP, including its direct provider and workspace tooling.",
6
6
  "license": "MIT",
@@ -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
+ }
@@ -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.404.1"; // x-release-please-version
2
+ export const PASEO_OMP_PACKAGE_VERSION = "5.4.0-next.405.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
+ }
@@ -83,10 +83,15 @@ function hasExpectedHeader(mimeType: string, bytes: readonly number[]): boolean
83
83
  );
84
84
  }
85
85
 
86
- const ompImageMimeTypeSchema = z.enum(["image/gif", "image/jpeg", "image/png", "image/webp"]);
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,