@jasondark/proompt
Version:
CLI tool for running AI prompts with structure and repeatability
171 lines • 7.97 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.documentProjectCommand = void 0;
const child_process_1 = require("child_process");
const fs_1 = require("fs");
const path = __importStar(require("path"));
const command_utils_1 = require("@/core/command-utils");
const resolver_1 = require("@/core/config/resolver");
const constants_1 = require("@/core/constants");
const doc_metadata_1 = require("@/core/utils/doc-metadata");
const file_tracker_1 = require("@/core/utils/file-tracker");
const git_1 = require("@/core/utils/git");
const repomix_1 = require("@/core/utils/repomix");
const rules_1 = require("@/core/utils/rules");
const temp_file_1 = require("@/core/utils/temp-file");
const schema_1 = require("./schema");
// Read proompt content
const proomptContent = (0, fs_1.readFileSync)(path.join(__dirname, 'proompt.md'), 'utf-8');
/**
* Custom handler that generates XML file before AI execution
*/
const customDocumentProjectHandler = async (args) => {
// Validate arguments using schema
const validatedArgs = schema_1.documentProjectArgsSchema.parse(args);
try {
// Get current commit hash for tracking
const commitHash = (0, git_1.getCurrentCommitHash)();
if (!commitHash) {
console.warn('⚠️ Warning: Not in a git repository, commit hash tracking disabled');
}
// Generate temporary XML file path
const xmlFilePath = (0, temp_file_1.generateTempXmlPath)('document-project');
// Log temp file location for user awareness
(0, temp_file_1.logTempFileLocation)(xmlFilePath);
// Execute repomix library to generate XML
console.log('📦 Packing repository with repomix...');
await (0, repomix_1.executeRepomix)({
outputPath: xmlFilePath,
workingDirectory: process.cwd(),
});
console.log('✅ Repository packed successfully');
// Resolve settings using hierarchy: args > user settings > defaults
const settingsOverride = {
llmCli: args?.llmCli,
outputFormat: args?.outputFormat,
};
const resolvedSettings = (0, resolver_1.resolveSettings)(settingsOverride);
const llmCli = resolvedSettings.llmCli;
const outputFormat = resolvedSettings.outputFormat;
// Generate output file names based on configured formats
const outputFileNames = outputFormat.map((format) => constants_1.OUTPUT_FILE_NAMES[format]);
const isPlural = outputFileNames.length > 1;
// Check for optional RULES.md file in project root
const projectRules = (0, rules_1.readRulesFile)(process.cwd());
const formattedRules = projectRules
? (0, rules_1.formatRulesForPrompt)(projectRules, 'project root')
: '';
// Inject template variables including XML file path and optional rules
const enhancedArgs = {
...validatedArgs,
repoXmlPath: xmlFilePath,
outputFiles: outputFileNames.map((name) => `\`${name}\``).join(' and '),
outputFileList: outputFileNames.join(' and '),
outputAction: isPlural ? 'Create identical' : 'Create a',
fileOrFiles: isPlural ? 'files' : 'file',
requiredDocFiles: outputFileNames.map((name) => `"${name}"`).join(', '),
allRequiredFilesExist: `all required files (${outputFileNames.join(', ')}) exist`,
projectRules: formattedRules,
};
// Replace variables with provided arguments using imported function
const processedContent = (0, command_utils_1.replaceVariables)(proomptContent, enhancedArgs);
// Record start time for file modification tracking
const startTime = new Date();
// Launch interactive CLI with initial prompt
console.log(`🤖 Launching ${llmCli} for repository analysis...`);
let child;
if (llmCli === 'claude') {
child = (0, child_process_1.spawn)('claude', [processedContent], {
stdio: 'inherit',
});
}
else if (llmCli === 'gemini') {
child = (0, child_process_1.spawn)('gemini', ['-i', processedContent], {
stdio: 'inherit',
});
}
else {
throw new Error(`Unsupported LLM CLI: ${llmCli}`);
}
return new Promise((resolve, reject) => {
child.on('close', (code) => {
if (code === 0) {
// Check if documentation files were actually modified
const filesModified = (0, file_tracker_1.anyDocumentationFilesModified)(startTime, outputFileNames);
// Update metadata if files were modified and we have a commit hash
if (filesModified && commitHash) {
try {
(0, doc_metadata_1.updateProjectDocHash)(commitHash);
console.log(`📝 Updated project documentation metadata with commit ${commitHash.substring(0, 7)}`);
}
catch (error) {
console.warn('⚠️ Warning: Failed to update documentation metadata:', error.message);
}
}
else if (filesModified && !commitHash) {
console.log('📝 Documentation files were modified but no commit hash available for tracking');
}
resolve();
}
else {
reject(new Error(`${llmCli} command failed with exit code ${code}`));
}
});
child.on('error', (error) => {
reject(error);
});
});
}
catch (error) {
console.error('❌ Error during repository processing:', error.message);
throw error;
}
};
// Create and export the command module with custom handler
exports.documentProjectCommand = (0, command_utils_1.createCommandModule)({
name: 'document-project',
description: 'Generate comprehensive codebase analysis and overview documentation for AI coding tools',
arguments: [
{
name: 'initial-documentation-path',
description: 'Path to initial documentation file (README.md, CLAUDE.md, GEMINI.md)',
required: true,
type: 'string',
positional: true,
},
],
}, schema_1.documentProjectArgsSchema, proomptContent, customDocumentProjectHandler);
//# sourceMappingURL=index.js.map