fix: polish ai agent and command palette

This commit is contained in:
Amruth Pillai
2026-07-04 20:24:39 +02:00
parent 3e96605d4c
commit 82d961241e
14 changed files with 387 additions and 13 deletions
+23 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { buildAgentDraftResumeName, buildUniqueAgentDraftSlug } from "./resume";
import { buildAgentDraftResumeName, buildUniqueAgentDraftSlug, normalizeAgentResumePatchOperations } from "./resume";
describe("agent resume setup helpers", () => {
it("names duplicated resumes as AI drafts", () => {
@@ -14,3 +14,25 @@ describe("agent resume setup helpers", () => {
);
});
});
describe("normalizeAgentResumePatchOperations", () => {
it("prefixes shorthand standard section paths without touching custom section paths", () => {
const result = normalizeAgentResumePatchOperations(
{
sections: {
experience: {},
education: {},
},
},
[
{ op: "replace", path: "/experience/items/0/description", value: "Updated" },
{ op: "copy", from: "/education/items/0", path: "/customSections/0/items/-" },
],
);
expect(result).toEqual([
{ op: "replace", path: "/sections/experience/items/0/description", value: "Updated" },
{ op: "copy", from: "/sections/education/items/0", path: "/customSections/0/items/-" },
]);
});
});
+29
View File
@@ -1,3 +1,4 @@
import type { JsonPatchOperation } from "@reactive-resume/resume/patch";
import { slugify } from "@reactive-resume/utils/string";
const AI_DRAFT_SUFFIX = " - AI Draft";
@@ -23,3 +24,31 @@ export function buildUniqueAgentDraftSlug(sourceName: string, existingSlugs: Set
return candidate;
}
function decodeJsonPointerSegment(segment: string) {
return segment.replace(/~1/g, "/").replace(/~0/g, "~");
}
function normalizeSectionShortcutPath(data: { sections: Record<string, unknown> }, path: string) {
if (!path.startsWith("/") || path.startsWith("/sections/")) return path;
const sectionId = decodeJsonPointerSegment(path.slice(1).split("/")[0] ?? "");
if (!Object.hasOwn(data.sections, sectionId)) return path;
return `/sections${path}`;
}
export function normalizeAgentResumePatchOperations(
data: { sections: Record<string, unknown> },
operations: JsonPatchOperation[],
): JsonPatchOperation[] {
return operations.map((operation) => {
const path = normalizeSectionShortcutPath(data, operation.path);
const normalized = path === operation.path ? operation : { ...operation, path };
if (!("from" in normalized)) return normalized;
const from = normalizeSectionShortcutPath(data, normalized.from);
return from === normalized.from ? normalized : { ...normalized, from };
});
}
+8 -3
View File
@@ -15,7 +15,7 @@ import { getAgentModel } from "../ai/service";
import { aiProvidersService } from "../ai-providers/service";
import { resumeService } from "../resume/service";
import { getStorageService, inferContentType } from "../storage/service";
import { buildAgentDraftResumeName, buildUniqueAgentDraftSlug } from "./resume";
import { buildAgentDraftResumeName, buildUniqueAgentDraftSlug, normalizeAgentResumePatchOperations } from "./resume";
import { claimActiveAgentRun, clearActiveAgentRunIfCurrent } from "./runs";
import { agentStreamLifecycle } from "./streams";
import { buildAgentInstructions, buildAgentTools } from "./tools";
@@ -717,12 +717,13 @@ async function applyResumePatch(input: {
}) {
const before = await resumeService.getById({ id: input.resumeId, userId: input.userId });
const snapshotData = cloneResumeData(before.data);
const operations = normalizeAgentResumePatchOperations(before.data, input.operations);
const { action, patched } = await db.transaction(async (tx) => {
const patched = await resumeService.patchInTransaction(tx, {
id: input.resumeId,
userId: input.userId,
operations: input.operations,
operations,
});
const [action] = await tx
@@ -735,7 +736,7 @@ async function applyResumePatch(input: {
status: "applied",
title: input.title,
...(input.summary !== undefined ? { summary: input.summary } : {}),
operations: input.operations,
operations,
snapshotData,
baseUpdatedAt: before.updatedAt,
appliedUpdatedAt: patched.updatedAt,
@@ -787,10 +788,14 @@ function createAgent(input: {
patchRoot: "data",
patchPathExamples: {
visibleName: "/basics/name",
standardExperienceDescription: "/sections/experience/items/0/description",
customSectionDescription: "/customSections/0/items/0/description",
},
patchNotes: [
"apply_resume_patch paths are rooted at the `data` object below.",
"Do not prefix paths with `/data`.",
"Built-in sections live under `/sections/<sectionId>`, for example `/sections/experience/items/0/description`.",
"Custom sections live under `/customSections/<index>`, even when their `type` is `experience`, `education`, or another built-in section type.",
"The resume file/title `name` metadata is read-only for apply_resume_patch.",
],
data: resume.data,
@@ -90,6 +90,12 @@ describe("agent tools", () => {
);
expect(buildAgentInstructions({ hasProviderNativeSearch: false })).toContain("Batch related JSON Patch operations");
expect(buildAgentInstructions({ hasProviderNativeSearch: false })).toContain("/basics/name");
expect(buildAgentInstructions({ hasProviderNativeSearch: false })).toContain(
"/sections/experience/items/0/description",
);
expect(buildAgentInstructions({ hasProviderNativeSearch: false })).toContain(
"/customSections/0/items/0/description",
);
expect(buildAgentInstructions({ hasProviderNativeSearch: false })).toContain("never /data/basics/name or /name");
expect(buildAgentInstructions({ hasProviderNativeSearch: false })).toContain("clean Markdown");
});
+1 -1
View File
@@ -52,7 +52,7 @@ function buildProviderNativeAgentTools(provider: AgentProviderConfig): ToolSet {
export function buildAgentInstructions({ hasProviderNativeSearch }: { hasProviderNativeSearch: boolean }) {
const baseInstructions =
"You are an expert resume-writing agent inside Reactive Resume. Help the user improve the working resume for a target role. Read the resume before editing. Respond to the user in clean Markdown with concise paragraphs, bullets, and bold text when it improves scanability. Apply concise, valid JSON Patch operations when changes are useful. Patch paths are evaluated against the resume data object returned by read_resume, so use paths like /basics/name for the visible name and never /data/basics/name or /name. apply_resume_patch cannot rename the resume file/title metadata. Batch related JSON Patch operations into one apply_resume_patch call for each coherent edit instead of making repeated patch calls for the same request. Ask the user a question when a missing preference blocks a high-confidence edit.";
"You are an expert resume-writing agent inside Reactive Resume. Help the user improve the working resume for a target role. Read the resume before editing. Respond to the user in clean Markdown with concise paragraphs, bullets, and bold text when it improves scanability. Apply concise, valid JSON Patch operations when changes are useful. Patch paths are evaluated against the resume data object returned by read_resume, so use paths like /basics/name for the visible name and never /data/basics/name or /name. Built-in sections must use /sections/<sectionId>, for example /sections/experience/items/0/description. Custom sections must use /customSections/<index>, for example /customSections/0/items/0/description, even when their type is experience, education, or another built-in section type. apply_resume_patch cannot rename the resume file/title metadata. Batch related JSON Patch operations into one apply_resume_patch call for each coherent edit instead of making repeated patch calls for the same request. Ask the user a question when a missing preference blocks a high-confidence edit.";
if (!hasProviderNativeSearch) {
return `${baseInstructions} Live web research is unavailable with the selected provider or model. If the user asks you to browse, search the web, fetch a URL, or use current online context, briefly tell them live web research is unavailable with the selected provider/model and ask them to paste or attach the relevant content. Continue normal resume editing using the resume, chat context, and attachments.`;