fix: prefer target entry for btw command

This commit is contained in:
Tak Hoffman
2026-04-10 20:49:26 -05:00
parent 8ae6d42faa
commit f5d0b54563
2 changed files with 34 additions and 2 deletions

View File

@@ -227,4 +227,34 @@ describe("handleBtwCommand", () => {
reply: { text: "resolved fallback", btw: { question: "what changed?" } },
});
});
it("prefers the target session entry for side-question context", async () => {
const params = buildParams("/btw what changed?");
params.sessionKey = "agent:worker-1:whatsapp:direct:12345";
params.sessionEntry = {
sessionId: "wrapper-session",
updatedAt: Date.now(),
};
params.sessionStore = {
"agent:worker-1:whatsapp:direct:12345": {
sessionId: "target-session",
updatedAt: Date.now(),
},
};
runBtwSideQuestionMock.mockResolvedValue({ text: "target context" });
const result = await handleBtwCommand(params, true);
expect(runBtwSideQuestionMock).toHaveBeenCalledWith(
expect.objectContaining({
sessionEntry: expect.objectContaining({
sessionId: "target-session",
}),
}),
);
expect(result).toEqual({
shouldContinue: false,
reply: { text: "target context", btw: { question: "what changed?" } },
});
});
});

View File

@@ -26,7 +26,9 @@ export const handleBtwCommand: CommandHandler = async (params, allowTextCommands
};
}
if (!params.sessionEntry?.sessionId) {
const targetSessionEntry = params.sessionStore?.[params.sessionKey] ?? params.sessionEntry;
if (!targetSessionEntry?.sessionId) {
return {
shouldContinue: false,
reply: { text: "⚠️ /btw requires an active session with existing context." },
@@ -56,7 +58,7 @@ export const handleBtwCommand: CommandHandler = async (params, allowTextCommands
provider: params.provider,
model: params.model,
question,
sessionEntry: params.sessionEntry,
sessionEntry: targetSessionEntry,
sessionStore: params.sessionStore,
sessionKey: params.sessionKey,
storePath: params.storePath,