UNPKG

aico-pack

Version:

A tool to pack repository contents to single file for AI consumption

68 lines 4.08 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import path from 'node:path'; import { z } from 'zod'; import { runCli } from '../../cli/cliRun.js'; import { buildMcpToolErrorResponse, createToolWorkspace, formatToolError, formatToolResponse, } from './mcpToolRuntime.js'; export const registerPackCodebaseTool = (mcpServer) => { mcpServer.tool('pack_codebase', 'Package a local code directory into a consolidated XML file for AI analysis. This tool analyzes the codebase structure, extracts relevant code content, and generates a comprehensive report including metrics, file tree, and formatted code content. Supports Tree-sitter compression for efficient token usage.', { directory: z.string().describe('Directory to pack (Absolute path)'), compress: z .boolean() .default(false) .describe('Enable Tree-sitter compression to extract essential code signatures and structure while removing implementation details. Reduces token usage by ~70% while preserving semantic meaning. Generally not needed since grep_repomix_output allows incremental content retrieval. Use only when you specifically need the entire codebase content for large repositories (default: false).'), includePatterns: z .string() .optional() .describe('Specify files to include using fast-glob patterns. Multiple patterns can be comma-separated (e.g., "**/*.{js,ts}", "src/**,docs/**"). Only matching files will be processed. Useful for focusing on specific parts of the codebase.'), ignorePatterns: z .string() .optional() .describe('Specify additional files to exclude using fast-glob patterns. Multiple patterns can be comma-separated (e.g., "test/**,*.spec.js", "node_modules/**,dist/**"). These patterns supplement .gitignore and built-in exclusions.'), topFilesLength: z .number() .optional() .default(10) .describe('Number of largest files by size to display in the metrics summary for codebase analysis (default: 10)'), }, { title: 'Pack Local Codebase', readOnlyHint: true, destructiveHint: false, idempotentHint: false, openWorldHint: false, }, (_a) => __awaiter(void 0, [_a], void 0, function* ({ directory, compress, includePatterns, ignorePatterns, topFilesLength }) { let tempDir = ''; try { tempDir = yield createToolWorkspace(); const outputFilePath = path.join(tempDir, 'output.xml'); const cliOptions = { compress, include: includePatterns, ignore: ignorePatterns, output: outputFilePath, style: 'xml', securityCheck: true, topFilesLen: topFilesLength, quiet: true, }; const result = yield runCli(['.'], directory, cliOptions); if (!result) { return buildMcpToolErrorResponse(['Failed to return a result']); } // Extract metrics information from the pack result const { packResult } = result; return yield formatToolResponse({ directory }, packResult, outputFilePath, topFilesLength); } catch (error) { return formatToolError(error); } })); }; //# sourceMappingURL=packCodebaseTool.js.map