Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

refactor: delete the client-side review save heuristic

Khuram Niaz93afb053f49c
diff --git a/__tests__/AgentChatClosePaths.spec.tsx b/__tests__/AgentChatClosePaths.spec.tsx
index 2efd547..54c923a 100644
--- a/__tests__/AgentChatClosePaths.spec.tsx
+++ b/__tests__/AgentChatClosePaths.spec.tsx
@@ -78,6 +78,19 @@ const approvalMessage = {
],
};
+const reviewRunningMessage = {
+ id: "a1",
+ role: "assistant",
+ parts: [
+ {
+ type: "tool-review_resume",
+ toolCallId: "rv1",
+ state: "input-available",
+ input: {},
+ },
+ ],
+};
+
describe("agent chat close paths", () => {
beforeEach(() => {
vi.clearAllMocks();
@@ -138,4 +151,17 @@ describe("agent chat close paths", () => {
screen.getByRole("button", { name: /open assistant/i }).textContent,
).toBe("Chat AI");
});
+
+ // The nested generation is inside the outer streamText's tool call, so the
+ // same abort covers it — nothing keeps reviewing while the panel is shut.
+ it("stops a running nested review when the panel closes", async () => {
+ chat.messages = [reviewRunningMessage];
+ chat.status = "streaming";
+ setup([reviewRunningMessage]);
+ await openPanel();
+ await act(async () => {
+ await userEvent.click(screen.getByRole("button", { name: "Close chat" }));
+ });
+ expect(chat.stop).toHaveBeenCalled();
+ });
});
diff --git a/__tests__/AgentChatMessages.spec.tsx b/__tests__/AgentChatMessages.spec.tsx
index f459a32..4931e6c 100644
--- a/__tests__/AgentChatMessages.spec.tsx
+++ b/__tests__/AgentChatMessages.spec.tsx
@@ -36,22 +36,6 @@ const user = (parts: any[]) => ({ id: "u1", role: "user", parts });
const posting = "Senior Platform Engineer at Acme. We run payments reliability.";
-const resumeRead = {
- type: "tool-get_resume",
- toolCallId: "t1",
- state: "output-available",
- input: {},
- output: {
- status: "ok",
- resumeId: "r1",
- title: "Senior Engineer Resume",
- resumeText: "TXT",
- chars: 3,
- truncated: false,
- source: "default",
- },
-} as any;
-
describe("AgentChatMessages", () => {
beforeEach(() => {
vi.clearAllMocks();
@@ -247,42 +231,20 @@ describe("AgentChatMessages", () => {
expect(screen.queryByRole("link")).not.toBeInTheDocument();
});
- it("renders a score card and hides the scores line for a review", () => {
- chat.messages = [
- assistant([
- resumeRead,
- {
- type: "text",
- text: "SCORES: overall=78 impact=72 clarity=81 ats=69\n\n## Summary\n\nSolid resume.",
- },
- ]),
- ];
- render(<AgentChatMessages />);
- expect(screen.getByText("Impact")).toBeInTheDocument();
- expect(screen.queryByText(/SCORES:/)).not.toBeInTheDocument();
- expect(screen.getByTestId("tiptap-content").innerHTML).toContain(
- "<h2>Summary</h2>",
- );
- });
-
- // The output format demands a leading scores line unconditionally, so a
- // model that declines to review still emits one, zeroed. A card rendered
- // from that told the user their resume scored 0 on a turn that read
- // nothing.
- it("renders no score card when the turn read no resume", () => {
+ // The transcript no longer parses assistant prose for a SCORES line at all
+ // — the card comes from the tool part. A model that emits one anyway is
+ // rendered as the plain text it is.
+ it("renders no score card for a scores line in assistant prose", () => {
chat.messages = [
assistant([
{
type: "text",
- text: "SCORES: overall=0 impact=0 clarity=0 ats=0\n\nI need to read your resume first.",
+ text: "SCORES: overall=78 impact=72 clarity=81 ats=69\n\nSolid resume.",
},
]),
];
render(<AgentChatMessages />);
expect(screen.queryByText("Impact")).not.toBeInTheDocument();
- expect(screen.getByTestId("tiptap-content")).toHaveTextContent(
- "I need to read your resume first.",
- );
});
it("renders a follow-up answer with no score card", () => {
diff --git a/__tests__/AgentChatProvider.spec.tsx b/__tests__/AgentChatProvider.spec.tsx
index 7fa30e5..e495dfe 100644
--- a/__tests__/AgentChatProvider.spec.tsx
+++ b/__tests__/AgentChatProvider.spec.tsx
@@ -38,10 +38,6 @@ vi.mock("@/actions/userSettings.actions", () => ({
vi.mock("@/utils/ai.utils", () => ({
checkOllamaConnection: vi.fn(async () => ({ isConnected: true })),
}));
-vi.mock("@/actions/profile.actions", () => ({
- saveResumeReviewResult: vi.fn().mockResolvedValue({ success: true }),
-}));
-vi.mock("@/lib/toast", () => ({ toastSuccess: vi.fn(), toastError: vi.fn() }));
import {
AgentChatProvider,
@@ -53,7 +49,6 @@ import { SidebarProvider, useSidebar } from "@/context/SidebarContext";
import { clearChatConversation } from "@/actions/agentChat.actions";
import { getUserSettings } from "@/actions/userSettings.actions";
import { checkOllamaConnection } from "@/utils/ai.utils";
-import { saveResumeReviewResult } from "@/actions/profile.actions";
function Probe() {
const c = useAgentChat();
@@ -70,6 +65,7 @@ function Probe() {
<span data-testid="state">{`${c.isOpen}|${c.approvalPending}|${c.interruptedTurn}|${holder}|${c.preflight.ok}`}</span>
<span data-testid="composer-nonce">{c.composerNonce}</span>
<span data-testid="panel-expanded">{String(c.isPanelExpanded)}</span>
+ <span data-testid="review-stream">{c.reviewStreams["rv1"] ?? ""}</span>
</div>
);
}
@@ -86,39 +82,6 @@ const tree = (initialMessages: any[] = []) => (
const setup = (initialMessages: any[] = []) => render(tree(initialMessages));
-const reviewMessage = {
- id: "a2",
- role: "assistant",
- parts: [
- {
- type: "text",
- text: "SCORES: overall=78 impact=72 clarity=81 ats=69\n\n## Summary\n\nSolid.",
- },
- ],
-} as any;
-
-const readMessage = {
- id: "a1",
- role: "assistant",
- parts: [
- {
- type: "tool-get_resume",
- toolCallId: "t1",
- state: "output-available",
- input: {},
- output: {
- status: "ok",
- resumeId: "r1",
- title: "Senior Engineer Resume",
- resumeText: "TXT",
- chars: 3,
- truncated: false,
- source: "default",
- },
- },
- ],
-} as any;
-
const approvalMessage = {
id: "a1",
role: "assistant",
@@ -268,50 +231,50 @@ describe("AgentChatProvider", () => {
expect(body.pageContext).toEqual({ route: "/dashboard/myjobs" });
});
- it("saves a completed review to the resume it read", async () => {
+ const reviewToolMessage = {
+ id: "a2",
+ role: "assistant",
+ parts: [
+ {
+ type: "tool-review_resume",
+ toolCallId: "rv1",
+ state: "output-available",
+ input: {},
+ output: {
+ status: "ok",
+ resumeId: "r1",
+ title: "Senior Engineer Resume",
+ scores: { overall: 78, impact: 72, clarity: 81, atsCompatibility: 69 },
+ body: "## Summary",
+ saved: true,
+ },
+ },
+ ],
+ } as any;
+
+ // The save lives in review_resume's execute now: it holds the resumeId and
+ // the finished text, so nothing client-side has to infer either. What is
+ // left here is the refresh, so a stale saved-review card behind the panel
+ // does not survive a review the user just watched land.
+ it("refreshes the page after a completed review", async () => {
setup();
await act(async () => {
chatInit().onFinish({
- message: reviewMessage,
- messages: [readMessage, reviewMessage],
+ message: reviewToolMessage,
+ messages: [reviewToolMessage],
});
});
- expect(saveResumeReviewResult).toHaveBeenCalledTimes(1);
- const [resumeId, payload] = (saveResumeReviewResult as any).mock.calls[0];
- expect(resumeId).toBe("r1");
- expect(JSON.parse(payload)).toMatchObject({
- overall: 78,
- atsCompatibility: 69,
- });
- expect(JSON.parse(payload).body).toContain("## Summary");
- });
-
- it("does not save a reply with no scores line", async () => {
- setup();
- const chatter = {
- id: "a2",
- role: "assistant",
- parts: [{ type: "text", text: "The tables hurt your ATS score." }],
- } as any;
- await act(async () => {
- chatInit().onFinish({ message: chatter, messages: [readMessage, chatter] });
- });
- expect(saveResumeReviewResult).not.toHaveBeenCalled();
+ expect(refresh).toHaveBeenCalled();
});
- // Closing the panel mid-stream aborts, and onFinish still fires with what
- // streamed. Since the SCORES line comes first, that partial parses — and
- // saving it would overwrite a complete review with no way back.
- it("does not save a review the user aborted mid-stream", async () => {
+ it("accumulates transient review deltas keyed by tool call id", async () => {
setup();
await act(async () => {
- chatInit().onFinish({
- message: reviewMessage,
- messages: [readMessage, reviewMessage],
- isAbort: true,
- });
+ chatInit().onData({ type: "data-review", id: "rv1", data: { delta: "SCO" } });
+ chatInit().onData({ type: "data-review", id: "rv1", data: { delta: "RES:" } });
+ chatInit().onData({ type: "data-paste", id: "rv1", data: { delta: "nope" } });
});
- expect(saveResumeReviewResult).not.toHaveBeenCalled();
+ expect(screen.getByTestId("review-stream")).toHaveTextContent("SCORES:");
});
it("restores an expanded panel when the sidebar re-expands", async () => {
diff --git a/__tests__/agentReviewSave.spec.ts b/__tests__/agentReviewSave.spec.ts
deleted file mode 100644
index d54fd07..0000000
--- a/__tests__/agentReviewSave.spec.ts
+++ /dev/null
@@ -1,147 +0,0 @@
-import { detectReviewSave } from "@/lib/agent/review";
-
-const REVIEW = "SCORES: overall=78 impact=72 clarity=81 ats=69\n\n## Summary\n\nSolid.";
-const REVIEW_2 = "SCORES: overall=61 impact=55 clarity=64 ats=70\n\n## Summary\n\nHarsher.";
-
-const text = (id: string, role: string, body: string) => ({
- id,
- role,
- parts: [{ type: "text", text: body }],
-}) as any;
-
-const readResult = (id: string, resumeId: string, title: string, status = "ok") =>
- ({
- id,
- role: "assistant",
- parts: [
- {
- type: "tool-get_resume",
- toolCallId: `t-${id}`,
- state: "output-available",
- input: {},
- output:
- status === "ok"
- ? { status: "ok", resumeId, title, resumeText: "TXT", chars: 3, truncated: false, source: "default" }
- : { status },
- },
- ],
- }) as any;
-
-// The shape the route actually produces: one assistant message carrying the
-// tool result AND the review, because both are steps of one streamText call.
-const readAndReview = (id: string, resumeId: string, title: string, body: string) =>
- ({
- id,
- role: "assistant",
- parts: [
- {
- type: "tool-get_resume",
- toolCallId: `t-${id}`,
- state: "output-available",
- input: {},
- output: { status: "ok", resumeId, title, resumeText: "TXT", chars: 3, truncated: false, source: "default" },
- },
- { type: "text", text: body },
- ],
- }) as any;
-
-describe("detectReviewSave", () => {
- // The normal case. A backwards-only scan misses this entirely, because the
- // read it needs is inside the very message it is being asked about.
- it("saves a review whose get_resume result is in the same message", () => {
- const finished = readAndReview("a1", "r1", "Senior Engineer Resume", REVIEW);
- expect(detectReviewSave([text("u1", "user", "Review my resume"), finished], finished)).toEqual({
- resumeId: "r1",
- title: "Senior Engineer Resume",
- scores: { overall: 78, impact: 72, clarity: 81, atsCompatibility: 69 },
- body: expect.stringContaining("## Summary"),
- });
- });
-
- // The same-message shape must not reopen the window either: the follow-up
- // walks back, hits that message, and has to see its scores before its read.
- it("does not save a follow-up after a same-message review", () => {
- const finished = text("a2", "assistant", REVIEW_2);
- const messages = [
- readAndReview("a1", "r1", "Senior Engineer Resume", REVIEW),
- text("u2", "user", "be harsher"),
- finished,
- ];
- expect(detectReviewSave(messages, finished)).toBeNull();
- });
-
- it("saves the first review after a get_resume result", () => {
- const finished = text("a2", "assistant", REVIEW);
- const messages = [
- text("u1", "user", "Review my resume"),
- readResult("a1", "r1", "Senior Engineer Resume"),
- finished,
- ];
- expect(detectReviewSave(messages, finished)).toEqual({
- resumeId: "r1",
- title: "Senior Engineer Resume",
- scores: { overall: 78, impact: 72, clarity: 81, atsCompatibility: 69 },
- body: expect.stringContaining("## Summary"),
- });
- });
-
- it("does not save a message with no scores line", () => {
- const finished = text("a2", "assistant", "The tables are hurting your ATS score.");
- const messages = [readResult("a1", "r1", "Resume"), finished];
- expect(detectReviewSave(messages, finished)).toBeNull();
- });
-
- it("does not save when no resume was read", () => {
- const finished = text("a1", "assistant", REVIEW);
- expect(detectReviewSave([finished], finished)).toBeNull();
- });
-
- it("does not save when the read failed", () => {
- const finished = text("a2", "assistant", REVIEW);
- const messages = [readResult("a1", "", "", "no_resumes"), finished];
- expect(detectReviewSave(messages, finished)).toBeNull();
- });
-
- // The guard the user chose: a chatty follow-up that restates the scores
- // must not replace the full saved review.
- it("does not save a second scoring message after the same read", () => {
- const finished = text("a3", "assistant", REVIEW_2);
- const messages = [
- readResult("a1", "r1", "Resume"),
- text("a2", "assistant", REVIEW),
- text("u2", "user", "be harsher"),
- finished,
- ];
- expect(detectReviewSave(messages, finished)).toBeNull();
- });
-
- // A deliberate redo re-reads the resume, which opens a fresh window.
- it("saves again after a second get_resume result", () => {
- const finished = text("a4", "assistant", REVIEW_2);
- const messages = [
- readResult("a1", "r1", "Resume"),
- text("a2", "assistant", REVIEW),
- text("u2", "user", "redo it, be harsher"),
- readResult("a3", "r1", "Resume"),
- finished,
- ];
- expect(detectReviewSave(messages, finished)?.scores.overall).toBe(61);
- });
-
- it("attributes each review to the resume it actually read", () => {
- const finished = text("a4", "assistant", REVIEW_2);
- const messages = [
- readResult("a1", "r1", "Engineer Resume"),
- text("a2", "assistant", REVIEW),
- readResult("a3", "r2", "PM Resume"),
- finished,
- ];
- expect(detectReviewSave(messages, finished)?.resumeId).toBe("r2");
- });
-
- it("ignores messages after the finished one", () => {
- const finished = text("a2", "assistant", REVIEW);
- const messages = [readResult("a1", "r1", "Resume"), finished, text("a3", "assistant", REVIEW_2)];
- expect(detectReviewSave(messages, finished)?.scores.overall).toBe(78);
- });
-});
diff --git a/src/components/agent/AgentChatMessages.tsx b/src/components/agent/AgentChatMessages.tsx
index 7771292..058ccb9 100644
--- a/src/components/agent/AgentChatMessages.tsx
+++ b/src/components/agent/AgentChatMessages.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useMemo, useState } from "react";
+import { useState } from "react";
import { FileTextIcon, XIcon } from "lucide-react";
import { getToolName, isStaticToolUIPart, type UIMessage } from "ai";
import {
@@ -13,12 +13,10 @@ import { AgentApprovalCard } from "@/components/agent/AgentApprovalCard";
import { AgentMarkdown } from "@/components/agent/AgentMarkdown";
import { AgentResultCard } from "@/components/agent/AgentResultCard";
import { AgentReviewContent } from "@/components/agent/AgentReviewContent";
-import { AgentReviewScoreCard } from "@/components/agent/AgentReviewScoreCard";
import { AgentStatusRow } from "@/components/agent/AgentStatusRow";
import { AgentToolRunningCard } from "@/components/agent/AgentToolRunningCard";
import { useAgentChat } from "@/components/agent/AgentChatProvider";
import { resolvePastedText } from "@/lib/agent/paste";
-import { detectReviewSave } from "@/lib/agent/review";
import { parseResumeReview } from "@/lib/ai/resumeReview/parse";
import { cn } from "@/lib/utils";
import { isAgentPastePart, type AgentPastePartData } from "@/models/agent.model";
@@ -70,38 +68,6 @@ function showThinking(messages: UIMessage[], status: string): boolean {
}
}
-// Every assistant message goes through the shared parser, not just reviews:
-// a message with no SCORES line simply comes back with scores undefined and
-// its body unchanged. One path means the scores line can never flash into
-// the prose mid-stream, which is what the old surface does too.
-//
-// A parsed scores line is not on its own proof of a review. The output format
-// says the first line MUST be the scores line, so a model that declines to
-// review still leads with one — all zeros — and a card rendered from that is
-// a lie. detectReviewSave is the same predicate the save uses, so the card
-// appears exactly when something persists.
-function AssistantText({
- text,
- message,
- messages,
-}: {
- text: string;
- message: UIMessage;
- messages: UIMessage[];
-}) {
- const { scores, body } = useMemo(() => parseResumeReview(text), [text]);
- const reviewed = useMemo(
- () => (scores ? detectReviewSave(messages, message) : null),
- [scores, messages, message],
- );
- return (
- <>
- {scores && reviewed && <AgentReviewScoreCard scores={scores} />}
- <AgentMarkdown text={body} />
- </>
- );
-}
-
export function AgentChatMessages() {
const {
messages,
@@ -149,14 +115,7 @@ export function AgentChatMessages() {
</p>
);
}
- return (
- <AssistantText
- key={i}
- message={message}
- messages={messages}
- text={part.text}
- />
- );
+ return <AgentMarkdown key={i} text={part.text} />;
}
if (isAgentPastePart(part))
return <PasteChip key={i} data={part.data} />;
diff --git a/src/components/agent/AgentChatProvider.tsx b/src/components/agent/AgentChatProvider.tsx
index 2efc5f8..eb6e400 100644
--- a/src/components/agent/AgentChatProvider.tsx
+++ b/src/components/agent/AgentChatProvider.tsx
@@ -13,14 +13,12 @@ import { useRouter, usePathname } from "next/navigation";
import { useChat } from "@ai-sdk/react";
import {
DefaultChatTransport,
+ getToolName,
isToolUIPart,
lastAssistantMessageIsCompleteWithApprovalResponses,
type UIMessage,
} from "ai";
import { hasPendingApproval } from "@/lib/agent/paste";
-import { detectReviewSave } from "@/lib/agent/review";
-import { saveResumeReviewResult } from "@/actions/profile.actions";
-import { toastSuccess, toastError } from "@/lib/toast";
import { useRightRail } from "@/context/RightRailContext";
import { useSidebar } from "@/context/SidebarContext";
import { useResizablePanel } from "@/hooks/useResizablePanel";
@@ -42,8 +40,6 @@ type Preflight = {
checked: boolean;
ok: boolean;
error?: string;
- // Kept for the review save's provenance fields, which mirror what the
- // review sheet writes.
provider?: string;
model?: string;
};
@@ -97,10 +93,6 @@ function useAgentChatValue(initialMessages: UIMessage[]) {
ok: true,
});
- // onFinish needs the preflight's provider/model without re-subscribing the
- // chat to preflight state.
- const aiRef = useRef<{ provider?: string; model?: string }>({});
-
const pageContextRef = useRef<PageContext>(pageContextFor(pathname));
useEffect(() => {
pageContextRef.current = pageContextFor(pathname);
@@ -128,40 +120,24 @@ function useAgentChatValue(initialMessages: UIMessage[]) {
const { delta } = part.data as AgentReviewStreamData;
setReviewStreams((prev) => ({ ...prev, [id]: (prev[id] ?? "") + delta }));
},
- onFinish: ({ message, messages, isAbort, isError }) => {
- // onFinish runs from a finally block, so it fires on abort too. The
- // SCORES line streams first, so a partial review parses — and
- // reviewData has no history to recover from.
+ onFinish: ({ message, isAbort, isError }) => {
+ // onFinish runs from a finally block, so it fires on abort too.
if (isAbort || isError) return;
- const wrote = (message?.parts ?? []).some((part) => {
- if (!isToolUIPart(part) || part.state !== "output-available")
- return false;
+ const finishedParts = message?.parts ?? [];
+ const wrote = finishedParts.some((part) => {
+ if (!isToolUIPart(part) || part.state !== "output-available") return false;
return (part.output as AgentAddJobResult | undefined)?.created === true;
});
-
- // The user watched the whole review stream, so there is nothing an
- // approval gate would show them that they have not already seen. Same
- // auto-save-after-stream pattern as the review sheet.
- const review = detectReviewSave(messages, message);
- if (review) {
- const reviewData = JSON.stringify({
- ...review.scores,
- body: review.body,
- reviewedAt: new Date().toISOString(),
- provider: aiRef.current.provider,
- model: aiRef.current.model,
- });
- void saveResumeReviewResult(review.resumeId, reviewData).then((res) => {
- if (res?.success) toastSuccess("Review saved");
- else toastError(res?.message || "Failed to save review");
- });
- }
+ const reviewed = finishedParts.some((part) => {
+ if (!isToolUIPart(part) || part.state !== "output-available") return false;
+ return getToolName(part) === "review_resume";
+ });
// Unconditional: an RSC refresh on an irrelevant page is a wasted
// request, not a bug. A stale jobs list or a stale saved review behind
// the panel right after watching one land reads as one.
- if (wrote || review) router.refresh();
+ if (wrote || reviewed) router.refresh();
},
});
@@ -190,7 +166,6 @@ function useAgentChatValue(initialMessages: UIMessage[]) {
// so the empty state says it and send is disabled — the user never
// spends a turn to learn it, and the route's 503 stays the backstop.
if (!ai?.model) {
- aiRef.current = { provider };
setPreflight({
checked: true,
ok: false,
@@ -201,7 +176,6 @@ function useAgentChatValue(initialMessages: UIMessage[]) {
return;
}
- aiRef.current = { provider, model: ai.model };
if (provider !== AiProvider.OLLAMA) {
setPreflight({ checked: true, ok: true, provider, model: ai.model });
return;
diff --git a/src/lib/agent/review.ts b/src/lib/agent/review.ts
deleted file mode 100644
index 6a57f7e..0000000
--- a/src/lib/agent/review.ts
+++ /dev/null
@@ -1,75 +0,0 @@
-import { getToolName, isToolUIPart, type UIMessage } from "ai";
-import { parseResumeReview } from "@/lib/ai/resumeReview/parse";
-import type { AgentGetResumeResult } from "@/models/agent.model";
-import type { ResumeScores } from "@/models/ai.schemas";
-
-// Client-safe: no server-only, no Prisma. The provider calls this in
-// onFinish and the tests call it directly.
-
-export type PendingReviewSave = {
- resumeId: string;
- title: string;
- scores: ResumeScores;
- body: string;
-};
-
-function assistantText(message: UIMessage): string {
- return (message.parts ?? [])
- .filter((part) => part.type === "text")
- .map((part) => (part as { text: string }).text)
- .join("");
-}
-
-function readResultIn(
- message: UIMessage,
-): { resumeId: string; title: string } | null {
- for (const part of message.parts ?? []) {
- if (!isToolUIPart(part)) continue;
- if (getToolName(part) !== "get_resume") continue;
- if (part.state !== "output-available") continue;
- const output = part.output as AgentGetResumeResult | undefined;
- if (output?.status === "ok") {
- return { resumeId: output.resumeId, title: output.title };
- }
- }
- return null;
-}
-
-/**
- * Saves only the FIRST scoring message after each successful get_resume. A
- * follow-up that happens to restate the scores must not replace a full saved
- * review; a deliberate redo re-reads the resume, which opens a new window.
- */
-export function detectReviewSave(
- messages: UIMessage[],
- finished: UIMessage,
-): PendingReviewSave | null {
- const { scores, body } = parseResumeReview(assistantText(finished));
- if (!scores) return null;
-
- // The route runs one streamText per turn, so a review's get_resume result
- // and its prose are parts of the SAME message. Check here before walking
- // back — a backwards-only scan skips the one message that has the answer.
- const own = readResultIn(finished);
- if (own) return { ...own, scores, body };
-
- // Split turn: "read my resume", then "now review it" as a second message.
- const end = messages.findIndex((m) => m.id === finished.id);
- const upto = end === -1 ? messages.length : end;
-
- for (let i = upto - 1; i >= 0; i--) {
- const message = messages[i];
- // Scores BEFORE the read check, not after: a prior review turn carries
- // both, and reacting to its read would let this follow-up overwrite the
- // review that message already saved.
- if (
- message.role === "assistant" &&
- parseResumeReview(assistantText(message)).scores
- ) {
- return null;
- }
- const read = readResultIn(message);
- if (read) return { ...read, scores, body };
- }
- return null;
-}