refactor: new design — sidecar services, moderator Gateway client, tool execute API

- Replace standalone no-reply-api Docker service with unified sidecar (services/main.mjs)
  that routes /no-reply/* and /moderator/* and starts/stops with openclaw-gateway
- Add moderator Discord Gateway client (services/moderator/index.mjs) for real-time
  MESSAGE_CREATE push instead of polling; notifies plugin via HTTP callback
- Add plugin HTTP routes (plugin/web/dirigent-api.ts) for moderator → plugin callbacks
  (wake-from-dormant, interrupt tail-match)
- Fix tool registration format: AgentTool requires execute: not handler:; factory form
  for tools needing ctx
- Rename no-reply-process.ts → sidecar-process.ts, startNoReplyApi → startSideCar
- Remove dead config fields from openclaw.plugin.json (humanList, agentList, listMode,
  channelPoliciesFile, endSymbols, waitIdentifier, multiMessage*, bypassUserIds, etc.)
- Rename noReplyPort → sideCarPort
- Remove docker-compose.yml, dev-up/down scripts, package-plugin.mjs, test-no-reply-api.mjs
- Update install.mjs: clean dist before build, copy services/, drop dead config writes
- Update README, Makefile, smoke script for new architecture

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
h z
2026-04-10 08:07:59 +01:00
parent d8ac9ee0f9
commit 32dc9a4233
28 changed files with 1310 additions and 900 deletions

View File

@@ -33,14 +33,23 @@ function parseDiscordChannelIdFromSession(sessionKey: string): string | undefine
return m?.[1];
}
function textResult(text: string) {
return { content: [{ type: "text" as const, text }], details: undefined };
}
function errorResult(text: string) {
return { content: [{ type: "text" as const, text }], details: { error: true } };
}
export function registerDirigentTools(deps: ToolDeps): void {
const { api, channelStore, identityRegistry, moderatorBotToken, scheduleIdentifier, onDiscussionCreate } = deps;
// ───────────────────────────────────────────────
// dirigent-register
// ───────────────────────────────────────────────
api.registerTool({
api.registerTool((ctx) => ({
name: "dirigent-register",
label: "Dirigent Register",
description: "Register or update this agent's Discord user ID in Dirigent's identity registry.",
parameters: {
type: "object",
@@ -51,18 +60,18 @@ export function registerDirigentTools(deps: ToolDeps): void {
},
required: ["discordUserId"],
},
handler: async (params, ctx) => {
execute: async (_toolCallId: string, params: unknown) => {
const agentId = ctx?.agentId;
if (!agentId) return { content: [{ type: "text", text: "Cannot resolve agentId from session context" }], isError: true };
if (!agentId) return errorResult("Cannot resolve agentId from session context");
const p = params as { discordUserId: string; agentName?: string };
identityRegistry.upsert({
agentId,
discordUserId: p.discordUserId,
agentName: p.agentName ?? agentId,
});
return { content: [{ type: "text", text: `Registered: agentId=${agentId} discordUserId=${p.discordUserId}` }] };
return textResult(`Registered: agentId=${agentId} discordUserId=${p.discordUserId}`);
},
});
}));
// ───────────────────────────────────────────────
// Helper: create channel + set mode
@@ -72,7 +81,6 @@ export function registerDirigentTools(deps: ToolDeps): void {
name: string;
memberDiscordIds: string[];
mode: "chat" | "report" | "work";
callerCtx: { agentId?: string };
}): Promise<{ ok: boolean; channelId?: string; error?: string }> {
if (!moderatorBotToken) return { ok: false, error: "moderatorBotToken not configured" };
@@ -112,6 +120,7 @@ export function registerDirigentTools(deps: ToolDeps): void {
// ───────────────────────────────────────────────
api.registerTool({
name: "create-chat-channel",
label: "Create Chat Channel",
description: "Create a new private Discord channel in the specified guild with mode=chat.",
parameters: {
type: "object",
@@ -126,16 +135,15 @@ export function registerDirigentTools(deps: ToolDeps): void {
},
required: ["guildId", "name"],
},
handler: async (params, ctx) => {
execute: async (_toolCallId: string, params: unknown) => {
const p = params as { guildId: string; name: string; participants?: string[] };
const result = await createManagedChannel({
guildId: p.guildId, name: p.name,
memberDiscordIds: p.participants ?? [],
mode: "chat",
callerCtx: { agentId: ctx?.agentId },
});
if (!result.ok) return { content: [{ type: "text", text: `Failed: ${result.error}` }], isError: true };
return { content: [{ type: "text", text: `Created chat channel: ${result.channelId}` }] };
if (!result.ok) return errorResult(`Failed: ${result.error}`);
return textResult(`Created chat channel: ${result.channelId}`);
},
});
@@ -144,6 +152,7 @@ export function registerDirigentTools(deps: ToolDeps): void {
// ───────────────────────────────────────────────
api.registerTool({
name: "create-report-channel",
label: "Create Report Channel",
description: "Create a new private Discord channel with mode=report. Agents can post to it but are not woken by messages.",
parameters: {
type: "object",
@@ -155,24 +164,24 @@ export function registerDirigentTools(deps: ToolDeps): void {
},
required: ["guildId", "name"],
},
handler: async (params, ctx) => {
execute: async (_toolCallId: string, params: unknown) => {
const p = params as { guildId: string; name: string; members?: string[] };
const result = await createManagedChannel({
guildId: p.guildId, name: p.name,
memberDiscordIds: p.members ?? [],
mode: "report",
callerCtx: { agentId: ctx?.agentId },
});
if (!result.ok) return { content: [{ type: "text", text: `Failed: ${result.error}` }], isError: true };
return { content: [{ type: "text", text: `Created report channel: ${result.channelId}` }] };
if (!result.ok) return errorResult(`Failed: ${result.error}`);
return textResult(`Created report channel: ${result.channelId}`);
},
});
// ───────────────────────────────────────────────
// create-work-channel
// ───────────────────────────────────────────────
api.registerTool({
api.registerTool((ctx) => ({
name: "create-work-channel",
label: "Create Work Channel",
description: "Create a new private Discord workspace channel with mode=work (turn-manager disabled, mode locked).",
parameters: {
type: "object",
@@ -184,7 +193,7 @@ export function registerDirigentTools(deps: ToolDeps): void {
},
required: ["guildId", "name"],
},
handler: async (params, ctx) => {
execute: async (_toolCallId: string, params: unknown) => {
const p = params as { guildId: string; name: string; members?: string[] };
// Include calling agent's Discord ID if known
const callerDiscordId = ctx?.agentId ? identityRegistry.findByAgentId(ctx.agentId)?.discordUserId : undefined;
@@ -195,18 +204,18 @@ export function registerDirigentTools(deps: ToolDeps): void {
guildId: p.guildId, name: p.name,
memberDiscordIds: members,
mode: "work",
callerCtx: { agentId: ctx?.agentId },
});
if (!result.ok) return { content: [{ type: "text", text: `Failed: ${result.error}` }], isError: true };
return { content: [{ type: "text", text: `Created work channel: ${result.channelId}` }] };
if (!result.ok) return errorResult(`Failed: ${result.error}`);
return textResult(`Created work channel: ${result.channelId}`);
},
});
}));
// ───────────────────────────────────────────────
// create-discussion-channel
// ───────────────────────────────────────────────
api.registerTool({
api.registerTool((ctx) => ({
name: "create-discussion-channel",
label: "Create Discussion Channel",
description: "Create a structured discussion channel between agents. The calling agent becomes the initiator.",
parameters: {
type: "object",
@@ -220,7 +229,7 @@ export function registerDirigentTools(deps: ToolDeps): void {
},
required: ["callbackGuildId", "callbackChannelId", "name", "discussionGuide", "participants"],
},
handler: async (params, ctx) => {
execute: async (_toolCallId: string, params: unknown) => {
const p = params as {
callbackGuildId: string;
callbackChannelId: string;
@@ -230,13 +239,13 @@ export function registerDirigentTools(deps: ToolDeps): void {
};
const initiatorAgentId = ctx?.agentId;
if (!initiatorAgentId) {
return { content: [{ type: "text", text: "Cannot resolve initiator agentId from session" }], isError: true };
return errorResult("Cannot resolve initiator agentId from session");
}
if (!moderatorBotToken) {
return { content: [{ type: "text", text: "moderatorBotToken not configured" }], isError: true };
return errorResult("moderatorBotToken not configured");
}
if (!onDiscussionCreate) {
return { content: [{ type: "text", text: "Discussion service not available" }], isError: true };
return errorResult("Discussion service not available");
}
const botId = getBotUserIdFromToken(moderatorBotToken);
@@ -262,7 +271,7 @@ export function registerDirigentTools(deps: ToolDeps): void {
logger: api.logger,
});
} catch (err) {
return { content: [{ type: "text", text: `Failed to create channel: ${String(err)}` }], isError: true };
return errorResult(`Failed to create channel: ${String(err)}`);
}
try {
@@ -273,7 +282,7 @@ export function registerDirigentTools(deps: ToolDeps): void {
concluded: false,
});
} catch (err) {
return { content: [{ type: "text", text: `Failed to register channel: ${String(err)}` }], isError: true };
return errorResult(`Failed to register channel: ${String(err)}`);
}
await onDiscussionCreate({
@@ -286,15 +295,16 @@ export function registerDirigentTools(deps: ToolDeps): void {
participants: p.participants,
});
return { content: [{ type: "text", text: `Discussion channel created: ${channelId}` }] };
return textResult(`Discussion channel created: ${channelId}`);
},
});
}));
// ───────────────────────────────────────────────
// discussion-complete
// ───────────────────────────────────────────────
api.registerTool({
api.registerTool((ctx) => ({
name: "discussion-complete",
label: "Discussion Complete",
description: "Mark a discussion as complete, archive the channel, and post the summary path to the callback channel.",
parameters: {
type: "object",
@@ -305,31 +315,25 @@ export function registerDirigentTools(deps: ToolDeps): void {
},
required: ["discussionChannelId", "summary"],
},
handler: async (params, ctx) => {
execute: async (_toolCallId: string, params: unknown) => {
const p = params as { discussionChannelId: string; summary: string };
const callerAgentId = ctx?.agentId;
if (!callerAgentId) {
return { content: [{ type: "text", text: "Cannot resolve agentId from session" }], isError: true };
return errorResult("Cannot resolve agentId from session");
}
const rec = channelStore.getRecord(p.discussionChannelId);
if (rec.mode !== "discussion") {
return { content: [{ type: "text", text: `Channel ${p.discussionChannelId} is not a discussion channel` }], isError: true };
return errorResult(`Channel ${p.discussionChannelId} is not a discussion channel`);
}
if (!rec.discussion) {
return { content: [{ type: "text", text: "Discussion metadata not found" }], isError: true };
return errorResult("Discussion metadata not found");
}
if (rec.discussion.initiatorAgentId !== callerAgentId) {
return {
content: [{ type: "text", text: `Only the initiator (${rec.discussion.initiatorAgentId}) may call discussion-complete` }],
isError: true,
};
return errorResult(`Only the initiator (${rec.discussion.initiatorAgentId}) may call discussion-complete`);
}
if (!p.summary.includes("discussion-summary")) {
return {
content: [{ type: "text", text: "Summary path must be under {workspace}/discussion-summary/" }],
isError: true,
};
return errorResult("Summary path must be under {workspace}/discussion-summary/");
}
channelStore.concludeDiscussion(p.discussionChannelId);
@@ -343,7 +347,7 @@ export function registerDirigentTools(deps: ToolDeps): void {
).catch(() => undefined);
}
return { content: [{ type: "text", text: `Discussion ${p.discussionChannelId} concluded. Summary posted to ${rec.discussion.callbackChannelId}.` }] };
return textResult(`Discussion ${p.discussionChannelId} concluded. Summary posted to ${rec.discussion.callbackChannelId}.`);
},
});
}));
}