// engine/registry/composio-publisher.ts — SPEC-273: Composio integration schema publisher
// Generates .composio-schema.json for composio.dev tool integration platform.
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
/** Current schema format version for Composio entries. */
const COMPOSIO_SCHEMA_VERSION = '1.0';
/**
 * Converts a tool name (snake_case or kebab-case) into a human-readable description.
 */
function toolNameToDescription(name) {
    return name.replace(/[-_]/g, ' ').replace(/\b\w/g, (ch) => ch.toUpperCase());
}
/**
 * Generates a Composio schema from a list of tool names.
 * Each tool gets a basic description derived from its name.
 *
 * @param tools  Array of tool names to include in the schema.
 * @returns A ComposioSchema with mapped tool descriptors.
 */
export function generateComposioSchema(tools) {
    return {
        tools: tools.map((name) => ({
            name,
            description: toolNameToDescription(name),
        })),
        version: COMPOSIO_SCHEMA_VERSION,
    };
}
/**
 * Writes .composio-schema.json to the given project directory.
 *
 * @param projectPath  Absolute path to the project root.
 * @param tools        Array of tool names to include.
 */
export function writeComposioSchema(projectPath, tools) {
    const filePath = join(projectPath, '.composio-schema.json');
    const schema = generateComposioSchema(tools);
    const content = JSON.stringify(schema, null, 2) + '\n';
    /* v8 ignore start */
    try {
        writeFileSync(filePath, content, 'utf-8');
    }
    catch (err) {
        const msg = err instanceof Error ? err.message : String(err);
        throw new Error(`Failed to write .composio-schema.json to ${filePath}: ${msg}`, { cause: err });
    }
    /* v8 ignore stop */
}
//# sourceMappingURL=composio-publisher.js.map