Skip to content

About

Public MIT source for the mergestorm npm CLI (mg). Build from source or npm install -g mergestorm.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

59 Commits

Folders and files

Repository files navigation

Mergestorm CLI

Review a local git diff with Mergestorm without opening a GitHub PR — for local loops and CI. Diffs are reviewed by the same engine as PR reviews and each review consumes one standard credit.

Requires Node.js 22+.

Install

Recommended — install from npm (same package the one-liner uses):

npm install -g mergestorm
mergestorm --version   # confirm install
mergestorm login
# or the short alias (same binary):
mg login

Optional curl installer (checks Node 22+, then runs npm install -g mergestorm):

curl -fsSL https://mergestorm.ai/install.sh | bash
mergestorm login

After install, both mergestorm and mg invoke the same CLI.

Source

This repository is the public source for the mergestorm npm package (MIT). Tags match npm versions (v0.3.71, …).

git clone https://github.com/marginsystems/mergestorm-cli.git
cd mergestorm-cli
npm install
npm run build
node dist/cli.js --help
# optional local global link:
npm link
mergestorm

Development without a build step: npm run dev.

Interactive shell

On a TTY, bare mergestorm (or mergestorm shell) opens a branded REPL: a compact full-width welcome panel (mark, version, status, usage bar) and a full-width bordered input box with a live / slash-command dropdown. The welcome panel reflows on terminal resize instead of wrapping or smearing. Non-TTY (CI/pipes) prints usage instead — no hanging prompt.

╭──────────────────────────────────────────────────────────────────────────────╮
│  ▀▀▀▀▀▀▀▀▀▀▘  mergestorm v0.3.71                                             │
│ ▀▀▀▀▀▀▀▀▀     ● msk_live_… · maelstrom                                       │
│  ▀▀▀▀▀▀       [████████░░░░░░░░░░░░░░░░░░░░░░] 25% used                      │
│   ▝▀▀▀▀▀      local reviews + stacked PRs · mergestorm.ai                    │
│     ▝▀▀▘      review a diff · usage for tabs · /help for all commands        │
│       ▀       New in v0.3.71: Watch: throttled heads wake you at once        │
╰──────────────────────────────────────────────────────────────────────────────╯
mergestorm
╭──────────────────────────────────────────────────────────────────────────────╮
│ › /re                                                                        │
╰──────────────────────────────────────────────────────────────────────────────╯
  /review       Review git diff (default origin/HEAD or main or master)

mergestorm> usage
mergestorm> branches
mergestorm> chain
mergestorm> exit

Bare command names still work exactly as before (review, help, exit, …) — typing / at the start of a line opens a compact autocomplete overlay (aliases folded onto the primary name, Up/Down scroll a viewport, Esc dismisses, Tab completes, Enter accepts a prefix or submits an exact name as typed, Left/Right move the cursor). Arrow-key history, Ctrl+A/E, Ctrl+U/K work as in a regular shell. At the idle prompt, Ctrl+C twice (within ~1.5s) exits the shell; a single Ctrl+C clears the line and shows a confirm hint. While review / status is waiting, Ctrl+C detaches or aborts that wait (job may keep running) — it does not exit the shell. Ctrl+D on an empty line, or exit / quit, also leave the shell. On a dumb terminal, without color, or when piped, the box falls back to plain ASCII borders (or no shell at all for non-TTY input).

credits / usage on a TTY open a tabbed Status / Usage / Jobs browser (Usage selected): Left/Right switch tabs, Up/Down scroll or select, Enter on a job opens its status detail in place, Esc backs out, q closes. status with no job id opens the same browser on the Status tab. Piped / non-TTY output keeps the static panel: key · plan, a credit bar sized to the terminal, Resets … (UTC), then the last five jobs; --json adds recent_jobs and is unchanged. branches (alias chains) lists recently reviewed branches; on a TTY you arrow-select one to open its review-chain timeline. chain [slug] shows that timeline directly (defaults to local/<current-git-branch>).

Commands

One-shot subcommands work the same inside the shell and from argv (scripts/CI):

