@gyeonghokim/gerrit-cli 0.0.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.
Files changed (4) hide show
  1. package/LICENSE +93 -0
  2. package/README.md +324 -0
  3. package/bin/cli.js +64 -0
  4. package/package.json +43 -0
package/LICENSE ADDED
@@ -0,0 +1,93 @@
1
+ Elastic License 2.0
2
+
3
+ URL: https://www.elastic.co/licensing/elastic-license
4
+
5
+ ## Acceptance
6
+
7
+ By using the software, you agree to all of the terms and conditions below.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
12
+ non-sublicensable, non-transferable license to use, copy, distribute, make
13
+ available, and prepare derivative works of the software, in each case subject to
14
+ the limitations and conditions below.
15
+
16
+ ## Limitations
17
+
18
+ You may not provide the software to third parties as a hosted or managed
19
+ service, where the service provides users with access to any substantial set of
20
+ the features or functionality of the software.
21
+
22
+ You may not move, change, disable, or circumvent the license key functionality
23
+ in the software, and you may not remove or obscure any functionality in the
24
+ software that is protected by the license key.
25
+
26
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
27
+ of the licensor in the software. Any use of the licensor’s trademarks is subject
28
+ to applicable law.
29
+
30
+ ## Patents
31
+
32
+ The licensor grants you a license, under any patent claims the licensor can
33
+ license, or becomes able to license, to make, have made, use, sell, offer for
34
+ sale, import and have imported the software, in each case subject to the
35
+ limitations and conditions in this license. This license does not cover any
36
+ patent claims that you cause to be infringed by modifications or additions to
37
+ the software. If you or your company make any written claim that the software
38
+ infringes or contributes to infringement of any patent, your patent license for
39
+ the software granted under these terms ends immediately. If your company makes
40
+ such a claim, your patent license ends immediately for work on behalf of your
41
+ company.
42
+
43
+ ## Notices
44
+
45
+ You must ensure that anyone who gets a copy of any part of the software from you
46
+ also gets a copy of these terms.
47
+
48
+ If you modify the software, you must include in any modified copies of the
49
+ software prominent notices stating that you have modified the software.
50
+
51
+ ## No Other Rights
52
+
53
+ These terms do not imply any licenses other than those expressly granted in
54
+ these terms.
55
+
56
+ ## Termination
57
+
58
+ If you use the software in violation of these terms, such use is not licensed,
59
+ and your licenses will automatically terminate. If the licensor provides you
60
+ with a notice of your violation, and you cease all violation of this license no
61
+ later than 30 days after you receive that notice, your licenses will be
62
+ reinstated retroactively. However, if you violate these terms after such
63
+ reinstatement, any additional violation of these terms will cause your licenses
64
+ to terminate automatically and permanently.
65
+
66
+ ## No Liability
67
+
68
+ *As far as the law allows, the software comes as is, without any warranty or
69
+ condition, and the licensor will not be liable to you for any damages arising
70
+ out of these terms or the use or nature of the software, under any kind of
71
+ legal claim.*
72
+
73
+ ## Definitions
74
+
75
+ The **licensor** is the entity offering these terms, and the **software** is the
76
+ software the licensor makes available under these terms, including any portion
77
+ of it.
78
+
79
+ **you** refers to the individual or entity agreeing to these terms.
80
+
81
+ **your company** is any legal entity, sole proprietorship, or other kind of
82
+ organization that you work for, plus all organizations that have control over,
83
+ are under the control of, or are under common control with that
84
+ organization. **control** means ownership of substantially all the assets of an
85
+ entity, or the power to direct its management and policies by vote, contract, or
86
+ otherwise. Control can be direct or indirect.
87
+
88
+ **your licenses** are all the licenses granted to you for the software under
89
+ these terms.
90
+
91
+ **use** means anything you do with the software requiring one of your licenses.
92
+
93
+ **trademark** means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,324 @@
1
+ # gerrit-mcp-server
2
+
3
+ [![CI](https://github.com/GyeongHoKim/gerrit-mcp-server/actions/workflows/ci.yml/badge.svg)](https://github.com/GyeongHoKim/gerrit-mcp-server/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/@gyeonghokim/gerrit-mcp-server)](https://www.npmjs.com/package/@gyeonghokim/gerrit-mcp-server)
5
+ [![Go](https://img.shields.io/badge/go-1.26-00ADD8)](https://go.dev)
6
+ [![License](https://img.shields.io/badge/license-Elastic--2.0-005571)](LICENSE)
7
+
8
+ Connect your AI coding agent to Gerrit code review.
9
+
10
+ Ask your agent to find the changes waiting on you, read a diff, draft line comments, and publish a
11
+ review — without leaving the session and without pasting change numbers back and forth.
12
+
13
+ It ships as **two frontends over the same code**, so you can pick how much of your agent's context
14
+ you want to spend:
15
+
16
+ | | What it is | Context cost |
17
+ | --- | --- | --- |
18
+ | **`gerrit-cli` + skill** | A command-line binary, plus an [agent skill](skills/gerrit-cli/SKILL.md) that teaches an agent to drive it | One line, until the skill triggers |
19
+ | **`gerrit-mcp-server`** | A [Model Context Protocol](https://modelcontextprotocol.io) server over **stdio** | 22 tool schemas, for the whole session |
20
+
21
+ The skill route is the lighter one and works with any agent that reads skills. The MCP server needs
22
+ no shell access and works with any MCP client: Claude Code, Codex, Cursor, Zed, Continue, or your
23
+ own.
24
+
25
+ Either way it is a single static binary with no runtime dependencies. You self-host it; nothing is
26
+ sent anywhere except to the Gerrit host you configure.
27
+
28
+ ## Quick start
29
+
30
+ Both routes start the same way.
31
+
32
+ **Create a Gerrit auth token.** In Gerrit, go to *Settings → HTTP Credentials* and generate one.
33
+ See [Credentials](#credentials) below if your Gerrit is older.
34
+
35
+ Node is needed only so that `npm` or `npx` can fetch the right binary for your machine. The binaries
36
+ are Go and have no Node runtime dependency.
37
+
38
+ ### Route A — `gerrit-cli` + agent skill
39
+
40
+ The lighter one. Nothing sits in your agent's context until it needs Gerrit.
41
+
42
+ **1. Install the binary.**
43
+
44
+ ```bash
45
+ npm i -g @gyeonghokim/gerrit-cli
46
+ ```
47
+
48
+ **2. Install the skill.** This works for Claude Code, Codex, Cursor and many others.
49
+
50
+ ```bash
51
+ npx skills add GyeongHoKim/gerrit-mcp-server
52
+ ```
53
+
54
+ **3. Configure it.** Run this yourself in a terminal — it asks for your token on stdin, and will
55
+ refuse to run where nothing can type into it.
56
+
57
+ ```bash
58
+ gerrit-cli init
59
+ ```
60
+
61
+ **4. Check it.** `gerrit-cli config` reports every setting and where it came from, naming anything
62
+ still missing. Then ask your agent: *"What changes am I reviewing?"*
63
+
64
+ To allow the commands that modify Gerrit, set `GERRIT_ALLOW_WRITE=true` — see
65
+ [Available tools and commands](#available-tools-and-commands).
66
+
67
+ You can also use the CLI on its own, without an agent:
68
+
69
+ ```bash
70
+ gerrit-cli query-changes --query "is:open reviewer:self -owner:self"
71
+ gerrit-cli get-file-diff --change-id 12345 --file src/main.go
72
+ gerrit-cli help
73
+ ```
74
+
75
+ ### Route B — MCP server
76
+
77
+ No shell access needed, and it works with any MCP client.
78
+
79
+ **Add the server to your client.**
80
+
81
+ <details open>
82
+ <summary><b>Claude Code</b></summary>
83
+
84
+ ```bash
85
+ claude mcp add gerrit \
86
+ --env GERRIT_URL=https://gerrit.example.com \
87
+ --env GERRIT_USER=your-username \
88
+ --env GERRIT_TOKEN=your-token \
89
+ -- npx -y @gyeonghokim/gerrit-mcp-server
90
+ ```
91
+
92
+ </details>
93
+
94
+ <details>
95
+ <summary><b>Codex</b></summary>
96
+
97
+ Add this to `~/.codex/config.toml`, or to `.codex/config.toml` for a single trusted project:
98
+
99
+ ```toml
100
+ [mcp_servers.gerrit]
101
+ command = "npx"
102
+ args = ["-y", "@gyeonghokim/gerrit-mcp-server"]
103
+ # npx downloads the binary on first run, which can exceed the 10s default.
104
+ startup_timeout_sec = 60
105
+
106
+ [mcp_servers.gerrit.env]
107
+ GERRIT_URL = "https://gerrit.example.com"
108
+ GERRIT_USER = "your-username"
109
+ GERRIT_TOKEN = "your-token"
110
+ ```
111
+
112
+ Or let the CLI write it for you:
113
+
114
+ ```bash
115
+ codex mcp add gerrit \
116
+ --env GERRIT_URL=https://gerrit.example.com \
117
+ --env GERRIT_USER=your-username \
118
+ --env GERRIT_TOKEN=your-token \
119
+ -- npx -y @gyeonghokim/gerrit-mcp-server
120
+ ```
121
+
122
+ </details>
123
+
124
+ <details>
125
+ <summary><b>Cursor, Zed, and other clients</b></summary>
126
+
127
+ Add this to the client's MCP configuration file:
128
+
129
+ ```jsonc
130
+ {
131
+ "mcpServers": {
132
+ "gerrit": {
133
+ "command": "npx",
134
+ "args": ["-y", "@gyeonghokim/gerrit-mcp-server"],
135
+ "env": {
136
+ "GERRIT_URL": "https://gerrit.example.com",
137
+ "GERRIT_USER": "your-username",
138
+ "GERRIT_TOKEN": "your-token"
139
+ }
140
+ }
141
+ }
142
+ }
143
+ ```
144
+
145
+ </details>
146
+
147
+ **Ask for something.** "What changes am I reviewing?" or "Summarise the diff on change 12345."
148
+
149
+ ## Credentials
150
+
151
+ Gerrit authenticates REST clients with HTTP Basic using a token from your account settings, and
152
+ expects authenticated requests to be prefixed with `/a/`. Both binaries handle the prefix for you.
153
+
154
+ Generate a token under *Settings → HTTP Credentials*. On Gerrit 3.13 and newer you can name the
155
+ token and give it a lifetime (`90 days`, `1 year`, and so on) — worth doing, so the credential this
156
+ holds is scoped and expires on its own. Older Gerrit versions call the same thing an *HTTP
157
+ password*; it still works, as that endpoint is now an alias that creates a token with the id
158
+ `legacy`.
159
+
160
+ **Where the token lives depends on which frontend you use.**
161
+
162
+ `gerrit-mcp-server` reads the environment and only the environment, so its credentials live in your
163
+ MCP client's config file and nowhere else. It never reads a file of its own.
164
+
165
+ `gerrit-cli` has no client config to inherit from, so `gerrit-cli init` writes one under the OS
166
+ configuration directory:
167
+
168
+ | OS | Path |
169
+ | --- | --- |
170
+ | Linux | `$XDG_CONFIG_HOME/gerrit-cli/config.json`, or `~/.config/gerrit-cli/config.json` |
171
+ | macOS | `~/Library/Application Support/gerrit-cli/config.json` |
172
+ | Windows | `%AppData%\gerrit-cli\config.json` |
173
+
174
+ Set `GERRIT_CONFIG` to put it somewhere else. Environment variables always take precedence over the
175
+ file, so a one-off `GERRIT_TOKEN=... gerrit-cli ...` works and CI never needs a file at all.
176
+ `gerrit-cli config` prints where each value actually came from.
177
+
178
+ What holds for both:
179
+
180
+ - **The token only ever travels in an `Authorization` header.** It is never passed as a process
181
+ argument, so it cannot be read out of `ps`, and it is never written to a log line or an error
182
+ message. `gerrit-cli init` has no `--token` flag for exactly this reason.
183
+ - **Nothing goes anywhere but your Gerrit host.**
184
+
185
+ What is worth knowing about the file:
186
+
187
+ - On Linux and macOS it is written `0600`, readable only by you. On Windows it inherits the ACL of
188
+ `%AppData%`, which is already restricted to your account plus SYSTEM and Administrators — setting
189
+ a tighter one needs a dependency this project does not take. If your `%AppData%` is redirected to
190
+ a network share, prefer keeping `GERRIT_TOKEN` in your environment instead.
191
+ - **`gerrit-cli init` echoes the token as you type it.** Hiding terminal input needs a dependency
192
+ this project does not take either. Pipe it in if that matters:
193
+ `printf 'https://gerrit.example.com
194
+ alice
195
+ %s
196
+ ' "$TOKEN" | gerrit-cli init -non-interactive`
197
+ - **Do not commit it, and do not commit an MCP config either.** A project-level `.mcp.json` holding
198
+ `GERRIT_TOKEN` is a credential in your repository. Keep it in your user-level client config, or
199
+ gitignore it.
200
+ - **Use a dedicated token with a lifetime**, so it can be revoked without touching your other
201
+ credentials.
202
+ - Your Gerrit permissions still apply. Neither frontend can see or do anything your account cannot.
203
+
204
+ ## Configuration
205
+
206
+ Both frontends read the same variables. For the MCP server they live in your client's config; for
207
+ the CLI they are optional, since `gerrit-cli init` writes the same settings to a file.
208
+
209
+ | Variable | Required | Default | Description |
210
+ | --- | --- | --- | --- |
211
+ | `GERRIT_URL` | yes | — | Base URL of the Gerrit host, for example `https://gerrit.example.com` |
212
+ | `GERRIT_USER` | yes | — | Your Gerrit username |
213
+ | `GERRIT_TOKEN` | yes | — | Auth token from *Settings → HTTP Credentials* |
214
+ | `GERRIT_ALLOW_WRITE` | no | `false` | Set to `true` to enable the tools and commands that modify Gerrit |
215
+ | `GERRIT_TIMEOUT` | no | `30s` | Per-request timeout |
216
+ | `GERRIT_LOG_LEVEL` | no | `info` | `debug`, `info`, `warn`, or `error`. Logs go to stderr |
217
+ | `GERRIT_CONFIG` | no | — | `gerrit-cli` only. Path to the configuration file, overriding the default |
218
+
219
+ ## Available tools and commands
220
+
221
+ **The two frontends expose exactly the same set**, and a test in the repository holds them there.
222
+ A CLI command is its MCP tool name with the underscores written as dashes — `query_changes` becomes
223
+ `query-changes` — and `gerrit-cli` accepts either spelling.
224
+
225
+ Reads are always available. **Writes are off unless you set `GERRIT_ALLOW_WRITE=true`**, so an
226
+ agent cannot abandon a change or post a review by accident. The MCP server does not register the
227
+ write tools at all; `gerrit-cli` still lists them in its help, marked, but refuses to run one.
228
+
229
+ ### Read
230
+
231
+ | Tool | Description |
232
+ | --- | --- |
233
+ | `query_changes` | Search changes with Gerrit query syntax (`status:open owner:self`) |
234
+ | `get_change_details` | Full summary of one change |
235
+ | `get_commit_message` | Commit message of the current patch set |
236
+ | `list_change_files` | Files touched by the latest patch set |
237
+ | `get_file_diff` | Diff for one file in a change |
238
+ | `list_change_comments` | Published comments on a change |
239
+ | `list_draft_comments` | Your unpublished draft comments |
240
+ | `changes_submitted_together` | Changes that would submit alongside this one |
241
+ | `suggest_reviewers` | Reviewer suggestions for a change |
242
+ | `get_bugs_from_cl` | Bug ids referenced in the commit message |
243
+
244
+ Every value is a flag; `gerrit-cli` has no positional arguments. Run `gerrit-cli help <command>`
245
+ for one command's flags — that is authoritative and cannot go stale.
246
+
247
+ There is deliberately **no `--json` output**. Everything passes through the same renderer that keeps
248
+ responses inside a sensible token budget, and handing an agent raw Gerrit JSON would undo that.
249
+
250
+ ### Write — requires `GERRIT_ALLOW_WRITE=true`
251
+
252
+ | Tool | Description |
253
+ | --- | --- |
254
+ | `post_review_comment` | Add a draft comment on a line, or reply in a thread |
255
+ | `publish_drafts` | Publish your draft comments as a review |
256
+ | `delete_draft_comment` | Delete one draft comment |
257
+ | `delete_draft_comments` | Delete every draft on a change |
258
+ | `add_reviewer` | Add a reviewer or CC |
259
+ | `set_topic` | Set or clear the topic |
260
+ | `set_ready_for_review` | Take a change out of WIP |
261
+ | `set_work_in_progress` | Mark a change WIP |
262
+ | `create_change` | Create a change |
263
+ | `abandon_change` | Abandon a change |
264
+ | `revert_change` | Revert a change |
265
+ | `revert_submission` | Revert a whole submission |
266
+
267
+ ## Exit codes
268
+
269
+ `gerrit-cli` reports what to do about a failure, not just that one happened. Rendered output goes to
270
+ stdout and everything else to stderr, so the answer is safe to pipe.
271
+
272
+ | Code | Meaning |
273
+ | --- | --- |
274
+ | 0 | Success |
275
+ | 1 | Something else failed; read stderr |
276
+ | 2 | Bad arguments |
277
+ | 3 | Not configured — run `gerrit-cli init` |
278
+ | 4 | Not permitted — the account, or `GERRIT_ALLOW_WRITE` |
279
+ | 5 | No such change, file or comment |
280
+ | 6 | The change is not in a state that allows this |
281
+
282
+ ## Supported Gerrit versions
283
+
284
+ Built against the Gerrit **3.14** REST API and tested against it. Expected to work with **3.12 and
285
+ newer**; older versions are missing some of the draft comment endpoints.
286
+
287
+ ## Other ways to install
288
+
289
+ `npm` is the easy path, but the binaries stand alone.
290
+
291
+ ```bash
292
+ # Go toolchain
293
+ go install github.com/GyeongHoKim/gerrit-mcp-server/cmd/gerrit-mcp-server@latest
294
+ go install github.com/GyeongHoKim/gerrit-mcp-server/cmd/gerrit-cli@latest
295
+ ```
296
+
297
+ Or download the archive for your platform from the
298
+ [releases page](https://github.com/GyeongHoKim/gerrit-mcp-server/releases). It contains both
299
+ binaries and the agent skill, and you can point your MCP client's `command` straight at
300
+ `gerrit-mcp-server`. No Node required.
301
+
302
+ ## Development
303
+
304
+ ```bash
305
+ mise install # toolchain, pinned in mise.toml
306
+ just setup # dependencies and git hooks
307
+ just ci # everything CI runs
308
+ just --list # all tasks
309
+ ```
310
+
311
+ See [AGENTS.md](AGENTS.md) for architecture, conventions, and the Gerrit API details worth knowing
312
+ before you touch the client.
313
+
314
+ ## License
315
+
316
+ [Elastic License 2.0](LICENSE).
317
+
318
+ **Using this at work is fine.** ELv2 places exactly three restrictions on you: you may not offer
319
+ this software to third parties as a hosted or managed service, you may not circumvent license key
320
+ functionality, and you may not strip the copyright notices. Running it, modifying it, forking it,
321
+ and deploying it across your engineering organisation are all expressly permitted.
322
+
323
+ Note that ELv2 is source-available rather than OSI-approved open source. If your organisation
324
+ screens dependencies by license, it may need to be allowlisted.
package/bin/cli.js ADDED
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ // Locates the gerrit-cli binary for the current platform and hands control to
3
+ // it.
4
+ //
5
+ // stdio is inherited, so the binary's own discipline applies unchanged:
6
+ // rendered output on stdout, everything else on stderr. Anything this wrapper
7
+ // has to say is a diagnostic, so it goes to stderr.
8
+
9
+ import { spawnSync } from "node:child_process";
10
+ import { createRequire } from "node:module";
11
+
12
+ const require = createRequire(import.meta.url);
13
+
14
+ // Kept in sync with scripts/platforms.mjs. It is duplicated rather than
15
+ // imported because this file ships on its own inside the published package.
16
+ //
17
+ // The packages are named after the server, not after this CLI: one platform
18
+ // package carries both binaries, so there is no @gyeonghokim/gerrit-cli-linux-x64
19
+ // and there should not be one.
20
+ const PACKAGES = {
21
+ "linux-x64": "@gyeonghokim/gerrit-mcp-server-linux-x64",
22
+ "linux-arm64": "@gyeonghokim/gerrit-mcp-server-linux-arm64",
23
+ "darwin-x64": "@gyeonghokim/gerrit-mcp-server-darwin-x64",
24
+ "darwin-arm64": "@gyeonghokim/gerrit-mcp-server-darwin-arm64",
25
+ "win32-x64": "@gyeonghokim/gerrit-mcp-server-win32-x64",
26
+ };
27
+
28
+ function fail(message) {
29
+ process.stderr.write(`gerrit-cli: ${message}\n`);
30
+ process.exit(1);
31
+ }
32
+
33
+ const target = `${process.platform}-${process.arch}`;
34
+ const packageName = PACKAGES[target];
35
+
36
+ if (packageName === undefined) {
37
+ fail(
38
+ `unsupported platform ${target}. ` +
39
+ `Supported platforms are ${Object.keys(PACKAGES).join(", ")}. ` +
40
+ `Build from source instead: go install github.com/GyeongHoKim/gerrit-mcp-server/cmd/gerrit-cli@latest`,
41
+ );
42
+ }
43
+
44
+ const binary = process.platform === "win32" ? "gerrit-cli.exe" : "gerrit-cli";
45
+
46
+ let executable;
47
+ try {
48
+ executable = require.resolve(`${packageName}/bin/${binary}`);
49
+ } catch {
50
+ fail(
51
+ `the ${packageName} package is not installed. ` +
52
+ `It is an optional dependency, so this usually means the install ran with ` +
53
+ `--no-optional, --omit=optional, or with a lockfile from another platform. ` +
54
+ `Reinstall with optional dependencies enabled.`,
55
+ );
56
+ }
57
+
58
+ const result = spawnSync(executable, process.argv.slice(2), { stdio: "inherit" });
59
+
60
+ if (result.error !== undefined) {
61
+ fail(`could not start ${executable}: ${result.error.message}`);
62
+ }
63
+
64
+ process.exit(result.status ?? 1);
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@gyeonghokim/gerrit-cli",
3
+ "version": "0.0.1",
4
+ "description": "Command-line client for Gerrit code review, and the binary behind the gerrit-cli agent skill.",
5
+ "license": "Elastic-2.0",
6
+ "author": "GyeongHoKim",
7
+ "type": "module",
8
+ "bin": {
9
+ "gerrit-cli": "bin/cli.js"
10
+ },
11
+ "files": [
12
+ "bin/",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "keywords": [
17
+ "gerrit",
18
+ "cli",
19
+ "code-review",
20
+ "agent",
21
+ "skill",
22
+ "ai",
23
+ "llm"
24
+ ],
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/GyeongHoKim/gerrit-mcp-server.git"
28
+ },
29
+ "homepage": "https://github.com/GyeongHoKim/gerrit-mcp-server#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/GyeongHoKim/gerrit-mcp-server/issues"
32
+ },
33
+ "engines": {
34
+ "node": ">=18"
35
+ },
36
+ "optionalDependencies": {
37
+ "@gyeonghokim/gerrit-mcp-server-linux-x64": "0.0.1",
38
+ "@gyeonghokim/gerrit-mcp-server-linux-arm64": "0.0.1",
39
+ "@gyeonghokim/gerrit-mcp-server-darwin-x64": "0.0.1",
40
+ "@gyeonghokim/gerrit-mcp-server-darwin-arm64": "0.0.1",
41
+ "@gyeonghokim/gerrit-mcp-server-win32-x64": "0.0.1"
42
+ }
43
+ }