Skip to content

Commit 5cdef05

Browse files
fix(channels): preserve empty docs prefixes (#103794)
Co-authored-by: Vincent Koc <[email protected]> Co-authored-by: Leon-SK668 <[email protected]>
1 parent 9fc5037 commit 5cdef05

9 files changed

Lines changed: 137 additions & 20 deletions

‎docs/plugins/sdk-setup.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ The released `setup`/`ChannelSetupInput` adapter stays available for existing ex
179179
| `aliases` | `string[]` | Extra lookup aliases for channel selection. |
180180
| `preferOver` | `string[]` | Lower-priority plugin/channel ids this channel should outrank. |
181181
| `systemImage` | `string` | Optional icon/system-image name for channel UI catalogs. |
182-
| `selectionDocsPrefix` | `string` | Prefix text before docs links in selection surfaces. |
182+
| `selectionDocsPrefix` | `string` | Prefix before docs links; omit for default or use `""` to suppress it. |
183183
| `selectionDocsOmitLabel` | `boolean` | Show the docs path directly instead of a labeled docs link in selection copy. |
184184
| `selectionExtras` | `string[]` | Extra short strings appended in selection copy. |
185185
| `markdownCapable` | `boolean` | Marks the channel as markdown-capable for outbound formatting decisions. |

‎src/channels/chat-meta-shared.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ function toChatChannelMeta(params: {
3737
detailLabel: normalizeOptionalString(params.channel.detailLabel),
3838
systemImage: normalizeOptionalString(params.channel.systemImage),
3939
arrayFieldMode: "non-empty",
40-
selectionDocsPrefixMode: "defined",
4140
});
4241
}
4342

‎src/channels/plugins/catalog.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,36 @@ function writeChannelCatalog(
5353
}
5454

