Files
Dirigent/plugin/commands/set-channel-mode-command.ts
zhi 5b05e91d4e fix: don't block one-shot openclaw subcommands; migrate to current plugin SDK
Sidecar lifecycle:
- Move startSideCar() out of register() into an api.on("gateway_start", ...)
  handler. register() runs in every CLI subprocess that loads plugins
  (e.g. `openclaw completion`, `openclaw doctor`); eagerly spawning a
  long-lived process there hung `openclaw update`'s post-update steps.
- Spawn the sidecar with detached: true, stdio routed to a log file fd,
  and call .unref() so the host's event loop is never held by the child.
  Even if a future caller invokes startSideCar in a non-gateway context,
  it can no longer block that host from exiting.
- Sidecar logs now go to ~/.openclaw/logs/dirigent-sidecar.log instead of
  being piped through the host logger.

Plugin SDK convention update:
- Wrap default export with definePluginEntry({ id, name, description, register })
  per the current openclaw plugin authoring contract.
- Switch all imports from the deprecated root barrel "openclaw/plugin-sdk"
  to focused subpaths "openclaw/plugin-sdk/core" and
  "openclaw/plugin-sdk/plugin-entry".
- Modernize openclaw.plugin.json: drop entry/version, add description,
  declare contracts.tools[] for the 6 tools, set activation.onStartup: true
  so gateway_start fires for this plugin at boot.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 07:36:00 +00:00

71 lines
2.2 KiB
TypeScript

import type { OpenClawPluginApi } from "openclaw/plugin-sdk/core";
import type { ChannelStore, ChannelMode } from "../core/channel-store.js";
import { parseDiscordChannelIdFromCommand } from "./command-utils.js";
const SWITCHABLE_MODES = new Set<ChannelMode>(["none", "chat", "report"]);
const LOCKED_MODES = new Set<ChannelMode>(["work", "discussion"]);
type Deps = {
api: OpenClawPluginApi;
channelStore: ChannelStore;
};
export function registerSetChannelModeCommand(deps: Deps): void {
const { api, channelStore } = deps;
api.registerCommand({
name: "set-channel-mode",
description: "Set the mode of the current Discord channel: none | chat | report",
acceptsArgs: true,
handler: async (cmdCtx) => {
const raw = (cmdCtx.args || "").trim().toLowerCase() as ChannelMode;
if (!raw) {
return {
text: "Usage: /set-channel-mode <none|chat|report>\n\nModes work and discussion are locked and can only be set via creation tools.",
isError: true,
};
}
if (LOCKED_MODES.has(raw)) {
return {
text: `Mode "${raw}" cannot be set via command — it is locked to its creation tool (create-${raw}-channel or create-discussion-channel).`,
isError: true,
};
}
if (!SWITCHABLE_MODES.has(raw)) {
return {
text: `Unknown mode "${raw}". Valid values: none, chat, report`,
isError: true,
};
}
// Extract channel ID from command context
const channelId = parseDiscordChannelIdFromCommand(cmdCtx);
if (!channelId) {
return {
text: "Could not determine Discord channel ID. Run this command inside a Discord channel.",
isError: true,
};
}
const current = channelStore.getMode(channelId);
if (LOCKED_MODES.has(current)) {
return {
text: `Channel ${channelId} is in locked mode "${current}" and cannot be changed.`,
isError: true,
};
}
try {
channelStore.setMode(channelId, raw);
} catch (err) {
return { text: `Failed: ${String(err)}`, isError: true };
}
return { text: `Channel ${channelId} mode set to "${raw}".` };
},
});
}