mergestorm                      Interactive shell (TTY only)
mergestorm shell                Explicit shell entry
mergestorm login                Sign in via browser and add the account (up to 3 saved)
mergestorm login --start        Print a sign-in URL and code, then exit (agents)
mergestorm login --finish       Store the API key once the code from --start is approved
mergestorm login --key          Paste an existing API key instead (headless/CI)
mergestorm logout               Log out of the active account (or --account <name>) and revoke its key
mergestorm account list [--json]  Saved accounts (up to 3), the active one marked
mergestorm account use <name>   Make <name> the active account
mergestorm account remove <name>  Log out of <name> and revoke its key
mergestorm review [base] [head] Review git diff base...head (default: origin/HEAD or main or master)
mergestorm status <job_id>      Fetch a review job (envelope; --json --wait --timeout)
mergestorm status               Tabbed Status / Usage / Jobs browser (TTY)
mergestorm credits [--json]     Usage panel (bar + last 5 jobs); tabbed browser on a TTY
mergestorm jobs [n] [--json]    Recent review jobs (default 10, max 50)
mergestorm branches [n]         Recently reviewed branches (arrow-pick on TTY)
mergestorm chain [slug]         Branch review-chain timeline (default: current branch)
mergestorm whoami [--json]      Active account, key prefix, plan, API base, config path
mergestorm skill install --claude|--cursor|--agents  Copy the Mergestorm skills into this repo
mergestorm thread <slug>        Jobs in a review thread
mergestorm issue create --title <t>  Open a GitHub issue through Mergestorm, no `gh` (`--body`, `--body-file`, `--label`, `--repo`, `--wait`)
mergestorm issue wait <n>       Wait for the next Vortex verdict; exits 0 once approved, 4 with points, 8 stalled (`--after-round R`)
mergestorm issue watch <n>      Background issue wait: silent, then one MS-ISSUE READY / POINTS / STALLED line
mergestorm stack create [name]  New local stack layer (optional `--onto` / `--trunk` / `--extend`)
mergestorm stack submit         Push layers, open PRs (`gh`), register via adopt (optional `--extend`, `--server-side`)
mergestorm stack publish        Publish the current branch through Mergestorm with no GitHub credentials (`--base <branch> --extend` to stack, `--status` to read it)
mergestorm stack list [--json]  List registered stacks
mergestorm stack adopt <owner/repo>#<pr>  Import an existing open PR chain
mergestorm stack restack <stack-id>  Restack descendants
mergestorm stack land <stack-id>     Land / promote (into review unit when present)
mergestorm stack wait <stack-id> [--timeout <s>]  Wait for stack attention (default 45s, max 300s; 0 = one snapshot, no wait)
mergestorm stack watch <stack-id> [--until attention|landed] [--ignore <text>] [--max <min>] [--head <sha>] [--json]  Background stack watcher (see below)
mergestorm stack reset --force  Clear local authoring state (not branches/PRs)
mergestorm dismiss <owner/repo>#<n> --head <sha> --review <id> --preview   List a Vortex review's finding ids and the seam gate
mergestorm dismiss <owner/repo>#<n> --head <sha> --review <id> --finding <id> --reason <text>  Dismiss verified-wrong findings (`--all` for the whole review, `--evidence <url>`, `--json`)

Watching a stack in the background

