Skip to content

Commit f5d0b54

Browse files
committed
fix: prefer target entry for btw command
1 parent 8ae6d42 commit f5d0b54

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/auto-reply/reply/commands-btw.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,34 @@ describe("handleBtwCommand", () => {
227227
reply: { text: "resolved fallback", btw: { question: "what changed?" } },
228228
});
229229
});
230+
231+
it("prefers the target session entry for side-question context", async () => {
232+
const params = buildParams("/btw what changed?");
233+
params.sessionKey = "agent:worker-1:whatsapp:direct:12345";
234+
params.sessionEntry = {
235+
sessionId: "wrapper-session",
236+
updatedAt: Date.now(),
237+
};
238+
params.sessionStore = {
239+
"agent:worker-1:whatsapp:direct:12345": {
240+
sessionId: "target-session",
241+
updatedAt: Date.now(),
242+
},
243+
};
244+
runBtwSideQuestionMock.mockResolvedValue({ text: "target context" });
245+
246+
const result = await handleBtwCommand(params, true);
247+
248+
expect(runBtwSideQuestionMock).toHaveBeenCalledWith(
249+
expect.objectContaining({
250+
sessionEntry: expect.objectContaining({
251+
sessionId: "target-session",
252+
}),
253+
}),
254+
);
255+
expect(result).toEqual({
256+
shouldContinue: false,
257+
reply: { text: "target context", btw: { question: "what changed?" } },
258+
});
259+
});
230260
});

src/auto-reply/reply/commands-btw.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export const handleBtwCommand: CommandHandler = async (params, allowTextCommands
2626
};
2727
}
2828

29-
if (!params.sessionEntry?.sessionId) {
29+
const targetSessionEntry = params.sessionStore?.[params.sessionKey] ?? params.sessionEntry;
30+
31+
if (!targetSessionEntry?.sessionId) {
3032
return {
3133
shouldContinue: false,
3234
reply: { text: "⚠️ /btw requires an active session with existing context." },
@@ -56,7 +58,7 @@ export const handleBtwCommand: CommandHandler = async (params, allowTextCommands
5658
provider: params.provider,
5759
model: params.model,
5860
question,
59-
sessionEntry: params.sessionEntry,
61+
sessionEntry: targetSessionEntry,
6062
sessionStore: params.sessionStore,
6163
sessionKey: params.sessionKey,
6264
storePath: params.storePath,

0 commit comments

Comments
 (0)