Complete rewrite of the Dirigent plugin turn management system to work correctly with OpenClaw's VM-context-per-session architecture: - All turn state stored on globalThis (persists across VM context hot-reloads) - Hooks registered unconditionally on every api instance; event-level dedup (runId Set for agent_end, WeakSet for before_model_resolve) prevents double-processing - Gateway lifecycle events (gateway_start/stop) guarded once via globalThis flag - Shared initializingChannels lock prevents concurrent channel init across VM contexts in message_received and before_model_resolve - New ChannelStore and IdentityRegistry replace old policy/session-state modules - Added agent_end hook with tail-match polling for Discord delivery confirmation - Added web control page, padded-cell auto-scan, discussion tool support - Removed obsolete v1 modules: channel-resolver, channel-modes, discussion-service, session-state, turn-bootstrap, policy/store, rules, decision-input Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
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}".` };
|
|
},
|
|
});
|
|
}
|