5555
describe("channel plugin catalog", () => {
56+
it.each([
57+
["omitted", undefined, undefined],
58+
["empty", "", ""],
59+
["spaced", " See docs: ", " See docs: "],
60+
] as const)("preserves %s selection docs prefixes", (_label, prefix, expected) => {
61+
listChannelCatalogEntriesMock.mockReturnValue([
62+
{
63+
pluginId: "workspace-chat",
64+
origin: "workspace",
65+
rootDir: "/tmp/workspace-chat",
66+
packageName: "@workspace/chat",
67+
channel: {
68+
id: "custom-chat",
69+
label: "Custom Chat",
70+
selectionLabel: "Custom Chat",
71+
docsPath: "/channels/custom-chat",
72+
blurb: "workspace",
73+
...(prefix !== undefined ? { selectionDocsPrefix: prefix } : {}),
74+
},
75+
install: { localPath: "/tmp/workspace-chat" },
76+
},
77+
] satisfies PluginChannelCatalogEntry[]);
78+
79+
const entry = getChannelPluginCatalogEntry("custom-chat", {
80+
workspaceDir: "/tmp",
81+
});
82+
83+
expect(entry?.meta.selectionDocsPrefix).toBe(expected);
84+
});
85+
5686
it("keeps third-party channel ids mapped with catalog install trust", () => {
5787
const options = {
5888
workspaceDir: "/tmp/openclaw-channel-catalog-empty-workspace",

‎src/channels/plugins/catalog.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ function buildCatalogEntryFromManifest(params: {
304304
detailLabel: channel.detailLabel?.trim(),
305305
...(systemImage ? { systemImage } : {}),
306306
arrayFieldMode: "defined",
307-
selectionDocsPrefixMode: "truthy",
308307
}),
309308
install,
310309
installSource: describePluginInstallSource(install, {

‎src/channels/plugins/channel-meta.ts‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { resolveChannelExposure } from "./exposure.js";
88
import type { ChannelMeta } from "./types.core.js";
99

1010
type ArrayFieldMode = "defined" | "non-empty";
11-
type OptionalStringMode = "defined" | "truthy";
1211

1312
/**
1413
* Builds normalized channel metadata from a plugin manifest channel declaration.
@@ -24,14 +23,9 @@ export function buildManifestChannelMeta(params: {
2423
detailLabel?: string;
2524
systemImage?: string;
2625
arrayFieldMode: ArrayFieldMode;
27-
selectionDocsPrefixMode: OptionalStringMode;
2826
}): ChannelMeta {
2927
const hasArrayField = (value: readonly string[] | undefined) =>
3028
params.arrayFieldMode === "defined" ? value !== undefined : Boolean(value?.length);
31-
const hasSelectionDocsPrefix =
32-
params.selectionDocsPrefixMode === "defined"
33-
? params.channel.selectionDocsPrefix !== undefined
34-
: Boolean(params.channel.selectionDocsPrefix);
3529

3630
return {
3731
id: params.id,
@@ -42,7 +36,9 @@ export function buildManifestChannelMeta(params: {
4236
blurb: params.blurb,
4337
...(hasArrayField(params.channel.aliases) ? { aliases: params.channel.aliases } : {}),
4438
...(params.channel.order !== undefined ? { order: params.channel.order } : {}),
45-
...(hasSelectionDocsPrefix ? { selectionDocsPrefix: params.channel.selectionDocsPrefix } : {}),
39+
...(typeof params.channel.selectionDocsPrefix === "string"
40+
? { selectionDocsPrefix: params.channel.selectionDocsPrefix }
41+
: {}),
4642
...(params.channel.selectionDocsOmitLabel !== undefined
4743
? { selectionDocsOmitLabel: params.channel.selectionDocsOmitLabel }
4844
: {}),

‎src/flows/channel-setup.status.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,42 @@ describe("resolveChannelSetupSelectionContributions", () => {
547547
expect(lines).toEqual(["Zalo\\nBot — Setup\\nhelp"]);
548548
});
549549

550+
it.each([
551+
["empty", "", ""],
552+
["whitespace", " \t ", "Docs:"],
553+
["control-only", "\u001B[2K\u0007", "Docs:"],
554+
] as const)("normalizes %s selection docs prefixes", (_label, prefix, expected) => {
555+
resolveChannelSetupEntries.mockReturnValue(
556+
makeChannelSetupEntries({
557+
entries: [
558+
{
559+
id: "custom-chat",
560+
meta: {
561+
id: "custom-chat",
562+
label: "Custom Chat",
563+
selectionLabel: "Custom Chat",
564+
docsPath: "/channels/custom-chat",
565+
blurb: "External channel.",
566+
selectionDocsPrefix: prefix,
567+
},
568+
},
569+
],
570+
}),
571+
);
572+
573+
resolveChannelSelectionNoteLines({
574+
cfg: {} as never,
575+
installedPlugins: [],
576+
selection: ["custom-chat"],
577+
});
578+
579+
const [selectionMeta] = requireFirstMockCall(
580+
formatChannelSelectionLine.mock.calls,
581+
"selection line",
582+
);
583+
expect(selectionMeta?.selectionDocsPrefix).toBe(expected);
584+
});
585+
550586
it("localizes built-in channel blurbs before selection notes", () => {
551587
resolveChannelSetupEntries.mockReturnValue(
552588
makeChannelSetupEntries({

‎src/flows/channel-setup.status.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,23 @@ function formatSetupDisplayList(values: readonly string[] | undefined): string[]
153153
}
154154

155155
function formatSetupDisplayMeta(meta: ChannelMeta): ChannelMeta {
156+
const { selectionDocsPrefix, ...displayMeta } = meta;
156157
const safeId = formatSetupDisplayText(meta.id, "<invalid channel>");
157158
const safeLabel = formatSetupDisplayText(meta.label, safeId);
158-
const safeSelectionDocsPrefix = formatSetupOptionalDisplayText(meta.selectionDocsPrefix);
159+
const safeSelectionDocsPrefix =
160+
selectionDocsPrefix === "" ? "" : formatSetupOptionalDisplayText(selectionDocsPrefix?.trim());
159161
const safeSelectionExtras = formatSetupDisplayList(meta.selectionExtras);
160162
return {
161-
...meta,
163+
...displayMeta,
162164
id: safeId,
163165
label: safeLabel,
164166
selectionLabel: formatSetupDisplayText(meta.selectionLabel, safeLabel),
165167
docsPath: formatSetupDisplayText(meta.docsPath, "/"),
166168
...(meta.docsLabel ? { docsLabel: formatSetupDisplayText(meta.docsLabel, safeId) } : {}),
167169
blurb: formatSetupFreeText(meta.blurb),
168-
...(safeSelectionDocsPrefix ? { selectionDocsPrefix: safeSelectionDocsPrefix } : {}),
170+
...(safeSelectionDocsPrefix !== undefined
171+
? { selectionDocsPrefix: safeSelectionDocsPrefix }
172+
: {}),
169173
...(safeSelectionExtras ? { selectionExtras: safeSelectionExtras } : {}),
170174
};
171175
}
@@ -180,11 +184,12 @@ function formatChannelPrimerBlurb(channel: { id: string; blurb: string }): strin
180184
}
181185

182186
function formatChannelSelectionMeta(meta: ChannelMeta): ChannelMeta {
183-
return formatSetupDisplayMeta({
187+
const formatted = formatSetupDisplayMeta({
184188
...meta,
185189
blurb: formatChannelPrimerBlurb(meta),
186-
selectionDocsPrefix: meta.selectionDocsPrefix ?? t("common.docs"),
187190
});
191+
formatted.selectionDocsPrefix ??= t("common.docs");
192+
return formatted;
188193
}
189194

190195
function localizeChannelStatusLabel(label: string): string {

‎src/plugins/manifest-registry-installed.test.ts‎

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function deepFreeze<T>(value: T, seen = new WeakSet<object>()): T {
120120
return Object.freeze(value);
121121
}
122122

123-
function writePackageManifest(rootDir: string, channelLabel: string) {
123+
function writePackageManifest(rootDir: string, channelLabel: string, selectionDocsPrefix?: string) {
124124
const packageJsonPath = path.join(rootDir, "package.json");
125125
fs.writeFileSync(
126126
packageJsonPath,
@@ -134,6 +134,7 @@ function writePackageManifest(rootDir: string, channelLabel: string) {
134134
channel: {
135135
id: "installed",
136136
label: channelLabel,
137+
...(selectionDocsPrefix !== undefined ? { selectionDocsPrefix } : {}),
137138
},
138139
},
139140
}),
@@ -142,9 +143,12 @@ function writePackageManifest(rootDir: string, channelLabel: string) {
142143
return packageJsonPath;
143144
}
144145

145-
function createIndexWithPackageJson(rootDir: string): InstalledPluginIndex {
146+
function createIndexWithPackageJson(
147+
rootDir: string,
148+
selectionDocsPrefix?: string,
149+
): InstalledPluginIndex {
146150
const index = createIndexWithFileSignatures(rootDir);
147-
const packageJsonPath = writePackageManifest(rootDir, "Installed");
151+
const packageJsonPath = writePackageManifest(rootDir, "Installed", selectionDocsPrefix);
148152
const record = index.plugins[0];
149153
if (!record) {
150154
throw new Error("expected index record");
@@ -179,6 +183,16 @@ function createIndexWithUnhashedPackageJson(rootDir: string): InstalledPluginInd
179183
}
180184

181185
describe("loadPluginManifestRegistryForInstalledIndex", () => {
186+
const loadRegistry = (index: InstalledPluginIndex) =>
187+
loadPluginManifestRegistryForInstalledIndex({
188+
index,
189+
env: {
190+
OPENCLAW_VERSION: "2026.4.25",
191+
VITEST: "true",
192+
},
193+
includeDisabled: true,
194+
});
195+
182196
it("reuses frozen installed-index fingerprints when file signatures are persisted", () => {
183197
const rootDir = makeTempDir();
184198
writePlugin(rootDir, "installed", "installed-");
@@ -330,6 +344,38 @@ describe("loadPluginManifestRegistryForInstalledIndex", () => {
330344
});
331345
});
332346

347+
it("preserves empty docs prefixes from package channel metadata", () => {
348+
const rootDir = makeTempDir();
349+
writePlugin(rootDir, "installed", "installed-");
350+
351+
const registry = loadRegistry(createIndexWithPackageJson(rootDir, ""));
352+
353+
expect(registry.plugins[0]?.packageChannel?.selectionDocsPrefix).toBe("");
354+
});
355+
356+
it("preserves empty docs prefixes from persisted installed-index metadata", () => {
357+
const rootDir = makeTempDir();
358+
writePlugin(rootDir, "installed", "installed-");
359+
const index = createIndex(rootDir);
360+
const record = expectDefined(index.plugins[0], "index.plugins[0] test invariant");
361+
362+
const registry = loadRegistry({
363+
...index,
364+
plugins: [
365+
{
366+
...record,
367+
packageChannel: {
368+
id: "installed",
369+
label: "Installed",
370+
selectionDocsPrefix: "",
371+
},
372+
},
373+
],
374+
});
375+
376+
expect(registry.plugins[0]?.packageChannel?.selectionDocsPrefix).toBe("");
377+
});
378+
333379
it("reuses installed package json path validation across registry loads", () => {
334380
const rootDir = makeTempDir();
335381
writePlugin(rootDir, "installed", "installed-");

‎src/plugins/manifest-registry-installed.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import fs from "node:fs";
33
import path from "node:path";
44
import { isRecord } from "@openclaw/normalization-core/record-coerce";
5-
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
5+
import {
6+
normalizeOptionalString,
7+
readStringValue,
8+
} from "@openclaw/normalization-core/string-coerce";
69
import { normalizeOptionalTrimmedStringList } from "@openclaw/normalization-core/string-normalization";
710
import {
811
resolveChannelSetupFieldCliAttributeName,
@@ -400,13 +403,16 @@ function normalizePersistedPackageChannel(value: unknown): PluginPackageChannel
400403
"docsLabel",
401404
"blurb",
402405
"systemImage",
403-
"selectionDocsPrefix",
404406
] as const) {
405407
const normalized = normalizeOptionalString(value[key]);
406408
if (normalized) {
407409
channel[key] = normalized;
408410
}
409411
}
412+
const selectionDocsPrefix = readStringValue(value.selectionDocsPrefix);
413+
if (selectionDocsPrefix !== undefined) {
414+
channel.selectionDocsPrefix = selectionDocsPrefix;
415+
}
410416
if (typeof value.order === "number" && Number.isFinite(value.order)) {
411417
channel.order = value.order;
412418
}

0 commit comments

Comments
 (0)