const VERSION_LABEL_PREFIX = "affects-"; const NEEDS_VERSION_LABEL = "needs-version-info"; const RETEST_LABEL = "needs-retest-on-latest"; const NEEDS_DECOMPOSITION_LABEL = "needs-decomposition"; const BUG_LABEL = "bug"; const DOCS_LABEL = "documentation"; const ENHANCEMENT_LABEL = "enhancement"; // Match a complete version token, not a valid-looking prefix of a malformed // value. An extra core component, unfinished suffix or empty prerelease // segment must not turn into an assertion about another release. Ordinary // sentence punctuation after a complete token remains harmless. const VERSION_TOKEN = String.raw`\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?![0-9A-Za-z_-]|\.+[0-9A-Za-z_-])`; // These headings end a secondary-topic field at its own level or above. // Deeper headings and legacy field-looking prose remain that topic's evidence, // not a second source of primary version or feedback metadata. const FORM_FIELD_NAMES = [ "Additional actionable topics", "Describe the bug", "Steps or original sequence", "Expected behavior", "Feedback type", "Pulse version", "Last known working Pulse version", "Agent version", "Image tag or digest", "Running Pulse container image tag or digest", "Install path", "Installation type", "OS / environment", "Installer or helper source", "Upgrade attempt and recovery", "License tier", "What happened?", "Steps or original sequence / usage context", "What did you expect instead?", "Additional context", "Logs, screenshots, or diagnostics", "Confirmations", "Problem", "Current workflow", "Desired outcome", "Alternatives considered", ]; const FORM_FIELD_KEYS = new Set(FORM_FIELD_NAMES.map((name) => name.toLowerCase())); function escapeRegExp(value) { return String(value || "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } // Use the same locked GFM lexer as Pulse's Markdown surfaces, without // rendering or executing any issue content. Only top-level declarations count. const { Lexer, lexer } = require("marked"); // Keep one immutable Markdown snapshot per classification decision. Reports can // contain long copied logs; reparsing that body for each field adds work without // adding evidence. Never share this context across reports or event revisions. function parseReportMarkdown(body) { const tokens = lexer(String(body || ""), { gfm: true }); return { lines: projectDeclarationLines(tokens), links: tokens.links }; } function lexFieldValue(value, report) { // Reference links can be defined anywhere in the report. Extracting a field // must not discard that context and turn visible declarations into missing // versions or invented topics. Use only the locked parser's definitions; // destinations are never fetched or treated as declaration text. const fieldLexer = new Lexer({ gfm: true }); // Field lexing can add definitions. Do not let it mutate the shared report // definitions or change the meaning of a sibling field. fieldLexer.tokens.links = Object.assign(Object.create(null), report.links); return fieldLexer.lex(value); } function inlineProjection(tokens) { return (tokens || []).map((token) => { const raw = token.raw || ""; // Keep line positions when removing hidden comments. A comment inside a // code span is a literal, not an HTML token, and remains evidence. if (token.type === "html" && /^