From eda69fed744b48e62d3e2e397fe783b323e8aa8f Mon Sep 17 00:00:00 2001 From: dotta Date: Mon, 23 Mar 2026 20:04:40 -0500 Subject: [PATCH] Fix imported agent bundle frontmatter leakage Co-Authored-By: Paperclip --- server/src/__tests__/company-portability.test.ts | 3 +++ server/src/services/company-portability.ts | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/server/src/__tests__/company-portability.test.ts b/server/src/__tests__/company-portability.test.ts index bf6cfabe..d8d14a77 100644 --- a/server/src/__tests__/company-portability.test.ts +++ b/server/src/__tests__/company-portability.test.ts @@ -2108,5 +2108,8 @@ describe("company portability", () => { replaceExisting: true, }), ); + const materializedFiles = agentInstructionsSvc.materializeManagedBundle.mock.calls[0]?.[1] as Record; + expect(materializedFiles["AGENTS.md"]).not.toMatch(/^---\n/); + expect(materializedFiles["AGENTS.md"]).not.toContain('name: "ClaudeCoder"'); }); }); diff --git a/server/src/services/company-portability.ts b/server/src/services/company-portability.ts index a1f6a7c8..a8c408e1 100644 --- a/server/src/services/company-portability.ts +++ b/server/src/services/company-portability.ts @@ -3864,6 +3864,16 @@ export function companyPortabilityService(db: Db, storage?: StorageService) { : []), ); const markdownRaw = bundleFiles["AGENTS.md"] ?? readPortableTextFile(plan.source.files, manifestAgent.path); + const entryRelativePath = normalizePortablePath(manifestAgent.path).startsWith(bundlePrefix) + ? normalizePortablePath(manifestAgent.path).slice(bundlePrefix.length) + : "AGENTS.md"; + if (typeof markdownRaw === "string") { + const importedInstructionsBody = parseFrontmatterMarkdown(markdownRaw).body; + bundleFiles[entryRelativePath] = importedInstructionsBody; + if (entryRelativePath !== "AGENTS.md" && !bundleFiles["AGENTS.md"]) { + bundleFiles["AGENTS.md"] = importedInstructionsBody; + } + } const fallbackPromptTemplate = asString((manifestAgent.adapterConfig as Record).promptTemplate) || ""; if (!markdownRaw && fallbackPromptTemplate) { bundleFiles["AGENTS.md"] = fallbackPromptTemplate;