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
Fix Skill Studio markdown dirty tracking (#9356)
Dotta991279f52ca7
diff --git a/ui/src/pages/SkillStudio.test.tsx b/ui/src/pages/SkillStudio.test.tsxindex 6c13216750..3ed0cb3afd 100644--- a/ui/src/pages/SkillStudio.test.tsx+++ b/ui/src/pages/SkillStudio.test.tsx@@ -95,7 +95,29 @@ vi.mock("@/components/SearchableSelect", () => ({}));vi.mock("@/components/MarkdownEditor", () => ({- MarkdownEditor: ({ value }: { value: string }) => <textarea readOnly value={value} />,+ MarkdownEditor: ({+ value,+ onChange,+ readOnly,+ }: {+ value: string;+ onChange: (value: string) => void;+ readOnly?: boolean;+ }) => (+ <textarea+ data-testid="markdown-editor"+ readOnly={readOnly}+ value={value}+ onChange={(event) => {+ if (!readOnly) onChange(event.target.value);+ }}+ onKeyDown={(event) => {+ if (!readOnly && event.key === "E") {+ onChange(`${value}\n\nEdited body\n`);+ }+ }}+ />+ ),}));vi.mock("@/components/MarkdownBody", () => ({@@ -181,6 +203,12 @@ async function click(button: HTMLButtonElement) {});}+async function keyDown(element: HTMLElement, key: string) {+ await act(async () => {+ element.dispatchEvent(new KeyboardEvent("keydown", { bubbles: true, key }));+ });+}+function makeSkill(overrides: Partial<CompanySkillDetail> = {}): CompanySkillDetail {return {id: "source-skill",@@ -556,6 +584,54 @@ describe("SkillStudio editor frontmatter", () => {expect(node.querySelector("#fm-name")).toBeNull();});+ it("marks rich markdown body edits dirty and saves the edited markdown", async () => {+ mockCompanySkillsApi.updateFile.mockImplementationOnce((+ _companyId: string,+ _skillId: string,+ path: string,+ content: string,+ ) => Promise.resolve({+ path,+ content,+ markdown: true,+ editable: true,+ editableReason: null,+ }));++ const node = await renderStudio();++ let bodyEditor: HTMLTextAreaElement | undefined;+ await waitFor(() => {+ bodyEditor = Array.from(node.querySelectorAll<HTMLTextAreaElement>('[data-testid="markdown-editor"]')).find(+ (editor) => editor.value.includes("# Demo Skill"),+ );+ expect(bodyEditor).toBeTruthy();+ });++ await keyDown(bodyEditor as HTMLElement, "E");++ await waitFor(() => expect(node.textContent).toContain("Unsaved"));++ const saveButton = buttonsNamed(node, "Save").find((button) => !button.disabled);+ expect(saveButton).toBeTruthy();+ await click(saveButton as HTMLButtonElement);++ await waitFor(() => {+ expect(mockCompanySkillsApi.updateFile).toHaveBeenCalledWith(+ "company-1",+ "source-skill",+ "SKILL.md",+ expect.stringContaining("Edited body"),+ );+ });+ expect(mockCompanySkillsApi.updateFile).toHaveBeenCalledWith(+ "company-1",+ "source-skill",+ "SKILL.md",+ expect.stringContaining("---\nname: Demo Skill"),+ );+ });+it("offers an 'Edit a copy' CTA on the read-only banner (PAP-13112)", async () => {mockCompanySkillsApi.detail.mockResolvedValueOnce(makeSkill({editable: false,diff --git a/ui/src/pages/SkillStudio.tsx b/ui/src/pages/SkillStudio.tsxindex 57ffe0e181..345889bba6 100644--- a/ui/src/pages/SkillStudio.tsx+++ b/ui/src/pages/SkillStudio.tsx@@ -1264,6 +1264,9 @@ function SkillPane({// MDXEditor can emit a normalizing onChange on mount, which would otherwise// dirty the file on open and break the byte-identity guarantee (PAP-13156).const bodyInteractedRef = useRef(false);+ const markBodyInteracted = useCallback(() => {+ bodyInteractedRef.current = true;+ }, []);const nodes: FileTreeNode[] = useMemo(() => buildFileTree(Object.fromEntries(paths.map((p) => [p, ""]))),@@ -1510,9 +1513,12 @@ function SkillPane({) : null}<divclassName="min-h-0 flex-1 overflow-auto px-3 pb-3"- onInput={() => {- bodyInteractedRef.current = true;- }}+ onBeforeInputCapture={markBodyInteracted}+ onDropCapture={markBodyInteracted}+ onInput={markBodyInteracted}+ onKeyDownCapture={markBodyInteracted}+ onPasteCapture={markBodyInteracted}+ onPointerDownCapture={markBodyInteracted}>{isMarkdown && markdownBlock ? (<MarkdownEditor