@mrkaran/hodor 0.6.3-rc.2 → 0.7.0-rc.1

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/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  # Hodor
4
4
 
5
- > Agentic code reviewer for GitHub PRs, GitLab MRs, Gitea/Forgejo PRs, and local diffs. Powered by the [pi-coding-agent](https://github.com/badlogic/pi-mono) SDK.
5
+ > Agentic code reviewer for GitHub PRs, GitLab MRs, Gitea/Forgejo PRs, and local diffs.
6
6
 
7
- Hodor runs as a stateful agent with tools (`bash`, `grep`, `read`, `git diff`) to autonomously analyze code changes, find bugs, and post structured reviews.
7
+ Hodor uses read-only tools to analyze code changes, identify bugs, and post structured reviews.
8
8
 
9
9
  ## Install
10
10
 
@@ -60,15 +60,33 @@ npx @mrkaran/hodor <PR_URL> --reasoning-effort high
60
60
  # Force a full review of the entire branch (ignore previous incremental reviews)
61
61
  npx @mrkaran/hodor <PR_URL> --full
62
62
 
63
- # Custom review instructions
64
- npx @mrkaran/hodor <PR_URL> --prompt "Focus on SQL injection and auth bypasses"
65
-
66
63
  # Verbose mode (watch the agent think)
67
64
  npx @mrkaran/hodor <PR_URL> -v
68
65
  ```
69
66
 
70
67
  > If you installed globally with `npm install -g`, replace `npx @mrkaran/hodor` with `hodor`.
71
68
 
69
+ ## Review instructions
70
+
71
+ Choose the default review profile, a custom security profile, or a one-off focus for a review:
72
+
73
+ ```bash
74
+ # Default profile
75
+ npx @mrkaran/hodor <PR_URL>
76
+
77
+ # Custom profile that replaces the bundled default
78
+ npx @mrkaran/hodor <PR_URL> \
79
+ --review-instructions ./review-profiles/security.md
80
+
81
+ # One-off request added after the selected profile
82
+ npx @mrkaran/hodor <PR_URL> \
83
+ --additional-instructions "Focus on authorization changes in the admin API."
84
+ ```
85
+
86
+ A review profile applies to the whole run. A custom profile replaces the bundled default profile. Additional instructions are additive. Repository-specific rules remain in `.agents/skills/` and are used when relevant. Hodor's review rules take precedence if these inputs conflict.
87
+
88
+ See [Review instructions](./docs/REVIEW_INSTRUCTIONS.md) for complete security and code-quality profiles, local and CI examples, migration guidance, and file validation troubleshooting.
89
+
72
90
  ## Local Mode
73
91
 
74
92
  Review local git changes without a PR URL. Useful for pre-push reviews, Bitbucket PRs, or any git repo.
@@ -102,24 +120,24 @@ Local mode:
102
120
 
103
121
  | Flag | Default | Description |
104
122
  |------|---------|-------------|
105
- | `--model` | `anthropic/claude-sonnet-4-5-20250929` | LLM model as `provider/model-id`. Recommended: Anthropic, OpenAI, Bedrock, OpenRouter. Other pi-ai providers (e.g., Mistral, Gemini, xAI, Groq) are best-effort. See [docs/MODELS.md](./docs/MODELS.md). |
106
- | `--reasoning-effort` | | Extended thinking: `low`, `medium`, `high` |
123
+ | `--model` | `anthropic/claude-sonnet-4-5-20250929` | LLM model as `provider/model-id`. Recommended: Anthropic, OpenAI, Bedrock, OpenRouter. Other configured providers such as Mistral, Gemini, xAI, and Groq are best-effort. See [docs/MODELS.md](./docs/MODELS.md). |
124
+ | `--reasoning-effort` | None | Extended thinking: `low`, `medium`, `high` |
107
125
  | `--ultrathink` | Off | Maximum reasoning effort |
108
126
  | `--full` | Off | Review the entire source-vs-target diff from scratch, ignoring previous hodor reviews (disables incremental mode) |
109
- | `--target-branch` | | Override the target branch to diff against under `--full` (default: the PR/MR's target branch) |
127
+ | `--target-branch` | None | Override the target branch to diff against under `--full` (default: the PR/MR's target branch) |
110
128
  | `--local` | Off | Review local git changes (no PR URL required) |
111
129
  | `--diff-against` | `origin/main` | Git ref to diff against in `--local` mode |
112
130
  | `--post` | Off | Post review as a comment on the PR/MR |
113
131
  | `--review-style` | `hybrid` | GitLab posting style: `summary`, `inline`, or `hybrid` |
114
- | `--code-quality` | | Write a CodeClimate JSON artifact for GitLab code quality reports |
132
+ | `--code-quality` | None | Write a CodeClimate JSON artifact for GitLab code quality reports |
115
133
  | `--commit-status` | Off | Post a pass/fail commit status to the GitLab MR head SHA |
116
134
  | `--require-delivery` | Off | Exit non-zero if requested comments, statuses, or artifacts are not delivered |
117
- | `--fail-on-priority` | | Exit non-zero for findings at or above `P0`, `P1`, `P2`, or `P3` |
118
- | `--prompt` | | Append custom instructions to the review prompt |
119
- | `--prompt-file` | | Use a custom prompt file |
135
+ | `--fail-on-priority` | None | Exit non-zero for findings at or above `P0`, `P1`, `P2`, or `P3` |
136
+ | `--review-instructions` | None | Read a custom review profile from a file. It replaces the bundled default profile for this run. |
137
+ | `--additional-instructions` | None | Add one-off review instructions after the selected profile. |
120
138
  | `--workspace` | Temp dir | Workspace directory (reuse for faster multi-PR reviews) |
121
- | `--bedrock-tags` | | JSON cost allocation tags for AWS Bedrock |
122
- | `--prometheus-push` | | Push review metrics to a Prometheus Pushgateway or VictoriaMetrics import endpoint |
139
+ | `--bedrock-tags` | None | JSON cost allocation tags for AWS Bedrock |
140
+ | `--prometheus-push` | None | Push review metrics to a Prometheus Pushgateway or VictoriaMetrics import endpoint |
123
141
  | `-v, --verbose` | Off | Stream agent reasoning and tool calls |
124
142
 
125
143
  ## Environment Variables
@@ -167,7 +185,7 @@ hodor "$MR_OR_PR_URL" --prometheus-push "$METRICS_PUSH_URL"
167
185
 
168
186
  In CI, set `METRICS_PUSH_URL` as a secret/variable and add `--prometheus-push "$METRICS_PUSH_URL"` to the Hodor command. Metrics are best-effort: push failures are logged as warnings and do not fail the review job.
169
187
 
170
- Each metric is labeled with `platform`, `model`, `verdict`, `outcome`, and for PR/MR URLs also `project` (`owner/repo`). MR/PR numbers are deliberately excluded to avoid unbounded time-series cardinality. Exported metrics include token usage, cache read/write tokens, cache hit ratio, cost, turns, tool calls, duration, and findings by priority (`P0`–`P3`). A generic Grafana dashboard is available in [`docs/grafana/`](./docs/grafana/).
188
+ Each metric is labeled with `platform`, `model`, `verdict`, `outcome`, and for PR/MR URLs also `project` (`owner/repo`). MR/PR numbers are deliberately excluded to avoid unbounded time-series cardinality. Exported metrics include token usage, cache read/write tokens, cache hit ratio, cost, turns, tool calls, duration, and findings by priority (`P0` to `P3`). A generic Grafana dashboard is available in [`docs/grafana/`](./docs/grafana/).
171
189
 
172
190
  ### GitHub Actions
173
191
 
@@ -233,8 +251,13 @@ See [AUTOMATED_REVIEWS.md](./docs/AUTOMATED_REVIEWS.md) for advanced workflows.
233
251
  Hodor automatically optimizes token usage:
234
252
 
235
253
  - **Diff embedding**: For PRs under 200KB, the diff is embedded directly in the prompt, cutting agent turns from ~60 to ~5.
236
- - **Incremental reviews**: On re-runs, only reviews changes since the last hodor comment (detected via SHA markers in posted comments). Pass `--full` to override this and re-review the entire source-vs-target diff from scratch.
237
- - **Compaction**: SDK auto-summarizes older conversation turns when context grows too large.
254
+ - **Incremental reviews**: On re-runs, only reviews changes since the last hodor comment. After a force-push or rebase, Hodor compares the last reviewed snapshot directly with the current HEAD instead of reviewing the whole MR again.
255
+ - **Identical-HEAD reuse**: Successful summaries include a versioned, compressed review payload. Pipeline retries with the same HEAD, model, reasoning request, review profile, and additional instructions reuse that result while still regenerating artifacts and retrying delivery.
256
+ - **Adaptive reasoning**: Models that default to `xhigh` use `high` for routine small and incremental diffs, while risky, large, explicitly configured, and `--full` reviews retain the requested depth.
257
+ - **Focused exploration**: Embedded diffs include a changed-file manifest and direct the agent toward bounded context reads without limiting how far it may investigate.
258
+ - **Compaction**: Hodor auto-summarizes older conversation turns when context grows too large.
259
+
260
+ Pass `--full` to bypass incremental mode and identical-HEAD reuse. Pass `--reasoning-effort` to override adaptive reasoning.
238
261
 
239
262
  ## Skills
240
263
 
@@ -280,16 +303,18 @@ Hodor is written in TypeScript and runs on [Bun](https://bun.sh). Key components
280
303
  | `src/cli.ts` | Commander.js CLI entry point |
281
304
  | `src/agent.ts` | Core review orchestration, URL parsing, comment posting |
282
305
  | `src/workspace.ts` | CI detection, repo cloning, branch checkout |
283
- | `src/prompt.ts` | Prompt template building and interpolation |
306
+ | `src/prompt.ts` | Dynamic review task construction from PR or local-diff context |
307
+ | `src/review-instructions.ts` | Default review profile loading and custom profile validation |
308
+ | `src/system-prompt.ts` | Review profile, additional instructions, and Hodor review protocol composition |
284
309
  | `src/model.ts` | Model string parsing, API key resolution |
285
310
  | `src/gitlab.ts` | GitLab API via `glab` CLI (comments, inline notes, draft notes, commit status) |
286
311
  | `src/github.ts` | GitHub API via `gh` CLI |
287
312
  | `src/render.ts` | JSON review output → markdown rendering |
288
313
  | `src/codequality.ts` | CodeClimate JSON artifact for GitLab code quality widget |
289
314
  | `src/metrics.ts` | Token usage and cost formatting |
290
- | `templates/` | Review prompt template (JSON schema) |
315
+ | `templates/` | Bundled default review profile and dynamic review task template |
291
316
 
292
- The agent runtime is provided by [`@earendil-works/pi-coding-agent`](https://github.com/earendil-works/pi) with [`@earendil-works/pi-ai`](https://github.com/earendil-works/pi) for LLM access. The agent session gets read-only tools (bash, read, grep, find, ls) and a review prompt, then autonomously analyzes the PR.
317
+ Hodor gives its read-only review agent the selected review profile, optional additional instructions, Hodor's review protocol, and a task built from the PR or local diff. The agent then analyzes the changed code and reports structured findings.
293
318
 
294
319
  ---
295
320
 
@@ -214,6 +214,7 @@ function formatLocation(loc) {
214
214
  // src/gitlab.ts
215
215
  var DEFAULT_GITLAB_HOST = "gitlab.com";
216
216
  var HODOR_NOTE_PREFIX_RE = /^\s*<!--\s*hodor[-:]/;
217
+ var HODOR_CACHE_MARKER_RE = /<!--\s*hodor:cache:v1:[A-Za-z0-9_-]+\s*-->\s*/g;
217
218
  function isHodorNote(body, marker = HODOR_REVIEW_MARKER) {
218
219
  if (typeof body !== "string") return false;
219
220
  if (body.trimStart().startsWith(marker)) return true;
@@ -390,7 +391,7 @@ function summarizeNotes(notes, maxEntries, include) {
390
391
  const filtered = [];
391
392
  for (const note of notes) {
392
393
  if (!include(note)) continue;
393
- const body = (note.body ?? "").trim();
394
+ const body = (note.body ?? "").replace(HODOR_CACHE_MARKER_RE, "").trim();
394
395
  if (!body) continue;
395
396
  if (note.system) continue;
396
397
  if (body.length < 20) continue;
@@ -650,4 +651,4 @@ export {
650
651
  listHodorDiscussions,
651
652
  resolveGitlabDiscussions
652
653
  };
653
- //# sourceMappingURL=chunk-LO2QJD45.js.map
654
+ //# sourceMappingURL=chunk-W7ZUJIFT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/exec.ts","../src/utils/logger.ts","../src/render.ts","../src/gitlab.ts"],"sourcesContent":["import { execFile, spawn } from \"node:child_process\";\nimport { promisify } from \"node:util\";\n\nconst execFileAsync = promisify(execFile);\n\nexport interface ExecResult {\n stdout: string;\n stderr: string;\n}\n\nexport interface ExecOptions {\n cwd?: string;\n env?: NodeJS.ProcessEnv;\n input?: string;\n}\n\nexport async function exec(\n cmd: string,\n args: string[],\n opts?: ExecOptions,\n): Promise<ExecResult> {\n if (typeof opts?.input === \"string\") {\n return new Promise<ExecResult>((resolve, reject) => {\n const child = spawn(cmd, args, {\n cwd: opts.cwd,\n env: opts.env ?? process.env,\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n });\n\n let stdout = \"\";\n let stderr = \"\";\n\n child.stdout.on(\"data\", (chunk: Buffer | string) => {\n stdout += chunk.toString();\n });\n child.stderr.on(\"data\", (chunk: Buffer | string) => {\n stderr += chunk.toString();\n });\n child.on(\"error\", (error) => {\n reject(error);\n });\n child.on(\"close\", (code, signal) => {\n if (code === 0) {\n resolve({ stdout, stderr });\n return;\n }\n\n const parts: string[] = [`Command failed: ${cmd} ${args.join(\" \")}`];\n if (stderr.trim()) {\n parts.push(`stderr:\\n${stderr.trim()}`);\n }\n if (stdout.trim()) {\n parts.push(`stdout:\\n${stdout.trim()}`);\n }\n if (signal) {\n parts.push(`signal: ${signal}`);\n }\n const error = new Error(parts.join(\"\\n\"));\n reject(error);\n });\n\n child.stdin.write(opts.input);\n child.stdin.end();\n });\n }\n\n const { stdout, stderr } = await execFileAsync(cmd, args, {\n cwd: opts?.cwd,\n env: opts?.env ?? process.env,\n maxBuffer: 50 * 1024 * 1024, // 50MB\n });\n return { stdout, stderr };\n}\n\nexport async function execJson<T = Record<string, unknown>>(\n cmd: string,\n args: string[],\n opts?: ExecOptions,\n): Promise<T> {\n const { stdout } = await exec(cmd, args, opts);\n return JSON.parse(stdout.trim()) as T;\n}\n","import chalk from \"chalk\";\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\nlet currentLevel: LogLevel = \"warn\";\n\nconst LEVELS: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n};\n\nexport function setLogLevel(level: LogLevel): void {\n currentLevel = level;\n}\n\nfunction shouldLog(level: LogLevel): boolean {\n return LEVELS[level] >= LEVELS[currentLevel];\n}\n\nfunction timestamp(): string {\n return new Date().toISOString();\n}\n\nexport const logger = {\n debug(msg: string): void {\n if (shouldLog(\"debug\")) {\n process.stderr.write(`${chalk.gray(timestamp())} ${chalk.gray(\"DEBUG\")} ${msg}\\n`);\n }\n },\n info(msg: string): void {\n if (shouldLog(\"info\")) {\n process.stderr.write(`${chalk.gray(timestamp())} ${chalk.blue(\"INFO\")} ${msg}\\n`);\n }\n },\n warn(msg: string): void {\n if (shouldLog(\"warn\")) {\n process.stderr.write(`${chalk.gray(timestamp())} ${chalk.yellow(\"WARN\")} ${msg}\\n`);\n }\n },\n error(msg: string): void {\n if (shouldLog(\"error\")) {\n process.stderr.write(`${chalk.gray(timestamp())} ${chalk.red(\"ERROR\")} ${msg}\\n`);\n }\n },\n};\n","/**\n * Render structured review output into clean markdown for PR/MR comments.\n */\n\nimport type { ReviewFinding, ReviewOutput } from \"./types.js\";\n\nexport const HODOR_REVIEW_MARKER = \"<!-- hodor-review -->\";\n\n/**\n * Render a ReviewOutput into clean markdown for posting as a PR/MR comment.\n */\nexport function renderMarkdown(review: ReviewOutput): string {\n const lines: string[] = [HODOR_REVIEW_MARKER];\n\n // Group findings by priority\n const critical: ReviewFinding[] = []; // P0, P1\n const important: ReviewFinding[] = []; // P2\n const minor: ReviewFinding[] = []; // P3\n\n for (const f of review.findings) {\n const p = f.priority;\n if (p <= 1) critical.push(f);\n else if (p === 2) important.push(f);\n else minor.push(f);\n }\n\n lines.push(\"### Issues Found\");\n lines.push(\"\");\n\n if (review.findings.length === 0) {\n lines.push(\"No issues found.\");\n lines.push(\"\");\n }\n\n if (critical.length > 0) {\n lines.push(\"**Critical (P0/P1)**\");\n for (const f of critical) {\n lines.push(formatFinding(f));\n }\n lines.push(\"\");\n }\n\n if (important.length > 0) {\n lines.push(\"**Important (P2)**\");\n for (const f of important) {\n lines.push(formatFinding(f));\n }\n lines.push(\"\");\n }\n\n if (minor.length > 0) {\n lines.push(\"**Minor (P3)**\");\n for (const f of minor) {\n lines.push(formatFinding(f));\n }\n lines.push(\"\");\n }\n\n // Summary\n lines.push(\"### Summary\");\n lines.push(\n `Total issues: ${critical.length} critical, ${important.length} important, ${minor.length} minor.`,\n );\n lines.push(\"\");\n\n // Overall verdict\n lines.push(\"### Overall Verdict\");\n const isCorrect = review.overall_correctness === \"patch is correct\";\n lines.push(\n `**Status**: ${isCorrect ? \"Patch is correct\" : \"Patch has blocking issues\"}`,\n );\n lines.push(\"\");\n if (review.overall_explanation) {\n lines.push(`**Explanation**: ${review.overall_explanation}`);\n }\n\n return lines.join(\"\\n\").trimEnd() + \"\\n\";\n}\n\nexport function renderSummaryMarkdown(review: ReviewOutput): string {\n const lines: string[] = [HODOR_REVIEW_MARKER];\n\n const counts = { critical: 0, important: 0, minor: 0 };\n for (const f of review.findings) {\n if (f.priority <= 1) counts.critical++;\n else if (f.priority === 2) counts.important++;\n else counts.minor++;\n }\n\n lines.push(\"\");\n lines.push(\"| Category | Count |\");\n lines.push(\"| --- | ---: |\");\n lines.push(`| Critical (P0/P1) | ${counts.critical} |`);\n lines.push(`| Important (P2) | ${counts.important} |`);\n lines.push(`| Minor (P3) | ${counts.minor} |`);\n\n const isCorrect = review.overall_correctness === \"patch is correct\";\n lines.push(\"\");\n lines.push(`**Overall verdict**: ${isCorrect ? \"Patch is correct\" : \"Patch has blocking issues\"}`);\n lines.push(\"\");\n lines.push(`**Explanation**: ${review.overall_explanation}`);\n\n if (review.findings.length > 0) {\n lines.push(\"\");\n lines.push(\"| Finding | Location | Priority |\");\n lines.push(\"| --- | --- | --- |\");\n for (const f of review.findings) {\n const loc = formatLocation(f.code_location);\n const safeTitle = f.title.replace(/\\|/g, \"\\\\|\");\n lines.push(`| ${safeTitle} | \\`${loc}\\` | P${f.priority} |`);\n }\n }\n\n return lines.join(\"\\n\").trimEnd() + \"\\n\";\n}\n\nfunction formatFinding(f: ReviewFinding): string {\n const loc = ` (\\`${formatLocation(f.code_location)}\\`)`;\n const title = `- **${f.title}**${loc}`;\n const body = ` - ${f.body}`;\n return `${title}\\n${body}`;\n}\n\nfunction formatLocation(loc: {\n absolute_file_path: string;\n line_range: { start: number; end: number };\n}): string {\n // Strip common workspace prefixes to get a clean relative path\n let filePath = loc.absolute_file_path;\n\n // GitLab CI: /builds/owner/repo/src/file.ts → src/file.ts\n const buildsMatch = filePath.match(/\\/builds\\/[^/]+\\/[^/]+\\/(.+)/);\n if (buildsMatch) {\n filePath = buildsMatch[1];\n }\n // GitHub Actions / generic workspace\n else if (filePath.includes(\"/workspace/\")) {\n filePath = filePath.slice(filePath.indexOf(\"/workspace/\") + \"/workspace/\".length);\n }\n // Temp review dirs: /tmp/hodor-review-<id>/src/file.ts → src/file.ts\n else {\n filePath = filePath.replace(/^.*\\/hodor-review-[^/]+\\//, \"\");\n }\n\n const { start, end } = loc.line_range;\n return start === end ? `${filePath}:${start}` : `${filePath}:${start}-${end}`;\n}\n","import { exec, execJson } from \"./utils/exec.js\";\nimport { logger } from \"./utils/logger.js\";\nimport type { MrMetadata, NoteEntry } from \"./types.js\";\nimport { HODOR_REVIEW_MARKER } from \"./render.js\";\n\nexport { HODOR_REVIEW_MARKER };\n\nexport interface DiffRefs {\n base_sha: string;\n head_sha: string;\n start_sha: string;\n}\n\nconst DEFAULT_GITLAB_HOST = \"gitlab.com\";\n\n/**\n * Match notes Hodor itself created. The body must begin with a hodor-owned HTML\n * comment (either `<!-- hodor-review -->` or a sibling like `<!-- hodor:sha:... -->`\n * that hodor prepends to summary comments). Anchoring at the start avoids deleting\n * human notes that quote the marker incidentally (e.g., a code block discussing hodor).\n */\nconst HODOR_NOTE_PREFIX_RE = /^\\s*<!--\\s*hodor[-:]/;\nconst HODOR_CACHE_MARKER_RE = /<!--\\s*hodor:cache:v1:[A-Za-z0-9_-]+\\s*-->\\s*/g;\n\nfunction isHodorNote(body: unknown, marker = HODOR_REVIEW_MARKER): boolean {\n if (typeof body !== \"string\") return false;\n // Default fast-path: body starts with the canonical marker (allowing leading whitespace).\n if (body.trimStart().startsWith(marker)) return true;\n // Accept hodor's own SHA prefix, e.g. `<!-- hodor:sha:abc -->\\n<!-- hodor-review -->\\n...`\n if (marker === HODOR_REVIEW_MARKER && HODOR_NOTE_PREFIX_RE.test(body)) {\n // Require the canonical marker to appear somewhere in the body so we don't\n // resolve unrelated `<!-- hodor:foo -->` notes that aren't review summaries.\n return body.includes(HODOR_REVIEW_MARKER);\n }\n return false;\n}\n\nexport function isHodorGeneratedNote(body: unknown): boolean {\n return isHodorNote(body);\n}\n\n/**\n * Parse concatenated JSON arrays from `glab api --paginate`.\n * glab outputs `[...][...][...]` — one array per page, no delimiter.\n * We track bracket depth (respecting strings/escapes) to find each\n * top-level array, parse them individually, and merge with flat().\n */\nexport function parseGlabPaginatedJson(raw: string): Array<Record<string, unknown>> {\n const trimmed = raw.trim();\n if (!trimmed) return [];\n\n const chunks: string[] = [];\n let depth = 0;\n let inString = false;\n let escaped = false;\n let start = -1;\n\n for (let i = 0; i < trimmed.length; i++) {\n const ch = trimmed[i];\n if (escaped) {\n escaped = false;\n continue;\n }\n if (ch === \"\\\\\" && inString) {\n escaped = true;\n continue;\n }\n if (ch === '\"') {\n inString = !inString;\n continue;\n }\n if (inString) continue;\n\n if (ch === \"[\") {\n if (depth === 0) start = i;\n depth++;\n } else if (ch === \"]\") {\n depth--;\n if (depth === 0 && start >= 0) {\n chunks.push(trimmed.slice(start, i + 1));\n start = -1;\n }\n }\n }\n\n const results: Array<Record<string, unknown>> = [];\n for (const chunk of chunks) {\n try {\n const parsed = JSON.parse(chunk) as Array<Record<string, unknown>>;\n if (Array.isArray(parsed)) results.push(...parsed);\n } catch (err) {\n logger.warn(\n `Skipping malformed glab pagination chunk: ${err instanceof Error ? err.message : err}`,\n );\n }\n }\n return results;\n}\n\nexport class GitLabAPIError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"GitLabAPIError\";\n }\n}\n\nfunction normalizeBaseUrl(host?: string | null): string {\n const candidate =\n host ||\n process.env.GITLAB_HOST ||\n process.env.CI_SERVER_URL ||\n DEFAULT_GITLAB_HOST;\n const trimmed = candidate.trim() || DEFAULT_GITLAB_HOST;\n if (trimmed.startsWith(\"http://\") || trimmed.startsWith(\"https://\")) {\n return trimmed.replace(/\\/+$/, \"\");\n }\n return `https://${trimmed}`.replace(/\\/+$/, \"\");\n}\n\nfunction encodedProjectPath(owner: string, repo: string): string {\n const projectPath = [owner.replace(/^\\/+|\\/+$/g, \"\"), repo.replace(/^\\/+|\\/+$/g, \"\")]\n .filter(Boolean)\n .join(\"/\");\n return encodeURIComponent(projectPath);\n}\n\nfunction glabEnv(host?: string | null): NodeJS.ProcessEnv {\n const env = { ...process.env };\n // Ensure glab knows which host to talk to\n const baseUrl = normalizeBaseUrl(host);\n const hostname = baseUrl.replace(/^https?:\\/\\//, \"\");\n env.GITLAB_HOST = hostname;\n return env;\n}\n\n/**\n * Fetch merge request metadata using glab api.\n */\nexport async function fetchGitlabMrInfo(\n owner: string,\n repo: string,\n mrNumber: number | string,\n host?: string | null,\n options?: { includeComments?: boolean },\n): Promise<MrMetadata> {\n const encoded = encodedProjectPath(owner, repo);\n const env = glabEnv(host);\n\n let mrData: Record<string, unknown>;\n try {\n mrData = await execJson<Record<string, unknown>>(\n \"glab\",\n [\"api\", `projects/${encoded}/merge_requests/${mrNumber}`],\n { env },\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n throw new GitLabAPIError(`Failed to fetch MR !${mrNumber}: ${msg}`);\n }\n\n const metadata: MrMetadata = {\n title: mrData.title as string | undefined,\n description: (mrData.description as string) ?? \"\",\n source_branch: mrData.source_branch as string | undefined,\n target_branch: mrData.target_branch as string | undefined,\n changes_count: mrData.changes_count as number | undefined,\n labels: mrData.labels as string[] | undefined,\n author: mrData.author as { username?: string; name?: string } | undefined,\n pipeline: mrData.pipeline as { status?: string; web_url?: string } | undefined,\n state: mrData.state as string | undefined,\n };\n\n if (options?.includeComments) {\n try {\n // glab --paginate concatenates JSON arrays across pages (e.g., `[...][...]`).\n // Parse each top-level array separately and merge, avoiding regex on raw JSON\n // which could corrupt string values containing `][`.\n const { stdout: rawNotes } = await exec(\n \"glab\",\n [\"api\", `projects/${encoded}/merge_requests/${mrNumber}/notes`, \"--paginate\"],\n { env },\n );\n const notes = parseGlabPaginatedJson(rawNotes);\n metadata.Notes = notes.map((n) => ({\n body: (n.body as string) ?? \"\",\n author: n.author as { username?: string; name?: string } | undefined,\n created_at: n.created_at as string | undefined,\n system: n.system as boolean | undefined,\n }));\n } catch (err) {\n logger.warn(`Failed to fetch MR notes: ${err instanceof Error ? err.message : err}`);\n }\n }\n\n return metadata;\n}\n\n/**\n * Post a comment on a GitLab merge request using glab api.\n */\nexport async function postGitlabMrComment(\n owner: string,\n repo: string,\n mrNumber: number | string,\n body: string,\n host?: string | null,\n): Promise<void> {\n const encoded = encodedProjectPath(owner, repo);\n const env = glabEnv(host);\n\n try {\n await exec(\n \"glab\",\n [\n \"api\",\n `projects/${encoded}/merge_requests/${mrNumber}/notes`,\n \"--method\",\n \"POST\",\n \"-H\",\n \"Content-Type: application/json\",\n \"--input\",\n \"-\",\n ],\n { env, input: JSON.stringify({ body }) },\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n throw new GitLabAPIError(`Failed to post comment to MR !${mrNumber}: ${msg}`);\n }\n}\n\n/**\n * Summarize GitLab notes into a human-readable bullet list.\n */\nexport function summarizeGitlabNotes(\n notes: NoteEntry[] | undefined | null,\n maxEntries = 5,\n): string {\n return summarizeNotes(notes, maxEntries, (note) => !isHodorNote(note.body));\n}\n\nexport function summarizeHodorNotes(\n notes: NoteEntry[] | undefined | null,\n maxEntries = 5,\n): string {\n return summarizeNotes(notes, maxEntries, (note) => isHodorNote(note.body));\n}\n\nfunction summarizeNotes(\n notes: NoteEntry[] | undefined | null,\n maxEntries: number,\n include: (note: NoteEntry) => boolean,\n): string {\n if (!notes || notes.length === 0) return \"\";\n\n const trivialPatterns = new Set([\n \"lgtm\",\n \"+1\",\n \"-1\",\n \"👍\",\n \"👎\",\n \"thanks\",\n \"thank you\",\n \"looks good\",\n \"approved\",\n \"🚀\",\n \"✅\",\n \"❌\",\n ]);\n\n const filtered: Array<{ username: string; body: string; createdAt: string }> = [];\n for (const note of notes) {\n if (!include(note)) continue;\n // Cache payloads are machine-only and can be large. Never feed their\n // compressed representation back into reviewer context.\n const body = (note.body ?? \"\").replace(HODOR_CACHE_MARKER_RE, \"\").trim();\n if (!body) continue;\n if (note.system) continue;\n if (body.length < 20) continue;\n\n const bodyLower = body.toLowerCase();\n let isTrivial = false;\n for (const pattern of trivialPatterns) {\n if (bodyLower.includes(pattern) && body.length < 50) {\n isTrivial = true;\n break;\n }\n }\n if (isTrivial) continue;\n\n const username =\n note.author?.username ?? note.author?.name ?? \"unknown\";\n filtered.push({ username, body, createdAt: note.created_at ?? \"\" });\n }\n\n // Sort oldest first\n filtered.sort((a, b) => a.createdAt.localeCompare(b.createdAt));\n\n // Take most recent\n const recent = filtered.slice(-maxEntries);\n\n const lines: string[] = [];\n for (const { username, body, createdAt } of recent) {\n let timestampStr = \"\";\n if (createdAt) {\n try {\n const dt = new Date(createdAt);\n timestampStr = dt.toISOString().replace(\"T\", \" \").slice(0, 16);\n } catch {\n timestampStr = createdAt.slice(0, 10);\n }\n }\n\n const header = timestampStr\n ? `- ${timestampStr} @${username}:`\n : `- @${username}:`;\n const boundedBody = body.length > 2_000 ? `${body.slice(0, 1_999).trimEnd()}…` : body;\n const indentedBody = boundedBody.split(\"\\n\").join(\"\\n \");\n lines.push(`${header}\\n ${indentedBody}`);\n }\n\n return lines.join(\"\\n\");\n}\n\nexport async function getGitlabMrDiffRefs(\n owner: string,\n repo: string,\n mrNumber: number | string,\n host?: string | null,\n): Promise<DiffRefs> {\n const encoded = encodedProjectPath(owner, repo);\n const env = glabEnv(host);\n\n let mrData: Record<string, unknown>;\n try {\n mrData = await execJson<Record<string, unknown>>(\n \"glab\",\n [\"api\", `projects/${encoded}/merge_requests/${mrNumber}`],\n { env },\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n throw new GitLabAPIError(`Failed to fetch diff refs for MR !${mrNumber}: ${msg}`);\n }\n\n const diffRefs = mrData.diff_refs as Record<string, unknown> | undefined;\n const base_sha = diffRefs?.base_sha;\n const head_sha = diffRefs?.head_sha;\n const start_sha = diffRefs?.start_sha;\n\n if (\n typeof base_sha !== \"string\" ||\n typeof head_sha !== \"string\" ||\n typeof start_sha !== \"string\" ||\n !base_sha ||\n !head_sha ||\n !start_sha\n ) {\n throw new GitLabAPIError(`MR !${mrNumber} has missing or incomplete diff_refs`);\n }\n\n return { base_sha, head_sha, start_sha };\n}\n\nexport async function createGitlabDraftNote(\n owner: string,\n repo: string,\n mrNumber: number | string,\n body: string,\n host?: string | null,\n opts?: { filePath?: string; line?: number; diffRefs?: DiffRefs },\n): Promise<Record<string, unknown>> {\n const encoded = encodedProjectPath(owner, repo);\n const env = glabEnv(host);\n const endpoint = `projects/${encoded}/merge_requests/${mrNumber}/draft_notes`;\n\n const payload: Record<string, unknown> = {\n note: body,\n };\n\n if (opts?.filePath && typeof opts.line === \"number\" && opts.diffRefs) {\n payload.position = {\n base_sha: opts.diffRefs.base_sha,\n head_sha: opts.diffRefs.head_sha,\n start_sha: opts.diffRefs.start_sha,\n position_type: \"text\",\n old_path: opts.filePath,\n new_path: opts.filePath,\n new_line: opts.line,\n };\n }\n\n try {\n return await execJson<Record<string, unknown>>(\n \"glab\",\n [\"api\", endpoint, \"--method\", \"POST\", \"-H\", \"Content-Type: application/json\", \"--input\", \"-\"],\n {\n env,\n input: JSON.stringify(payload),\n },\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n throw new GitLabAPIError(`Failed to create draft note for MR !${mrNumber}: ${msg}`);\n }\n}\n\nexport async function bulkPublishGitlabDraftNotes(\n owner: string,\n repo: string,\n mrNumber: number | string,\n host?: string | null,\n): Promise<void> {\n const encoded = encodedProjectPath(owner, repo);\n const env = glabEnv(host);\n\n try {\n await exec(\n \"glab\",\n [\n \"api\",\n `projects/${encoded}/merge_requests/${mrNumber}/draft_notes/bulk_publish`,\n \"--method\",\n \"POST\",\n ],\n { env },\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n throw new GitLabAPIError(`Failed to bulk publish draft notes for MR !${mrNumber}: ${msg}`);\n }\n}\n\ntype GitlabCommitStatusState = \"pending\" | \"running\" | \"success\" | \"failed\" | \"canceled\";\n\nexport async function postGitlabCommitStatus(\n owner: string,\n repo: string,\n sha: string,\n state: GitlabCommitStatusState,\n host?: string | null,\n opts?: { name?: string; description?: string; targetUrl?: string },\n): Promise<void> {\n const allowedStates = new Set<GitlabCommitStatusState>([\n \"pending\",\n \"running\",\n \"success\",\n \"failed\",\n \"canceled\",\n ]);\n if (!allowedStates.has(state)) {\n throw new GitLabAPIError(`Invalid GitLab commit status state: ${state}`);\n }\n\n const encoded = encodedProjectPath(owner, repo);\n const env = glabEnv(host);\n const endpoint = `projects/${encoded}/statuses/${sha}`;\n const payload: Record<string, unknown> = {\n state,\n name: opts?.name ?? \"hodor\",\n };\n\n if (opts?.description) {\n payload.description = opts.description;\n }\n if (opts?.targetUrl) {\n payload.target_url = opts.targetUrl;\n }\n\n try {\n await exec(\n \"glab\",\n [\"api\", endpoint, \"--method\", \"POST\", \"-H\", \"Content-Type: application/json\", \"--input\", \"-\"],\n {\n env,\n input: JSON.stringify(payload),\n },\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n throw new GitLabAPIError(`Failed to post commit status for ${sha}: ${msg}`);\n }\n}\n\nexport async function listHodorDiscussions(\n owner: string,\n repo: string,\n mrNumber: number | string,\n host?: string | null,\n marker = HODOR_REVIEW_MARKER,\n): Promise<\n Array<{\n discussionId: string;\n noteId: number;\n body: string;\n resolved: boolean;\n filePath?: string;\n line?: number;\n }>\n> {\n const encoded = encodedProjectPath(owner, repo);\n const env = glabEnv(host);\n\n let discussions: Array<Record<string, unknown>>;\n try {\n const { stdout: rawDiscussions } = await exec(\n \"glab\",\n [\n \"api\",\n `projects/${encoded}/merge_requests/${mrNumber}/discussions?per_page=100`,\n \"--paginate\",\n ],\n { env },\n );\n discussions = parseGlabPaginatedJson(rawDiscussions);\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n throw new GitLabAPIError(`Failed to list discussions for MR !${mrNumber}: ${msg}`);\n }\n\n const results: Array<{\n discussionId: string;\n noteId: number;\n body: string;\n resolved: boolean;\n filePath?: string;\n line?: number;\n }> = [];\n\n for (const discussion of discussions) {\n const discussionId = discussion.id;\n if (typeof discussionId !== \"string\") {\n continue;\n }\n\n const notes = discussion.notes;\n if (!Array.isArray(notes)) {\n continue;\n }\n\n for (const note of notes) {\n if (!note || typeof note !== \"object\") {\n continue;\n }\n const noteObj = note as Record<string, unknown>;\n const noteId = noteObj.id;\n const body = noteObj.body;\n if (typeof noteId !== \"number\" || typeof body !== \"string\" || !isHodorNote(body, marker)) {\n continue;\n }\n\n const position =\n noteObj.position && typeof noteObj.position === \"object\"\n ? (noteObj.position as Record<string, unknown>)\n : undefined;\n\n const filePath = typeof position?.new_path === \"string\" ? position.new_path : undefined;\n const line = typeof position?.new_line === \"number\" ? position.new_line : undefined;\n\n // Skip non-resolvable threads. GitLab wraps the summary-comment note in a\n // discussion envelope with `resolvable: false`; PUT resolved=true on those\n // returns 403, independent of the caller's project role. Only diff/review\n // threads (resolvable: true) belong in the resolver's queue.\n if (noteObj.resolvable !== true) {\n continue;\n }\n\n results.push({\n discussionId,\n noteId,\n body,\n resolved: Boolean(noteObj.resolved),\n filePath,\n line,\n });\n }\n }\n\n return results;\n}\n\nexport async function resolveGitlabDiscussions(\n owner: string,\n repo: string,\n mrNumber: number | string,\n discussionIds: string[],\n host?: string | null,\n): Promise<number> {\n const encoded = encodedProjectPath(owner, repo);\n const env = glabEnv(host);\n\n let resolvedCount = 0;\n\n for (const discussionId of discussionIds) {\n try {\n await exec(\n \"glab\",\n [\n \"api\",\n `projects/${encoded}/merge_requests/${mrNumber}/discussions/${discussionId}`,\n \"--method\",\n \"PUT\",\n \"-H\",\n \"Content-Type: application/json\",\n \"--input\",\n \"-\",\n ],\n {\n env,\n input: JSON.stringify({ resolved: true }),\n },\n );\n resolvedCount += 1;\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n logger.warn(`Failed to resolve discussion ${discussionId} on MR !${mrNumber}: ${msg}`);\n }\n }\n\n return resolvedCount;\n}\n"],"mappings":";AAAA,SAAS,UAAU,aAAa;AAChC,SAAS,iBAAiB;AAE1B,IAAM,gBAAgB,UAAU,QAAQ;AAaxC,eAAsB,KACpB,KACA,MACA,MACqB;AACrB,MAAI,OAAO,MAAM,UAAU,UAAU;AACnC,WAAO,IAAI,QAAoB,CAAC,SAAS,WAAW;AAClD,YAAM,QAAQ,MAAM,KAAK,MAAM;AAAA,QAC7B,KAAK,KAAK;AAAA,QACV,KAAK,KAAK,OAAO,QAAQ;AAAA,QACzB,OAAO,CAAC,QAAQ,QAAQ,MAAM;AAAA,MAChC,CAAC;AAED,UAAIA,UAAS;AACb,UAAIC,UAAS;AAEb,YAAM,OAAO,GAAG,QAAQ,CAAC,UAA2B;AAClD,QAAAD,WAAU,MAAM,SAAS;AAAA,MAC3B,CAAC;AACD,YAAM,OAAO,GAAG,QAAQ,CAAC,UAA2B;AAClD,QAAAC,WAAU,MAAM,SAAS;AAAA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