Compare commits

...

1 Commits

Author SHA1 Message Date
Colin McDonnell 5b5df2bdca Truncate prompt 2025-12-08 20:06:03 -08:00
4 changed files with 1357 additions and 1691 deletions
+1316 -1658
View File
File diff suppressed because it is too large Load Diff
+8
View File
@@ -57,6 +57,14 @@ export type PayloadEvent =
branch: string;
[key: string]: any;
}
| {
trigger: "pull_request_ready_for_review";
issue_number: number;
pr_title: string;
pr_body: string | null;
branch: string;
[key: string]: any;
}
| {
trigger: "pull_request_review_requested";
issue_number: number;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@pullfrog/action",
"version": "0.0.127",
"version": "0.0.128",
"type": "module",
"files": [
"index.js",
+32 -32
View File
@@ -10,6 +10,30 @@ import { table } from "table";
const isGitHubActions = !!process.env.GITHUB_ACTIONS;
const isDebugEnabled = () => process.env.LOG_LEVEL === "debug";
/**
* Get the terminal width, or a reasonable default if not available
*/
function getTerminalWidth(): number {
if (process.stdout.columns && process.stdout.columns > 0) {
return process.stdout.columns;
}
// reasonable default for most terminals
return 120;
}
/**
* Truncate a line to fit within maxLength, adding ellipsis if needed
*/
function truncateLine(line: string, maxLength: number): string {
if (line.length <= maxLength) {
return line;
}
if (maxLength <= 3) {
return "...".slice(0, maxLength);
}
return line.slice(0, maxLength - 3) + "...";
}
/**
* Start a collapsed group (GitHub Actions) or regular group (local)
*/
@@ -44,40 +68,16 @@ function boxString(
padding?: number;
}
): string {
const { title, maxWidth = 80, indent = "", padding = 1 } = options || {};
const terminalWidth = getTerminalWidth();
const { title, maxWidth = terminalWidth, indent = "", padding = 1 } = options || {};
// account for box borders (2 chars: │ on each side) and padding
const maxContentWidth = maxWidth - 2 - padding * 2;
const lines = text.trim().split("\n");
const wrappedLines: string[] = [];
const truncatedLines = lines.map((line) => truncateLine(line, maxContentWidth));
for (const line of lines) {
if (line.length <= maxWidth - padding * 2) {
wrappedLines.push(line);
} else {
const words = line.split(" ");
let currentLine = "";
for (const word of words) {
const testLine = currentLine ? `${currentLine} ${word}` : word;
if (testLine.length <= maxWidth - padding * 2) {
currentLine = testLine;
} else {
if (currentLine) {
wrappedLines.push(currentLine);
currentLine = word;
} else {
wrappedLines.push(word.substring(0, maxWidth - padding * 2));
currentLine = word.substring(maxWidth - padding * 2);
}
}
}
if (currentLine) {
wrappedLines.push(currentLine);
}
}
}
const maxLineLength = Math.max(...wrappedLines.map((line) => line.length));
const maxLineLength = Math.max(...truncatedLines.map((line) => line.length));
const contentBoxWidth = maxLineLength + padding * 2;
// ensure box width is at least as wide as the title line when title exists
@@ -96,7 +96,7 @@ function boxString(
result += `${indent}${"─".repeat(boxWidth)}\n`;
}
for (const line of wrappedLines) {
for (const line of truncatedLines) {
const paddedLine = line.padEnd(maxLineLength);
result += `${indent}${" ".repeat(padding)}${paddedLine}${" ".repeat(padding)}\n`;
}