mg stack watch <stack-id> is for agents that cannot hold a long turn open. Run it as a background command only after confirming that your host can resume the task on completion or output matching MS-WATCH (ATTENTION|LANDED). The process monitors the stack; it does not itself resume a Codex, Claude Code, or Cursor conversation. Without a notification mechanism, keep using bounded stack_wait calls or explicitly report that automatic follow-up is unavailable. While it waits it spends no model tokens and talks only to the Mergestorm API, not GitHub.

  • It calls stack wait in slices of at most 300s and carries the cursor (enrolled_head_sha, after_finished_at, bounce_id) from one slice to the next.
  • It prints nothing while the stack is waiting or in_progress, including while Cyclone or Vortex holds the blocked PR (busy[], actAfter: "agents_idle").
  • On attention it prints MS-WATCH ATTENTION pr=<n> head=<sha> blocker="<blocker>" repair=<kind> and exits 3. Attention names the lowest layer with a blocker an agent must fix, on any layer of the stack, not only the current candidate.
  • A confirmed landing prints MS-WATCH LANDED stack=<id> reason=landed and exits 0. closed, archived and not_found end the watch with MS-WATCH ATTENTION stack=<id> reason=<reason> and exit 3. A missing stack does not prove a landing; verify each PR before reporting it merged.
  • A permanent read error is retried once; if the retry fails too, it prints MS-WATCH ATTENTION failed stack=<id> error="<message>" and exits 3. Timeouts, 5xx and rate limits are retried, but after 15 minutes with no stack read it prints the same line and exits 3.
  • A watch that cannot start (bad flags, a config it cannot read, a crash) prints MS-WATCH ATTENTION failed too, so the command never exits without an MS-WATCH line unless you stop it (Ctrl+C or an abort, exit 130). Pass each flag as its own word: in zsh an unquoted $args holding several flags stays one word and the command refuses it.
  • --head <sha> enrolls the SHA you just pushed. After fixing a blocker, restart the watcher with it.
  • --ignore <text> keeps it silent on the first attention whose blocker contains that text (case-insensitive), until the blocker, its PR or its head changes. Use it for a blocker a human has taken over. Repeat the flag for more than one.
  • --until landed keeps running after an attention, printing each new attention once, and exits only when the watch is done or reads keep failing.
  • --max <minutes> caps the whole watch; when it runs out it prints MS-WATCH TIMEOUT and exits 5. The stack is not landed then.
  • --json writes exactly one JSON document to stdout: the final mergestorm.stack_watch/v1 envelope, or { stackId, outcome } when there is none (a repeated failed read, --max timeout, or abort). The MS-WATCH marker lines go to stderr, so do not merge the streams (2>&1) before parsing stdout.
mg stack watch 11111111-1111-4111-8111-111111111111 --head "$(git rev-parse HEAD)"

Dismissing a finding

Use mergestorm dismiss when a Vortex finding is wrong and you have checked it against the code. It is recorded server side with your GitHub login, the reason, the evidence URL, the scope and the time. Rules:

  • You need write access to the repository on GitHub, and the repository must be monitored by your Mergestorm account or the PR must be in one of your stacks.
  • --head must be the PR's live head and --review a Vortex review made at that head. A moved head, another review, or a finding id that is not in that review is refused, and nothing is written.
  • Retrying the same dismissal is safe; it reports the earlier record.
  • The seam gate clears only when every finding of that integration review is dismissed and the review is still the current seam verdict.
  • The Vortex gate at the head clears once every Vortex Blocker (error finding) at the live head is dismissed (every Core review merged into that head, not only the one named), and no Vortex review of the head is still running or incomplete: that head reads as approved for Auto land, the stack watch, the dashboard and Cyclone. A partial dismissal clears nothing. CI and Auto land policy still apply.
  • Vortex does not raise a dismissed finding again on the same diff (the same head, or a restack with an unchanged diff).
  • With --json, the result carries gate and, for a stack PR, watch.next (the next stack_wait call, plus watch.next.background, the mg stack watch command to run in the background instead).

mg is a short alias for mergestorm (same binary), e.g. mg stack create. Happy path: create → commit → submit → restack → land. On review-unit stacks, stack land promotes the tip into the unit (same gates as the dashboard); otherwise it lands the bottom open PR. stack adopt is for importing a chain that already exists on GitHub (legacy / Graphite). Restack/land use the same login key (/api/v1/stacks). Unattended landing is mg queue add.

stack create always starts a new single PR from trunk unless you pass --extend, even when the worktree is still on an earlier PR's branch: it checks out the new branch from origin/<trunk> (or local trunk; from HEAD when trunk is checked out). It discovers trunk (main / master / origin/HEAD, overridable with --trunk) and records { branch, parentBranch } in CLI-managed state under ~/.mergestorm/stacks/<repo-id>/stack.json. The CLI updates this automatically; never edit it. Each worktree has its own authoring state; independent clones stay isolated too. Creating onto trunk with a non-empty active stack starts a new one.

