feat: support multiline console output and decode HTML entities
Lint / pre-commit Linting (push) Successful in 56s
Test / Run Tests (push) Successful in 1m14s

This commit is contained in:
2026-05-16 18:55:44 +02:00
parent fe7c14540e
commit c3d595e2e1
2 changed files with 34 additions and 9 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+33 -8
View File
@@ -76,12 +76,37 @@ export function detectWarning(logLines) {
* @returns {string}
*/
export function safeDecode(text) {
if (typeof text !== "string" || !text.includes("%")) return text;
try {
return decodeURIComponent(text);
} catch (err) {
return text;
if (typeof text !== "string") return text;
let result = text;
if (result.includes("%")) {
try {
result = decodeURIComponent(result);
} catch (err) {
// Ignore decoding errors
}
}
// Screeps console often contains HTML entities
return result
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&quot;/g, '"')
.replace(/&amp;/g, "&");
}
/**
* Outputs text to the action log, splitting by newline to ensure proper display.
*
* @param {string} text
* @param {"info"|"warning"|"error"} level
*/
export function outputMultiline(text, level = "info") {
if (!text) return;
const lines = text.split(/\r?\n/);
lines.forEach((line) => {
if (level === "error") core.error(line);
else if (level === "warning") core.warning(line);
else core.info(line);
});
}
// ────────────────────────────────────────────────────────────────────────────
@@ -185,7 +210,7 @@ export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
const warnPattern = /<font\s+color=['"](?:orange|yellow)['"]/i;
logLines
.filter((l) => warnPattern.test(l))
.forEach((l) => core.warning(safeDecode(l)));
.forEach((l) => outputMultiline(safeDecode(l), "warning"));
}
// ── Traceback detection in log lines (Screeps sometimes sends errors here) ─
@@ -200,7 +225,7 @@ export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
if (logToFile) {
stdoutBuffer.push(...allStdout);
} else {
allStdout.forEach((l) => core.info(l));
allStdout.forEach((l) => outputMultiline(l, "info"));
}
}
@@ -208,7 +233,7 @@ export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
if (errorText) {
state.sawErrorLog = true;
const decodedError = safeDecode(errorText);
core.error(decodedError);
outputMultiline(decodedError, "error");
if (detectTraceback(decodedError)) {
state.sawTraceback = true;
}