@mrkaran/hodor 0.5.0 → 0.6.2-rc.2

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,7 +2,7 @@
2
2
 
3
3
  # Hodor
4
4
 
5
- > Agentic code reviewer for GitHub PRs, GitLab MRs, 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. Powered by the [pi-coding-agent](https://github.com/badlogic/pi-mono) SDK.
6
6
 
7
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.
8
8
 
@@ -22,13 +22,17 @@ Docker images are also available at `ghcr.io/mr-karan/hodor:latest` for CI envir
22
22
 
23
23
  ```bash
24
24
  # Set an API key for your LLM provider
25
- export ANTHROPIC_API_KEY=sk-... # Anthropic (default)
26
- export OPENAI_API_KEY=sk-... # OpenAI
27
- export AWS_PROFILE=default # AWS Bedrock (no API key needed)
25
+ export ANTHROPIC_API_KEY=sk-... # Anthropic (default)
26
+ export OPENAI_API_KEY=sk-... # OpenAI
27
+ export OPENROUTER_API_KEY=sk-or-... # OpenRouter (e.g., Kimi K2.6)
28
+ export AWS_PROFILE=default # AWS Bedrock (no API key needed)
28
29
 
29
30
  # For posting reviews as comments
30
31
  gh auth login # GitHub
31
32
  glab auth login # GitLab
33
+
34
+ # For Gitea/Forgejo private repos or posting comments
35
+ export GITEA_TOKEN=your-token # or FORGEJO_TOKEN
32
36
  ```
33
37
 
34
38
  ## Usage
@@ -40,13 +44,12 @@ npx @mrkaran/hodor https://github.com/owner/repo/pull/123
40
44
  # Review a GitLab MR (including self-hosted)
41
45
  npx @mrkaran/hodor https://gitlab.example.com/org/project/-/merge_requests/42
42
46
 
47
+ # Review a Gitea or Forgejo PR
48
+ npx @mrkaran/hodor https://git.example.com/owner/repo/pulls/123
49
+
43
50
  # Post the review as a PR/MR comment
44
51
  npx @mrkaran/hodor <PR_URL> --post
45
52
 
46
- # Review local changes (no PR URL needed)
47
- npx @mrkaran/hodor --local # diff against origin/main
48
- npx @mrkaran/hodor --local --diff-against HEAD~1 # diff against specific ref
49
-
50
53
  # Use a different model
51
54
  npx @mrkaran/hodor <PR_URL> --model openai/gpt-5
52
55
  npx @mrkaran/hodor <PR_URL> --model bedrock/converse/anthropic.claude-sonnet-4-5-v2
@@ -63,21 +66,53 @@ npx @mrkaran/hodor <PR_URL> -v
63
66
 
64
67
  > If you installed globally with `npm install -g`, replace `npx @mrkaran/hodor` with `hodor`.
65
68
 
69
+ ## Local Mode
70
+
71
+ Review local git changes without a PR URL. Useful for pre-push reviews, Bitbucket PRs, or any git repo.
72
+
73
+ ```bash
74
+ # Review uncommitted changes against origin/main (default)
75
+ npx @mrkaran/hodor --local
76
+
77
+ # Review against a specific branch or ref
78
+ npx @mrkaran/hodor --local --diff-against develop
79
+ npx @mrkaran/hodor --local --diff-against HEAD~3
80
+
81
+ # Review a feature branch against main
82
+ git checkout feature-branch
83
+ npx @mrkaran/hodor --local --diff-against origin/main
84
+
85
+ # Use a specific workspace directory
86
+ npx @mrkaran/hodor --local --workspace /path/to/repo
87
+
88
+ # Combine with other flags
89
+ npx @mrkaran/hodor --local --diff-against origin/main --model openai/gpt-5 -v
90
+ ```
91
+
92
+ Local mode:
93
+ - Includes **uncommitted changes** (staged + unstaged), not just commits
94
+ - Auto-resolves to the **git repo root** (works from subdirectories)
95
+ - Skips PR metadata fetching and workspace cloning
96
+ - `--post` is disabled (no remote to post to)
97
+
66
98
  ## CLI Flags
67
99
 
68
100
  | Flag | Default | Description |
69
101
  |------|---------|-------------|
70
- | `--model` | `anthropic/claude-sonnet-4-5-20250929` | LLM model (Anthropic, OpenAI, or Bedrock) |
102
+ | `--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). |
71
103
  | `--reasoning-effort` | – | Extended thinking: `low`, `medium`, `high` |
72
104
  | `--ultrathink` | Off | Maximum reasoning effort |
73
105
  | `--local` | Off | Review local git changes (no PR URL required) |
74
106
  | `--diff-against` | `origin/main` | Git ref to diff against in `--local` mode |
75
107
  | `--post` | Off | Post review as a comment on the PR/MR |
108
+ | `--review-style` | `hybrid` | GitLab posting style: `summary`, `inline`, or `hybrid` |
109
+ | `--code-quality` | – | Write a CodeClimate JSON artifact for GitLab code quality reports |
110
+ | `--commit-status` | Off | Post a pass/fail commit status to the GitLab MR head SHA |
76
111
  | `--prompt` | – | Append custom instructions to the review prompt |
77
112
  | `--prompt-file` | – | Use a custom prompt file |
78
113
  | `--workspace` | Temp dir | Workspace directory (reuse for faster multi-PR reviews) |
79
114
  | `--bedrock-tags` | – | JSON cost allocation tags for AWS Bedrock |
80
- | `--prometheus-push` | – | Push review metrics to a Prometheus Pushgateway |
115
+ | `--prometheus-push` | – | Push review metrics to a Prometheus Pushgateway or VictoriaMetrics import endpoint |
81
116
  | `-v, --verbose` | Off | Stream agent reasoning and tool calls |
82
117
 
83
118
  ## Environment Variables
@@ -86,12 +121,47 @@ npx @mrkaran/hodor <PR_URL> -v
86
121
  |----------|---------|
87
122
  | `ANTHROPIC_API_KEY` | Claude API key |
88
123
  | `OPENAI_API_KEY` | OpenAI API key |
124
+ | `OPENROUTER_API_KEY` | OpenRouter API key (for `openrouter/...` models, e.g. `openrouter/moonshotai/kimi-k2.6`) |
125
+ | Provider-specific keys | For best-effort pi-ai providers, use the env var pi-ai expects (e.g. `MISTRAL_API_KEY`, `GEMINI_API_KEY`, `XAI_API_KEY`, `GROQ_API_KEY`) |
89
126
  | `LLM_API_KEY` | Generic fallback (when provider-specific key is not set) |
90
- | `GITHUB_TOKEN` / `GITLAB_TOKEN` | Post comments to PRs/MRs (with `--post`) |
127
+ | `GITHUB_TOKEN` / `GITLAB_TOKEN` | Post comments to GitHub PRs / GitLab MRs (with `--post`) |
128
+ | `GITEA_TOKEN` / `FORGEJO_TOKEN` | Read private repos and post comments on Gitea/Forgejo PRs |
129
+ | `GITEA_HOST` / `FORGEJO_HOST` | Hostname for Gitea/Forgejo when not inferable from a full PR URL |
91
130
  | `AWS_PROFILE` or `AWS_ACCESS_KEY_ID` | AWS Bedrock auth (no API key needed) |
92
131
 
132
+ See [docs/MODELS.md](./docs/MODELS.md) for the full model/provider matrix and [docs/OPENROUTER.md](./docs/OPENROUTER.md) for an end-to-end Kimi K2.6 example.
133
+
134
+ ## Gitea / Forgejo
135
+
136
+ Hodor supports Gitea and Forgejo pull request URLs in this format:
137
+
138
+ ```bash
139
+ npx @mrkaran/hodor https://git.example.com/owner/repo/pulls/123
140
+ ```
141
+
142
+ For public repositories, metadata fetching may work without a token. Set `GITEA_TOKEN` or `FORGEJO_TOKEN` for private repositories, higher API limits, and `--post`:
143
+
144
+ ```bash
145
+ export GITEA_TOKEN=your-token
146
+ npx @mrkaran/hodor https://git.example.com/owner/repo/pulls/123 --post
147
+ ```
148
+
149
+ Fork PRs are checked out from the PR source repository when Gitea exposes the source clone URL. If the source branch or fork has been deleted, checkout will fail with a workspace error.
150
+
93
151
  ## CI/CD
94
152
 
153
+ ### Metrics in CI
154
+
155
+ Hodor can push per-review metrics at the end of a CI run to either a Prometheus Pushgateway base URL or a VictoriaMetrics Prometheus import endpoint (`/api/v1/import/prometheus`):
156
+
157
+ ```bash
158
+ hodor "$MR_OR_PR_URL" --prometheus-push "$METRICS_PUSH_URL"
159
+ ```
160
+
161
+ 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.
162
+
163
+ Each metric is labeled with `platform`, `model`, `verdict`, and for PR/MR URLs also `project` (`owner/repo`) and `mr_iid`/PR number. 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/).
164
+
95
165
  ### GitHub Actions
96
166
 
97
167
  ```yaml
@@ -109,23 +179,47 @@ jobs:
109
179
  env:
110
180
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111
181
  ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
182
+ METRICS_PUSH_URL: ${{ secrets.METRICS_PUSH_URL }} # optional
112
183
  run: |
113
- hodor "https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}" --post
184
+ EXTRA_ARGS=""
185
+ if [ -n "${METRICS_PUSH_URL:-}" ]; then EXTRA_ARGS="--prometheus-push $METRICS_PUSH_URL"; fi
186
+ bun run /app/dist/cli.js "https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}" --post $EXTRA_ARGS
114
187
  ```
115
188
 
116
189
  ### GitLab CI
117
190
 
118
191
  ```yaml
119
- include:
120
- - project: 'commons/gitlab-templates'
121
- ref: master
122
- file: '/hodor/.gitlab-ci-template.yml'
192
+ # .gitlab-ci.yml
193
+ workflow:
194
+ rules:
195
+ - if: $CI_PIPELINE_SOURCE == "merge_request_event"
123
196
 
124
197
  hodor-review:
125
- extends: .hodor-review
198
+ stage: test
199
+ image:
200
+ name: ghcr.io/mr-karan/hodor:latest
201
+ entrypoint: [""]
202
+ variables:
203
+ HODOR_MODEL: "anthropic/claude-sonnet-4-5-20250929"
204
+ before_script:
205
+ - glab auth login --hostname $CI_SERVER_HOST --token $GITLAB_TOKEN
206
+ script:
207
+ - MR_URL="${CI_PROJECT_URL}/-/merge_requests/${CI_MERGE_REQUEST_IID}"
208
+ - |
209
+ EXTRA_ARGS=""
210
+ if [ -n "${METRICS_PUSH_URL:-}" ]; then EXTRA_ARGS="--prometheus-push $METRICS_PUSH_URL"; fi
211
+ bun run /app/dist/cli.js "$MR_URL" --model "$HODOR_MODEL" --post --code-quality gl-code-quality-report.json --commit-status $EXTRA_ARGS
212
+ artifacts:
213
+ reports:
214
+ codequality: gl-code-quality-report.json
215
+ when: always
216
+ allow_failure: true
217
+ timeout: 15m
126
218
  ```
127
219
 
128
- See [AUTOMATED_REVIEWS.md](./docs/AUTOMATED_REVIEWS.md) for advanced CI workflows.
220
+ This posts inline comments on the diff, a summary note, a pass/fail commit status, and a code quality report visible in the MR widget.
221
+
222
+ See [AUTOMATED_REVIEWS.md](./docs/AUTOMATED_REVIEWS.md) for advanced workflows.
129
223
 
130
224
  ## Token Optimization
131
225
 
@@ -137,14 +231,14 @@ Hodor automatically optimizes token usage:
137
231
 
138
232
  ## Skills
139
233
 
140
- Hodor discovers repository-specific review guidelines from `.pi/skills/` or `.hodor/skills/`:
234
+ Hodor discovers repository-specific review guidelines from `.agents/skills/`, the cross-client Agent Skills convention:
141
235
 
142
236
  ```bash
143
- mkdir -p .hodor/skills/review-guidelines
237
+ mkdir -p .agents/skills/review-guidelines
144
238
  ```
145
239
 
146
240
  ```markdown
147
- # .hodor/skills/review-guidelines/SKILL.md
241
+ # .agents/skills/review-guidelines/SKILL.md
148
242
  ---
149
243
  name: review-guidelines
150
244
  description: Security and performance review checklist.
@@ -166,6 +260,40 @@ bun run test # Run tests
166
260
  bun run dev -- <url> # Run from source
167
261
  ```
168
262
 
263
+ ---
264
+
265
+ ## Architecture
266
+
267
+ Hodor is written in TypeScript and runs on [Bun](https://bun.sh). Key components:
268
+
269
+ | Module | Purpose |
270
+ |--------|---------|
271
+ | `src/cli.ts` | Commander.js CLI entry point |
272
+ | `src/agent.ts` | Core review orchestration, URL parsing, comment posting |
273
+ | `src/workspace.ts` | CI detection, repo cloning, branch checkout |
274
+ | `src/prompt.ts` | Prompt template building and interpolation |
275
+ | `src/model.ts` | Model string parsing, API key resolution |
276
+ | `src/gitlab.ts` | GitLab API via `glab` CLI (comments, inline notes, draft notes, commit status) |
277
+ | `src/github.ts` | GitHub API via `gh` CLI |
278
+ | `src/render.ts` | JSON review output → markdown rendering |
279
+ | `src/codequality.ts` | CodeClimate JSON artifact for GitLab code quality widget |
280
+ | `src/metrics.ts` | Token usage and cost formatting |
281
+ | `templates/` | Review prompt template (JSON schema) |
282
+
283
+ The agent runtime is provided by [`@mariozechner/pi-coding-agent`](https://github.com/badlogic/pi-mono) with [`@mariozechner/pi-ai`](https://github.com/badlogic/pi-mono) for LLM access. The agent session gets read-only tools (bash, read, grep, find, ls) and a review prompt, then autonomously analyzes the PR.
284
+
285
+ ---
286
+
287
+ ## Learn More
288
+
289
+ ### Hodor Documentation
290
+ - **[SKILLS.md](./docs/SKILLS.md)** - Creating repository-specific review guidelines
291
+ - **[AUTOMATED_REVIEWS.md](./docs/AUTOMATED_REVIEWS.md)** - Advanced CI/CD workflows
292
+
293
+ ### Contributing
294
+ Found a bug? Want to add a feature? Open an issue at https://github.com/mr-karan/hodor/issues.
295
+
296
+ ---
169
297
  ## License
170
298
 
171
299
  MIT
@@ -0,0 +1,23 @@
1
+ // src/utils/path.ts
2
+ function relativizeWorkspacePath(absolutePath, workspacePrefix) {
3
+ let filePath = absolutePath;
4
+ const prefix = workspacePrefix ?? process.env.CI_PROJECT_DIR;
5
+ if (prefix) {
6
+ const trimmed = prefix.replace(/\/+$/, "");
7
+ if (filePath.startsWith(`${trimmed}/`)) {
8
+ return filePath.slice(trimmed.length + 1);
9
+ }
10
+ }
11
+ const buildsMatch = filePath.match(/\/builds\/[^/]+\/[^/]+\/(.+)/);
12
+ if (buildsMatch) return buildsMatch[1];
13
+ if (filePath.includes("/workspace/")) {
14
+ return filePath.slice(filePath.indexOf("/workspace/") + "/workspace/".length);
15
+ }
16
+ const stripped = filePath.replace(/^.*\/hodor-review-[^/]+\//, "");
17
+ return stripped !== filePath ? stripped : filePath;
18
+ }
19
+
20
+ export {
21
+ relativizeWorkspacePath
22
+ };
23
+ //# sourceMappingURL=chunk-AMUK6GDX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/path.ts"],"sourcesContent":["/**\n * Strip workspace/CI prefixes from an absolute path so it becomes repo-relative.\n *\n * Used both for inline-comment paths posted to GitLab (must match the diff path)\n * and for the CodeClimate code quality artifact (GitLab compares against repo\n * paths, not the temp-dir absolute paths Hodor sees during a review).\n *\n * Honors `CI_PROJECT_DIR` first when set (GitLab CI sets it to the checkout root).\n * Otherwise, falls through generic patterns: GitLab `/builds/<group>/<project>/...`,\n * a `/workspace/...` segment, and Hodor's own `/tmp/hodor-review-<id>/...` temp dirs.\n */\nexport function relativizeWorkspacePath(absolutePath: string, workspacePrefix?: string): string {\n let filePath = absolutePath;\n\n const prefix = workspacePrefix ?? process.env.CI_PROJECT_DIR;\n if (prefix) {\n const trimmed = prefix.replace(/\\/+$/, \"\");\n if (filePath.startsWith(`${trimmed}/`)) {\n return filePath.slice(trimmed.length + 1);\n }\n }\n\n const buildsMatch = filePath.match(/\\/builds\\/[^/]+\\/[^/]+\\/(.+)/);\n if (buildsMatch) return buildsMatch[1];\n\n if (filePath.includes(\"/workspace/\")) {\n return filePath.slice(filePath.indexOf(\"/workspace/\") + \"/workspace/\".length);\n }\n\n const stripped = filePath.replace(/^.*\\/hodor-review-[^/]+\\//, \"\");\n return stripped !== filePath ? stripped : filePath;\n}\n"],"mappings":";AAWO,SAAS,wBAAwB,cAAsB,iBAAkC;AAC9F,MAAI,WAAW;AAEf,QAAM,SAAS,mBAAmB,QAAQ,IAAI;AAC9C,MAAI,QAAQ;AACV,UAAM,UAAU,OAAO,QAAQ,QAAQ,EAAE;AACzC,QAAI,SAAS,WAAW,GAAG,OAAO,GAAG,GAAG;AACtC,aAAO,SAAS,MAAM,QAAQ,SAAS,CAAC;AAAA,IAC1C;AAAA,EACF;AAEA,QAAM,cAAc,SAAS,MAAM,8BAA8B;AACjE,MAAI,YAAa,QAAO,YAAY,CAAC;AAErC,MAAI,SAAS,SAAS,aAAa,GAAG;AACpC,WAAO,SAAS,MAAM,SAAS,QAAQ,aAAa,IAAI,cAAc,MAAM;AAAA,EAC9E;AAEA,QAAM,WAAW,SAAS,QAAQ,6BAA6B,EAAE;AACjE,SAAO,aAAa,WAAW,WAAW;AAC5C;","names":[]}