fix(auto-reply): avoid duplicate reset hook acknowledgements

This commit is contained in:
Peter Steinberger
2026-04-28 09:36:55 +01:00
parent e2bcec33b3
commit 3ee5490c60
3 changed files with 14 additions and 6 deletions

View File

@@ -251,7 +251,7 @@ describe("handleCommands reset hooks", () => {
},
);
await maybeHandleResetCommand(params);
const result = await maybeHandleResetCommand(params);
expect(routeReplyMock).toHaveBeenCalledWith(
expect.objectContaining({
@@ -262,6 +262,7 @@ describe("handleCommands reset hooks", () => {
threadId: "thread-1",
}),
);
expect(result).toEqual({ shouldContinue: false });
});
it("prefers the target session entry when emitting reset hooks", async () => {

View File

@@ -104,7 +104,7 @@ export async function emitResetCommandHooks(params: {
sessionEntry?: HandleCommandsParams["sessionEntry"];
previousSessionEntry?: HandleCommandsParams["previousSessionEntry"];
workspaceDir: string;
}): Promise<void> {
}): Promise<{ routedReply: boolean }> {
const hookEvent = createInternalHookEvent("command", params.action, params.sessionKey ?? "", {
sessionEntry: params.sessionEntry,
previousSessionEntry: params.previousSessionEntry,
@@ -116,6 +116,7 @@ export async function emitResetCommandHooks(params: {
await triggerInternalHook(hookEvent);
params.command.resetHookTriggered = true;
let routedReply = false;
if (hookEvent.messages.length > 0) {
const channel = params.ctx.OriginatingChannel || params.command.channel;
const to = params.ctx.OriginatingTo || params.command.from || params.command.to;
@@ -134,6 +135,7 @@ export async function emitResetCommandHooks(params: {
threadId: params.ctx.MessageThreadId,
cfg: params.cfg,
});
routedReply = true;
}
}
@@ -160,4 +162,5 @@ export async function emitResetCommandHooks(params: {
}
})();
}
return { routedReply };
}

View File

@@ -156,7 +156,7 @@ export async function maybeHandleResetCommand(
const targetSessionEntry = params.sessionStore?.[params.sessionKey] ?? params.sessionEntry;
await emitResetCommandHooks({
const hookResult = await emitResetCommandHooks({
action: commandAction,
ctx: params.ctx,
cfg: params.cfg,
@@ -169,9 +169,13 @@ export async function maybeHandleResetCommand(
if (!resetTail) {
return {
shouldContinue: false,
reply: {
text: commandAction === "reset" ? "✅ Session reset." : "✅ New session started.",
},
...(hookResult.routedReply
? {}
: {
reply: {
text: commandAction === "reset" ? "✅ Session reset." : "✅ New session started.",
},
}),
};
}
return null;