The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
Handle nested imported AGENTS edge case
dotta08bdc3d28e16
diff --git a/server/src/__tests__/company-portability.test.ts b/server/src/__tests__/company-portability.test.tsindex d8d14a7777..a3410df6ad 100644--- a/server/src/__tests__/company-portability.test.ts+++ b/server/src/__tests__/company-portability.test.ts@@ -2112,4 +2112,74 @@ describe("company portability", () => {expect(materializedFiles["AGENTS.md"]).not.toMatch(/^---\n/);expect(materializedFiles["AGENTS.md"]).not.toContain('name: "ClaudeCoder"');});++ it("strips root AGENTS frontmatter when importing a nested agent entry path", async () => {+ const portability = companyPortabilityService({} as any);++ companySvc.create.mockResolvedValue({+ id: "company-imported",+ name: "Imported Paperclip",+ });+ accessSvc.ensureMembership.mockResolvedValue(undefined);+ agentSvc.create.mockResolvedValue({+ id: "agent-created",+ name: "ClaudeCoder",+ });++ const exported = await portability.exportBundle("company-1", {+ include: {+ company: true,+ agents: true,+ projects: false,+ issues: false,+ },+ });+ const originalAgentsMarkdown = exported.files["agents/claudecoder/AGENTS.md"];+ expect(typeof originalAgentsMarkdown).toBe("string");++ const files = {+ ...exported.files,+ "agents/claudecoder/nested/AGENTS.md": originalAgentsMarkdown!,+ };++ agentSvc.list.mockResolvedValue([]);++ await portability.importBundle({+ source: {+ type: "inline",+ rootPath: exported.rootPath,+ files,+ },+ include: {+ company: true,+ agents: true,+ projects: false,+ issues: false,+ },+ target: {+ mode: "new_company",+ newCompanyName: "Imported Paperclip",+ },+ agents: ["claudecoder"],+ collisionStrategy: "rename",+ adapterOverrides: {+ claudecoder: {+ adapterType: "codex_local",+ adapterConfig: {+ dangerouslyBypassApprovalsAndSandbox: true,+ },+ },+ },+ }, "user-1");++ const nestedMaterializedFiles = agentInstructionsSvc.materializeManagedBundle.mock.calls+ .map(([, filesArg]) => filesArg as Record<string, string>)+ .find((filesArg) => typeof filesArg["nested/AGENTS.md"] === "string");++ expect(nestedMaterializedFiles).toBeDefined();+ expect(nestedMaterializedFiles?.["nested/AGENTS.md"]).toContain("You are ClaudeCoder.");+ expect(nestedMaterializedFiles?.["AGENTS.md"]).toContain("You are ClaudeCoder.");+ expect(nestedMaterializedFiles?.["AGENTS.md"]).not.toMatch(/^---\n/);+ expect(nestedMaterializedFiles?.["AGENTS.md"]).not.toContain('name: "ClaudeCoder"');+ });});diff --git a/server/src/services/company-portability.ts b/server/src/services/company-portability.tsindex a8c408e189..7cfe8ffabc 100644--- a/server/src/services/company-portability.ts+++ b/server/src/services/company-portability.ts@@ -3870,7 +3870,7 @@ export function companyPortabilityService(db: Db, storage?: StorageService) {if (typeof markdownRaw === "string") {const importedInstructionsBody = parseFrontmatterMarkdown(markdownRaw).body;bundleFiles[entryRelativePath] = importedInstructionsBody;- if (entryRelativePath !== "AGENTS.md" && !bundleFiles["AGENTS.md"]) {+ if (entryRelativePath !== "AGENTS.md") {bundleFiles["AGENTS.md"] = importedInstructionsBody;}}