Both paths are one command:

  • New stack from trunk: mg stack create <name> (from any branch), then mg stack submit.
  • Grow a stack: mg stack create <name> --extend on the branch to stack onto (or --onto <branch> --extend), then mg stack submit --extend when the parent is a layer of a registered stack. mg stack publish --base <branch> --extend does the same for publish.

--onto or --base with a branch other than trunk and no --extend is refused, so nothing is added to a stack by accident. Every create, submit and publish prints which one it made: a new single PR onto trunk, or a layer stacked on its parent.

stack submit walks the active local stack: git push -u origin each layer, opens a PR with gh (--base = parent or trunk; adopt then moves the bottom of a 2+ PR stack onto mg-stack-<n> — leave it there; skips heads that already have an open PR; body from the tip commit — its body under Summary as written, with hard-wrapped lines of a paragraph joined and Markdown unchanged, the subject only when the body is empty, Co-Authored-By: and Signed-off-by: dropped, then a Test plan stub unless the body has its own Test plan heading, and each Fixes/Closes/Resolves once), registers the stack with POST /api/v1/stacks/adopt internally (Mergestorm API key), then drops that local stack entry so the next create onto trunk is clean. Push is always your local git credentials. PRs open as you when gh is installed and gh api user succeeds; otherwise stack submit asks the Mergestorm API (POST /api/v1/stacks/pulls) to open them as the Mergestorm Surge App on your behalf, after checking your GitHub account has write access, and assigns you. Stacks, the merge queue and Auto land run through Surge, and Cyclone is the auto-patch App. Without Surge, submit stops before pushing and prints the server's message, which names the App to install and links its install page. mg settings prints a Stacks, merge queue, Auto land line when the server reports whether that App is ready.

Publishing without GitHub credentials

mg stack submit --server-side and mg stack publish are for a machine that can reach Mergestorm but cannot authenticate to GitHub, such as a cloud coding sandbox. They never run gh, git push or git fetch. mg reads your commits from the local repository and sends them to Mergestorm with your API key; Mergestorm writes those exact commits and the branch on GitHub as the Surge App, opens a ready pull request, and registers the stack. Surge must be installed on the repository and your linked GitHub account needs write access to it.

The stack is registered with Auto land on for a new stack (--auto-land off to keep it off). Auto patch and Auto review follow the stack, repository and account settings like any other stack; --auto-patch and --auto-review pin them on the stack after it is registered. Send later commits with mg stack publish.

mg issue create --title "The thing is broken" --body-file issue.md --label bug --json   # no gh
mg stack create my-fix --onto main      # local only
git commit -am "Fix the thing"
mg stack submit --server-side --json    # branch, PR and stack, no gh and no push
git commit -am "Address a finding"
mg stack publish --json                 # appends the new commit to the published branch
mg stack publish --status               # absent | pushed | opened | registered
  • Issues too. mg issue create opens the issue a PR needs through the same Surge App, with existing labels only. Running it again with the same title returns the issue it already opened. Put Fixes #<n> in the commit message; stack submit carries it into the PR body.
  • Issue reviews first. On a repository with Vortex issue reviews on, Vortex reviews each new issue before any PR. mg issue wait <n> (or mg issue create --wait) waits for that review: it exits 0 once the issue is approved, or exits 4 with the numbered points to answer. Reply once in a comment on the issue, accepting each blocking point's suggested fix or saying why not, then run the printed mg issue wait <n> --after-round <r> once: it never hands back the verdict you already saw, and exits 8 with MS-ISSUE STALLED … reason=… if no round starts within 10 minutes. An issue with no review at all stalls after 2 minutes with reason=no_review_started: tag @mergestorm-vortex once in a comment on the issue to start one, then wait once more. mg issue watch <n> is the same wait as a silent background command, like mg stack watch. Never poll GitHub with gh or sleep loops while you wait. Vortex re-checks only the blocking points, once, and approves the issue. Notes never block; the PR review checks them against the code. A person can approve early with an issue comment whose first line is mergestorm-issue: approve. stack submit refuses to open a PR whose tip commit links an issue that is not approved yet, or links no issue at all while issue reviews are on.
  • Exact contents. Every commit travels with its Git tree SHA and the whole content of each changed file, so binaries, deletions, renames, executable bits and symlinks arrive unchanged. Mergestorm moves the branch only when GitHub builds the same tree, and mg checks the returned tree against your local branch.
  • Never overwrites surprises. mg looks at the branch on GitHub first. If its files match one of your local commits, only the commits after that one are appended. If they match none (someone else pushed, or you rebased), mg stops with head_changed; --replace-head <sha> replaces exactly that head and nothing else. Mergestorm refuses main, master, the default branch, protected branches and its own mg-stack-*, mg-park-* and mq-batch-* branches.
  • Safe to run again. After a timeout or an error, run the same command again. It finds the branch, pull request and stack it already made and finishes the missing step; it does not create duplicates.
  • Read-only home directory. mg keeps the saved login and the local stack state of stack create / stack submit under ~/.mergestorm. Where the home directory cannot be written, set MERGESTORM_HOME to a writable directory (outside the repository) and every command uses that instead. MERGESTORM_API_KEY supplies the key without mg login.
  • Several accounts. mg login keeps up to three accounts signed in; mg account use <name> picks the active one, and --account <name> or MERGESTORM_ACCOUNT runs one command as another.
  • Limits. 20 commits, 500 changed paths, 2 MiB a file and 8 MiB in total per publication. Submodules and merge commits are refused with the path or the reason. stack submit --server-side publishes the first two layers of a stack; a third layer needs a park freeze, which this mode does not create, so add it once the first two are registered.

