Files
oh-my-pi/packages/coding-agent/scripts/format-prompts.ts
T
can1357 b7c801fab2 feat(tools): added GitHub Actions workflow renderer and enhanced gh-* tool outputs
- Added gh-renderer.ts module with GitHub Actions workflow visualization for terminal output.
- Enhanced gh_pr_view tool to fetch and display inline review comments alongside pull request reviews.
- Improved gh_run_watch tool output with structured job state tracking and failed log formatting.
- Fixed gh_run_watch to resolve explicit branch watches against GitHub API branch head instead of local HEAD.
- Fixed gh_* tool outputs to spill full large results to artifacts instead of pre-truncating.
- Standardized trailing newlines across 100+ prompt template files for POSIX compliance.
2026-04-01 17:35:39 +02:00

69 lines
2.1 KiB
TypeScript

#!/usr/bin/env bun
/**
* Format prompt files (mixed XML + Markdown + Handlebars).
*
* Rules:
* 1. No blank line before list items
* 2. No blank line after opening XML tag or Handlebars block
* 3. No blank line before closing XML tag or Handlebars block
* 4. Strip leading whitespace from top-level closing XML tags (opened at col 0) and Handlebars (lines starting with {{)
* 5. Compact markdown tables (remove padding)
* 6. Collapse 2+ blank lines to single blank line
* 7. Trim trailing whitespace (preserve indentation)
* 8. Trailing newline at EOF (disk only; runtime omits it)
* 9. Bold RFC 2119 keywords (MUST, SHOULD, MAY, etc.) in prompt content
*/
import { Glob } from "bun";
import { formatPromptContent } from "../src/utils/prompt-format";
const PROMPTS_DIR = new URL("../src/prompts/", import.meta.url).pathname;
const COMMIT_PROMPTS_DIR = new URL("../src/commit/prompts/", import.meta.url).pathname;
const AGENTIC_PROMPTS_DIR = new URL("../src/commit/agentic/prompts/", import.meta.url).pathname;
const PROMPT_DIRS = [PROMPTS_DIR, COMMIT_PROMPTS_DIR, AGENTIC_PROMPTS_DIR];
const PROMPT_FORMAT_OPTIONS = {
renderPhase: "pre-render",
replaceAsciiSymbols: true,
boldRfc2119Keywords: true,
} as const;
async function main() {
const glob = new Glob("**/*.md");
const files: string[] = [];
let changed = 0;
const check = process.argv.includes("--check");
for (const dir of PROMPT_DIRS) {
for await (const path of glob.scan(dir)) {
files.push(`${dir}${path}`);
}
}
for (const fullPath of files) {
const original = await Bun.file(fullPath).text();
const formatted = formatPromptContent(original, PROMPT_FORMAT_OPTIONS);
if (original !== `${formatted}\n`) {
if (check) {
console.log(`Would format: ${fullPath}`);
} else {
await Bun.write(fullPath, `${formatted}\n`);
console.log(`Formatted: ${fullPath}`);
}
changed++;
}
}
if (check && changed > 0) {
console.log(`\n${changed} file(s) need formatting. Run 'bun run format-prompts' to fix.`);
process.exit(1);
} else if (changed === 0) {
console.log("All prompt files are formatted.");
} else {
console.log(`\nFormatted ${changed} file(s).`);
}
}
main();