@omercnet/paseo-omp 5.4.0 → 5.5.0-next.429.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 +7 -1
- package/README.md +2 -1
- package/client/ast-edit.tsx +53 -0
- package/client/composer-pill-settings.tsx +0 -5
- package/client/config-sidebar.tsx +15 -0
- package/client/generated-image.tsx +79 -0
- package/client/lsp-diagnostics.tsx +69 -0
- package/client/omp-config-surface.tsx +438 -108
- package/client/omp-config-views.ts +32 -5
- package/client/omp-extensions-section.tsx +145 -0
- package/client/omp-local-models-section.tsx +215 -0
- package/client/omp-plugin-manager.tsx +198 -3
- package/client/omp-routing-editor.tsx +123 -2
- package/client/omp-rule-test.tsx +140 -0
- package/client/omp-rules-section.tsx +353 -0
- package/client/omp-security-section.tsx +99 -0
- package/client/omp-security-state.ts +14 -0
- package/client/omp-skills-section.tsx +195 -0
- package/client/omp-tool-config-section.tsx +204 -0
- package/client/omp-tool-policy-state.ts +101 -0
- package/client/omp-tool-policy.tsx +435 -0
- package/client/omp-update-row.tsx +87 -0
- package/client/provider-diagnostics-state.ts +38 -1
- package/client/provider-image.tsx +1 -1
- package/client/rule-notice.tsx +33 -0
- package/client/sidebar-compat.ts +0 -109
- package/client/web.ts +34 -0
- package/index.client.tsx +79 -46
- package/index.server.ts +77 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -4
- package/server/generated-images.ts +57 -0
- package/server/omp-agents.ts +170 -0
- package/server/omp-extensions.ts +235 -0
- package/server/omp-list-setting.ts +98 -0
- package/server/omp-local-models.ts +202 -0
- package/server/omp-models-file.ts +178 -0
- package/server/omp-plugins.ts +182 -0
- package/server/omp-prompt-files.ts +41 -0
- package/server/omp-rule-firings.ts +211 -0
- package/server/omp-rule-switch.ts +38 -0
- package/server/omp-rule-test.ts +82 -0
- package/server/omp-rules.ts +452 -0
- package/server/omp-security.ts +169 -0
- package/server/omp-settings.ts +92 -16
- package/server/omp-skills.ts +179 -0
- package/server/omp-tool-config.ts +144 -0
- package/server/omp-update.ts +203 -0
- package/server/package-version.ts +1 -1
- package/server/provider/connection.ts +1 -1
- package/server/provider/image-cache.ts +1 -1
- package/server/provider/omp-rpc-environment.ts +1 -1
- package/server/provider/session-descriptors.ts +3 -0
- package/server/provider-diagnostics.ts +26 -4
- package/server/regular-file.ts +30 -0
- package/server/rule-notices.ts +112 -0
- package/server/turn-rows.ts +59 -0
- package/server/turn-screenshots.ts +140 -0
- package/shared/ast-edit.ts +124 -0
- package/shared/composer-pill-settings.ts +0 -2
- package/shared/generated-image.ts +68 -0
- package/shared/lsp-diagnostics.ts +141 -0
- package/shared/omp-agents.ts +26 -0
- package/shared/omp-extensions.ts +45 -0
- package/shared/omp-local-models.ts +44 -0
- package/shared/omp-models-file.ts +30 -0
- package/shared/omp-plugins.ts +90 -0
- package/shared/omp-prompt-files.ts +24 -0
- package/shared/omp-rules.ts +134 -0
- package/shared/omp-security.ts +50 -0
- package/shared/omp-settings.ts +211 -2
- package/shared/omp-skills.ts +80 -0
- package/shared/omp-tool-config.ts +283 -0
- package/shared/omp-update.ts +27 -0
- package/shared/provider-image.ts +10 -3
- package/shared/rule-notices.ts +20 -0
- package/client/hub-sidebar.tsx +0 -99
- package/client/sessions-popover.tsx +0 -78
- package/server/sessions.ts +0 -58
- package/shared/sessions.ts +0 -24
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { isAbsolute, join } from "node:path";
|
|
3
|
+
import { setImmediate as yieldToEventLoop } from "node:timers/promises";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { OMP_IMAGE_TIMELINE_KIND, ompImageTimelineSchema } from "../shared/provider-image";
|
|
6
|
+
import { ompDataDir } from "./paths";
|
|
7
|
+
import { isOmpImageMimeType, isValidImagePayload, type OmpImageMimeType } from "./provider/image";
|
|
8
|
+
import { MAX_CACHED_IMAGE_BYTES, type OmpImageCache, ompImageCache } from "./provider/image-cache";
|
|
9
|
+
import { readRegularFile } from "./regular-file";
|
|
10
|
+
import { readTail } from "./rule-notices";
|
|
11
|
+
import type { OmpTurnRow } from "./turn-rows";
|
|
12
|
+
|
|
13
|
+
const BLOB_REFERENCE = /^blob:sha256:([0-9a-f]{64})$/u;
|
|
14
|
+
const BASE64 = /^[A-Za-z0-9+/]+={0,2}$/u;
|
|
15
|
+
/** OMP moves image data of 1,024 or more base64 characters into a blob; shorter stays inline. */
|
|
16
|
+
const MAX_INLINE_BASE64_LENGTH = 1_023;
|
|
17
|
+
const MAX_SCREENSHOTS = 16;
|
|
18
|
+
const LABEL = "Screenshots";
|
|
19
|
+
|
|
20
|
+
interface ScreenshotImage {
|
|
21
|
+
/** SHA-256 of the image bytes; names the blob file. */
|
|
22
|
+
hash: string;
|
|
23
|
+
mimeType: OmpImageMimeType;
|
|
24
|
+
/** Present for an image persisted inline instead of as a blob. */
|
|
25
|
+
bytes?: Buffer;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const evalResultEntrySchema = z.object({
|
|
29
|
+
id: z.string(),
|
|
30
|
+
timestamp: z.string(),
|
|
31
|
+
message: z.object({
|
|
32
|
+
role: z.literal("toolResult"),
|
|
33
|
+
toolName: z.literal("eval"),
|
|
34
|
+
content: z.array(
|
|
35
|
+
z.looseObject({
|
|
36
|
+
type: z.string(),
|
|
37
|
+
data: z.string().optional(),
|
|
38
|
+
mimeType: z.string().optional(),
|
|
39
|
+
}),
|
|
40
|
+
),
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/** One persisted `eval` tool result: its image blocks, as blob references or small inline data. */
|
|
45
|
+
function parseEvalResult(
|
|
46
|
+
line: string,
|
|
47
|
+
): { id: string; at: number; images: ScreenshotImage[] } | undefined {
|
|
48
|
+
let json: unknown;
|
|
49
|
+
try {
|
|
50
|
+
json = JSON.parse(line);
|
|
51
|
+
} catch {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const entry = evalResultEntrySchema.safeParse(json);
|
|
55
|
+
if (!entry.success) return undefined;
|
|
56
|
+
const images = entry.data.message.content.flatMap((block): ScreenshotImage[] => {
|
|
57
|
+
const mimeType = block.mimeType ?? "";
|
|
58
|
+
const data = block.data ?? "";
|
|
59
|
+
if (block.type !== "image" || !isOmpImageMimeType(mimeType)) return [];
|
|
60
|
+
const hash = BLOB_REFERENCE.exec(data)?.[1];
|
|
61
|
+
if (hash) return [{ hash, mimeType }];
|
|
62
|
+
if (data.length > MAX_INLINE_BASE64_LENGTH || !BASE64.test(data)) return [];
|
|
63
|
+
const bytes = Buffer.from(data, "base64");
|
|
64
|
+
return [{ hash: createHash("sha256").update(bytes).digest("hex"), mimeType, bytes }];
|
|
65
|
+
});
|
|
66
|
+
return { id: entry.data.id, at: Date.parse(entry.data.timestamp), images };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function copyToCache(
|
|
70
|
+
directory: string,
|
|
71
|
+
image: ScreenshotImage,
|
|
72
|
+
cache: OmpImageCache,
|
|
73
|
+
): string | undefined {
|
|
74
|
+
const bytes = image.bytes ?? readRegularFile(join(directory, image.hash), MAX_CACHED_IMAGE_BYTES);
|
|
75
|
+
if (!bytes || createHash("sha256").update(bytes).digest("hex") !== image.hash) return undefined;
|
|
76
|
+
// Only the magic bytes are checked, so encode only the header (12 bytes are 16 characters).
|
|
77
|
+
if (!isValidImagePayload(bytes.subarray(0, 12).toString("base64"), image.mimeType, 16)) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
return cache.store(bytes, image.mimeType);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The `eval` screenshots of the turn between `since` and `until` (epoch ms). OMP persists each as
|
|
85
|
+
* a content-addressed file in `blobDirectory` (or inline when it is tiny); they are copied into
|
|
86
|
+
* the image cache so the row can name them by cache reference and the stock image renderer shows
|
|
87
|
+
* them.
|
|
88
|
+
*/
|
|
89
|
+
export async function readOmpScreenshots(
|
|
90
|
+
sessionFile: string,
|
|
91
|
+
since: number,
|
|
92
|
+
until: number,
|
|
93
|
+
cache: OmpImageCache,
|
|
94
|
+
blobDirectory: string,
|
|
95
|
+
): Promise<OmpTurnRow | undefined> {
|
|
96
|
+
if (!isAbsolute(sessionFile) || !sessionFile.endsWith(".jsonl")) return;
|
|
97
|
+
const tail = await readTail(sessionFile);
|
|
98
|
+
if (!tail) return;
|
|
99
|
+
let id: string | undefined;
|
|
100
|
+
const found: ScreenshotImage[] = [];
|
|
101
|
+
for (const line of tail.split("\n")) {
|
|
102
|
+
if (!line.includes("toolResult")) continue;
|
|
103
|
+
const result = parseEvalResult(line);
|
|
104
|
+
if (!result || !(result.at >= since && result.at <= until) || result.images.length === 0)
|
|
105
|
+
continue;
|
|
106
|
+
id ??= result.id;
|
|
107
|
+
found.push(...result.images);
|
|
108
|
+
}
|
|
109
|
+
if (!id) return;
|
|
110
|
+
const unique = new Map(found.map((image) => [image.hash, image]));
|
|
111
|
+
const images: z.infer<typeof ompImageTimelineSchema>["images"] = [];
|
|
112
|
+
for (const image of unique.values()) {
|
|
113
|
+
if (images.length >= MAX_SCREENSHOTS) break;
|
|
114
|
+
const ref = copyToCache(blobDirectory, image, cache);
|
|
115
|
+
if (ref) images.push({ id: ref.slice(0, 16), ref, mimeType: image.mimeType });
|
|
116
|
+
// Each copy reads and hashes up to 6 MiB synchronously; let other daemon work run between images.
|
|
117
|
+
await yieldToEventLoop();
|
|
118
|
+
}
|
|
119
|
+
if (images.length === 0) return;
|
|
120
|
+
return {
|
|
121
|
+
id: `screenshots:${id}`,
|
|
122
|
+
kind: OMP_IMAGE_TIMELINE_KIND,
|
|
123
|
+
data: ompImageTimelineSchema.parse({ label: LABEL, images }),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Paseo's bundled `omp` provider keeps only the text of `eval`, so its screenshots are read from the session file. */
|
|
128
|
+
export function ompScreenshotRow(
|
|
129
|
+
sessionFile: string,
|
|
130
|
+
since: number,
|
|
131
|
+
until: number,
|
|
132
|
+
): Promise<OmpTurnRow | undefined> {
|
|
133
|
+
return readOmpScreenshots(
|
|
134
|
+
sessionFile,
|
|
135
|
+
since,
|
|
136
|
+
until,
|
|
137
|
+
ompImageCache(),
|
|
138
|
+
join(ompDataDir(), "blobs"),
|
|
139
|
+
);
|
|
140
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -5,7 +5,6 @@ export const DEFAULT_COMPOSER_PILL_SETTINGS = {
|
|
|
5
5
|
mcp: true,
|
|
6
6
|
hub: true,
|
|
7
7
|
memory: true,
|
|
8
|
-
sessions: true,
|
|
9
8
|
quota: true,
|
|
10
9
|
} as const;
|
|
11
10
|
|
|
@@ -13,7 +12,6 @@ export const composerPillSettingsSchema = z.object({
|
|
|
13
12
|
mcp: z.boolean().default(DEFAULT_COMPOSER_PILL_SETTINGS.mcp),
|
|
14
13
|
hub: z.boolean().default(DEFAULT_COMPOSER_PILL_SETTINGS.hub),
|
|
15
14
|
memory: z.boolean().default(DEFAULT_COMPOSER_PILL_SETTINGS.memory),
|
|
16
|
-
sessions: z.boolean().default(DEFAULT_COMPOSER_PILL_SETTINGS.sessions),
|
|
17
15
|
quota: z.boolean().default(DEFAULT_COMPOSER_PILL_SETTINGS.quota),
|
|
18
16
|
});
|
|
19
17
|
|
|
@@ -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,141 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const OMP_LSP_DIAGNOSTICS_KIND = "omp-lsp-diagnostics";
|
|
4
|
+
|
|
5
|
+
const severitySchema = z.enum(["error", "warning", "info", "hint"]);
|
|
6
|
+
export type OmpLspSeverity = z.infer<typeof severitySchema>;
|
|
7
|
+
|
|
8
|
+
export const ompLspDiagnosticsSchema = z.object({
|
|
9
|
+
files: z
|
|
10
|
+
.array(
|
|
11
|
+
z.object({
|
|
12
|
+
path: z.string().min(1),
|
|
13
|
+
diagnostics: z
|
|
14
|
+
.array(
|
|
15
|
+
z.object({
|
|
16
|
+
line: z.number().int().positive(),
|
|
17
|
+
column: z.number().int().positive(),
|
|
18
|
+
severity: severitySchema,
|
|
19
|
+
message: z.string(),
|
|
20
|
+
}),
|
|
21
|
+
)
|
|
22
|
+
.min(1),
|
|
23
|
+
}),
|
|
24
|
+
)
|
|
25
|
+
.min(1),
|
|
26
|
+
});
|
|
27
|
+
export type OmpLspDiagnostics = z.infer<typeof ompLspDiagnosticsSchema>;
|
|
28
|
+
|
|
29
|
+
const COUNTS =
|
|
30
|
+
"\\d+ (?:error|warning|info|hint)\\(s\\)(?:, \\d+ (?:error|warning|info|hint)\\(s\\))*";
|
|
31
|
+
const HEADING = /^(#+) (.+)$/u;
|
|
32
|
+
const DIAGNOSTIC = /^\s+(\d+):(\d+) \[(error|warning|info|hint)\] (.+)$/u;
|
|
33
|
+
/** `3 error(s):` opens a single-target result. */
|
|
34
|
+
const TOTAL = new RegExp(`^${COUNTS}:$`, "u");
|
|
35
|
+
/** A glob result opens each file with `<icon> <path>: 1 error(s)` or `<icon> <path>: no issues`. */
|
|
36
|
+
const FILE_SUMMARY = new RegExp(`^\\S+ .+: (?:${COUNTS}|no issues)$`, "u");
|
|
37
|
+
/** OMP's own warnings (`<icon> a.ts: some servers failed (...)`, `[Showing lines ...]`) are not diagnostics. */
|
|
38
|
+
const NOTE =
|
|
39
|
+
/^(?:\S+ .+: (?:no diagnostics report yet|some servers failed|all language servers failed|No language server found)|\[.*\])/u;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Parses the text of an OMP `lsp` diagnostics result: a headed tree (`# dir/`, `## file`) whose
|
|
43
|
+
* files list `line:col [severity] message` rows. Returns `undefined` unless every file group is
|
|
44
|
+
* recognized, so unknown output keeps its original row.
|
|
45
|
+
*/
|
|
46
|
+
export function parseOmpLspDiagnostics(text: string): OmpLspDiagnostics | undefined {
|
|
47
|
+
const files = new Map<string, OmpLspDiagnostics["files"][number]["diagnostics"]>();
|
|
48
|
+
const directories: string[] = [];
|
|
49
|
+
let current: OmpLspDiagnostics["files"][number]["diagnostics"] | undefined;
|
|
50
|
+
let summarized = false;
|
|
51
|
+
let afterBlank = false;
|
|
52
|
+
for (const line of text.split("\n")) {
|
|
53
|
+
if (line.trim() === "") {
|
|
54
|
+
afterBlank = true;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const wasAfterBlank = afterBlank;
|
|
58
|
+
afterBlank = false;
|
|
59
|
+
if (TOTAL.test(line) || FILE_SUMMARY.test(line)) {
|
|
60
|
+
summarized = true;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (NOTE.test(line)) return undefined;
|
|
64
|
+
const heading = HEADING.exec(line);
|
|
65
|
+
if (heading) {
|
|
66
|
+
const depth = (heading[1] ?? "").length - 1;
|
|
67
|
+
const name = heading[2] ?? "";
|
|
68
|
+
directories.length = depth;
|
|
69
|
+
if (name.endsWith("/")) {
|
|
70
|
+
directories[depth] = name;
|
|
71
|
+
current = undefined;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const path = directories.join("") + name;
|
|
75
|
+
current = files.get(path) ?? [];
|
|
76
|
+
files.set(path, current);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const diagnostic = DIAGNOSTIC.exec(line);
|
|
80
|
+
if (diagnostic && current) {
|
|
81
|
+
current.push({
|
|
82
|
+
line: Number(diagnostic[1]),
|
|
83
|
+
column: Number(diagnostic[2]),
|
|
84
|
+
severity: severitySchema.parse(diagnostic[3]),
|
|
85
|
+
message: diagnostic[4] ?? "",
|
|
86
|
+
});
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const last = current?.at(-1);
|
|
90
|
+
if (!last || wasAfterBlank) return undefined;
|
|
91
|
+
last.message += `\n${line.trim()}`;
|
|
92
|
+
}
|
|
93
|
+
if (!summarized) return undefined;
|
|
94
|
+
const parsed = ompLspDiagnosticsSchema.safeParse({
|
|
95
|
+
files: [...files].map(([path, diagnostics]) => ({ path, diagnostics })),
|
|
96
|
+
});
|
|
97
|
+
return parsed.success ? parsed.data : undefined;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const textBlockSchema = z.object({ type: z.string(), text: z.string().optional() }).loose();
|
|
101
|
+
const lspToolRowSchema = z.object({
|
|
102
|
+
name: z.literal("lsp"),
|
|
103
|
+
callId: z.string(),
|
|
104
|
+
status: z.literal("completed"),
|
|
105
|
+
detail: z.union([
|
|
106
|
+
z.object({ type: z.literal("plain_text"), text: z.string() }),
|
|
107
|
+
z.object({
|
|
108
|
+
type: z.literal("unknown"),
|
|
109
|
+
output: z.object({ content: z.array(textBlockSchema) }).loose(),
|
|
110
|
+
}),
|
|
111
|
+
]),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Replaces a completed built-in `lsp` tool row with a diagnostics card. The built-in provider keeps
|
|
116
|
+
* only the result text (and raw JSON for an unmapped tool), so anything unparsable stays as is.
|
|
117
|
+
*/
|
|
118
|
+
export function transformOmpLspToolItem(item: unknown) {
|
|
119
|
+
const row = lspToolRowSchema.safeParse(item);
|
|
120
|
+
if (!row.success) return undefined;
|
|
121
|
+
const { detail } = row.data;
|
|
122
|
+
const text =
|
|
123
|
+
detail.type === "plain_text"
|
|
124
|
+
? detail.text
|
|
125
|
+
: detail.output.content
|
|
126
|
+
.flatMap((block) => (block.text === undefined ? [] : [block.text]))
|
|
127
|
+
.join("\n");
|
|
128
|
+
const data = parseOmpLspDiagnostics(text);
|
|
129
|
+
if (!data) return undefined;
|
|
130
|
+
return {
|
|
131
|
+
items: [
|
|
132
|
+
{
|
|
133
|
+
type: "plugin" as const,
|
|
134
|
+
kind: OMP_LSP_DIAGNOSTICS_KIND,
|
|
135
|
+
id: row.data.callId,
|
|
136
|
+
version: 1,
|
|
137
|
+
data,
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineRpc } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { OmpWorkspaceCwdSchema } from "./hub";
|
|
4
|
+
import { OmpAgentNameSchema } from "./omp-settings";
|
|
5
|
+
import { OmpStoreSchema } from "./omp-store";
|
|
6
|
+
|
|
7
|
+
export const OMP_AGENT_LIMIT = 256;
|
|
8
|
+
|
|
9
|
+
export const OmpAgentSchema = z
|
|
10
|
+
.object({ name: OmpAgentNameSchema, source: z.enum(["bundled", "user", "project"]) })
|
|
11
|
+
.strict();
|
|
12
|
+
export type OmpAgent = z.infer<typeof OmpAgentSchema>;
|
|
13
|
+
|
|
14
|
+
export const listOmpAgents = defineRpc({
|
|
15
|
+
name: "paseo-omp.list-agents",
|
|
16
|
+
input: z
|
|
17
|
+
.object({ store: OmpStoreSchema.optional(), cwd: OmpWorkspaceCwdSchema.optional() })
|
|
18
|
+
.strict(),
|
|
19
|
+
output: z
|
|
20
|
+
.object({
|
|
21
|
+
agents: z.array(OmpAgentSchema).max(OMP_AGENT_LIMIT),
|
|
22
|
+
/** Set when the bundled agents could not be listed; user and project agents still appear. */
|
|
23
|
+
error: z.string().max(256).optional(),
|
|
24
|
+
})
|
|
25
|
+
.strict(),
|
|
26
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { defineRpc } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { OmpWorkspaceCwdSchema } from "./hub";
|
|
4
|
+
import { OmpStoreSchema } from "./omp-store";
|
|
5
|
+
|
|
6
|
+
export const OmpExtensionKindSchema = z.enum(["extension", "hook", "tool"]);
|
|
7
|
+
export type OmpExtensionKind = z.infer<typeof OmpExtensionKindSchema>;
|
|
8
|
+
|
|
9
|
+
export const OmpExtensionItemSchema = z.object({
|
|
10
|
+
kind: OmpExtensionKindSchema,
|
|
11
|
+
/** A hook reads `pre/<file>` or `post/<file>`. */
|
|
12
|
+
name: z.string(),
|
|
13
|
+
level: z.enum(["project", "user"]),
|
|
14
|
+
path: z.string(),
|
|
15
|
+
/** The entry OMP matches in `disabledExtensions`. */
|
|
16
|
+
id: z.string(),
|
|
17
|
+
enabled: z.boolean(),
|
|
18
|
+
});
|
|
19
|
+
export type OmpExtensionItem = z.infer<typeof OmpExtensionItemSchema>;
|
|
20
|
+
|
|
21
|
+
export const OmpExtensionsListSchema = z.discriminatedUnion("status", [
|
|
22
|
+
z.object({ status: z.literal("ready"), items: z.array(OmpExtensionItemSchema) }),
|
|
23
|
+
z.object({ status: z.literal("error"), message: z.string() }),
|
|
24
|
+
]);
|
|
25
|
+
export type OmpExtensionsList = z.infer<typeof OmpExtensionsListSchema>;
|
|
26
|
+
|
|
27
|
+
const ScopeSchema = { store: OmpStoreSchema.optional(), cwd: OmpWorkspaceCwdSchema.optional() };
|
|
28
|
+
|
|
29
|
+
export const listOmpExtensions = defineRpc({
|
|
30
|
+
name: "paseo-omp.list-extensions",
|
|
31
|
+
input: z.object(ScopeSchema).strict(),
|
|
32
|
+
output: OmpExtensionsListSchema,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/** Off adds `id` to `disabledExtensions`; on removes it. A workspace writes its own `.omp/config.yml`. */
|
|
36
|
+
export const setOmpExtensionEnabled = defineRpc({
|
|
37
|
+
name: "paseo-omp.set-extension-enabled",
|
|
38
|
+
input: z
|
|
39
|
+
.object({ ...ScopeSchema, id: z.string().trim().min(1).max(512), enabled: z.boolean() })
|
|
40
|
+
.strict(),
|
|
41
|
+
output: z.discriminatedUnion("status", [
|
|
42
|
+
z.object({ status: z.literal("ok") }),
|
|
43
|
+
z.object({ status: z.literal("error"), message: z.string() }),
|
|
44
|
+
]),
|
|
45
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { defineRpc } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { OmpStoreSchema } from "./omp-store";
|
|
4
|
+
|
|
5
|
+
/** Model keys come from `omp tiny-models list`, for example `lfm2.5-230m` or `llama3.2:3b`. */
|
|
6
|
+
export const OmpLocalModelKeySchema = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/u);
|
|
7
|
+
|
|
8
|
+
export const OmpLocalModelSchema = z.object({
|
|
9
|
+
key: OmpLocalModelKeySchema,
|
|
10
|
+
label: z.string(),
|
|
11
|
+
description: z.string(),
|
|
12
|
+
/** Approximate download size parsed from OMP's description, when it names one. */
|
|
13
|
+
sizeMb: z.number().nullable(),
|
|
14
|
+
/** Found in OMP's cache folder. OMP's list does not report this itself. */
|
|
15
|
+
downloaded: z.boolean(),
|
|
16
|
+
download: z.enum(["idle", "running", "failed"]),
|
|
17
|
+
error: z.string().nullable(),
|
|
18
|
+
});
|
|
19
|
+
export type OmpLocalModel = z.infer<typeof OmpLocalModelSchema>;
|
|
20
|
+
|
|
21
|
+
export const listOmpLocalModels = defineRpc({
|
|
22
|
+
name: "paseo-omp.list-local-models",
|
|
23
|
+
input: z.object({ store: OmpStoreSchema.optional() }).strict(),
|
|
24
|
+
output: z.object({
|
|
25
|
+
available: z.boolean(),
|
|
26
|
+
models: z.array(OmpLocalModelSchema),
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const downloadOmpLocalModel = defineRpc({
|
|
31
|
+
name: "paseo-omp.download-local-model",
|
|
32
|
+
input: z.object({ store: OmpStoreSchema.optional(), key: OmpLocalModelKeySchema }).strict(),
|
|
33
|
+
output: z.object({ outcome: z.enum(["started", "busy", "unknown-model", "unavailable"]) }),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** The roles record with `role` pointed at `selector`, or removed when `selector` is null. */
|
|
37
|
+
export function withLocalModelRole(
|
|
38
|
+
roles: Readonly<Record<string, unknown>>,
|
|
39
|
+
role: string,
|
|
40
|
+
selector: string | null,
|
|
41
|
+
): Record<string, unknown> {
|
|
42
|
+
const { [role]: _replaced, ...rest } = roles;
|
|
43
|
+
return selector === null ? rest : { ...rest, [role]: selector };
|
|
44
|
+
}
|
|
@@ -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
|
+
});
|