fix: simplify walkthrough prompt requests (#1660)
* fix: simplify walkthrough prompt requests * fix: address walkthrough review feedback
This commit is contained in:
@@ -40,12 +40,12 @@ function storeState(sessionState: string, planMode = false) {
|
||||
};
|
||||
}
|
||||
|
||||
function renderRequestHook(files = [{ path: "src/app.ts", source: "uncommitted" }]) {
|
||||
function renderRequestHook(ready = true) {
|
||||
return renderHook(() =>
|
||||
useRequestChangesWalkthrough({
|
||||
taskId: "task-1",
|
||||
sessionId: "session-1",
|
||||
files,
|
||||
ready,
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -59,7 +59,7 @@ describe("useRequestChangesWalkthrough", () => {
|
||||
{
|
||||
id: "builtin-changes-walkthrough",
|
||||
name: "changes-walkthrough",
|
||||
content: "CUSTOM_WALKTHROUGH_PROMPT\n{{changed_files}}\nshow_walkthrough_kandev",
|
||||
content: "CUSTOM_WALKTHROUGH_PROMPT\nshow_walkthrough_kandev",
|
||||
builtin: true,
|
||||
},
|
||||
],
|
||||
@@ -87,13 +87,16 @@ describe("useRequestChangesWalkthrough", () => {
|
||||
expect.objectContaining({
|
||||
task_id: "task-1",
|
||||
session_id: "session-1",
|
||||
content: expect.stringMatching(/^@changes-walkthrough\n\nChanged files:/),
|
||||
content: expect.stringMatching(/^@changes-walkthrough\n\n<kandev-system>/),
|
||||
}),
|
||||
10000,
|
||||
);
|
||||
const sentContent = mockRequest.mock.calls[0]?.[1]?.content as string;
|
||||
expect(sentContent).toContain("<kandev-system>");
|
||||
expect(sentContent).toContain("CUSTOM_WALKTHROUGH_PROMPT");
|
||||
expect(sentContent).not.toContain("Diff context:");
|
||||
expect(sentContent).not.toContain("Base branch:");
|
||||
expect(sentContent).not.toContain("Base commit:");
|
||||
expect(mockListPrompts).toHaveBeenCalledWith({ cache: "no-store" });
|
||||
expect(mockAddMessage).toHaveBeenCalledWith(expect.objectContaining({ id: "msg-1" }));
|
||||
expect(mockQueueMessage).not.toHaveBeenCalled();
|
||||
@@ -115,7 +118,7 @@ describe("useRequestChangesWalkthrough", () => {
|
||||
session_id: "session-1",
|
||||
task_id: "task-1",
|
||||
plan_mode: true,
|
||||
content: expect.stringMatching(/^@changes-walkthrough\n\nChanged files:/),
|
||||
content: expect.stringMatching(/^@changes-walkthrough\n\n<kandev-system>/),
|
||||
}),
|
||||
);
|
||||
const queuedContent = mockQueueMessage.mock.calls[0]?.[0]?.content as string;
|
||||
@@ -127,8 +130,8 @@ describe("useRequestChangesWalkthrough", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("does not send a low-context prompt before changed files are loaded", async () => {
|
||||
const { result } = renderRequestHook([]);
|
||||
it("does not send a low-context prompt before diff context is ready", async () => {
|
||||
const { result } = renderRequestHook(false);
|
||||
|
||||
await act(async () => {
|
||||
await result.current();
|
||||
|
||||
@@ -7,7 +7,6 @@ import { getWebSocketClient } from "@/lib/ws/connection";
|
||||
import {
|
||||
buildChangesWalkthroughPrompt,
|
||||
CHANGES_WALKTHROUGH_PROMPT_NAME,
|
||||
type WalkthroughPromptFile,
|
||||
} from "@/lib/walkthrough-request";
|
||||
import type { Message } from "@/lib/types/http";
|
||||
import type { AppState } from "@/lib/state/store";
|
||||
@@ -15,7 +14,7 @@ import type { AppState } from "@/lib/state/store";
|
||||
type UseRequestChangesWalkthroughParams = {
|
||||
taskId: string | null | undefined;
|
||||
sessionId: string | null | undefined;
|
||||
files: WalkthroughPromptFile[];
|
||||
ready?: boolean;
|
||||
};
|
||||
|
||||
function isAgentBusy(state: string | undefined): boolean {
|
||||
@@ -75,7 +74,7 @@ async function sendWalkthroughRequest(params: {
|
||||
export function useRequestChangesWalkthrough({
|
||||
taskId,
|
||||
sessionId,
|
||||
files,
|
||||
ready = true,
|
||||
}: UseRequestChangesWalkthroughParams) {
|
||||
const storeApi = useAppStoreApi();
|
||||
const { toast } = useToast();
|
||||
@@ -87,13 +86,13 @@ export function useRequestChangesWalkthrough({
|
||||
const activeSession = state.taskSessions.items[sessionId] ?? null;
|
||||
const shouldQueue = isAgentBusy(activeSession?.state);
|
||||
const planModeEnabled = state.chatInput.planModeBySessionId[sessionId] ?? false;
|
||||
if (files.length === 0) {
|
||||
if (!ready) {
|
||||
toast({ title: "Changes are still loading", variant: "error" });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const template = await loadChangesWalkthroughPromptTemplate();
|
||||
const content = buildChangesWalkthroughPrompt(template, files);
|
||||
const content = buildChangesWalkthroughPrompt(template);
|
||||
if (shouldQueue) {
|
||||
await queueWalkthroughRequest({
|
||||
taskId,
|
||||
@@ -111,5 +110,5 @@ export function useRequestChangesWalkthrough({
|
||||
console.error("Failed to request walkthrough:", error);
|
||||
toast({ title: "Failed to request walkthrough", variant: "error" });
|
||||
}
|
||||
}, [files, sessionId, storeApi, taskId, toast]);
|
||||
}, [ready, sessionId, storeApi, taskId, toast]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user