@jasondark/proompt
Version:
CLI tool for running AI prompts with structure and repeatability
157 lines (138 loc) • 5.96 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.formatMultipleRulesForPrompt = exports.formatRulesForPrompt = exports.readRulesFromDirectories = exports.readRulesFile = void 0;
const fs_1 = require("fs");
const path = __importStar(require("path"));
/**
* Reads a RULES.md file from the specified directory if it exists and has content.
* This is an optional feature - missing files are expected and handled silently.
*
* @param directoryPath - The directory to check for RULES.md
* @returns The content of RULES.md if found and has content, undefined otherwise
*/
const readRulesFile = (directoryPath) => {
const rulesPath = path.join(directoryPath, 'RULES.md');
try {
if (!(0, fs_1.existsSync)(rulesPath)) {
return undefined;
}
const content = (0, fs_1.readFileSync)(rulesPath, 'utf-8').trim();
// Return undefined if file exists but has no meaningful content
if (content.length === 0) {
return undefined;
}
return content;
}
catch {
// Silently handle any file reading errors - this is an optional feature
return undefined;
}
};
exports.readRulesFile = readRulesFile;
/**
* Reads RULES.md files from multiple directories and combines them.
* Used by document-dirs command to collect rules from all specified directories.
*
* @param directoryPaths - Array of directory paths to check for RULES.md
* @returns Object mapping directory paths to their rules content (only includes directories with rules)
*/
const readRulesFromDirectories = (directoryPaths) => {
const rulesMap = {};
for (const dirPath of directoryPaths) {
const rules = (0, exports.readRulesFile)(dirPath);
if (rules) {
rulesMap[dirPath] = rules;
}
}
return rulesMap;
};
exports.readRulesFromDirectories = readRulesFromDirectories;
/**
* Formats rules content for inclusion in prompts with strong emphasis on compliance.
*
* @param rules - The rules content to format
* @param source - Description of where the rules came from (e.g., "project root" or "directory X")
* @returns Formatted rules text for prompt inclusion
*/
const formatRulesForPrompt = (rules, source) => {
return `
It is imperative you write the following information verbatim into your output at the end of the file:
## CRITICAL PROJECT RULES FROM ${source.toUpperCase()}
**⚠️ MANDATORY COMPLIANCE NOTICE ⚠️**
The following rules are **NON-NEGOTIABLE** and **SUPERSEDE** any patterns, conventions, or practices you may discover in the codebase analysis. These rules come directly from the project maintainers and represent absolute requirements.
**FAILURE TO FOLLOW THESE RULES IS A CRITICAL FAILURE** for any agentic coder working on this project.
---
${rules}
---
Remember: These rules are **mandatory** and **non-negotiable**. They override any conflicting information you may find elsewhere in the codebase or documentation.
**END OF CRITICAL PROJECT RULES**
`;
};
exports.formatRulesForPrompt = formatRulesForPrompt;
/**
* Formats multiple rules from different directories for the document-dirs command.
*
* @param rulesMap - Object mapping directory paths to their rules content
* @returns Formatted rules text for prompt inclusion, or undefined if no rules found
*/
const formatMultipleRulesForPrompt = (rulesMap) => {
const directories = Object.keys(rulesMap);
if (directories.length === 0) {
return undefined;
}
let formattedRules = `
It is imperative you write the following information verbatim into your output at the end of the file:
## CRITICAL PROJECT RULES FROM ANALYZED DIRECTORIES
**⚠️ MANDATORY COMPLIANCE NOTICE ⚠️**
The following rules are **NON-NEGOTIABLE** and **SUPERSEDE** any patterns, conventions, or practices you may discover in the codebase analysis. These rules come directly from the project maintainers and represent absolute requirements.
**FAILURE TO FOLLOW THESE RULES IS A CRITICAL FAILURE** for any agentic coder working on this project.
---
`;
for (const [dirPath, rules] of Object.entries(rulesMap)) {
formattedRules += `
### Rules from: ${dirPath}
${rules}
---
`;
}
formattedRules += `
Remember: These rules are **mandatory** and **non-negotiable**. They override any conflicting information you may find elsewhere in the codebase or documentation.
**END OF CRITICAL PROJECT RULES**
`;
return formattedRules;
};
exports.formatMultipleRulesForPrompt = formatMultipleRulesForPrompt;
//# sourceMappingURL=rules.js.map