paseo-plugin-genui 0.1.7 → 0.2.0
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 +3 -3
- package/README.md +1 -1
- package/client/components/content.tsx +62 -3
- package/client/components/data.tsx +26 -17
- package/client/components/dev.tsx +2 -1
- package/client/components/image-lightbox.tsx +153 -33
- package/client/components/inputs.tsx +3 -2
- package/client/components/media.tsx +37 -24
- package/client/components/project.tsx +24 -1
- package/client/components/widgets.tsx +2 -2
- package/client/live-ui.tsx +7 -2
- package/client/markdown.tsx +20 -1
- package/client/render.tsx +2 -0
- package/client/settings.tsx +22 -1
- package/gallery/Draft-long.ui +1 -0
- package/gallery/Draft.ui +1 -0
- package/index.server.ts +10 -4
- package/package.json +2 -2
- package/paseo-plugin.json +1 -1
- package/server/data-source.ts +20 -4
- package/server/project.test.ts +81 -0
- package/server/project.ts +51 -12
- package/shared/core/catalog.ts +5 -0
- package/shared/core/markdown.ts +5 -0
- package/shared/diagram/markdown.test.ts +28 -0
- package/shared/diagram/markdown.ts +12 -2
- package/shared/genui.test.ts +53 -1
- package/shared/instructions.ts +4 -2
- package/shared/logic/lightbox.test.ts +32 -0
- package/shared/logic/lightbox.ts +27 -0
- package/shared/settings.ts +8 -0
package/client/live-ui.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PluginTheme } from "@getpaseo/plugin";
|
|
2
2
|
import { openExternalUrl, usePaseo, type PluginTimelineItemProps } from "@getpaseo/plugin/client";
|
|
3
3
|
import { Icon, copyText, useRevealedText, useToast } from "@getpaseo/plugin/client/react-native";
|
|
4
|
+
import { Markdown } from "@getpaseo/plugin/client/ui";
|
|
4
5
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
6
|
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
6
7
|
import {
|
|
@@ -15,7 +16,6 @@ import {
|
|
|
15
16
|
import type { Action, Diagnostic, Value } from "../shared/core/types";
|
|
16
17
|
import type { GenUiBlockData, GenUiTextData } from "../shared/rpc";
|
|
17
18
|
import { useAudioLoader, useImageLoader, useLoadedData, useTextLoader, type FileScope } from "./loaders";
|
|
18
|
-
import { MarkdownText } from "./markdown";
|
|
19
19
|
import { RenderNodes } from "./render";
|
|
20
20
|
import { UiRuntimeContext, type UiRuntime } from "./runtime";
|
|
21
21
|
import { canRenderWebIframe, mountSandboxedAppIframe, openWorkspaceFile, readStorage, writeStorage } from "./web";
|
|
@@ -521,5 +521,10 @@ export function TimelineTextItem({
|
|
|
521
521
|
layout,
|
|
522
522
|
}: PluginTimelineItemProps<GenUiTextData>) {
|
|
523
523
|
const revealed = useRevealedText(item.data.text, item.data.phase ?? "complete");
|
|
524
|
-
|
|
524
|
+
// Paseo's own renderer and testID give this text the host's links, selection and copy, and plugin styles such as Chat Polish.
|
|
525
|
+
return (
|
|
526
|
+
<View testID="assistant-message">
|
|
527
|
+
<Markdown>{revealed}</Markdown>
|
|
528
|
+
</View>
|
|
529
|
+
);
|
|
525
530
|
}
|
package/client/markdown.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { PluginTheme } from "@getpaseo/plugin";
|
|
2
|
+
import { openExternalUrl } from "@getpaseo/plugin/client";
|
|
2
3
|
import React, { useMemo } from "react";
|
|
3
4
|
import { StyleSheet, Text, View } from "react-native";
|
|
4
|
-
import { parseMarkdown, type Block, type Inline } from "../shared/diagram/markdown";
|
|
5
|
+
import { parseInline, parseMarkdown, type Block, type Inline } from "../shared/diagram/markdown";
|
|
5
6
|
|
|
6
7
|
export function MarkdownText({
|
|
7
8
|
text,
|
|
@@ -24,6 +25,12 @@ export function MarkdownText({
|
|
|
24
25
|
);
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
/** One line of inline Markdown (links, emphasis, code), nested inside a caller's styled Text. */
|
|
29
|
+
export function InlineMarkdown({ text, theme }: { text: string; theme: PluginTheme }) {
|
|
30
|
+
const content = useMemo(() => parseInline(text), [text]);
|
|
31
|
+
return <Spans content={content} theme={theme} />;
|
|
32
|
+
}
|
|
33
|
+
|
|
27
34
|
function BlockView({
|
|
28
35
|
block,
|
|
29
36
|
theme,
|
|
@@ -165,6 +172,18 @@ function Spans({ content, theme }: { content: Inline[]; theme: PluginTheme }) {
|
|
|
165
172
|
</Text>
|
|
166
173
|
);
|
|
167
174
|
}
|
|
175
|
+
if (span.kind === "link") {
|
|
176
|
+
return (
|
|
177
|
+
<Text
|
|
178
|
+
key={index}
|
|
179
|
+
accessibilityRole="link"
|
|
180
|
+
onPress={() => void openExternalUrl(span.url)}
|
|
181
|
+
style={{ color: theme.colors.accent, textDecorationLine: "underline" }}
|
|
182
|
+
>
|
|
183
|
+
{span.text}
|
|
184
|
+
</Text>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
168
187
|
return <Text key={index}>{span.text}</Text>;
|
|
169
188
|
})}
|
|
170
189
|
</>
|
package/client/render.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import type { Props } from "../shared/logic/values";
|
|
|
4
4
|
import {
|
|
5
5
|
Badge,
|
|
6
6
|
Callout,
|
|
7
|
+
Draft,
|
|
7
8
|
Entity,
|
|
8
9
|
File,
|
|
9
10
|
Icon,
|
|
@@ -102,6 +103,7 @@ export const RENDERERS = {
|
|
|
102
103
|
Divider,
|
|
103
104
|
Text,
|
|
104
105
|
Callout,
|
|
106
|
+
Draft,
|
|
105
107
|
Metric,
|
|
106
108
|
Badge,
|
|
107
109
|
Icon,
|
package/client/settings.tsx
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useSettings, type PluginSurfaceProps } from "@getpaseo/plugin/client";
|
|
2
|
-
import { SettingsCard, SettingsSection, SettingsSwitch } from "@getpaseo/plugin/client/ui";
|
|
2
|
+
import { SettingsAction, SettingsCard, SettingsInput, SettingsSection, SettingsSwitch } from "@getpaseo/plugin/client/ui";
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { Text, View } from "react-native";
|
|
5
5
|
import { genuiSettings } from "../shared/settings";
|
|
6
6
|
|
|
7
7
|
export function GenUiSettingsScreen({ theme }: PluginSurfaceProps) {
|
|
8
8
|
const settings = useSettings(genuiSettings);
|
|
9
|
+
const [folders, setFolders] = React.useState<string | null>(null);
|
|
9
10
|
|
|
10
11
|
if (settings.status === "loading") {
|
|
11
12
|
return (
|
|
@@ -52,6 +53,26 @@ export function GenUiSettingsScreen({ theme }: PluginSurfaceProps) {
|
|
|
52
53
|
/>
|
|
53
54
|
</SettingsCard>
|
|
54
55
|
</SettingsSection>
|
|
56
|
+
|
|
57
|
+
<SettingsSection title="Files">
|
|
58
|
+
<SettingsCard>
|
|
59
|
+
<SettingsInput
|
|
60
|
+
label="Extra folders"
|
|
61
|
+
hint="Comma-separated folders, besides the workspace, thread storage and /tmp, that Load, Snippet and Image can read."
|
|
62
|
+
initialValue={values.extraFolders}
|
|
63
|
+
placeholder="~/dev/scratch"
|
|
64
|
+
onChangeText={setFolders}
|
|
65
|
+
/>
|
|
66
|
+
<SettingsAction
|
|
67
|
+
label="Apply folder changes"
|
|
68
|
+
actionLabel="Save"
|
|
69
|
+
disabled={folders === null || folders === values.extraFolders}
|
|
70
|
+
onPress={() => {
|
|
71
|
+
if (folders !== null) void save({ ...values, extraFolders: folders }, revision);
|
|
72
|
+
}}
|
|
73
|
+
/>
|
|
74
|
+
</SettingsCard>
|
|
75
|
+
</SettingsSection>
|
|
55
76
|
</View>
|
|
56
77
|
);
|
|
57
78
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Card("Draft PR comment", [Draft("**Suggestion:** `requeue()` passes only the job id, so a retried job loses its payload and the worker fails with `undefined is not iterable` on the second attempt. Passing the whole job object, or reading the payload back from the store before requeueing, would fix it.")])
|
package/gallery/Draft.ui
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Card("Draft reply to the review", [Draft("Thanks, fixed in `a1b2c3d`:\n\n- the retry now keeps the payload\n- added a regression test\n\nCan you take another look?", "PR #42 reply")])
|
package/index.server.ts
CHANGED
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
webTileRpc,
|
|
30
30
|
} from "./shared/rpc";
|
|
31
31
|
import { GENUI_BLOCK_KIND } from "./shared/segment";
|
|
32
|
-
import { genuiSettings } from "./shared/settings";
|
|
32
|
+
import { genuiSettings, parseFolders } from "./shared/settings";
|
|
33
33
|
import {
|
|
34
34
|
agentStorageDir,
|
|
35
35
|
examplesReport,
|
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
loadGalleryFile,
|
|
42
42
|
loadGalleryImage,
|
|
43
43
|
readGallerySpec,
|
|
44
|
+
setExtraLoadFolders,
|
|
44
45
|
sketchFontDataUrl,
|
|
45
46
|
} from "./server/data-source";
|
|
46
47
|
import {
|
|
@@ -69,10 +70,14 @@ export default function contribute(server: PluginServerContext) {
|
|
|
69
70
|
let webLookupsEnabled = true;
|
|
70
71
|
|
|
71
72
|
void settings.read().then((state) => {
|
|
72
|
-
if (state.status
|
|
73
|
+
if (state.status !== "ready") return;
|
|
74
|
+
webLookupsEnabled = state.values.webLookups;
|
|
75
|
+
setExtraLoadFolders(parseFolders(state.values.extraFolders));
|
|
73
76
|
});
|
|
74
77
|
const unsubscribeSettings = settings.subscribe((state) => {
|
|
75
|
-
if (state.status
|
|
78
|
+
if (state.status !== "ready") return;
|
|
79
|
+
webLookupsEnabled = state.values.webLookups;
|
|
80
|
+
setExtraLoadFolders(parseFolders(state.values.extraFolders));
|
|
76
81
|
});
|
|
77
82
|
|
|
78
83
|
const web = createWebLookups(
|
|
@@ -92,13 +97,14 @@ export default function contribute(server: PluginServerContext) {
|
|
|
92
97
|
const current = await settings.read();
|
|
93
98
|
if (current.status === "ready" && !current.values.autoInstructions) return;
|
|
94
99
|
const webOn = current.status === "ready" ? current.values.webLookups : true;
|
|
100
|
+
const extraFolders = current.status === "ready" ? parseFolders(current.values.extraFolders) : [];
|
|
95
101
|
const existing = request.config.systemPrompt ?? "";
|
|
96
102
|
if (existing.includes(GENUI_MARKER)) return;
|
|
97
103
|
return {
|
|
98
104
|
...request,
|
|
99
105
|
config: {
|
|
100
106
|
...request.config,
|
|
101
|
-
systemPrompt: [existing, buildFullInstructions(webOn)].filter(Boolean).join("\n\n"),
|
|
107
|
+
systemPrompt: [existing, buildFullInstructions(webOn, extraFolders)].filter(Boolean).join("\n\n"),
|
|
102
108
|
},
|
|
103
109
|
};
|
|
104
110
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paseo-plugin-genui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Paseo plugin: agents answer with charts, diagrams, maps, plans and forms rendered inline in the chat.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"paseo",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"test": "vitest run"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@getpaseo/plugin": "0.
|
|
42
|
+
"@getpaseo/plugin": "0.13.0",
|
|
43
43
|
"@tanstack/react-query": "^5.90.11",
|
|
44
44
|
"@types/node": "^24.19.2",
|
|
45
45
|
"@types/react": "~19.2.0",
|
package/paseo-plugin.json
CHANGED
package/server/data-source.ts
CHANGED
|
@@ -3,10 +3,12 @@ import { mkdir, open, readdir, readFile, realpath } from "node:fs/promises";
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
-
import type {
|
|
6
|
+
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
7
7
|
import { collectLoads, compile, parseDataFile, type LoadedData } from "../shared/core";
|
|
8
8
|
import { COMPONENTS, componentSignature, type ComponentName } from "../shared/core/catalog";
|
|
9
9
|
|
|
10
|
+
type PaseoApi = PluginHandlerContext["paseo"];
|
|
11
|
+
|
|
10
12
|
export const MAX_DATA_BYTES = 2 * 1024 * 1024;
|
|
11
13
|
export const MAX_IMAGE_BYTES = 5 * 1024 * 1024;
|
|
12
14
|
export const MAX_AUDIO_BYTES = 25 * 1024 * 1024;
|
|
@@ -47,7 +49,20 @@ type FileContent =
|
|
|
47
49
|
|
|
48
50
|
type FileReader = (requested: string, maxBytes: number) => Promise<FileContent>;
|
|
49
51
|
|
|
50
|
-
const AGENT_REFUSAL =
|
|
52
|
+
const AGENT_REFUSAL =
|
|
53
|
+
"only files in this agent's workspace, its thread storage, /tmp or a folder added in Generative UI settings can be loaded; copy the file to $BB_THREAD_STORAGE to show it";
|
|
54
|
+
|
|
55
|
+
let extraRoots: readonly string[] = [];
|
|
56
|
+
|
|
57
|
+
/** Folders, besides the workspace, thread storage and /tmp, that agents may load files from. */
|
|
58
|
+
export function setExtraLoadFolders(folders: readonly string[]): void {
|
|
59
|
+
extraRoots = folders.map(expandHome).filter((folder) => path.isAbsolute(folder));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function expandHome(requested: string): string {
|
|
63
|
+
return requested === "~" || requested.startsWith("~/") ? path.join(os.homedir(), requested.slice(1)) : requested;
|
|
64
|
+
}
|
|
65
|
+
|
|
51
66
|
const GALLERY_REFUSAL = "gallery specs can only load files in gallery/";
|
|
52
67
|
|
|
53
68
|
function contains(root: string, target: string): boolean {
|
|
@@ -189,10 +204,11 @@ async function readAgentFile(
|
|
|
189
204
|
} else if (requested.startsWith(PASEO_STORAGE_PREFIX)) {
|
|
190
205
|
const rel = requested.slice(PASEO_STORAGE_PREFIX.length);
|
|
191
206
|
attempts = inside(storageRoot, path.resolve(storageRoot, rel));
|
|
192
|
-
} else if (path.isAbsolute(requested)) {
|
|
193
|
-
const target = path.resolve(requested);
|
|
207
|
+
} else if (path.isAbsolute(expandHome(requested))) {
|
|
208
|
+
const target = path.resolve(expandHome(requested));
|
|
194
209
|
attempts = [...inside(storageRoot, target), ...inside(workspaceCwd, target)].slice(0, 1);
|
|
195
210
|
if (attempts.length === 0) attempts = tempAttempts(target);
|
|
211
|
+
if (attempts.length === 0) attempts = extraRoots.flatMap((root) => inside(root, target)).slice(0, 1);
|
|
196
212
|
} else {
|
|
197
213
|
attempts = [
|
|
198
214
|
...inside(workspaceCwd, workspaceCwd !== null ? path.resolve(workspaceCwd, requested) : ""),
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
6
|
+
import { detectGitBranches } from "./project";
|
|
7
|
+
|
|
8
|
+
const dirs: string[] = [];
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function repo(): { dir: string; git: (...args: string[]) => void; commit: (name: string) => void } {
|
|
14
|
+
const dir = mkdtempSync(join(tmpdir(), "genui-base-"));
|
|
15
|
+
dirs.push(dir);
|
|
16
|
+
const git = (...args: string[]) => {
|
|
17
|
+
execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd: dir, stdio: "ignore" });
|
|
18
|
+
};
|
|
19
|
+
const commit = (name: string) => {
|
|
20
|
+
writeFileSync(join(dir, name), name);
|
|
21
|
+
git("add", name);
|
|
22
|
+
git("commit", "-m", name);
|
|
23
|
+
};
|
|
24
|
+
git("init", "-q", "-b", "main");
|
|
25
|
+
commit("root");
|
|
26
|
+
return { dir, git, commit };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe("detectGitBranches", () => {
|
|
30
|
+
it("picks dev for a branch cut from dev, not the default branch", async () => {
|
|
31
|
+
const { dir, git, commit } = repo();
|
|
32
|
+
git("checkout", "-q", "-b", "dev");
|
|
33
|
+
for (const n of ["d1", "d2", "d3"]) commit(n);
|
|
34
|
+
git("checkout", "-q", "-b", "fix/thing");
|
|
35
|
+
commit("mine");
|
|
36
|
+
const info = await detectGitBranches(dir);
|
|
37
|
+
expect(info.ok && info.base).toBe("dev");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("keeps main for a branch cut from main", async () => {
|
|
41
|
+
const { dir, git, commit } = repo();
|
|
42
|
+
git("checkout", "-q", "-b", "dev");
|
|
43
|
+
commit("d1");
|
|
44
|
+
git("checkout", "-q", "main");
|
|
45
|
+
git("checkout", "-q", "-b", "fix/thing");
|
|
46
|
+
commit("mine");
|
|
47
|
+
const info = await detectGitBranches(dir);
|
|
48
|
+
expect(info.ok && info.base).toBe("main");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("treats dev itself as on its base", async () => {
|
|
52
|
+
const { dir, git, commit } = repo();
|
|
53
|
+
git("checkout", "-q", "-b", "dev");
|
|
54
|
+
commit("d1");
|
|
55
|
+
const info = await detectGitBranches(dir);
|
|
56
|
+
expect(info.ok && info.base).toBe("dev");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("uses local dev when it is ahead of a stale origin/dev", async () => {
|
|
60
|
+
const { dir, git, commit } = repo();
|
|
61
|
+
git("checkout", "-q", "-b", "dev");
|
|
62
|
+
git("update-ref", "refs/remotes/origin/dev", "HEAD");
|
|
63
|
+
for (const n of ["d1", "d2", "d3"]) commit(n);
|
|
64
|
+
git("checkout", "-q", "-b", "fix/thing");
|
|
65
|
+
commit("mine");
|
|
66
|
+
const info = await detectGitBranches(dir);
|
|
67
|
+
expect(info.ok && info.baseRef).toBe("dev");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("keeps main for a branch from main that is already merged into dev", async () => {
|
|
71
|
+
const { dir, git, commit } = repo();
|
|
72
|
+
git("checkout", "-q", "-b", "fix/thing");
|
|
73
|
+
commit("mine");
|
|
74
|
+
git("checkout", "-q", "-b", "dev", "main");
|
|
75
|
+
commit("d1");
|
|
76
|
+
git("merge", "-q", "--no-ff", "-m", "merge", "fix/thing");
|
|
77
|
+
git("checkout", "-q", "fix/thing");
|
|
78
|
+
const info = await detectGitBranches(dir);
|
|
79
|
+
expect(info.ok && info.base).toBe("main");
|
|
80
|
+
});
|
|
81
|
+
});
|
package/server/project.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { promisify } from "node:util";
|
|
3
|
-
import type {
|
|
3
|
+
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
4
4
|
import type {
|
|
5
5
|
EnvironmentDetail,
|
|
6
6
|
EnvironmentDetailResult,
|
|
@@ -34,6 +34,8 @@ import {
|
|
|
34
34
|
import { lastMessage } from "../shared/core/thread-activity";
|
|
35
35
|
import { resolveAgentCwd } from "./data-source";
|
|
36
36
|
|
|
37
|
+
type PaseoApi = PluginHandlerContext["paseo"];
|
|
38
|
+
|
|
37
39
|
const execFileAsync = promisify(execFile);
|
|
38
40
|
|
|
39
41
|
function failure(reason: ProjectFailure["reason"], message: string): ProjectFailure {
|
|
@@ -56,12 +58,14 @@ async function runGit(
|
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
async function detectGitBranches(cwd: string): Promise<
|
|
61
|
+
export async function detectGitBranches(cwd: string): Promise<
|
|
60
62
|
| {
|
|
61
63
|
ok: true;
|
|
62
64
|
branch: string | null;
|
|
63
65
|
head: string | null;
|
|
64
66
|
base: string;
|
|
67
|
+
/** The ref to diff against: origin/<base> when it exists, so a stale local branch doesn't skew it. */
|
|
68
|
+
baseRef: string;
|
|
65
69
|
checkout: "branch" | "detached" | "unborn";
|
|
66
70
|
}
|
|
67
71
|
| ProjectFailure
|
|
@@ -77,12 +81,47 @@ async function detectGitBranches(cwd: string): Promise<
|
|
|
77
81
|
const checkout = head === null ? "unborn" : branch !== null ? "branch" : "detached";
|
|
78
82
|
|
|
79
83
|
const originHead = await runGit(cwd, ["symbolic-ref", "--short", "-q", "refs/remotes/origin/HEAD"]);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
const defaultBranch = originHead.ok ? originHead.stdout.trim().replace(/^origin\//, "") : "";
|
|
85
|
+
const { base, baseRef } = await closestBase(cwd, branch, head !== null, defaultBranch);
|
|
86
|
+
return { ok: true, branch, head, base, baseRef, checkout };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const BASE_CANDIDATES = ["main", "master", "dev", "develop"];
|
|
90
|
+
|
|
91
|
+
/** Feature branches often fork from dev rather than the default branch, so pick the candidate fewest commits behind HEAD. */
|
|
92
|
+
async function closestBase(
|
|
93
|
+
cwd: string,
|
|
94
|
+
branch: string | null,
|
|
95
|
+
hasHead: boolean,
|
|
96
|
+
defaultBranch: string,
|
|
97
|
+
): Promise<{ base: string; baseRef: string }> {
|
|
98
|
+
const names = [...new Set([defaultBranch, ...BASE_CANDIDATES].filter(Boolean))];
|
|
99
|
+
// Both the remote and local ref of each name compete, so neither a stale origin nor a stale local copy wins.
|
|
100
|
+
const refs = names.flatMap((name) => [`origin/${name}`, name].map((ref) => ({ name, ref })));
|
|
101
|
+
const resolved = await Promise.all(
|
|
102
|
+
refs.map(async (c) => ((await runGit(cwd, ["rev-parse", "--verify", "-q", `${c.ref}^{commit}`])).ok ? c : null)),
|
|
103
|
+
);
|
|
104
|
+
const existing = resolved.filter((c): c is { name: string; ref: string } => c !== null);
|
|
105
|
+
const fallback = existing[0] ?? { name: defaultBranch || "main", ref: defaultBranch || "main" };
|
|
106
|
+
const own = existing.find((c) => c.name === branch);
|
|
107
|
+
if (own) return { base: own.name, baseRef: own.ref };
|
|
108
|
+
if (!hasHead || existing.length < 2) return { base: fallback.name, baseRef: fallback.ref };
|
|
109
|
+
|
|
110
|
+
const scored = await Promise.all(
|
|
111
|
+
existing.map(async (c) => {
|
|
112
|
+
const [ahead, behind] = await Promise.all([
|
|
113
|
+
runGit(cwd, ["rev-list", "--count", `${c.ref}..HEAD`]),
|
|
114
|
+
runGit(cwd, ["rev-list", "--count", `HEAD..${c.ref}`]),
|
|
115
|
+
]);
|
|
116
|
+
const aheadCount = ahead.ok ? Number(ahead.stdout.trim()) : Number.POSITIVE_INFINITY;
|
|
117
|
+
// A ref that already holds every HEAD commit and more has merged this branch; it isn't where it forked from.
|
|
118
|
+
const mergedIn = aheadCount === 0 && behind.ok && Number(behind.stdout.trim()) > 0;
|
|
119
|
+
return { ...c, ahead: aheadCount, mergedIn };
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
const pool = scored.some((c) => !c.mergedIn) ? scored.filter((c) => !c.mergedIn) : scored;
|
|
123
|
+
const best = pool.reduce((a, b) => (b.ahead < a.ahead ? b : a));
|
|
124
|
+
return { base: best.name, baseRef: best.ref };
|
|
86
125
|
}
|
|
87
126
|
|
|
88
127
|
function mapStatusChar(code: string): ChangeKind {
|
|
@@ -450,8 +489,8 @@ export async function readProjectChanges(
|
|
|
450
489
|
base: gitInfo.base,
|
|
451
490
|
onBase: false,
|
|
452
491
|
};
|
|
453
|
-
diffArgs = ["diff", `${gitInfo.
|
|
454
|
-
numstatArgs = ["diff", `${gitInfo.
|
|
492
|
+
diffArgs = ["diff", `${gitInfo.baseRef}...HEAD`, "--unified=3"];
|
|
493
|
+
numstatArgs = ["diff", `${gitInfo.baseRef}...HEAD`, "--numstat", "--find-renames"];
|
|
455
494
|
}
|
|
456
495
|
|
|
457
496
|
const [numstatRes, nameStatusRes, patchRes] = await Promise.all([
|
|
@@ -558,7 +597,7 @@ export async function readProjectCommits(paseo: PaseoApi, agentId: string): Prom
|
|
|
558
597
|
if (!gitInfo.ok) return gitInfo;
|
|
559
598
|
|
|
560
599
|
const onBase = gitInfo.branch === gitInfo.base;
|
|
561
|
-
const range = onBase ? `-n ${MAX_COMMITS}` : `${gitInfo.
|
|
600
|
+
const range = onBase ? `-n ${MAX_COMMITS}` : `${gitInfo.baseRef}..HEAD`;
|
|
562
601
|
const logArgs = onBase
|
|
563
602
|
? ["log", `-n`, String(MAX_COMMITS), "--format=%H%x09%h%x09%s%x09%an%x09%at"]
|
|
564
603
|
: ["log", range, "--format=%H%x09%h%x09%s%x09%an%x09%at"];
|
|
@@ -579,7 +618,7 @@ export async function readProjectCommits(paseo: PaseoApi, agentId: string): Prom
|
|
|
579
618
|
let ahead: number | null = null;
|
|
580
619
|
let behind: number | null = null;
|
|
581
620
|
if (!onBase) {
|
|
582
|
-
const counts = await runGit(cwd, ["rev-list", "--left-right", "--count", `${gitInfo.
|
|
621
|
+
const counts = await runGit(cwd, ["rev-list", "--left-right", "--count", `${gitInfo.baseRef}...HEAD`]);
|
|
583
622
|
if (counts.ok) {
|
|
584
623
|
const [bStr, aStr] = counts.stdout.trim().split(/\s+/);
|
|
585
624
|
behind = Number(bStr) || 0;
|
package/shared/core/catalog.ts
CHANGED
|
@@ -101,6 +101,11 @@ export const COMPONENTS = {
|
|
|
101
101
|
group: "Content",
|
|
102
102
|
params: [{ name: "text", kind: "text" }, tone, { name: "title", kind: "string", optional: true }],
|
|
103
103
|
},
|
|
104
|
+
Draft: {
|
|
105
|
+
group: "Content",
|
|
106
|
+
params: [{ name: "markdown", kind: "text" }, { name: "title", kind: "string", optional: true }],
|
|
107
|
+
summary: "text the user approves before it is posted: rendered, with Source and Copy",
|
|
108
|
+
},
|
|
104
109
|
Metric: {
|
|
105
110
|
group: "Content",
|
|
106
111
|
params: [
|
package/shared/core/markdown.ts
CHANGED
|
@@ -434,6 +434,11 @@ function block(node: UiNode): string {
|
|
|
434
434
|
return "---";
|
|
435
435
|
case "Text":
|
|
436
436
|
return inline(props.text);
|
|
437
|
+
case "Draft": {
|
|
438
|
+
const title = inline(props.title);
|
|
439
|
+
const body = inline(props.markdown);
|
|
440
|
+
return paragraphs([title === "" ? "**Draft**" : `**Draft: ${title}**`, body]);
|
|
441
|
+
}
|
|
437
442
|
case "Callout": {
|
|
438
443
|
const title = inline(props.title);
|
|
439
444
|
const text = inline(props.text);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { parseInline } from "./markdown";
|
|
3
|
+
|
|
4
|
+
describe("parseInline links", () => {
|
|
5
|
+
it("reads a Markdown link", () => {
|
|
6
|
+
expect(parseInline("see [the docs](https://paseo.sh/docs) now")).toEqual([
|
|
7
|
+
{ kind: "text", text: "see " },
|
|
8
|
+
{ kind: "link", text: "the docs", url: "https://paseo.sh/docs" },
|
|
9
|
+
{ kind: "text", text: " now" },
|
|
10
|
+
]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("links a bare URL without its trailing punctuation", () => {
|
|
14
|
+
expect(parseInline("go to https://paseo.sh/a_b_c.")).toEqual([
|
|
15
|
+
{ kind: "text", text: "go to " },
|
|
16
|
+
{ kind: "link", text: "https://paseo.sh/a_b_c", url: "https://paseo.sh/a_b_c" },
|
|
17
|
+
{ kind: "text", text: "." },
|
|
18
|
+
]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("leaves a URL inside code alone", () => {
|
|
22
|
+
expect(parseInline("`https://paseo.sh`")).toEqual([{ kind: "code", text: "https://paseo.sh" }]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("shows a link with an unsafe scheme as its text", () => {
|
|
26
|
+
expect(parseInline("[x](javascript:void)")).toEqual([{ kind: "text", text: "x" }]);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -11,7 +11,8 @@ export type Inline =
|
|
|
11
11
|
| { kind: "text"; text: string }
|
|
12
12
|
| { kind: "bold"; text: string }
|
|
13
13
|
| { kind: "italic"; text: string }
|
|
14
|
-
| { kind: "code"; text: string }
|
|
14
|
+
| { kind: "code"; text: string }
|
|
15
|
+
| { kind: "link"; text: string; url: string };
|
|
15
16
|
|
|
16
17
|
export type Block =
|
|
17
18
|
| { kind: "heading"; level: number; content: Inline[] }
|
|
@@ -22,14 +23,23 @@ export type Block =
|
|
|
22
23
|
| { kind: "quote"; content: Inline[] }
|
|
23
24
|
| { kind: "rule" };
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
// A bare URL drops trailing punctuation, so "see https://x.dev." links to https://x.dev.
|
|
27
|
+
const INLINE =
|
|
28
|
+
/(`[^`]+`|\[[^\]\n]+\]\([^)\s]+\)|https?:\/\/[^\s<>]*[^\s<>.,;:!?'")\]*_]|\*\*[^*]+\*\*|__[^_]+__|\*[^*\n]+\*|_[^_\n]+_)/;
|
|
29
|
+
const LINK = /^\[([^\]\n]+)\]\(([^)\s]+)\)$/;
|
|
26
30
|
|
|
27
31
|
export function parseInline(text: string): Inline[] {
|
|
28
32
|
const out: Inline[] = [];
|
|
29
33
|
for (const piece of text.split(INLINE)) {
|
|
30
34
|
if (piece.length === 0) continue;
|
|
35
|
+
const link = LINK.exec(piece);
|
|
31
36
|
if (piece.startsWith("`") && piece.endsWith("`") && piece.length > 1) {
|
|
32
37
|
out.push({ kind: "code", text: piece.slice(1, -1) });
|
|
38
|
+
} else if (link) {
|
|
39
|
+
// Only web and mail links open; any other scheme (javascript:, file:) shows as its text.
|
|
40
|
+
out.push(/^(https?:|mailto:)/i.test(link[2]) ? { kind: "link", text: link[1], url: link[2] } : { kind: "text", text: link[1] });
|
|
41
|
+
} else if (/^https?:\/\//.test(piece)) {
|
|
42
|
+
out.push({ kind: "link", text: piece, url: piece });
|
|
33
43
|
} else if ((piece.startsWith("**") && piece.endsWith("**")) || (piece.startsWith("__") && piece.endsWith("__"))) {
|
|
34
44
|
out.push({ kind: "bold", text: piece.slice(2, -2) });
|
|
35
45
|
} else if ((piece.startsWith("*") && piece.endsWith("*")) || (piece.startsWith("_") && piece.endsWith("_"))) {
|
package/shared/genui.test.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { mkdir, rm, symlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { describe, expect, it } from "vitest";
|
|
4
|
-
import type {
|
|
5
|
+
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
5
6
|
import {
|
|
6
7
|
collectLoads,
|
|
7
8
|
compile,
|
|
@@ -26,8 +27,11 @@ import {
|
|
|
26
27
|
loadAgentImage,
|
|
27
28
|
loadGalleryFile,
|
|
28
29
|
readGallerySpec,
|
|
30
|
+
setExtraLoadFolders,
|
|
29
31
|
} from "../server/data-source";
|
|
30
32
|
|
|
33
|
+
type PaseoApi = PluginHandlerContext["paseo"];
|
|
34
|
+
|
|
31
35
|
describe("paseo-plugin-genui core, instructions, and gallery", () => {
|
|
32
36
|
it("compiles every example in the agent instructions cleanly", () => {
|
|
33
37
|
for (const section of [
|
|
@@ -234,4 +238,52 @@ describe("paseo-plugin-genui core, instructions, and gallery", () => {
|
|
|
234
238
|
await rm(testRoot, { recursive: true, force: true });
|
|
235
239
|
}
|
|
236
240
|
});
|
|
241
|
+
it("loads files from extra folders only once they are added in settings", async () => {
|
|
242
|
+
const folder = path.join(os.homedir(), `.genui-extra-folder-test-${Date.now()}`);
|
|
243
|
+
await mkdir(folder, { recursive: true });
|
|
244
|
+
try {
|
|
245
|
+
const file = path.join(folder, "notes.txt");
|
|
246
|
+
await writeFile(file, "scratch-line\n", "utf8");
|
|
247
|
+
const mockPaseo = {
|
|
248
|
+
agents: { ref: () => ({ current: () => ({ cwd: "/nonexistent-workspace" }), refresh: async () => null }) },
|
|
249
|
+
} as unknown as PaseoApi;
|
|
250
|
+
const tilde = `~/${path.basename(folder)}/notes.txt`;
|
|
251
|
+
|
|
252
|
+
expect((await loadAgentFile(mockPaseo, "agent_extra_test", file, { raw: true })).ok).toBe(false);
|
|
253
|
+
|
|
254
|
+
setExtraLoadFolders([`~/${path.basename(folder)}`]);
|
|
255
|
+
expect(await loadAgentFile(mockPaseo, "agent_extra_test", file, { raw: true })).toEqual({ ok: true, value: "scratch-line\n" });
|
|
256
|
+
expect(await loadAgentFile(mockPaseo, "agent_extra_test", tilde, { raw: true })).toEqual({ ok: true, value: "scratch-line\n" });
|
|
257
|
+
expect((await loadAgentFile(mockPaseo, "agent_extra_test", path.join(os.homedir(), ".bashrc"), { raw: true })).ok).toBe(false);
|
|
258
|
+
} finally {
|
|
259
|
+
setExtraLoadFolders([]);
|
|
260
|
+
await rm(folder, { recursive: true, force: true });
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
describe("Draft", () => {
|
|
266
|
+
it("is in the catalog and compiles with and without a title", () => {
|
|
267
|
+
expect(COMPONENTS.Draft.group).toBe("Content");
|
|
268
|
+
for (const call of ['Draft("**hi**")', 'Draft("**hi**", "PR reply")']) {
|
|
269
|
+
const compiled = compile(`Card("x", [${call}])`);
|
|
270
|
+
expect(compiled.diagnostics, call).toEqual([]);
|
|
271
|
+
expect(compiled.program).not.toBeNull();
|
|
272
|
+
}
|
|
273
|
+
expect(compile('Card("x", [Draft()])').diagnostics.length).toBeGreaterThan(0);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("keeps the draft label in the markdown fallback", async () => {
|
|
277
|
+
const load = (req: { path: string }) => loadGalleryFile(req.path, req);
|
|
278
|
+
const untitled = await renderReplyMarkdown('```ui\nDraft("Looks good")\n```', load);
|
|
279
|
+
expect(untitled).toContain("**Draft**");
|
|
280
|
+
expect(untitled).toContain("Looks good");
|
|
281
|
+
const titled = await renderReplyMarkdown('```ui\nDraft("Looks good", "PR reply")\n```', load);
|
|
282
|
+
expect(titled).toContain("**Draft: PR reply**");
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("is listed in the agent reference with a rule against markdown Code", () => {
|
|
286
|
+
expect(UI_REFERENCE).toContain("Draft(markdown, title?)");
|
|
287
|
+
expect(CODE_WORK_INSTRUCTIONS).toContain("Draft(markdown, title)");
|
|
288
|
+
});
|
|
237
289
|
});
|
package/shared/instructions.ts
CHANGED
|
@@ -28,7 +28,7 @@ Syntax: one statement per line. \`$x = 8\` is state inputs bind to; \`name = exp
|
|
|
28
28
|
Components (? optional; tone: neutral|good|warn|bad|info if meaningful; more in the next section):
|
|
29
29
|
${componentLines(REFERENCE_GROUPS)}
|
|
30
30
|
Actions: ${actionList}; a list runs in order; Send posts as the user.
|
|
31
|
-
Data: Load("path") reads JSON/CSV/TSV/JSONL from the workspace, "$BB_THREAD_STORAGE/x.json" or /tmp into lists and objects, and other files (a log, tsc output) as text; never retype values a file or command output holds. Snippet and Image read files the same way.
|
|
31
|
+
Data: Load("path") reads JSON/CSV/TSV/JSONL from the workspace, "$BB_THREAD_STORAGE/x.json" or /tmp into lists and objects, and other files (a log, tsc output) as text; never retype values a file or command output holds. Snippet and Image read files the same way. Any other path fails to load: copy the file into $BB_THREAD_STORAGE first.
|
|
32
32
|
Games, simulations, custom visuals: write \`\`\`app, a self-contained HTML page (inline CSS/JS, CSS vars --foreground --muted-foreground --border --primary --card; sandboxed, no network).`;
|
|
33
33
|
|
|
34
34
|
export const UI_REFERENCE_MORE = `# Inline UI reference, continued
|
|
@@ -49,6 +49,7 @@ Replies here are read in Paseo, which draws these components; pasted output, a m
|
|
|
49
49
|
- outdated or vulnerable packages → Dependencies: \`npm outdated --json --long\`, \`npm audit --json\`, \`pip list --outdated --format=json\`
|
|
50
50
|
- a CI run → Pipeline: \`gh run view <id> --json name,displayTitle,status,conclusion,event,headBranch,headSha,url,createdAt,updatedAt,jobs\`
|
|
51
51
|
- timings you measured (before/after, A vs B) → Benchmark([{name, before, after, unit}]) or Load(\`hyperfine --export-json\`); a page load → Waterfall(Load(a HAR)); what takes space → Treemap(Load(\`du -k -d 2 <dir>\` or an esbuild metafile))
|
|
52
|
+
- text the user must approve before it is posted (PR comments, replies, messages) → Draft(markdown, title), never Code(…, "markdown")
|
|
52
53
|
- an API response → Json(Load(…)) from \`curl -s -o\`
|
|
53
54
|
- what you changed → Changes(); a commit → Changes(sha); this branch's commits → Commits(); the pull request → PullRequest(); subthreads → Threads()
|
|
54
55
|
- tasks or issues → Board(Load(…)) from \`gh issue list --json number,title,state,labels,assignees,url,updatedAt\`
|
|
@@ -133,10 +134,11 @@ export const AGENT_INSTRUCTIONS_WEB_OFF = AGENT_INSTRUCTIONS.replace(MAP_EXAMPLE
|
|
|
133
134
|
|
|
134
135
|
export const GENUI_MARKER = "[paseo-plugin-genui]";
|
|
135
136
|
|
|
136
|
-
export function buildFullInstructions(webLookups: boolean): string {
|
|
137
|
+
export function buildFullInstructions(webLookups: boolean, extraFolders: readonly string[] = []): string {
|
|
137
138
|
return [
|
|
138
139
|
GENUI_MARKER,
|
|
139
140
|
UI_REFERENCE,
|
|
141
|
+
...(extraFolders.length > 0 ? [`Load, Snippet and Image also read absolute paths under: ${extraFolders.join(", ")}.`] : []),
|
|
140
142
|
UI_REFERENCE_MORE,
|
|
141
143
|
CODE_WORK_INSTRUCTIONS,
|
|
142
144
|
webLookups ? AGENT_INSTRUCTIONS : AGENT_INSTRUCTIONS_WEB_OFF,
|