refactor(auto-reply): split reply pipeline

This commit is contained in:
Peter Steinberger
2026-01-14 09:11:16 +00:00
parent 1089444807
commit ea018a68cc
26 changed files with 4380 additions and 3285 deletions

View File

@@ -0,0 +1,81 @@
import { logVerbose } from "../../globals.js";
import { resolveSendPolicy } from "../../sessions/send-policy.js";
import { shouldHandleTextCommands } from "../commands-registry.js";
import { handleBashCommand } from "./commands-bash.js";
import { handleCompactCommand } from "./commands-compact.js";
import { handleConfigCommand, handleDebugCommand } from "./commands-config.js";
import {
handleCommandsListCommand,
handleHelpCommand,
handleStatusCommand,
handleWhoamiCommand,
} from "./commands-info.js";
import {
handleAbortTrigger,
handleActivationCommand,
handleRestartCommand,
handleSendPolicyCommand,
handleStopCommand,
} from "./commands-session.js";
import type {
CommandHandler,
CommandHandlerResult,
HandleCommandsParams,
} from "./commands-types.js";
const HANDLERS: CommandHandler[] = [
handleBashCommand,
handleActivationCommand,
handleSendPolicyCommand,
handleRestartCommand,
handleHelpCommand,
handleCommandsListCommand,
handleStatusCommand,
handleWhoamiCommand,
handleConfigCommand,
handleDebugCommand,
handleStopCommand,
handleCompactCommand,
handleAbortTrigger,
];
export async function handleCommands(
params: HandleCommandsParams,
): Promise<CommandHandlerResult> {
const resetRequested =
params.command.commandBodyNormalized === "/reset" ||
params.command.commandBodyNormalized === "/new";
if (resetRequested && !params.command.isAuthorizedSender) {
logVerbose(
`Ignoring /reset from unauthorized sender: ${params.command.senderId || "<unknown>"}`,
);
return { shouldContinue: false };
}
const allowTextCommands = shouldHandleTextCommands({
cfg: params.cfg,
surface: params.command.surface,
commandSource: params.ctx.CommandSource,
});
for (const handler of HANDLERS) {
const result = await handler(params, allowTextCommands);
if (result) return result;
}
const sendPolicy = resolveSendPolicy({
cfg: params.cfg,
entry: params.sessionEntry,
sessionKey: params.sessionKey,
channel: params.sessionEntry?.channel ?? params.command.channel,
chatType: params.sessionEntry?.chatType,
});
if (sendPolicy === "deny") {
logVerbose(
`Send blocked by policy for session ${params.sessionKey ?? "unknown"}`,
);
return { shouldContinue: false };
}
return { shouldContinue: true };
}