@koinzhang/paseo-plugin-customize 0.1.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/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +58 -0
- package/client/category-visibility.test.ts +26 -0
- package/client/design-tokens.test.ts +39 -0
- package/client/design-tokens.ts +104 -0
- package/client/dropdown.tsx +139 -0
- package/client/entries.test.ts +50 -0
- package/client/entries.ts +47 -0
- package/client/entry-row.tsx +89 -0
- package/client/mechanism-card.tsx +75 -0
- package/client/preview-pane.tsx +101 -0
- package/client/provider-options.test.ts +31 -0
- package/client/provider-options.ts +37 -0
- package/client/query-policy.test.ts +57 -0
- package/client/query-policy.ts +20 -0
- package/client/route.ts +29 -0
- package/client/selection-settings.test.ts +16 -0
- package/client/slash-command.test.ts +94 -0
- package/client/slash-command.ts +36 -0
- package/client/surface.tsx +332 -0
- package/client/ui.tsx +265 -0
- package/client/use-app-language.ts +28 -0
- package/client/web.ts +111 -0
- package/index.client.tsx +57 -0
- package/index.server.ts +13 -0
- package/package.json +37 -0
- package/paseo-plugin.json +6 -0
- package/server/agent-plugins.ts +41 -0
- package/server/compatibility.test.ts +104 -0
- package/server/compatibility.ts +46 -0
- package/server/frontmatter.ts +49 -0
- package/server/glob.ts +46 -0
- package/server/handlers.ts +193 -0
- package/server/jsonc.ts +40 -0
- package/server/mcp.ts +87 -0
- package/server/parsers.test.ts +92 -0
- package/server/providers/acp.ts +186 -0
- package/server/providers/claude.ts +284 -0
- package/server/providers/codex.ts +219 -0
- package/server/providers/copilot.ts +116 -0
- package/server/providers/cursor.ts +194 -0
- package/server/providers/omp.ts +263 -0
- package/server/providers/opencode.ts +215 -0
- package/server/providers/pi.ts +102 -0
- package/server/providers.test.ts +306 -0
- package/server/scan-kit.ts +368 -0
- package/server/scan-snapshot.test.ts +56 -0
- package/server/scan-snapshot.ts +58 -0
- package/server/skill-aliases.ts +60 -0
- package/server/toml.ts +240 -0
- package/server/yaml-lite.ts +172 -0
- package/shared/acp-configs.ts +107 -0
- package/shared/category-visibility.ts +26 -0
- package/shared/compatibility.ts +6 -0
- package/shared/contracts.ts +116 -0
- package/shared/i18n.ts +293 -0
- package/shared/mechanisms.ts +380 -0
- package/shared/providers.ts +27 -0
- package/shared/selection-settings.ts +14 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
2
|
+
import { useState, type ReactNode } from "react";
|
|
3
|
+
import { Pressable, Text, View } from "react-native";
|
|
4
|
+
import type { Mechanism } from "../shared/mechanisms.ts";
|
|
5
|
+
import type { AppLanguage, Messages } from "../shared/i18n.ts";
|
|
6
|
+
import { CONTROL, FONT_WEIGHT, ICON_SIZE, RADIUS, TEXT } from "./design-tokens.ts";
|
|
7
|
+
import type { Colors } from "./ui.tsx";
|
|
8
|
+
|
|
9
|
+
/** Collapsible “How it loads” note: first fact always visible, locations and the rest on expand. */
|
|
10
|
+
export function MechanismCard({
|
|
11
|
+
mechanism,
|
|
12
|
+
language,
|
|
13
|
+
colors,
|
|
14
|
+
m,
|
|
15
|
+
}: {
|
|
16
|
+
mechanism: Mechanism;
|
|
17
|
+
language: AppLanguage;
|
|
18
|
+
colors: Colors;
|
|
19
|
+
m: Messages;
|
|
20
|
+
}): ReactNode {
|
|
21
|
+
const [open, setOpen] = useState(false);
|
|
22
|
+
const pick = (text: { en: string; zh: string }) => (language === "zh-CN" ? text.zh : text.en);
|
|
23
|
+
const [first, ...rest] = mechanism.notes;
|
|
24
|
+
const expandable = mechanism.locations.length > 0 || rest.length > 0;
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<View
|
|
28
|
+
style={{
|
|
29
|
+
borderRadius: RADIUS.overlay,
|
|
30
|
+
borderWidth: 1,
|
|
31
|
+
borderColor: colors.border,
|
|
32
|
+
backgroundColor: colors.surface1,
|
|
33
|
+
paddingHorizontal: 12,
|
|
34
|
+
paddingVertical: 8,
|
|
35
|
+
gap: 6,
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
<Pressable
|
|
39
|
+
accessibilityRole="button"
|
|
40
|
+
accessibilityState={{ expanded: open }}
|
|
41
|
+
accessibilityLabel={open ? m.hideDetails : m.showDetails}
|
|
42
|
+
disabled={!expandable}
|
|
43
|
+
hitSlop={CONTROL.hitSlop}
|
|
44
|
+
onPress={() => setOpen((prev) => !prev)}
|
|
45
|
+
style={{ flexDirection: "row", alignItems: "flex-start", gap: 8 }}
|
|
46
|
+
>
|
|
47
|
+
<View style={{ paddingTop: 1 }}>
|
|
48
|
+
<Icon name={mechanism.supported ? "Info" : "Ban"} size={ICON_SIZE.inline} color={colors.foregroundMuted} />
|
|
49
|
+
</View>
|
|
50
|
+
<Text style={{ ...TEXT.meta, color: colors.foreground, flex: 1 }}>
|
|
51
|
+
<Text style={{ fontWeight: FONT_WEIGHT.semibold }}>{mechanism.supported ? m.howItWorks : m.unsupported}</Text>
|
|
52
|
+
{first ? ` ${pick(first)}` : ""}
|
|
53
|
+
</Text>
|
|
54
|
+
{expandable ? <Icon name={open ? "ChevronUp" : "ChevronDown"} size={ICON_SIZE.inline} color={colors.foregroundMuted} /> : null}
|
|
55
|
+
</Pressable>
|
|
56
|
+
{open ? (
|
|
57
|
+
<View style={{ gap: 6, paddingLeft: 22 }}>
|
|
58
|
+
{mechanism.locations.map((location, index) => (
|
|
59
|
+
<View key={index} style={{ flexDirection: "row", gap: 8 }}>
|
|
60
|
+
<Text style={{ ...TEXT.meta, color: colors.foregroundMuted, minWidth: 56 }}>{m.scopes[location.scope]}</Text>
|
|
61
|
+
<Text style={{ ...TEXT.path, color: colors.foreground, flex: 1 }} selectable>
|
|
62
|
+
{location.path}
|
|
63
|
+
</Text>
|
|
64
|
+
</View>
|
|
65
|
+
))}
|
|
66
|
+
{rest.map((note, index) => (
|
|
67
|
+
<Text key={index} style={{ ...TEXT.meta, color: colors.foregroundMuted }}>
|
|
68
|
+
• {pick(note)}
|
|
69
|
+
</Text>
|
|
70
|
+
))}
|
|
71
|
+
</View>
|
|
72
|
+
) : null}
|
|
73
|
+
</View>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { openExternalUrl, useRpc } from "@getpaseo/plugin/client";
|
|
2
|
+
import { ScrollView, copyText, useToast } from "@getpaseo/plugin/client/react-native";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
|
+
import type { ReactNode } from "react";
|
|
5
|
+
import { Text, View } from "react-native";
|
|
6
|
+
import { openRpc, previewRpc, type Entry } from "../shared/contracts.ts";
|
|
7
|
+
import { formatBytes, type Messages } from "../shared/i18n.ts";
|
|
8
|
+
import { RADIUS, TEXT } from "./design-tokens.ts";
|
|
9
|
+
import { entryMeta } from "./entry-row.tsx";
|
|
10
|
+
import { ErrorState, IconButton, LoadingState, StatusBadge, TextButton, type Colors } from "./ui.tsx";
|
|
11
|
+
|
|
12
|
+
export function PreviewPane({
|
|
13
|
+
entry,
|
|
14
|
+
onClose,
|
|
15
|
+
colors,
|
|
16
|
+
compact,
|
|
17
|
+
m,
|
|
18
|
+
}: {
|
|
19
|
+
entry: Entry;
|
|
20
|
+
onClose: () => void;
|
|
21
|
+
colors: Colors;
|
|
22
|
+
compact: boolean;
|
|
23
|
+
m: Messages;
|
|
24
|
+
}): ReactNode {
|
|
25
|
+
const preview = useRpc(previewRpc);
|
|
26
|
+
const open = useRpc(openRpc);
|
|
27
|
+
const toast = useToast();
|
|
28
|
+
const isUrl = entry.tags.includes("url");
|
|
29
|
+
const query = useQuery({
|
|
30
|
+
queryKey: ["customize", "preview", entry.path, entry.mcp?.name ?? null],
|
|
31
|
+
queryFn: () => preview({ path: entry.path, ...(entry.mcp ? { mcpName: entry.mcp.name } : {}) }),
|
|
32
|
+
enabled: !isUrl,
|
|
33
|
+
staleTime: 5_000,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const run = (reveal: boolean) => {
|
|
37
|
+
if (isUrl) {
|
|
38
|
+
void openExternalUrl(entry.path).catch((error: unknown) => toast.error(`${m.preview.openFailed}: ${String(error)}`));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
open({ path: entry.path, reveal }).catch((error: unknown) =>
|
|
42
|
+
toast.error(`${m.preview.openFailed}: ${error instanceof Error ? error.message : String(error)}`),
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const data = query.data;
|
|
47
|
+
return (
|
|
48
|
+
<View style={{ flex: 1, minHeight: 0, gap: 8, paddingHorizontal: compact ? 16 : 24, paddingTop: 12, paddingBottom: compact ? 12 : 16 }}>
|
|
49
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
|
|
50
|
+
<Text style={{ ...TEXT.rowTitle, color: colors.foreground, flexShrink: 1 }} numberOfLines={1}>
|
|
51
|
+
{entry.name}
|
|
52
|
+
</Text>
|
|
53
|
+
<StatusBadge status={entry.status} label={m.statuses[entry.status]} colors={colors} />
|
|
54
|
+
<View style={{ flex: 1 }} />
|
|
55
|
+
<TextButton icon="ExternalLink" label={m.preview.open} onPress={() => run(false)} colors={colors} />
|
|
56
|
+
{!compact && !isUrl ? <TextButton icon="FolderOpen" label={m.preview.reveal} onPress={() => run(true)} colors={colors} /> : null}
|
|
57
|
+
<IconButton
|
|
58
|
+
icon="Copy"
|
|
59
|
+
label={m.preview.copyPath}
|
|
60
|
+
color={colors.foregroundMuted}
|
|
61
|
+
onPress={() => {
|
|
62
|
+
copyText(entry.path).then(() => toast.show(m.preview.copied), () => {});
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
<IconButton icon="X" label={m.preview.close} color={colors.foregroundMuted} onPress={onClose} />
|
|
66
|
+
</View>
|
|
67
|
+
<Text style={{ ...TEXT.path, color: colors.foregroundMuted }} numberOfLines={2} selectable>
|
|
68
|
+
{entry.path}
|
|
69
|
+
</Text>
|
|
70
|
+
<Text style={{ ...TEXT.meta, color: colors.foregroundMuted }} numberOfLines={2}>
|
|
71
|
+
{entryMeta(entry, m, true)}
|
|
72
|
+
</Text>
|
|
73
|
+
<ScrollView
|
|
74
|
+
style={{ flex: 1, minHeight: 0, borderRadius: RADIUS.block, backgroundColor: colors.surface1 }}
|
|
75
|
+
contentContainerStyle={{ padding: 12, gap: 8 }}
|
|
76
|
+
>
|
|
77
|
+
{isUrl ? (
|
|
78
|
+
<Text style={{ ...TEXT.small, color: colors.foregroundMuted }}>{m.preview.url}</Text>
|
|
79
|
+
) : query.isPending ? (
|
|
80
|
+
<LoadingState color={colors.foregroundMuted} />
|
|
81
|
+
) : query.isError ? (
|
|
82
|
+
<ErrorState error={query.error} onRetry={() => void query.refetch()} colors={colors} />
|
|
83
|
+
) : data?.kind === "missing" ? (
|
|
84
|
+
<Text style={{ ...TEXT.small, color: colors.foregroundMuted }}>{m.preview.missing}</Text>
|
|
85
|
+
) : data?.kind === "directory" ? (
|
|
86
|
+
<Text style={{ ...TEXT.small, color: colors.foregroundMuted }}>{m.preview.directory}</Text>
|
|
87
|
+
) : (
|
|
88
|
+
<>
|
|
89
|
+
{data?.kind === "mcp" ? <Text style={{ ...TEXT.caption, color: colors.foregroundMuted }}>{m.preview.redacted}</Text> : null}
|
|
90
|
+
<Text style={{ ...TEXT.code, color: colors.foreground }} selectable>
|
|
91
|
+
{data?.content ?? ""}
|
|
92
|
+
</Text>
|
|
93
|
+
{data?.truncated ? (
|
|
94
|
+
<Text style={{ ...TEXT.caption, color: colors.foregroundMuted }}>{m.preview.truncated(formatBytes(data.bytes))}</Text>
|
|
95
|
+
) : null}
|
|
96
|
+
</>
|
|
97
|
+
)}
|
|
98
|
+
</ScrollView>
|
|
99
|
+
</View>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { enabledProviderOptions, selectedProvider } from "./provider-options.ts";
|
|
4
|
+
|
|
5
|
+
test("only enabled providers with Customize scanners appear, including unavailable ones", () => {
|
|
6
|
+
const options = enabledProviderOptions([
|
|
7
|
+
{ provider: "claude", enabled: false, source: "builtin" },
|
|
8
|
+
{ provider: "codex", enabled: true, source: "builtin", label: "My Codex" },
|
|
9
|
+
{ provider: "cursor", enabled: true, source: "custom", label: "Cursor" },
|
|
10
|
+
{ provider: "pi", enabled: true, source: "builtin" },
|
|
11
|
+
{ provider: "gemini", enabled: true, source: "custom" },
|
|
12
|
+
], "Built-in");
|
|
13
|
+
|
|
14
|
+
assert.deepEqual(options, [
|
|
15
|
+
{ id: "codex", label: "My Codex", badge: "Built-in" },
|
|
16
|
+
{ id: "cursor", label: "Cursor", badge: "ACP" },
|
|
17
|
+
{ id: "pi", label: "Pi", badge: "Built-in" },
|
|
18
|
+
{ id: "gemini", label: "Gemini CLI", badge: "ACP" },
|
|
19
|
+
]);
|
|
20
|
+
assert.equal(selectedProvider("claude", options), "codex");
|
|
21
|
+
assert.equal(selectedProvider("cursor", options), "cursor");
|
|
22
|
+
assert.equal(selectedProvider("claude", []), null);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("snapshot duplicates and older source omissions keep one option", () => {
|
|
26
|
+
const options = enabledProviderOptions([
|
|
27
|
+
{ provider: "cursor", enabled: true },
|
|
28
|
+
{ provider: "cursor", enabled: true, source: "custom" },
|
|
29
|
+
], "内置");
|
|
30
|
+
assert.deepEqual(options, [{ id: "cursor", label: "Cursor", badge: "ACP" }]);
|
|
31
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { PROVIDER_IDS, PROVIDER_LABELS, type ProviderId } from "../shared/providers.ts";
|
|
2
|
+
|
|
3
|
+
export interface ProviderSnapshotOptionEntry {
|
|
4
|
+
provider: string;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
source?: "builtin" | "custom";
|
|
7
|
+
label?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ProviderMenuOption {
|
|
11
|
+
id: ProviderId;
|
|
12
|
+
label: string;
|
|
13
|
+
badge: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const BUILTIN_IDS = new Set<ProviderId>(["claude", "codex", "copilot", "opencode", "pi", "omp"]);
|
|
17
|
+
|
|
18
|
+
/** Only providers with a Customize scanner can be offered. */
|
|
19
|
+
export function enabledProviderOptions(
|
|
20
|
+
entries: readonly ProviderSnapshotOptionEntry[],
|
|
21
|
+
builtinLabel: string,
|
|
22
|
+
): ProviderMenuOption[] {
|
|
23
|
+
const byId = new Map(entries.map((entry) => [entry.provider, entry]));
|
|
24
|
+
return PROVIDER_IDS.flatMap((id) => {
|
|
25
|
+
const entry = byId.get(id);
|
|
26
|
+
if (!entry?.enabled) return [];
|
|
27
|
+
return [{
|
|
28
|
+
id,
|
|
29
|
+
label: entry.label || PROVIDER_LABELS[id],
|
|
30
|
+
badge: entry.source === "custom" || (entry.source == null && !BUILTIN_IDS.has(id)) ? "ACP" : builtinLabel,
|
|
31
|
+
}];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function selectedProvider(saved: ProviderId, options: readonly ProviderMenuOption[]): ProviderId | null {
|
|
36
|
+
return options.some((option) => option.id === saved) ? saved : options[0]?.id ?? null;
|
|
37
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { QueryClient, QueryObserver } from "@tanstack/react-query";
|
|
4
|
+
import { newestScan, SCAN_QUERY_POLICY, shouldScanSnapshot } from "./query-policy.ts";
|
|
5
|
+
|
|
6
|
+
test("fresh persisted snapshots skip scans and stale snapshots trigger them", () => {
|
|
7
|
+
assert.equal(shouldScanSnapshot({ stale: false }, false, false), false);
|
|
8
|
+
assert.equal(shouldScanSnapshot({ stale: true }, false, false), true);
|
|
9
|
+
assert.equal(shouldScanSnapshot(undefined, true, false), false);
|
|
10
|
+
assert.equal(shouldScanSnapshot(undefined, false, true), true);
|
|
11
|
+
const saved = { scannedAt: "2026-01-01T00:00:00.000Z", entries: ["old"] };
|
|
12
|
+
const live = { scannedAt: "2026-01-02T00:00:00.000Z", entries: ["new"] };
|
|
13
|
+
assert.deepEqual(newestScan(saved, live), live);
|
|
14
|
+
assert.deepEqual(newestScan(live, saved), live);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("a revisited scan paints cached entries while refreshing and retains them after a refresh error", async () => {
|
|
18
|
+
const client = new QueryClient();
|
|
19
|
+
const key = ["customize", "scan", "codex", "/project"];
|
|
20
|
+
const cached = { entries: ["old"] };
|
|
21
|
+
client.setQueryData(key, cached);
|
|
22
|
+
|
|
23
|
+
let rejectRefresh: (error: Error) => void = () => {};
|
|
24
|
+
const observer = new QueryObserver(client, {
|
|
25
|
+
queryKey: key,
|
|
26
|
+
queryFn: () => new Promise<{ entries: string[] }>((_resolve, reject) => { rejectRefresh = reject; }),
|
|
27
|
+
retry: false,
|
|
28
|
+
...SCAN_QUERY_POLICY,
|
|
29
|
+
});
|
|
30
|
+
const unsubscribe = observer.subscribe(() => {});
|
|
31
|
+
assert.deepEqual(observer.getCurrentResult().data, cached);
|
|
32
|
+
assert.equal(observer.getCurrentResult().fetchStatus, "fetching");
|
|
33
|
+
|
|
34
|
+
const settled = new Promise<void>((resolve) => {
|
|
35
|
+
const stop = observer.subscribe((result) => {
|
|
36
|
+
if (result.fetchStatus === "idle" && result.isError) {
|
|
37
|
+
stop();
|
|
38
|
+
resolve();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
rejectRefresh(new Error("offline"));
|
|
43
|
+
await settled;
|
|
44
|
+
assert.deepEqual(observer.getCurrentResult().data, cached);
|
|
45
|
+
unsubscribe();
|
|
46
|
+
assert.deepEqual(client.getQueryData(key), cached);
|
|
47
|
+
|
|
48
|
+
const firstVisit = new QueryObserver(client, {
|
|
49
|
+
queryKey: ["customize", "scan", "cursor", "/project"],
|
|
50
|
+
queryFn: async () => ({ entries: ["new"] }),
|
|
51
|
+
...SCAN_QUERY_POLICY,
|
|
52
|
+
});
|
|
53
|
+
const stopFirstVisit = firstVisit.subscribe(() => {});
|
|
54
|
+
assert.equal(firstVisit.getCurrentResult().isPending, true);
|
|
55
|
+
stopFirstVisit();
|
|
56
|
+
client.clear();
|
|
57
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Preserve results for this plugin/host lifetime and reload saved metadata when revisited. */
|
|
2
|
+
export const REVISIT_QUERY_POLICY = {
|
|
3
|
+
gcTime: Infinity,
|
|
4
|
+
refetchOnMount: "always",
|
|
5
|
+
} as const;
|
|
6
|
+
|
|
7
|
+
export const SCAN_QUERY_POLICY = {
|
|
8
|
+
...REVISIT_QUERY_POLICY,
|
|
9
|
+
staleTime: 0,
|
|
10
|
+
} as const;
|
|
11
|
+
|
|
12
|
+
export function shouldScanSnapshot(saved: { stale: boolean } | undefined, fetching: boolean, failed: boolean): boolean {
|
|
13
|
+
return !fetching && (saved?.stale ?? failed);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function newestScan<T extends { scannedAt: string }>(saved: T | null | undefined, live: T | null | undefined): T | null {
|
|
17
|
+
if (!saved) return live ?? null;
|
|
18
|
+
if (!live) return saved;
|
|
19
|
+
return Date.parse(live.scannedAt) >= Date.parse(saved.scannedAt) ? live : saved;
|
|
20
|
+
}
|
package/client/route.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const BASE64_PREFIX = "b64_";
|
|
2
|
+
|
|
3
|
+
function decodeBase64Url(value: string): string | null {
|
|
4
|
+
try {
|
|
5
|
+
const padded = value.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(value.length / 4) * 4, "=");
|
|
6
|
+
const binary = globalThis.atob(padded);
|
|
7
|
+
return new TextDecoder().decode(Uint8Array.from(binary, (char) => char.charCodeAt(0)));
|
|
8
|
+
} catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Workspace id from a Paseo host route (`/h/<server>/workspace/<id>[/…]`), mirroring
|
|
15
|
+
* `decodeWorkspaceIdFromPathSegment` in `packages/app/src/utils/host-routes.ts`.
|
|
16
|
+
*/
|
|
17
|
+
export function workspaceIdFromPath(pathname: string): string | null {
|
|
18
|
+
const match = pathname.split(/[?#]/)[0]?.match(/^\/h\/[^/]+\/workspace\/([^/]+)/);
|
|
19
|
+
if (!match?.[1]) return null;
|
|
20
|
+
let segment: string;
|
|
21
|
+
try {
|
|
22
|
+
segment = decodeURIComponent(match[1]).trim();
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (!segment) return null;
|
|
27
|
+
if (segment.startsWith(BASE64_PREFIX)) return decodeBase64Url(segment.slice(BASE64_PREFIX.length))?.trim() || null;
|
|
28
|
+
return segment;
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { selectionSettings } from "../shared/selection-settings.ts";
|
|
4
|
+
|
|
5
|
+
test("board selection defaults only before a project is chosen", () => {
|
|
6
|
+
assert.deepEqual(selectionSettings.schema.parse({}), { provider: "claude", projectRoot: null });
|
|
7
|
+
assert.deepEqual(selectionSettings.schema.parse({ provider: "codex", projectRoot: "" }), {
|
|
8
|
+
provider: "codex",
|
|
9
|
+
projectRoot: "",
|
|
10
|
+
});
|
|
11
|
+
assert.deepEqual(selectionSettings.schema.parse({ provider: "pi", projectRoot: "/project" }), {
|
|
12
|
+
provider: "pi",
|
|
13
|
+
projectRoot: "/project",
|
|
14
|
+
});
|
|
15
|
+
assert.equal(selectionSettings.schema.safeParse({ provider: "unknown" }).success, false);
|
|
16
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import type { PluginAgentCommandContext } from "@getpaseo/plugin/client";
|
|
4
|
+
import { openCustomizeFromAgent } from "./slash-command.ts";
|
|
5
|
+
|
|
6
|
+
function commandContext(provider: string, projectRootPath: string, rpc: (name: string, input: unknown) => Promise<unknown>) {
|
|
7
|
+
const opened: string[] = [];
|
|
8
|
+
const context = {
|
|
9
|
+
agent: { provider },
|
|
10
|
+
workspace: { projectRootPath },
|
|
11
|
+
rpc: (contract: { name: string }, input: unknown) => rpc(contract.name, input),
|
|
12
|
+
openSurface: (id: string) => opened.push(id),
|
|
13
|
+
} as unknown as PluginAgentCommandContext;
|
|
14
|
+
return { context, opened };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test("/customize selects the current agent provider and workspace project", async () => {
|
|
18
|
+
const calls: Array<{ name: string; input: unknown }> = [];
|
|
19
|
+
const { context, opened } = commandContext("codex", "/repo", async (name, input) => {
|
|
20
|
+
calls.push({ name, input });
|
|
21
|
+
return name.endsWith(".read")
|
|
22
|
+
? { status: "ready", revision: "one", values: { provider: "claude", projectRoot: "/old" } }
|
|
23
|
+
: { status: "saved", revision: "two", values: { provider: "codex", projectRoot: "/repo" } };
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
await openCustomizeFromAgent(context);
|
|
27
|
+
|
|
28
|
+
assert.deepEqual(calls, [
|
|
29
|
+
{ name: "settings.board-selection.read", input: {} },
|
|
30
|
+
{ name: "settings.board-selection.write", input: { revision: "one", values: { provider: "codex", projectRoot: "/repo" } } },
|
|
31
|
+
]);
|
|
32
|
+
assert.deepEqual(opened, ["customize"]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("/customize updates each available selection and keeps the unavailable one", async () => {
|
|
36
|
+
const cases = [
|
|
37
|
+
{ provider: "", project: "/repo", expected: { provider: "claude", projectRoot: "/repo" } },
|
|
38
|
+
{ provider: "codex", project: "", expected: { provider: "codex", projectRoot: "/old" } },
|
|
39
|
+
{ provider: "unknown", project: "/repo", expected: { provider: "claude", projectRoot: "/repo" } },
|
|
40
|
+
];
|
|
41
|
+
for (const { provider, project, expected } of cases) {
|
|
42
|
+
const calls: Array<{ name: string; input: unknown }> = [];
|
|
43
|
+
const { context, opened } = commandContext(provider, project, async (name, input) => {
|
|
44
|
+
calls.push({ name, input });
|
|
45
|
+
return name.endsWith(".read")
|
|
46
|
+
? { status: "ready", revision: "one", values: { provider: "claude", projectRoot: "/old" } }
|
|
47
|
+
: { status: "saved", revision: "two", values: expected };
|
|
48
|
+
});
|
|
49
|
+
await openCustomizeFromAgent(context);
|
|
50
|
+
assert.deepEqual(calls, [
|
|
51
|
+
{ name: "settings.board-selection.read", input: {} },
|
|
52
|
+
{ name: "settings.board-selection.write", input: { revision: "one", values: expected } },
|
|
53
|
+
]);
|
|
54
|
+
assert.deepEqual(opened, ["customize"]);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("/customize only opens the board when neither selection is available", async () => {
|
|
59
|
+
const { context, opened } = commandContext("unknown", "", async () => {
|
|
60
|
+
throw new Error("Settings should not be read");
|
|
61
|
+
});
|
|
62
|
+
await openCustomizeFromAgent(context);
|
|
63
|
+
assert.deepEqual(opened, ["customize"]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("/customize retries a conflicting selection with the latest revision", async () => {
|
|
67
|
+
const writes: unknown[] = [];
|
|
68
|
+
let reads = 0;
|
|
69
|
+
const { context, opened } = commandContext("pi", "/repo", async (name, input) => {
|
|
70
|
+
if (name.endsWith(".read")) {
|
|
71
|
+
reads++;
|
|
72
|
+
return { status: "ready", revision: `revision-${reads}`, values: { provider: "claude", projectRoot: "/another" } };
|
|
73
|
+
}
|
|
74
|
+
writes.push(input);
|
|
75
|
+
return writes.length === 1 ? { status: "conflict", error: "revision changed" } : { status: "saved", revision: "revision-3", values: {} };
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await openCustomizeFromAgent(context);
|
|
79
|
+
|
|
80
|
+
assert.equal(reads, 2);
|
|
81
|
+
assert.deepEqual(writes, [
|
|
82
|
+
{ revision: "revision-1", values: { provider: "pi", projectRoot: "/repo" } },
|
|
83
|
+
{ revision: "revision-2", values: { provider: "pi", projectRoot: "/repo" } },
|
|
84
|
+
]);
|
|
85
|
+
assert.deepEqual(opened, ["customize"]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("/customize opens the board when settings cannot be read", async () => {
|
|
89
|
+
const { context, opened } = commandContext("codex", "/repo", async () => {
|
|
90
|
+
throw new Error("offline");
|
|
91
|
+
});
|
|
92
|
+
await assert.rejects(openCustomizeFromAgent(context), /offline/);
|
|
93
|
+
assert.deepEqual(opened, ["customize"]);
|
|
94
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { settingsRpc } from "@getpaseo/plugin";
|
|
2
|
+
import type { PluginAgentCommandContext } from "@getpaseo/plugin/client";
|
|
3
|
+
import { isProviderId } from "../shared/providers.ts";
|
|
4
|
+
import { selectionSettings } from "../shared/selection-settings.ts";
|
|
5
|
+
|
|
6
|
+
const { read, write } = settingsRpc(selectionSettings.id);
|
|
7
|
+
|
|
8
|
+
/** Navigate even if the current agent cannot supply a usable board selection. */
|
|
9
|
+
export async function openCustomizeFromAgent({ agent, workspace, rpc, openSurface }: PluginAgentCommandContext): Promise<void> {
|
|
10
|
+
const provider = isProviderId(agent.provider) ? agent.provider : null;
|
|
11
|
+
const projectRoot = workspace.projectRootPath?.trim() ? workspace.projectRootPath : null;
|
|
12
|
+
try {
|
|
13
|
+
if (!provider && !projectRoot) return;
|
|
14
|
+
|
|
15
|
+
// Preserve the rest of the host-scoped document and retry once if another client writes first.
|
|
16
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
17
|
+
const current = await rpc(read, {});
|
|
18
|
+
if (current.status !== "ready") return;
|
|
19
|
+
const parsed = selectionSettings.schema.safeParse(current.values);
|
|
20
|
+
if (!parsed.success) return;
|
|
21
|
+
|
|
22
|
+
const values = {
|
|
23
|
+
...parsed.data,
|
|
24
|
+
...(provider ? { provider } : {}),
|
|
25
|
+
...(projectRoot ? { projectRoot } : {}),
|
|
26
|
+
};
|
|
27
|
+
if (parsed.data.provider === values.provider && parsed.data.projectRoot === values.projectRoot) return;
|
|
28
|
+
const result = await rpc(write, { revision: current.revision, values });
|
|
29
|
+
if (result.status === "saved") return;
|
|
30
|
+
if (result.status !== "conflict") throw new Error(result.error);
|
|
31
|
+
}
|
|
32
|
+
throw new Error("Customize selection changed concurrently; try again");
|
|
33
|
+
} finally {
|
|
34
|
+
openSurface("customize");
|
|
35
|
+
}
|
|
36
|
+
}
|