If local authoring state is stale or malformed, use mg stack reset --force; this clears only pre-submit CLI state and never deletes branches, PRs, or registered stacks.

login

Runs a browser device-authorization flow: prints a short code, opens https://mergestorm.ai/cli/auth, and — once you approve — mints an API key and saves it as an account in ~/.mergestorm/config.json (mode 600), or in $MERGESTORM_HOME/config.json when MERGESTORM_HOME is set. No key copy/paste needed. The account is named by its GitHub login (or its email when there is no GitHub login), as mg whoami reports it, and becomes the active account.

Up to three accounts can stay logged in at once. mg login again adds another account, or replaces the key of an account that is already saved. A fourth login is refused with the three names; remove one first. A login saved by an older mg migrates on first read into an account named by its key prefix (msk_live_abcd), and takes its real name the next time a command such as mg whoami reaches the API. The file also keeps the active account's key at its top level, so an older mg or mergestorm-mcp on the same machine keeps signing in as the active account.

For headless or CI environments, use mergestorm login --key to paste an existing msk_live_… key (create one on the dashboard Settings → API). On a TTY the paste is hidden (not echoed); the CLI verifies the key with the API before saving.

For an agent, which cannot sit in a prompt while a person signs in, use two steps. mergestorm login --start prints the URL and the short code and exits. Give both to the account owner, who opens mergestorm.ai/cli/auth on any device, signs in, and approves the code. Then mergestorm login --finish stores the API key. The code lasts 10 minutes, and --finish can be run again if it is interrupted before the approval.

account

mg account list            # saved accounts, the active one marked ● (--json for machines)
mg account use work        # make "work" the active account for every later command
mg account remove work     # log "work" out: revoke its API key and drop it

Every command runs as the active account. To run one command as another saved account without switching, pass --account <name> anywhere on the command line (mg --account work stack submit, mg whoami --account work), or set MERGESTORM_ACCOUNT=<name>; the flag wins over the variable, and both win over the active account. An unknown name stops the command and lists the saved accounts. MERGESTORM_API_KEY still overrides every saved account. The mergestorm-mcp server reads the same store, so MERGESTORM_ACCOUNT in its environment picks the account it serves.

logout

Logs out of the active account (or the one named with --account): revokes that API key on the server when it can, then drops the account from the store. The next saved account, if any, becomes active. mg account remove <name> does the same for a named account.

review [base] [head]

Collects git diff base...head (default: discovered trunk — origin/HEAD, main, or master), attaches the changed file contents (up to 40 files, skipping files > 400 KB), submits the job, and polls until it finishes (~8 min max — Core plus a Max fleet can exceed 3 minutes). The thread slug defaults to the current branch (local/<branch>); pass --thread to override so follow-ups chain on a chosen slug. The CLI still does not scan a repo folder for review context. GitHub Vortex will read house-rule files in a later PR (AGENTS.md, CLAUDE.md, alwaysApply Cursor rules). That ingest is not shipping yet.

