/** * Pure-TypeScript comment-slop detector. * * No external binary, no network, no fs. Given the added/removed lines of a * file edit, it finds net-new code comments (present in the added lines but * not in the removed lines) that look unnecessary, while leaving genuinely * valuable comments (TODO/FIXME, license headers, docstrings, pragmas, linter * directives, shebangs, decorators) untouched. * * The mechanism mirrors oh-my-opencode comment-checker hook (the * hasNewCommentsOnly heuristic) but replaces its external binary with an * in-process classifier so the suite stays headless and pure-TS. * * Language-agnostic: recognizes comment markers from many languages: * // /* * (C/C++/Java/C#/JS/TS/Rust/Go/Swift/Scala/Kotlin, JSDoc continuation) * # (Python, Ruby, Shell, Perl, YAML, TOML, Makefile, PowerShell, R) * -- (SQL, Lua, Haskell, Ada, Elm) * (HTML, XML, SVG, Markdown) * triple quotes (Python docstrings) * : (some config/scripting dialects) */ export type Strictness = "conservative" | "balanced" | "aggressive"; export interface CommentFinding { filePath: string; /** Absolute 1-based line number when resolvable from the written file. */ line?: number; /** Full original comment line. */ text: string; /** Classifier reason: restate-code | filler | decorative | generic-explanation | non-essential-comment. */ reason: string; } /** * An extracted edit. removedLines are the lines being replaced (old text), * addedLines are the new lines. For full-file writes, removedLines is empty * because every comment in the new content is by definition newly added. */ export interface Edit { filePath: string; removedLines: readonly string[]; addedLines: readonly string[]; /** * Absolute 1-based line number of the FIRST line in `addedLines` within the * target file, when known. Used to report accurate finding line numbers. * For full-file writes this is 1; for edits/apply_patch it is resolved by * locating the block in the already-written file; when unknown, undefined. */ baseLineNumber?: number; } const MARKER_RE = /^\s*(\/\/+|\/\*+|\*+|#+|--+|