Skip to content

Commit 3276aba

Browse files
committed
fix(cli): distinguish unsupported self lookups
1 parent 8e93724 commit 3276aba

5 files changed

Lines changed: 84 additions & 12 deletions

File tree

‎docs/cli/directory.md‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,28 @@ openclaw message send --channel slack --target user:U012ABCDEF --message "hello"
5555
openclaw directory self --channel zalouser
5656
```
5757

58-
A channel may legitimately return no self identity, including channels that only expose peer or
59-
group directories. This is a successful empty result (exit code `0`), not a failed lookup. The text
60-
output names the queried channel and account and explains that the plugin returned no identity. In
61-
JSON mode, the result is structured so scripts can distinguish it from an error:
58+
A channel may legitimately return no self identity. This is a successful empty result (exit code
59+
`0`), not a failed lookup. Channels without a self resolver report that the channel does not expose
60+
a self identity, without suggesting account troubleshooting:
6261

6362
```json
6463
{
6564
"status": "unavailable",
6665
"channel": "telegram",
6766
"accountId": "default",
67+
"reason": "self-identity-unsupported"
68+
}
69+
```
70+
71+
When a channel implements self lookup but returns no identity, the text output names the channel and
72+
account and suggests checking its configuration and authentication. JSON callers can distinguish
73+
that case by its reason:
74+
75+
```json
76+
{
77+
"status": "unavailable",
78+
"channel": "msteams",
79+
"accountId": "default",
6880
"reason": "plugin-returned-no-self-identity"
6981
}
7082
```

‎src/channels/plugins/directory-adapters.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ describe("directory adapters", () => {
1313
await expect(adapter.self?.({ cfg: {}, runtime: {} as never })).resolves.toBeNull();
1414
});
1515

16+
it("defaults an explicitly undefined self to the null resolver", async () => {
17+
const adapter = createChannelDirectoryAdapter({ self: undefined });
18+
expect(adapter.self).toBe(nullChannelDirectorySelf);
19+
await expect(adapter.self?.({ cfg: {}, runtime: {} as never })).resolves.toBeNull();
20+
});
21+
1622
it("preserves provided resolvers", async () => {
1723
const adapter = createChannelDirectoryAdapter({
1824
listPeers: async () => [{ kind: "user", id: "u-1" }],

‎src/channels/plugins/directory-adapters.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export function createChannelDirectoryAdapter(
1919
} = {},
2020
): ChannelDirectoryAdapter {
2121
return {
22-
self: params.self ?? nullChannelDirectorySelf,
2322
...params,
23+
self: params.self ?? nullChannelDirectorySelf,
2424
};
2525
}
2626

‎src/cli/directory-cli.test.ts‎

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Directory CLI tests cover directory command registration and plugin-backed lookups.
22
import { Command } from "commander";
33
import { beforeEach, describe, expect, it, vi } from "vitest";
4+
import { nullChannelDirectorySelf } from "../channels/plugins/directory-adapters.js";
45
import { registerDirectoryCli } from "./directory-cli.js";
56

67
const runtimeState = await vi.hoisted(async () => {
@@ -192,7 +193,7 @@ describe("registerDirectoryCli", () => {
192193
"--json",
193194
],
194195
},
195-
])("explains an unavailable self identity in $mode mode", async ({ mode, args }) => {
196+
])("explains an empty implemented self lookup in $mode mode", async ({ mode, args }) => {
196197
const self = vi.fn().mockResolvedValue(null);
197198
mocks.resolveInstallableChannelPlugin.mockResolvedValue({
198199
cfg: { channels: { "demo-directory": {} } },
@@ -215,10 +216,57 @@ describe("registerDirectoryCli", () => {
215216
});
216217
} else {
217218
const output = runtimeState.runtimeLogs.join("\n");
218-
expect(output).toContain('channel "demo-directory"');
219-
expect(output).toContain('account "account-1"');
220-
expect(output).toContain("returned no self identity");
221-
expect(output).toContain("did not provide a reason");
219+
expect(output).toBe(
220+
'No self identity was returned for channel "demo-directory", account "account-1". Verify the account is configured and authenticated, then retry.',
221+
);
222+
}
223+
expect(runtimeState.defaultRuntime.exit).not.toHaveBeenCalled();
224+
});
225+
226+
it.each([
227+
{
228+
mode: "human",
229+
args: ["directory", "self", "--channel", "demo-directory", "--account", "account-1"],
230+
},
231+
{
232+
mode: "JSON",
233+
args: [
234+
"directory",
235+
"self",
236+
"--channel",
237+
"demo-directory",
238+
"--account",
239+
"account-1",
240+
"--json",
241+
],
242+
},
243+
])("explains an unsupported self lookup in $mode mode", async ({ mode, args }) => {
244+
mocks.resolveInstallableChannelPlugin.mockResolvedValue({
245+
cfg: { channels: { "demo-directory": {} } },
246+
channelId: "demo-directory",
247+
plugin: {
248+
id: "demo-directory",
249+
directory: { self: nullChannelDirectorySelf },
250+
},
251+
configChanged: false,
252+
});
253+
254+
const program = new Command().name("openclaw");
255+
registerDirectoryCli(program);
256+
257+
await program.parseAsync(args, { from: "user" });
258+
259+
if (mode === "JSON") {
260+
expect(runtimeState.defaultRuntime.writeJson).toHaveBeenCalledWith({
261+
status: "unavailable",
262+
channel: "demo-directory",
263+
accountId: "account-1",
264+
reason: "self-identity-unsupported",
265+
});
266+
} else {
267+
expect(runtimeState.runtimeLogs.join("\n")).toBe(
268+
'Channel "demo-directory" does not expose a self identity.',
269+
);
222270
}
223271
expect(runtimeState.defaultRuntime.exit).not.toHaveBeenCalled();
224272
});

‎src/cli/directory-cli.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
renderTerminalSafeTable,
1313
} from "../../packages/terminal-core/src/table.js";
1414
import { theme } from "../../packages/terminal-core/src/theme.js";
15+
import { nullChannelDirectorySelf } from "../channels/plugins/directory-adapters.js";
1516
import { resolveChannelDefaultAccountId } from "../channels/plugins/helpers.js";
1617
import { resolveInstallableChannelPlugin } from "../commands/channel-setup/channel-plugin-resolution.js";
1718
import { getRuntimeConfig, readConfigFileSnapshot, replaceConfigFile } from "../config/config.js";
@@ -228,17 +229,22 @@ export function registerDirectoryCli(program: Command) {
228229
}
229230
const result = await fn({ cfg, accountId, runtime: defaultRuntime });
230231
if (!result) {
232+
const unsupported = fn === nullChannelDirectorySelf;
231233
if (opts.json) {
232234
defaultRuntime.writeJson({
233235
status: "unavailable",
234236
channel: channelId,
235237
accountId,
236-
reason: "plugin-returned-no-self-identity",
238+
reason: unsupported
239+
? "self-identity-unsupported"
240+
: "plugin-returned-no-self-identity",
237241
});
238242
} else {
239243
defaultRuntime.log(
240244
theme.muted(
241-
`The channel plugin returned no self identity for ${formatDirectoryScope(channelId, accountId)}. It did not provide a reason; verify the account is configured and authenticated, then retry. Some channels do not expose a self identity.`,
245+
unsupported
246+
? `Channel ${JSON.stringify(sanitizeTerminalText(channelId))} does not expose a self identity.`
247+
: `No self identity was returned for ${formatDirectoryScope(channelId, accountId)}. Verify the account is configured and authenticated, then retry.`,
242248
),
243249
);
244250
}

0 commit comments

Comments
 (0)