mergestorm review              # discovered trunk (origin/HEAD, main, or master)...HEAD
mergestorm review develop      # develop...HEAD
mergestorm review main feat/x  # main...feat/x
mergestorm review main --router max
mergestorm review main --router manual --specialists security,frontend
mergestorm review --json --context "focus on auth" --context-file docs/adr/007.md

--router is the same smart-router mode as Agents settings (off / standard / max / manual). --specialists pins or invokes lanes on that request (comma-separated). Omit both to use the signed-in user's saved fleet settings (paid default is Standard, same as the dashboard). Manual accepts up to 5 lane ids — the same cap as Agents (the smart router caps standard at 3 and max at 5).

--context is author guidance (or --context - to read stdin). --context-file is repeatable up to 10 files (16 KB each, 60 KB total). --idempotency-key replays a prior 202 for the same key. --webhook-url must be https; the one-time webhook_secret is printed only in --json output. Webhook delivery is best-effort (no retry).

Exit codes for review and status:

Exit Meaning
0 Success (completed or no_changes)
2 Usage / bad flags
3 Quota (402 or quota_exceeded)
4 Failed job or other submission error
5 Poll / request timeout
6 Auth (missing or invalid API key)
7 Rate limited (429) — wait retry_after_seconds, or check a running review with mergestorm jobs / status

In the interactive shell, Ctrl+C during the wait detaches (job keeps running) — use status <job_id> later.

status <job_id>

Fetches a job by id. One-shot default (and --json in either mode) prints the same mergestorm.review_job/v1 object as review --json. --wait [--timeout seconds] polls until the job finishes; timeout is exit 5 with the id in the object. In the shell, default output is pretty (requested vs run specialists and credits).

credits / jobs / whoami

Require a logged-in key and API support for GET /api/v1/me and GET /api/v1/reviews. Older API deployments degrade gracefully (banner shows local key only).

branches / chain

branches calls GET /api/v1/threads for recently active review threads (branches). On a TTY it opens an arrow-key selector; Enter loads that thread's job timeline. chain [slug] is the direct timeline view — omit the slug to use local/<current-git-branch> (same slug review stamps).

Environment

Variable Purpose Default
MERGESTORM_API_KEY API key (overrides every saved account) —
MERGESTORM_ACCOUNT Saved account to run as; --account <name> on a command wins over it the active account
MERGESTORM_API_URL API base URL https://api.mergestorm.ai
MERGESTORM_HOME Directory for the saved login and local stack state, for machines whose home directory is read-only ~/.mergestorm
NO_COLOR Disable ANSI colors —

Verify (public source vs npm)

Build only from marginsystems/mergestorm-cli. Tags there (vX.Y.Z) match npm versions. Compare your local pack to the registry hashes below (or npm view mergestorm@VERSION dist).

npm Public git tag Public commit npm dist.shasum (sha1) npm dist.integrity
0.3.9 v0.3.9 89eaebc29cf793db52baf3e9af0f2bed6e42e458 f904f4f642a07c0f9716fe36ed9e5a813be47530 sha512-zkbEhwkog13xC70LcM77bWFzLTyoE7Q81daaxz/1Gk3IqVyEoyhKpR+PAtfTp+Mk3MqJ7yVhvZ8/9UG4hpT/Dw==
git clone https://github.com/marginsystems/mergestorm-cli.git
cd mergestorm-cli
git checkout v0.3.9
git rev-parse HEAD   # expect 89eaebc29cf793db52baf3e9af0f2bed6e42e458
npm ci
npm run build
npm pack
shasum -a 1 mergestorm-0.3.9.tgz
# expect f904f4f642a07c0f9716fe36ed9e5a813be47530
# also: npm view mergestorm@0.3.9 dist.shasum dist.integrity

After each release, the new row’s git commit is the public v* tag tip; shasum/integrity come from the npm registry for that version.

See also

About

Public MIT source for the mergestorm npm CLI (mg). Build from source or npm install -g mergestorm.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages