@koinzhang/paseo-plugin-customize 0.2.1 → 0.3.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 +27 -0
- package/README.md +6 -2
- package/client/design-tokens.ts +6 -0
- package/client/dropdown.tsx +41 -34
- package/client/entry-card.tsx +86 -0
- package/client/entry-row.tsx +16 -4
- package/client/grid.test.ts +19 -0
- package/client/grid.ts +18 -0
- package/client/preview-pane.tsx +10 -3
- package/client/provider-options.test.ts +16 -5
- package/client/provider-options.ts +14 -3
- package/client/selection-settings.test.ts +5 -2
- package/client/slash-command.test.ts +23 -6
- package/client/surface.tsx +141 -89
- package/client/ui.tsx +25 -1
- package/index.client.tsx +3 -3
- package/package.json +1 -1
- package/server/compatibility.test.ts +13 -0
- package/server/handlers.ts +9 -4
- package/server/provider-version.test.ts +74 -0
- package/server/provider-version.ts +60 -0
- package/server/providers/opencode.ts +25 -8
- package/server/providers.test.ts +48 -3
- package/server/scan-kit.ts +2 -1
- package/server/scan-snapshot.test.ts +9 -9
- package/server/scan-snapshot.ts +1 -1
- package/server/tokens.test.ts +146 -0
- package/server/tokens.ts +178 -0
- package/shared/contracts.ts +14 -0
- package/shared/i18n.ts +29 -0
- package/shared/mechanisms.ts +15 -5
- package/shared/selection-settings.ts +1 -0
package/client/surface.tsx
CHANGED
|
@@ -9,10 +9,12 @@ import { messagesFor } from "../shared/i18n.ts";
|
|
|
9
9
|
import { MECHANISMS, mechanismFor } from "../shared/mechanisms.ts";
|
|
10
10
|
import { type ProviderId } from "../shared/providers.ts";
|
|
11
11
|
import { selectionSettings } from "../shared/selection-settings.ts";
|
|
12
|
-
import { CONTROL, ICON_SIZE, PREVIEW_FRACTION, RADIUS, TEXT, pageLayout, titleGap } from "./design-tokens.ts";
|
|
12
|
+
import { CONTROL, GRID, ICON_SIZE, PREVIEW_FRACTION, RADIUS, TEXT, pageLayout, titleGap } from "./design-tokens.ts";
|
|
13
13
|
import { Dropdown, type DropdownOption } from "./dropdown.tsx";
|
|
14
14
|
import { countByCategory, countSkillInvocation, groupEntries, matchesSkillInvocation, projectLabel, SKILL_INVOCATION_FILTERS, type SkillInvocationFilter } from "./entries.ts";
|
|
15
|
+
import { EntryCard } from "./entry-card.tsx";
|
|
15
16
|
import { EntryRow } from "./entry-row.tsx";
|
|
17
|
+
import { cardWidth, gridColumns } from "./grid.ts";
|
|
16
18
|
import { MechanismCard } from "./mechanism-card.tsx";
|
|
17
19
|
import { PreviewPane } from "./preview-pane.tsx";
|
|
18
20
|
import { enabledProviderOptions, selectedProvider } from "./provider-options.ts";
|
|
@@ -77,6 +79,9 @@ export function CustomizeSurface({ theme, layout }: PluginSurfaceProps): ReactNo
|
|
|
77
79
|
const [searchFocused, setSearchFocused] = useState(false);
|
|
78
80
|
const [skillFilter, setSkillFilter] = useState<SkillInvocationFilter>("all");
|
|
79
81
|
const [selected, setSelected] = useState<Entry | null>(null);
|
|
82
|
+
const [contentWidth, setContentWidth] = useState(0);
|
|
83
|
+
const viewLayout = settings.status === "ready" ? settings.values.layout : "list";
|
|
84
|
+
const cardWidthValue = cardWidth(contentWidth, gridColumns(contentWidth));
|
|
80
85
|
|
|
81
86
|
const setProvider = (id: string) => {
|
|
82
87
|
if (settings.status !== "ready" || settings.saving || !providerOptions.some((option) => option.id === id)) return;
|
|
@@ -88,6 +93,10 @@ export function CustomizeSurface({ theme, layout }: PluginSurfaceProps): ReactNo
|
|
|
88
93
|
setSearchFocused(false);
|
|
89
94
|
setSelected(null);
|
|
90
95
|
};
|
|
96
|
+
const toggleLayout = () => {
|
|
97
|
+
if (settings.status !== "ready" || settings.saving) return;
|
|
98
|
+
void settings.save({ ...settings.values, layout: viewLayout === "list" ? "card" : "list" }, settings.revision);
|
|
99
|
+
};
|
|
91
100
|
|
|
92
101
|
useEffect(() => {
|
|
93
102
|
setCategoryState((current) => resolveCategory(provider, current));
|
|
@@ -136,7 +145,7 @@ export function CustomizeSurface({ theme, layout }: PluginSurfaceProps): ReactNo
|
|
|
136
145
|
() => groupEntries(entries, activeCategory, query, skillFilter),
|
|
137
146
|
[entries, activeCategory, query, skillFilter],
|
|
138
147
|
);
|
|
139
|
-
const mechanism = mechanismFor(provider, activeCategory, displayed?.compatibility);
|
|
148
|
+
const mechanism = mechanismFor(provider, activeCategory, displayed?.compatibility, displayed?.providerVersion);
|
|
140
149
|
const compatibility = displayed?.compatibility;
|
|
141
150
|
const compatibilityState = compatibility?.source === "builtIn" ? "supported"
|
|
142
151
|
: compatibility?.enabled === true ? "on" : compatibility?.enabled === false ? "off" : "unknown";
|
|
@@ -190,7 +199,7 @@ export function CustomizeSurface({ theme, layout }: PluginSurfaceProps): ReactNo
|
|
|
190
199
|
return (
|
|
191
200
|
<View style={{ flex: 1, minHeight: 0, backgroundColor: colors.surface0 }}>
|
|
192
201
|
<View style={{ flex: selected ? 1 - (compact ? PREVIEW_FRACTION.compact : PREVIEW_FRACTION.regular) : 1, minHeight: 0 }}>
|
|
193
|
-
<View style={{ paddingHorizontal: page.padding, paddingTop: page.padding, gap: titleGap(compact), zIndex: 1 }}>
|
|
202
|
+
<View style={{ paddingHorizontal: page.padding, paddingTop: page.padding, paddingBottom: titleGap(compact), gap: titleGap(compact), zIndex: 1 }}>
|
|
194
203
|
<View
|
|
195
204
|
style={{
|
|
196
205
|
flexDirection: "row",
|
|
@@ -199,23 +208,34 @@ export function CustomizeSurface({ theme, layout }: PluginSurfaceProps): ReactNo
|
|
|
199
208
|
zIndex: 30,
|
|
200
209
|
}}
|
|
201
210
|
>
|
|
202
|
-
<View style={{ flexDirection: "row", alignItems: "center", gap: 14, flexShrink: 1, minWidth: 0 }}>
|
|
203
|
-
{
|
|
204
|
-
|
|
205
|
-
<
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
211
|
+
<View style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", justifyContent: "flex-end", gap: 14, flexShrink: 1, minWidth: 0 }}>
|
|
212
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 8, flexShrink: 1, minWidth: 0 }}>
|
|
213
|
+
{compatibility ? (
|
|
214
|
+
<View accessible accessibilityRole="image" accessibilityLabel={m.compatibility(compatibilityState)}>
|
|
215
|
+
<Icon name={compatibilityState === "off" ? "Link2Off" : "Link2"} size={ICON_SIZE.action} color={compatibilityState === "on" || compatibilityState === "supported" ? colors.statusSuccess : compatibilityState === "off" ? colors.foregroundMuted : colors.statusWarning} />
|
|
216
|
+
</View>
|
|
217
|
+
) : null}
|
|
218
|
+
{displayed?.providerVersion?.version ? (
|
|
219
|
+
<Text
|
|
220
|
+
style={{ ...TEXT.meta, color: colors.foregroundMuted, maxWidth: CONTROL.providerVersionMaxWidth, flexShrink: 1 }}
|
|
221
|
+
numberOfLines={1}
|
|
222
|
+
accessibilityLabel={m.providerVersion(`v${displayed.providerVersion.version}`)}
|
|
223
|
+
>
|
|
224
|
+
{`v${displayed.providerVersion.version}`}
|
|
225
|
+
</Text>
|
|
226
|
+
) : null}
|
|
227
|
+
<Dropdown
|
|
228
|
+
label={m.provider}
|
|
229
|
+
options={providerOptions}
|
|
230
|
+
value={provider}
|
|
231
|
+
onChange={setProvider}
|
|
232
|
+
colors={colors}
|
|
233
|
+
triggerLabel={m.chooseProvider}
|
|
234
|
+
closeLabel={m.closeMenu}
|
|
235
|
+
menuAlign={compact ? "left" : "right"}
|
|
236
|
+
disabled={settings.saving}
|
|
237
|
+
/>
|
|
238
|
+
</View>
|
|
219
239
|
<Dropdown
|
|
220
240
|
label={m.project}
|
|
221
241
|
options={projectOptions}
|
|
@@ -235,6 +255,7 @@ export function CustomizeSurface({ theme, layout }: PluginSurfaceProps): ReactNo
|
|
|
235
255
|
icon="RefreshCw"
|
|
236
256
|
label={m.refresh}
|
|
237
257
|
color={colors.foregroundMuted}
|
|
258
|
+
size={ICON_SIZE.inline}
|
|
238
259
|
busy={result.isFetching}
|
|
239
260
|
tooltip={displayed ? {
|
|
240
261
|
text: m.lastScanned(new Date(displayed.scannedAt).toLocaleString(language)),
|
|
@@ -249,7 +270,7 @@ export function CustomizeSurface({ theme, layout }: PluginSurfaceProps): ReactNo
|
|
|
249
270
|
</View>
|
|
250
271
|
<View style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 8 }}>
|
|
251
272
|
<CategoryTabs options={tabs} value={activeCategory} onChange={setCategory} colors={colors} />
|
|
252
|
-
<View style={{
|
|
273
|
+
<View style={{ flexGrow: 1, flexShrink: 1, minWidth: 0, flexDirection: "row", flexWrap: "wrap", justifyContent: "flex-end", alignItems: "center", gap: 8 }}>
|
|
253
274
|
{mechanism.supported && activeCategory === "skills" ? (
|
|
254
275
|
<SegmentedControl
|
|
255
276
|
label={m.skillInvocation}
|
|
@@ -261,35 +282,45 @@ export function CustomizeSurface({ theme, layout }: PluginSurfaceProps): ReactNo
|
|
|
261
282
|
) : null}
|
|
262
283
|
<MechanismCard key={`${provider}:${activeCategory}`} mechanism={mechanism} language={language} colors={colors} m={m} compact={compact} />
|
|
263
284
|
{mechanism.supported ? (
|
|
264
|
-
<View
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
285
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 6, flexShrink: 1, minWidth: 0 }}>
|
|
286
|
+
<View
|
|
287
|
+
style={{
|
|
288
|
+
width: 220,
|
|
289
|
+
minWidth: 180,
|
|
290
|
+
flexShrink: 1,
|
|
291
|
+
flexDirection: "row",
|
|
292
|
+
alignItems: "center",
|
|
293
|
+
gap: 6,
|
|
294
|
+
height: CONTROL.searchHeight,
|
|
295
|
+
paddingHorizontal: 10,
|
|
296
|
+
borderRadius: RADIUS.control,
|
|
297
|
+
borderWidth: 1,
|
|
298
|
+
borderColor: searchFocused ? colors.foregroundMuted : colors.border,
|
|
299
|
+
backgroundColor: colors.surface1,
|
|
300
|
+
}}
|
|
301
|
+
>
|
|
302
|
+
<Icon name="Search" size={ICON_SIZE.inline} color={colors.foregroundMuted} />
|
|
303
|
+
<TextInput
|
|
304
|
+
value={query}
|
|
305
|
+
onChangeText={setQuery}
|
|
306
|
+
onFocus={() => setSearchFocused(true)}
|
|
307
|
+
onBlur={() => setSearchFocused(false)}
|
|
308
|
+
placeholder={m.search}
|
|
309
|
+
placeholderTextColor={colors.foregroundMuted}
|
|
310
|
+
accessibilityLabel={m.search}
|
|
311
|
+
autoCorrect={false}
|
|
312
|
+
autoCapitalize="none"
|
|
313
|
+
style={{ flex: 1, ...TEXT.small, color: colors.foreground, paddingVertical: 0, borderWidth: 0, ...(Platform.OS === "web" ? ({ outlineStyle: "none" } as object) : null) }}
|
|
314
|
+
/>
|
|
315
|
+
{queryActive ? <IconButton icon="X" label={m.preview.close} color={colors.foregroundMuted} size={ICON_SIZE.inline} onPress={() => setQuery("")} /> : null}
|
|
316
|
+
</View>
|
|
317
|
+
<IconButton
|
|
318
|
+
icon={viewLayout === "card" ? "List" : "LayoutGrid"}
|
|
319
|
+
label={viewLayout === "card" ? m.showList : m.showCards}
|
|
320
|
+
color={colors.foregroundMuted}
|
|
321
|
+
disabled={settings.saving}
|
|
322
|
+
onPress={toggleLayout}
|
|
291
323
|
/>
|
|
292
|
-
{queryActive ? <IconButton icon="X" label={m.preview.close} color={colors.foregroundMuted} size={ICON_SIZE.inline} onPress={() => setQuery("")} /> : null}
|
|
293
324
|
</View>
|
|
294
325
|
) : null}
|
|
295
326
|
</View>
|
|
@@ -300,50 +331,71 @@ export function CustomizeSurface({ theme, layout }: PluginSurfaceProps): ReactNo
|
|
|
300
331
|
|
|
301
332
|
<ScrollView
|
|
302
333
|
style={{ flex: 1, minHeight: 0, ...(Platform.OS === "web" ? ({ scrollbarWidth: "none", msOverflowStyle: "none" } as object) : null) }}
|
|
303
|
-
contentContainerStyle={{ paddingHorizontal: page.padding, paddingTop: page.gap, paddingBottom: page.padding
|
|
334
|
+
contentContainerStyle={{ paddingHorizontal: page.padding, paddingTop: page.gap, paddingBottom: page.padding }}
|
|
304
335
|
keyboardShouldPersistTaps="handled"
|
|
305
336
|
showsVerticalScrollIndicator={false}
|
|
306
337
|
>
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
color={colors.foregroundMuted}
|
|
338
|
+
<View
|
|
339
|
+
style={{ gap: page.gap }}
|
|
340
|
+
onLayout={(event) => setContentWidth(event.nativeEvent.layout.width)}
|
|
341
|
+
>
|
|
342
|
+
{!displayed && (saved.isPending || result.isPending) ? (
|
|
343
|
+
<LoadingState color={colors.foregroundMuted} />
|
|
344
|
+
) : !displayed && (result.isError || saved.isError) ? (
|
|
345
|
+
<ErrorState error={result.error ?? saved.error} onRetry={() => void result.refetch()} colors={colors} />
|
|
346
|
+
) : !mechanism.supported ? null : (
|
|
347
|
+
groups.map((group) => (
|
|
348
|
+
<View key={group.scope} style={{ gap: titleGap(compact) }}>
|
|
349
|
+
<SectionHeader
|
|
350
|
+
title={m.scopes[group.scope]}
|
|
351
|
+
count={group.count}
|
|
352
|
+
colors={colors}
|
|
353
|
+
compact={compact}
|
|
324
354
|
/>
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
355
|
+
{group.count === 0 ? (
|
|
356
|
+
<InlineEmpty
|
|
357
|
+
text={listNarrowed ? m.noMatches : group.scope === "project" && !projectRoot ? m.noProject : m.emptyScope(m.scopes[group.scope])}
|
|
358
|
+
color={colors.foregroundMuted}
|
|
359
|
+
/>
|
|
360
|
+
) : (
|
|
361
|
+
group.sources.map((source) => (
|
|
362
|
+
<View key={source.source} style={{ gap: viewLayout === "card" ? GRID.labelGap : 2 }}>
|
|
363
|
+
<Text style={{ ...TEXT.path, color: colors.foregroundMuted, paddingBottom: 2 }} numberOfLines={1}>
|
|
364
|
+
{source.source}
|
|
365
|
+
</Text>
|
|
366
|
+
{viewLayout === "card" ? (
|
|
367
|
+
<View style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "stretch", gap: GRID.gap }}>
|
|
368
|
+
{source.entries.map((entry) => (
|
|
369
|
+
<EntryCard
|
|
370
|
+
key={entry.id}
|
|
371
|
+
entry={entry}
|
|
372
|
+
selected={selected?.id === entry.id}
|
|
373
|
+
onSelect={onSelect}
|
|
374
|
+
colors={colors}
|
|
375
|
+
m={m}
|
|
376
|
+
width={cardWidthValue}
|
|
377
|
+
/>
|
|
378
|
+
))}
|
|
379
|
+
</View>
|
|
380
|
+
) : (
|
|
381
|
+
source.entries.map((entry) => (
|
|
382
|
+
<EntryRow
|
|
383
|
+
key={entry.id}
|
|
384
|
+
entry={entry}
|
|
385
|
+
selected={selected?.id === entry.id}
|
|
386
|
+
onSelect={onSelect}
|
|
387
|
+
colors={colors}
|
|
388
|
+
m={m}
|
|
389
|
+
/>
|
|
390
|
+
))
|
|
391
|
+
)}
|
|
392
|
+
</View>
|
|
393
|
+
))
|
|
394
|
+
)}
|
|
395
|
+
</View>
|
|
396
|
+
))
|
|
397
|
+
)}
|
|
398
|
+
</View>
|
|
347
399
|
</ScrollView>
|
|
348
400
|
</View>
|
|
349
401
|
|
package/client/ui.tsx
CHANGED
|
@@ -195,7 +195,7 @@ export function CategoryTabs<T extends string>({
|
|
|
195
195
|
colors: Pick<Colors, "foreground" | "foregroundMuted">;
|
|
196
196
|
}): ReactNode {
|
|
197
197
|
return (
|
|
198
|
-
<View accessibilityRole="tablist" style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center",
|
|
198
|
+
<View accessibilityRole="tablist" style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", columnGap: 18, rowGap: 2, flexShrink: 1, minWidth: 0 }}>
|
|
199
199
|
{options.map((option) => {
|
|
200
200
|
const active = option.id === value;
|
|
201
201
|
return (
|
|
@@ -328,3 +328,27 @@ export function StatusBadge({ status, label, colors }: { status: Status; label:
|
|
|
328
328
|
</View>
|
|
329
329
|
);
|
|
330
330
|
}
|
|
331
|
+
|
|
332
|
+
/** Outlined token pill: same shell as `StatusBadge`, neutral color so it never competes with status. */
|
|
333
|
+
export function TokenBadge({ label, hint, colors }: { label: string; hint: string; colors: Colors }): ReactNode {
|
|
334
|
+
return (
|
|
335
|
+
<View
|
|
336
|
+
accessible
|
|
337
|
+
accessibilityLabel={hint}
|
|
338
|
+
style={{
|
|
339
|
+
height: CONTROL.pillBadgeHeight,
|
|
340
|
+
paddingHorizontal: 7,
|
|
341
|
+
borderRadius: pillRadius(CONTROL.pillBadgeHeight),
|
|
342
|
+
borderWidth: 1,
|
|
343
|
+
borderColor: colors.border,
|
|
344
|
+
alignItems: "center",
|
|
345
|
+
justifyContent: "center",
|
|
346
|
+
flexShrink: 0,
|
|
347
|
+
}}
|
|
348
|
+
>
|
|
349
|
+
<Text style={{ ...TEXT.pillBadge, color: colors.foregroundMuted }} numberOfLines={1}>
|
|
350
|
+
{label}
|
|
351
|
+
</Text>
|
|
352
|
+
</View>
|
|
353
|
+
);
|
|
354
|
+
}
|
package/index.client.tsx
CHANGED
|
@@ -10,10 +10,10 @@ const SURFACE_ID = "customize";
|
|
|
10
10
|
|
|
11
11
|
/** Command titles follow the app language; the host has no update(), so re-register on change. */
|
|
12
12
|
function addCommands(client: PluginClientContext): () => void {
|
|
13
|
-
const
|
|
13
|
+
const messages = messagesFor(currentAppLanguage());
|
|
14
14
|
const removeCommandCenterItem = client.addCommandCenterItem({
|
|
15
15
|
id: "open-customize",
|
|
16
|
-
title:
|
|
16
|
+
title: messages.title,
|
|
17
17
|
icon: "FolderCog",
|
|
18
18
|
keywords: ["customize", "agents.md", "claude.md", "rules", "skills", "mcp", "instructions", "provider"],
|
|
19
19
|
context: "global",
|
|
@@ -23,7 +23,7 @@ function addCommands(client: PluginClientContext): () => void {
|
|
|
23
23
|
});
|
|
24
24
|
const removeSlashCommand = client.addSlashCommand({
|
|
25
25
|
name: "customize",
|
|
26
|
-
description,
|
|
26
|
+
description: messages.openBoard,
|
|
27
27
|
argumentHint: "",
|
|
28
28
|
context: "agent",
|
|
29
29
|
onSubmit: openCustomizeFromAgent,
|
package/package.json
CHANGED
|
@@ -102,3 +102,16 @@ test("a changed compatibility switch makes an otherwise fresh snapshot stale", (
|
|
|
102
102
|
rmSync(paseoHome, { recursive: true, force: true });
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
|
+
|
|
106
|
+
test("OpenCode's mechanism preserves version-dependent behavior without repeating the toolbar version", () => {
|
|
107
|
+
const state = { enabled: true, source: "default" };
|
|
108
|
+
const v2 = mechanismFor("opencode", "skills", state, { version: "2.0.18", source: "host" });
|
|
109
|
+
assert.equal(v2.notes.some((note) => note.en.includes("2.0.18") || note.en.includes("host diagnostic")), false);
|
|
110
|
+
assert.ok(v2.notes.some((note) => note.zh.includes("仍可按 ID 显式加载")));
|
|
111
|
+
const v1 = mechanismFor("opencode", "skills", state, { version: "1.18.32", source: "cli" });
|
|
112
|
+
assert.equal(v1.notes.some((note) => note.en.includes("CLI fallback") || note.en.includes("1.18.32")), false);
|
|
113
|
+
assert.ok(v1.notes.some((note) => note.en.includes("v1 advertises")));
|
|
114
|
+
assert.equal(v1.notes.some((note) => note.en.includes("can still be loaded explicitly")), false);
|
|
115
|
+
const unknown = mechanismFor("opencode", "skills", state, { version: null, source: "unknown" });
|
|
116
|
+
assert.ok(unknown.notes.some((note) => note.en.includes("await version confirmation")));
|
|
117
|
+
});
|
package/server/handlers.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { homedir } from "node:os";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
import type { RpcInput, RpcOutput } from "@getpaseo/plugin";
|
|
6
|
+
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
6
7
|
import type { Entry } from "../shared/contracts.ts";
|
|
7
8
|
import { cachedScanRpc, openRpc, previewRpc, scanRpc } from "../shared/contracts.ts";
|
|
8
9
|
import type { ProviderId } from "../shared/providers.ts";
|
|
@@ -22,6 +23,8 @@ import { compatibilityFor } from "./compatibility.ts";
|
|
|
22
23
|
import { mergeSkillAliases } from "./skill-aliases.ts";
|
|
23
24
|
import { parseToml } from "./toml.ts";
|
|
24
25
|
import { parseYaml } from "./yaml-lite.ts";
|
|
26
|
+
import { detectProviderVersion } from "./provider-version.ts";
|
|
27
|
+
import { withTokens } from "./tokens.ts";
|
|
25
28
|
|
|
26
29
|
const execFileAsync = promisify(execFile);
|
|
27
30
|
|
|
@@ -62,15 +65,16 @@ function nestedIndex(root: string): NestedIndex {
|
|
|
62
65
|
return index;
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
export function scanProvider(provider: ProviderId, projectRoot: string | null, env: Pick<ScanContext, "home" | "env" | "platform">): Entry[] {
|
|
68
|
+
export function scanProvider(provider: ProviderId, projectRoot: string | null, env: Pick<ScanContext, "home" | "env" | "platform" | "providerVersion">): Entry[] {
|
|
66
69
|
const root = projectRoot && isDir(projectRoot) ? path.resolve(projectRoot) : null;
|
|
67
70
|
const ctx: ScanContext = { ...env, projectRoot: root, nested: root ? nestedIndex(root) : null };
|
|
68
|
-
return mergeSkillAliases(provider, SCANNERS[provider](ctx));
|
|
71
|
+
return withTokens(mergeSkillAliases(provider, SCANNERS[provider](ctx)));
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
export async function handleScan(input: RpcInput<typeof scanRpc
|
|
74
|
+
export async function handleScan(input: RpcInput<typeof scanRpc>, context?: PluginHandlerContext): Promise<RpcOutput<typeof scanRpc>> {
|
|
72
75
|
const home = homedir();
|
|
73
|
-
const
|
|
76
|
+
const providerVersion = await detectProviderVersion(input.provider, context ? (provider) => context.paseo.providers.diagnostic(provider) : undefined);
|
|
77
|
+
const entries = scanProvider(input.provider, input.projectRoot, { home, env: process.env, platform: process.platform, providerVersion });
|
|
74
78
|
const ctx: ScanContext = { home, env: process.env, platform: process.platform, projectRoot: input.projectRoot, nested: null };
|
|
75
79
|
for (const entry of entries) allowed.add(entry.path);
|
|
76
80
|
const result = {
|
|
@@ -79,6 +83,7 @@ export async function handleScan(input: RpcInput<typeof scanRpc>): Promise<RpcOu
|
|
|
79
83
|
home,
|
|
80
84
|
entries,
|
|
81
85
|
compatibility: compatibilityFor(input.provider, ctx),
|
|
86
|
+
providerVersion,
|
|
82
87
|
scannedAt: new Date().toISOString(),
|
|
83
88
|
};
|
|
84
89
|
try {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { detectProviderVersion, parseProviderVersion } from "./provider-version.ts";
|
|
4
|
+
import { PROVIDER_IDS } from "../shared/providers.ts";
|
|
5
|
+
|
|
6
|
+
test("OpenCode version parsing accepts CLI formats and rejects diagnostic error numbers", () => {
|
|
7
|
+
for (const [output, expected] of [
|
|
8
|
+
["1.18.32\n", "1.18.32"], ["v2.0.0", "2.0.0"], ["opencode v2.0.18\n", "2.0.18"],
|
|
9
|
+
["opencode v2.0.0-beta.1+local", "2.0.0-beta.1+local"],
|
|
10
|
+
["error: command 2.0.18 failed", null], ["/opt/opencode/2.0.18/bin", null], ["unknown", null], ["2.0", null],
|
|
11
|
+
] as const) assert.equal(parseProviderVersion("opencode", output), expected);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("provider versions support product labels, wrappers and date-based Cursor builds", () => {
|
|
15
|
+
for (const [provider, output, expected] of [
|
|
16
|
+
["claude", "2.1.0 (Claude Code)", "2.1.0"], ["claude", "@tencent/tclaude 0.1.8", "0.1.8"],
|
|
17
|
+
["codex", "codex-cli 0.157.1", "0.157.1"], ["cursor", "2026.09.26-dd393fe", "2026.09.26-dd393fe"],
|
|
18
|
+
["copilot", "GitHub Copilot CLI 0.0.400", "0.0.400"], ["pi", "0.87.1", "0.87.1"], ["omp", "omp/18.3.5", "18.3.5"],
|
|
19
|
+
["gemini", "0.52.0", "0.52.0"], ["kimi", "kimi, version 1.0.0", null],
|
|
20
|
+
["codex", "error: command 0.157.1 failed", null], ["cursor", "/opt/cursor/2026.09.26-dd393fe", null],
|
|
21
|
+
["omp", "error 18.3.5", null], ["pi", "unknown", null],
|
|
22
|
+
] as const) assert.equal(parseProviderVersion(provider, output), expected, output);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("host diagnostic wins over a different PATH CLI version", async () => {
|
|
26
|
+
const result = await detectProviderVersion("opencode", async (provider) => {
|
|
27
|
+
assert.equal(provider, "opencode");
|
|
28
|
+
return { provider, diagnostic: "OpenCode\n Configured command: /custom/opencode\n Version: opencode v2.0.18\n Auth: Not checked", requestId: "test" };
|
|
29
|
+
}, async () => { throw new Error("Fallback must not run"); });
|
|
30
|
+
assert.deepEqual(result, { version: "2.0.18", source: "host" });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("missing, failed, unparseable and timed-out host diagnostics use a bounded CLI fallback", async () => {
|
|
34
|
+
const fallback = async (command: string, args: string[], options: { timeout: number; maxBuffer: number }) => {
|
|
35
|
+
assert.equal(command, "opencode");
|
|
36
|
+
assert.deepEqual(args, ["--version"]);
|
|
37
|
+
assert.equal(options.timeout, 3000);
|
|
38
|
+
assert.equal(options.maxBuffer, 32 * 1024);
|
|
39
|
+
return { stdout: "opencode v2.0.18" };
|
|
40
|
+
};
|
|
41
|
+
const missingVersion = async (provider: string) => ({ provider, diagnostic: "Version: error: 2.0.18 failed", requestId: "test" });
|
|
42
|
+
const unavailable = async () => { throw new Error("Host unavailable"); };
|
|
43
|
+
const hanging = () => new Promise<never>(() => {});
|
|
44
|
+
for (const diagnostic of [undefined, missingVersion, unavailable, hanging]) {
|
|
45
|
+
assert.deepEqual(await detectProviderVersion("opencode", diagnostic, fallback, 10), { version: "2.0.18", source: "cli" });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("failed or unparseable CLI versions stay unknown without failing scans", async () => {
|
|
50
|
+
for (const run of [async () => { throw new Error("ENOENT"); }, async () => ({ stdout: "unknown" })]) {
|
|
51
|
+
assert.deepEqual(await detectProviderVersion("opencode", undefined, run), { version: null, source: "unknown" });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("all Customize providers use their own host diagnostic, preserving configured overrides", async () => {
|
|
56
|
+
for (const provider of PROVIDER_IDS) {
|
|
57
|
+
const result = await detectProviderVersion(provider, async (requested) => {
|
|
58
|
+
assert.equal(requested, provider);
|
|
59
|
+
return { provider, diagnostic: "Provider\n Version: 1.2.3", requestId: "test" };
|
|
60
|
+
}, async () => { throw new Error("Fallback must not run"); });
|
|
61
|
+
assert.deepEqual(result, { version: "1.2.3", source: "host" });
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("CLI fallbacks use actual binary names and never install ACP packages", async () => {
|
|
66
|
+
for (const [provider, binary] of [["cursor", "cursor-agent"], ["codebuddy-code", "codebuddy"], ["kiro", "kiro-cli"], ["qwen-code", "qwen"]] as const) {
|
|
67
|
+
const result = await detectProviderVersion(provider, undefined, async (command, args) => {
|
|
68
|
+
assert.equal(command, binary);
|
|
69
|
+
assert.deepEqual(args, ["--version"]);
|
|
70
|
+
return { stdout: "1.2.3" };
|
|
71
|
+
});
|
|
72
|
+
assert.deepEqual(result, { version: "1.2.3", source: "cli" });
|
|
73
|
+
}
|
|
74
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
4
|
+
import type { ProviderVersion } from "../shared/contracts.ts";
|
|
5
|
+
import type { ProviderId } from "../shared/providers.ts";
|
|
6
|
+
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
8
|
+
type Diagnostic = PluginHandlerContext["paseo"]["providers"]["diagnostic"];
|
|
9
|
+
type VersionRunner = (command: string, args: string[], options: { timeout: number; maxBuffer: number }) => Promise<{ stdout: string }>;
|
|
10
|
+
|
|
11
|
+
/** Local binaries only; package runners could install software while probing. */
|
|
12
|
+
const VERSION_BINARIES: Record<ProviderId, string> = {
|
|
13
|
+
claude: "claude", codex: "codex", cursor: "cursor-agent", copilot: "copilot", opencode: "opencode", pi: "pi", omp: "omp",
|
|
14
|
+
cline: "cline", "codebuddy-code": "codebuddy", gemini: "gemini", goose: "goose", grok: "grok", kilo: "kilo",
|
|
15
|
+
kiro: "kiro-cli", kimi: "kimi", "qwen-code": "qwen", traecli: "traecli",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Accept version output, not arbitrary numbers in diagnostic errors or paths. */
|
|
19
|
+
export function parseProviderVersion(provider: ProviderId, output: string): string | null {
|
|
20
|
+
const text = output.trim();
|
|
21
|
+
if (provider === "opencode") {
|
|
22
|
+
return /^(?:opencode\s+)?v?(\d+\.\d+\.\d+(?:-[\da-z.-]+)?(?:\+[\da-z.-]+)?)$/i.exec(text)?.[1] ?? null;
|
|
23
|
+
}
|
|
24
|
+
if (text.length > 200 || /\b(?:error|failed|failure|unknown|unavailable)\b/i.test(text)) return null;
|
|
25
|
+
// Product prefixes, e.g. codex-cli / @tencent/tclaude / omp/, and
|
|
26
|
+
// suffix labels, e.g. 2.1.0 (Claude Code). Date-based Cursor builds also fit.
|
|
27
|
+
return /^(?:[a-z@][a-z\d@._/-]*(?:[ \t]+[a-z][a-z\d._-]*)*[ \t/]+)?v?(\d+\.\d+\.\d+(?:-[\da-z.-]+)?(?:\+[\da-z.-]+)?)(?:[ \t]+\([a-z][a-z \t-]*\))?$/i.exec(text)?.[1] ?? null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function detectProviderVersion(
|
|
31
|
+
provider: ProviderId,
|
|
32
|
+
diagnostic?: Diagnostic,
|
|
33
|
+
run: VersionRunner = execFileAsync,
|
|
34
|
+
hostTimeoutMs = 5000,
|
|
35
|
+
): Promise<ProviderVersion> {
|
|
36
|
+
if (diagnostic) {
|
|
37
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
38
|
+
try {
|
|
39
|
+
const response = await Promise.race([
|
|
40
|
+
diagnostic(provider),
|
|
41
|
+
new Promise<never>((_, reject) => { timer = setTimeout(() => reject(new Error("Provider diagnostic timed out")), hostTimeoutMs); }),
|
|
42
|
+
]);
|
|
43
|
+
const row = /^\s*Version:[ \t]*(.*)$/m.exec(response.diagnostic)?.[1];
|
|
44
|
+
const version = row ? parseProviderVersion(provider, row) : null;
|
|
45
|
+
if (version) return { version, source: "host" };
|
|
46
|
+
} catch {
|
|
47
|
+
// Older hosts and unavailable providers can still have a usable PATH CLI.
|
|
48
|
+
} finally {
|
|
49
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const { stdout } = await run(VERSION_BINARIES[provider], ["--version"], { timeout: 3000, maxBuffer: 32 * 1024 });
|
|
54
|
+
const version = parseProviderVersion(provider, stdout);
|
|
55
|
+
if (version) return { version, source: "cli" };
|
|
56
|
+
} catch {
|
|
57
|
+
// Missing binaries, timeout and failed version commands do not fail a scan.
|
|
58
|
+
}
|
|
59
|
+
return { version: null, source: "unknown" };
|
|
60
|
+
}
|