import { z } from "zod"; import { withAuth } from "../../auth/index.js"; import { handleToolError } from "../helpers/errorHandler.js"; import { withAuthParams } from "../helpers/authSchema.js"; import fs from "fs"; import path from "path"; import { resolveCurrentProjectDir } from "../files/helpers.js"; export function registerSaveProjectStylesTool(server) { server.tool( "save_project_styles", `Save the project's visual design styles summary to docs/project-styles.md. Call this after exploring existing modules to cache the style reference for future module creation. This avoids re-exploring modules every time a new module is created. The content should include: color palette (hex values), typography, spacing patterns, Tailwind classes, button/card/section styles, and recurring design patterns.`, withAuthParams({ content: z.string().describe("Markdown content with the project styles summary"), }), { readOnlyHint: false, destructiveHint: false }, withAuth(async ({ content }, extra) => { try { if (!content || !content.trim()) { return { content: [{ type: "text", text: "Error: content is required" }], isError: true, }; } // Get project directory from session (HTTP) or env (stdio fallback) const projectDir = resolveCurrentProjectDir(); if (!projectDir) { return { content: [{ type: "text", text: "Error: ACAI_PROJECT_DIR not set" }], isError: true, }; } // Ensure docs/ directory exists const docsDir = path.join(projectDir, "docs"); if (!fs.existsSync(docsDir)) { fs.mkdirSync(docsDir, { recursive: true }); } // Write the file const filePath = path.join(docsDir, "project-styles.md"); fs.writeFileSync(filePath, content.trim() + "\n", "utf-8"); return { content: [{ type: "text", text: JSON.stringify({ success: true, message: "Project styles saved successfully", filePath: "docs/project-styles.md", }) }], }; } catch (error) { return handleToolError(error, "save_project_styles", {}); } }) ); }