@cortexkit/magic-context 0.21.5 → 0.21.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +107 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28563,6 +28563,91 @@ var init_diagnostics_opencode = __esm(() => {
|
|
|
28563
28563
|
PLUGIN_ENTRY_WITH_VERSION = `${PLUGIN_NAME5}@latest`;
|
|
28564
28564
|
});
|
|
28565
28565
|
|
|
28566
|
+
// src/lib/issue-body.ts
|
|
28567
|
+
function isErrorLogLine(line) {
|
|
28568
|
+
return ERROR_LOG_PATTERNS.some((rx) => rx.test(line));
|
|
28569
|
+
}
|
|
28570
|
+
function extractRecentErrors(sanitized, limit = 20) {
|
|
28571
|
+
const matches = [];
|
|
28572
|
+
const lines = sanitized.split(/\r?\n/);
|
|
28573
|
+
for (let i = lines.length - 1;i >= 0 && matches.length < limit; i -= 1) {
|
|
28574
|
+
if (isErrorLogLine(lines[i])) {
|
|
28575
|
+
matches.push(lines[i]);
|
|
28576
|
+
}
|
|
28577
|
+
}
|
|
28578
|
+
return matches.reverse();
|
|
28579
|
+
}
|
|
28580
|
+
function capBodyToGithubLimit(body, maxBytes = MAX_GITHUB_BODY_BYTES) {
|
|
28581
|
+
if (Buffer.byteLength(body, "utf8") <= maxBytes)
|
|
28582
|
+
return body;
|
|
28583
|
+
const heading = "## Log (last";
|
|
28584
|
+
const headingIdx = body.indexOf(heading);
|
|
28585
|
+
if (headingIdx === -1) {
|
|
28586
|
+
const marker = `
|
|
28587
|
+
|
|
28588
|
+
[truncated for GitHub 64KB limit]
|
|
28589
|
+
`;
|
|
28590
|
+
const markerBytes2 = Buffer.byteLength(marker, "utf8");
|
|
28591
|
+
return truncateToByteBudget(body, maxBytes - markerBytes2) + marker;
|
|
28592
|
+
}
|
|
28593
|
+
const fenceOpenIdx = body.indexOf("\n```", headingIdx);
|
|
28594
|
+
if (fenceOpenIdx === -1)
|
|
28595
|
+
return body;
|
|
28596
|
+
const logStart = fenceOpenIdx + "\n```\n".length;
|
|
28597
|
+
const fenceCloseIdx = body.indexOf("\n```", logStart);
|
|
28598
|
+
if (fenceCloseIdx === -1)
|
|
28599
|
+
return body;
|
|
28600
|
+
const head = body.slice(0, logStart);
|
|
28601
|
+
const log3 = body.slice(logStart, fenceCloseIdx);
|
|
28602
|
+
const tail = body.slice(fenceCloseIdx);
|
|
28603
|
+
const overheadBytes = Buffer.byteLength(head, "utf8") + Buffer.byteLength(tail, "utf8");
|
|
28604
|
+
const truncationMarker = `[truncated for GitHub 64KB limit — older log lines dropped]
|
|
28605
|
+
`;
|
|
28606
|
+
const markerBytes = Buffer.byteLength(truncationMarker, "utf8");
|
|
28607
|
+
const logBudget = maxBytes - overheadBytes - markerBytes;
|
|
28608
|
+
if (logBudget <= 0) {
|
|
28609
|
+
return `${head}${truncationMarker}${tail}`;
|
|
28610
|
+
}
|
|
28611
|
+
const lines = log3.split(`
|
|
28612
|
+
`);
|
|
28613
|
+
let keepLines = lines;
|
|
28614
|
+
let kept = keepLines.join(`
|
|
28615
|
+
`);
|
|
28616
|
+
while (Buffer.byteLength(kept, "utf8") > logBudget && keepLines.length > 1) {
|
|
28617
|
+
const dropCount = Math.max(1, Math.floor(keepLines.length * 0.05));
|
|
28618
|
+
keepLines = keepLines.slice(dropCount);
|
|
28619
|
+
kept = keepLines.join(`
|
|
28620
|
+
`);
|
|
28621
|
+
}
|
|
28622
|
+
if (Buffer.byteLength(kept, "utf8") > logBudget) {
|
|
28623
|
+
kept = truncateToByteBudget(kept, logBudget);
|
|
28624
|
+
}
|
|
28625
|
+
return `${head}${truncationMarker}${kept}${tail}`;
|
|
28626
|
+
}
|
|
28627
|
+
function truncateToByteBudget(input, maxBytes) {
|
|
28628
|
+
if (maxBytes <= 0)
|
|
28629
|
+
return "";
|
|
28630
|
+
const buf = Buffer.from(input, "utf8");
|
|
28631
|
+
if (buf.length <= maxBytes)
|
|
28632
|
+
return input;
|
|
28633
|
+
let end = maxBytes;
|
|
28634
|
+
while (end > 0 && (buf[end] & 192) === 128) {
|
|
28635
|
+
end -= 1;
|
|
28636
|
+
}
|
|
28637
|
+
return buf.subarray(0, end).toString("utf8");
|
|
28638
|
+
}
|
|
28639
|
+
var MAX_GITHUB_BODY_BYTES = 60000, ERROR_LOG_PATTERNS;
|
|
28640
|
+
var init_issue_body = __esm(() => {
|
|
28641
|
+
ERROR_LOG_PATTERNS = [
|
|
28642
|
+
/\bfailed:/i,
|
|
28643
|
+
/\b(?:[A-Z][a-zA-Z]*)?Error:\s/,
|
|
28644
|
+
/\bEMERGENCY\b/,
|
|
28645
|
+
/\bexception\b/i,
|
|
28646
|
+
/^\s+at\s+[\w.<>$]+\s+\(/,
|
|
28647
|
+
/^\s+at\s+(?:file:|node_modules\/|[^/\s]+:\d+)/
|
|
28648
|
+
];
|
|
28649
|
+
});
|
|
28650
|
+
|
|
28566
28651
|
// src/lib/logs-opencode.ts
|
|
28567
28652
|
import { readFileSync as readFileSync12, writeFileSync as writeFileSync9 } from "node:fs";
|
|
28568
28653
|
import { homedir as homedir12 } from "node:os";
|
|
@@ -28615,9 +28700,12 @@ async function bundleIssueReport(report, description, _title, sessionFilter = nu
|
|
|
28615
28700
|
const historianScanWindow = sanitizeLogContent(logLines.slice(-4000).join(`
|
|
28616
28701
|
`));
|
|
28617
28702
|
const historianFailureLines = extractHistorianFailureLines(historianScanWindow, 30);
|
|
28703
|
+
const errorScanWindow = sanitizeLogContent(logLines.slice(-4000).join(`
|
|
28704
|
+
`));
|
|
28705
|
+
const recentErrorLines = extractRecentErrors(errorScanWindow, 20);
|
|
28618
28706
|
const configBody = JSON.stringify(sanitizeConfigValue(report.magicContextConfig.flags), null, 2);
|
|
28619
28707
|
const sanitizedConfigPath = report.configPaths.magicContextConfig.replace(homedir12(), "~");
|
|
28620
|
-
const
|
|
28708
|
+
const rawBodyMarkdown = [
|
|
28621
28709
|
"## Description",
|
|
28622
28710
|
description,
|
|
28623
28711
|
"",
|
|
@@ -28639,6 +28727,11 @@ async function bundleIssueReport(report, description, _title, sessionFilter = nu
|
|
|
28639
28727
|
"## Historian failure signals (log, sanitized)",
|
|
28640
28728
|
historianFailureLines.length === 0 ? "_No historian failure log lines found in recent history._" : ["```", historianFailureLines.join(`
|
|
28641
28729
|
`), "```"].join(`
|
|
28730
|
+
`),
|
|
28731
|
+
"",
|
|
28732
|
+
"## Recent errors (last 20, sanitized)",
|
|
28733
|
+
recentErrorLines.length === 0 ? "_No error-shaped log lines found in recent history._" : ["```", recentErrorLines.join(`
|
|
28734
|
+
`), "```"].join(`
|
|
28642
28735
|
`),
|
|
28643
28736
|
"",
|
|
28644
28737
|
`## Log (last ${LOG_TAIL_LINES} lines, sanitized)`,
|
|
@@ -28647,6 +28740,7 @@ async function bundleIssueReport(report, description, _title, sessionFilter = nu
|
|
|
28647
28740
|
"```"
|
|
28648
28741
|
].join(`
|
|
28649
28742
|
`);
|
|
28743
|
+
const bodyMarkdown = capBodyToGithubLimit(rawBodyMarkdown);
|
|
28650
28744
|
const path4 = join15(process.cwd(), `magic-context-issue-${formatTimestamp(new Date)}.md`);
|
|
28651
28745
|
writeFileSync9(path4, `${bodyMarkdown}
|
|
28652
28746
|
`);
|
|
@@ -28655,6 +28749,7 @@ async function bundleIssueReport(report, description, _title, sessionFilter = nu
|
|
|
28655
28749
|
var HISTORIAN_LOG_PATTERNS;
|
|
28656
28750
|
var init_logs_opencode = __esm(() => {
|
|
28657
28751
|
init_diagnostics_opencode();
|
|
28752
|
+
init_issue_body();
|
|
28658
28753
|
init_redaction();
|
|
28659
28754
|
HISTORIAN_LOG_PATTERNS = [
|
|
28660
28755
|
/historian failure:/,
|
|
@@ -164008,7 +164103,10 @@ async function bundleIssueReport2(report, description, title, options = {}) {
|
|
|
164008
164103
|
const logLines = filterLogLinesBySession2(allLogLines, options.sessionFilter ?? null);
|
|
164009
164104
|
const recentLog = sanitizeLogContent2(logLines.slice(-LOG_TAIL_LINES).join(`
|
|
164010
164105
|
`)).trim();
|
|
164011
|
-
const
|
|
164106
|
+
const errorScanWindow = sanitizeLogContent2(logLines.slice(-4000).join(`
|
|
164107
|
+
`));
|
|
164108
|
+
const recentErrorLines = extractRecentErrors(errorScanWindow, 20);
|
|
164109
|
+
const rawBodyMarkdown = [
|
|
164012
164110
|
"## Title",
|
|
164013
164111
|
`[pi] ${sanitizeString2(title)}`,
|
|
164014
164112
|
"",
|
|
@@ -164023,6 +164121,11 @@ async function bundleIssueReport2(report, description, title, options = {}) {
|
|
|
164023
164121
|
"",
|
|
164024
164122
|
"## Diagnostics",
|
|
164025
164123
|
renderDiagnosticsMarkdown2(report),
|
|
164124
|
+
"",
|
|
164125
|
+
"## Recent errors (last 20, sanitized)",
|
|
164126
|
+
recentErrorLines.length === 0 ? "_No error-shaped log lines found in recent history._" : ["```", recentErrorLines.join(`
|
|
164127
|
+
`), "```"].join(`
|
|
164128
|
+
`),
|
|
164026
164129
|
"",
|
|
164027
164130
|
`## Log (last ${LOG_TAIL_LINES} lines, sanitized)`,
|
|
164028
164131
|
"```",
|
|
@@ -164030,6 +164133,7 @@ async function bundleIssueReport2(report, description, title, options = {}) {
|
|
|
164030
164133
|
"```"
|
|
164031
164134
|
].join(`
|
|
164032
164135
|
`);
|
|
164136
|
+
const bodyMarkdown = capBodyToGithubLimit(rawBodyMarkdown);
|
|
164033
164137
|
const cwd = options.cwd ?? process.cwd();
|
|
164034
164138
|
const path4 = join21(cwd, `magic-context-pi-issue-${formatTimestamp2(options.now ?? new Date)}.md`);
|
|
164035
164139
|
writeFileSync11(path4, `${bodyMarkdown}
|
|
@@ -164038,6 +164142,7 @@ async function bundleIssueReport2(report, description, title, options = {}) {
|
|
|
164038
164142
|
}
|
|
164039
164143
|
var init_logs_pi = __esm(() => {
|
|
164040
164144
|
init_diagnostics_pi();
|
|
164145
|
+
init_issue_body();
|
|
164041
164146
|
});
|
|
164042
164147
|
|
|
164043
164148
|
// src/commands/doctor-pi.ts
|