Metadata-Version: 2.4
Name: meridian-governance-cli
Version: 0.19.19
Summary: Command-line client for Meridian Governance Router — not the unrelated 'meridian-cli' package also on PyPI
License-Expression: MIT
Project-URL: Homepage, https://github.com/knjpollard/meridian-cli
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: meridian-client>=0.9.1
Requires-Dist: requests>=2.28.0
Requires-Dist: prompt_toolkit>=3.0.36
Provides-Extra: bedrock
Requires-Dist: boto3>=1.35.0; extra == "bedrock"
Requires-Dist: langchain-core>=1.2.0; extra == "bedrock"
Requires-Dist: langchain-aws>=1.0.0; extra == "bedrock"
Provides-Extra: anthropic
Requires-Dist: langchain-core>=1.2.0; extra == "anthropic"
Requires-Dist: langchain-anthropic>=1.0.0; extra == "anthropic"
Provides-Extra: mcp
Requires-Dist: mcp>=1.2; python_version >= "3.10" and extra == "mcp"
Dynamic: license-file

# meridian-governance-cli

Scriptable command-line client for [Meridian Governance Router](https://ai-server-01.knjhome.org:8444/), over [`meridian-client`](https://pypi.org/project/meridian-client/). Installs as the `meridian` command — one short command, same shape as `mta` or `claude`.

The PyPI package is `meridian-governance-cli`; the command it installs is `meridian`. Not to be confused with the unrelated `meridian-cli` package also on PyPI.

## Getting started

```bash
pipx install meridian-governance-cli
meridian
```

Run `meridian` on its own at a terminal. If you have no account it asks for an organization name, email and
password; if your account has no model it can use, it offers to look for a local Ollama or vLLM server, registers it
at an address the server can reach, tests it, and opens the chat. If you are already set up it opens the chat
straight away. In a script (no terminal) a bare `meridian` still prints the usage. Everything it does is also
available as separate commands: `meridian signup`, `meridian hubs discover`, `meridian chat`.

Closer in spirit to the `aws` or `stripe` CLIs than to an app's own CLI:
subcommands over an API, scriptable, mostly no interactive loop required —
with one exception. `chat` absorbed
[Local-AI](https://github.com/knjpollard/Local-AI)'s reference
implementation upstream (`meridian-agent-v1.0.py`, decided 2026-10-18) so
customers get one governed resolve -> dispatch -> audit loop from Meridian
itself, interactively or scripted, rather than writing that sequence
themselves against the SDK.

## Install

```bash
curl -fsSL https://ai-server-01.knjhome.org:8444/install.sh | bash
```

On Windows, in PowerShell (it installs `uv` for you if you have neither it nor `pipx`):

```powershell
irm https://ai-server-01.knjhome.org:8444/install.ps1 | iex
```

Open a new PowerShell window afterwards if `meridian` is not found; the installer also puts it on
this window's PATH where it can. To remove it: `uv tool uninstall meridian-governance-cli`.

The installer asks the Meridian server which client version it ships and installs
exactly that, **from the server** (it builds the client from the same commit as
itself and serves it at `/dist/`), so the client always matches the server and
nothing depends on a PyPI upload. It uses `uv` (or `pipx` if that's what you
have, installing `uv` if you have neither) and upgrades an existing install in
place. It then checks that the `meridian` which actually runs is the one it
just installed, and exits with an error naming every copy if an older one
earlier on your PATH is shadowing it.

`MERIDIAN_URL=https://your-host bash install.sh` installs from a different
Meridian server. `meridian --version` shows what is installed.

By hand, the same thing:

```bash
pipx install --pip-args="--find-links https://ai-server-01.knjhome.org:8444/dist/" meridian-governance-cli
# or: uv tool install --find-links https://ai-server-01.knjhome.org:8444/dist/ meridian-governance-cli
```

Remove it with `uv tool uninstall meridian-governance-cli` (or `pipx uninstall`),
or run the uninstaller, which also offers to revoke your API key on the server
and to delete `~/.meridian` (saved credentials, chat logs), asking before each:

```bash
curl -fsSL https://ai-server-01.knjhome.org:8444/uninstall.sh | bash
```

Writing code against Meridian instead of using the command? That's the SDK:
`pip install --find-links https://ai-server-01.knjhome.org:8444/dist/ meridian-client`
— see `SKILL.md` in the meridian-client repo.

## Get credentials

```bash
meridian signup          # new org — prompts for org name, email, password
# or
meridian login           # existing account — authenticates, mints a new key
meridian whoami           # confirm what's saved
```

Credentials live in `~/.meridian/config.json` (mode 600 — `api_key` is in
there in plaintext, same tradeoff `mta-cli` makes for its own token). Override
the location with `MERIDIAN_CLI_HOME` if you want more than one profile.

## Projects have a default agent

Selecting a project has to bring an agent with it. A client cannot guess which
agent a project means to be talked to, and keeping the previous name was a bug:
`/project 283` left `agent=concierge`, which project 283 does not have, and every
message after it failed. Now a project can name a default agent, and:

- `/project 283` switches to that project **and its default agent**;
  `/project 283 NAME` names one explicitly.
- `/agent` shows the agents in the project (default marked); `/agent NAME` switches.
- `meridian chat --project-id 283` with no `--agent` uses the project's default.
- With several agents and no default, the CLI says so and lists them instead of
  guessing; nothing is sent until you pick one.

A new project is created with one agent called `default`, already set as its
default (`meridian projects create --no-default-agent` skips it). Rename it to
whatever you like: the project's default is linked by id, so it follows. In the
console, the project's *Default agent* selector sets it and the agent editor
renames it.

Set it from the CLI with `meridian projects set-default-agent PROJECT_ID AGENT_NAME`,
or by `default_agent_id` on `PUT /projects/{id}`. Projects that already had
exactly one agent were backfilled; projects with several were left unset on
purpose, and a project made with `--no-default-agent` makes its first agent the
default.

Renaming changes the address callers use: anything that resolves the agent by
its old name (scripts, MTA, `meridian chat --agent`) must be updated, and will
be told the agent is not in the project until it is. Pending change requests
follow the rename; history keeps the name that was current at the time, and each
rename is recorded.

## Who calls the model

By default **Meridian calls the model for you.** `meridian chat` sends the conversation to
Meridian (`POST /api/v1/invoke`), which resolves the agent's route, calls the model, streams
the answer back and records the usage. There is nothing to set up on your machine: no
provider keys, no cloud credentials, no extras. Models in the hosted catalogue (served
through OpenRouter) work out of the box. Running your own Azure, AWS Bedrock or on-premises
hubs through Meridian is set up with us (talk to us).

`--dispatch` (or `MERIDIAN_CHAT_DISPATCH`) chooses who makes the call:

| mode | behaviour |
|---|---|
| `auto` (default) | Meridian calls the model. If Meridian cannot run that route for you, this machine tries with credentials you have set locally. |
| `server` | Meridian only. Never falls back; says so if it cannot. |
| `local` | Meridian only decides; this machine calls the hub with keys from its own environment. |

`--tools meridian` calls the model from this machine for now.

If a call has to be made from this machine (`local`, or the `auto` fallback) it needs what
that hub needs: Bedrock needs AWS credentials and the `bedrock` extra, Anthropic needs
`ANTHROPIC_API_KEY`, and a hub with an `auth_key_env` needs that variable set. In that case
`meridian chat` works out what it can reach and tells Meridian, which leaves the others out
when scoring and records why (`unreachable_from_client`). This only narrows: it never
overrides policy. If nothing is reachable the error says what was excluded and why. A
**pinned** agent cannot be rerouted, so if neither Meridian nor this machine can call its
hub, the error says so.

## Calling Meridian from another program

If you are writing a program that needs Meridian (MTA's CLI is one), do not import
the SDK into it and do not hunt for an interpreter. Run the installed command and
read JSON. It needs only that `meridian` is on PATH, so it behaves the same on
Linux, macOS and Windows, and no directory layout or `sys.path` can shadow it.
(Importing the SDK broke exactly that way: a directory called `meridian/` earlier
on the path won over the SDK, because the Meridian server package shares the name.)

```bash
meridian api search "update agent"               # find the operation
meridian api describe put_projects_project_id_agents_agent_name   # parameters, body, risk, gotchas
meridian call get_projects_project_id_agents -p project_id=283
meridian call put_projects_project_id_agents_agent_name -p project_id=283 -p agent_name=default \
        -d '{"agent_name": "concierge"}'
meridian call post_projects -d @new-project.json
echo '{"display_name": "x"}' | meridian call put_projects_project_id -p project_id=283 -d -
meridian ping                                     # reachable? which build? (needs no login)
```

**The contract**

| | |
|---|---|
| stdout | exactly one JSON document, always, failures included |
| stderr | human text, only when the exit code is non-zero |
| exit 0 | success (`call`: the server answered HTTP < 400) |
| exit 1 | the server said no (HTTP >= 400). stdout still holds the response; `body.detail` is the reason |
| exit 2 | bad arguments, **nothing was sent**: unknown operation (with a suggestion), a missing path or query value, a body that is not JSON, a write under `--mode read` |
| exit 3 | setup or network: not logged in, key rejected, server unreachable |

`call` prints `{"operation", "ok", "status", "body", "truncated"}`; `body` is the
parsed response and is never truncated. Branch on the exit code, then read the JSON.

- **Operation ids** come from method + path (`PUT /api/v1/projects/{project_id}` is
  `put_projects_project_id`), so they change only when a route does. `meridian api
  describe` shows the server's real parameters, so a program can check what it is
  about to send. Each operation has a `risk` of `read`, `write` or `destructive`.
- **Credentials** are the saved login, or `MERIDIAN_API_KEY` and `MERIDIAN_BASE_URL`
  in the environment (`MERIDIAN_CLI_HOME` relocates the config).
- **Writes take effect immediately.** `--mode read` (or `MERIDIAN_TOOLS_MODE=read`)
  refuses them with exit 2 before anything is sent.
- **Version gate:** `meridian --version` prints `meridian-governance-cli X.Y.Z (...)`.
  `call`, `api` and `ping` exist from 0.17.0; on an older install they are an
  "invalid choice" error (argparse exit 2), so treat that as "not available".
- Values given with `-p` and `-q` are strings; the server converts them. A path value
  is escaped into its own segment, so `../x` cannot reach another route.

## Let an agent run Meridian

An agent can manage Meridian for you in plain language, and learn its API as it
goes. **`meridian chat` starts with these tools on** (when you have a key), and
the agent is told it has them, so "what projects do I have?" is looked up, not
answered with a guess. It gets four API tools, not ninety: `meridian_whoami`,
`meridian_api_search` (find an operation by what you want to do),
`meridian_api_describe` (schema, risk, and verified gotchas), and `meridian_call`;
plus three that keep it from guessing about Meridian itself: `meridian_version`
(what is installed, what the server offers, how to upgrade), `meridian_docs` (the
server's published docs) and `meridian_cli_help` (the real `--help`). The catalog behind them is
the server's own `GET /api/v1/tools`, built from its live OpenAPI, so the agent
learns the API it is actually talking to.

**In `meridian chat`** (this is how a concierge agent does your admin):

```bash
meridian chat --agent concierge --project-id 283      # tools are on by default
meridian chat --no-tools                              # or MERIDIAN_CHAT_TOOLS=off
meridian chat --tools-mode read                       # look, don't touch
meridian chat --delegate auto                         # may ask the worker agent on its own (default: only when you ask)
meridian chat --tools meridian ...                    # require them: an error if impossible
> move the concierge onto the on-prem hubs only
  → CALL put_projects_project_id_agents_agent_name [write]
    ← HTTP 200
```

**From Claude Code, Codex, or any MCP client:**

```bash
pipx inject meridian-governance-cli mcp        # MCP needs Python 3.10+
claude mcp add meridian -- meridian mcp
```

Things to know:

- **Tools need a model on a hub this machine can call directly.** Tool turns are
  dispatched from here, not through Meridian, so a hub that needs a credential
  you do not have is left out when Meridian picks the model (the decision records
  why). If nothing else is allowed, that turn runs through Meridian without tools,
  says `(tools off for this turn: ...)`, and the agent is told. Naming
  `--tools meridian` makes that an error instead.
- **Worker delegation is opt-in.** The assistant can hand a hard question (writing SDK code,
  explaining a routing decision) to the project's *worker agent* (`worker_agent_id`) with the
  `meridian_delegate` tool. The worker reasons over text only: no tools, no access to your Meridian,
  and API keys are refused before anything is sent. The call goes through Meridian, so it needs no
  key on this machine, and which model the worker is stays that agent's own configuration. The
  cheaper model is the default and delegation is the exception, so `--delegate` picks how readily
  it is used: `ask` (default) only when you ask it to, `auto` by its own judgment, `off` not
  offered. Also `MERIDIAN_CHAT_DELEGATE`, or `"chat_delegate"` in the config file (flag, then
  env, then config). A project with no worker agent says so instead of delegating.
- **Writes execute immediately** by default, as the signed-in user, and reach
  everything that routes through that Meridian. Every call is printed to stderr
  as it happens. `--tools-mode read` (or `meridian mcp --mode read`) allows GET
  only.
- **Reach is whatever the key allows.** A tenant key sees only the operations
  it can call. Org and model registration are not among them; that takes a
  house key, deliberately never offered to a tenant's agent.
- **The model must support tool calling.** A hub that rejects `tools` gives a
  clear error. Tool turns are not streamed.
- **`chat` now sends the agent's configured system prompt**, with or without
  `--tools`. Before, a persona set on an agent in Meridian had no effect in the
  CLI.
- Needs a Meridian that serves `/api/v1/tools`; an older one answers 404.

## Commands

```bash
meridian resolve my_agent [--project-id ID] [--json]
meridian explain ROUTING_LOG_ID
meridian audit ROUTING_LOG_ID --input-tokens N --output-tokens N

meridian projects create --name NAME [--quality Q] [--cost C] [--risk R]
meridian projects list

meridian agents create PROJECT_ID AGENT_NAME [--pinned-model M] [--quality-override Q] [--allowed-hubs h1,h2]
meridian agents list PROJECT_ID
meridian agents update PROJECT_ID AGENT_NAME [--pinned-model M] [--quality-override Q] [--enable|--disable]
                                              # --pinned-model "" clears the pin; M is a deployment key
                                              # from `meridian catalog` (its model_key field), not a model name

meridian hubs list
meridian hubs discover

meridian voice-hubs list                        # full admin shape - needs a tenant key
meridian voice-hubs available                   # safe-to-browser shape: has_credential, no endpoint/key fields
meridian voice-hubs create --name N --hub-type T [--endpoint-url U] [--auth-key-env NAME] [--region R]
meridian voice-hubs update HUB_ID [--name N] [--endpoint-url U] [--auth-key-env NAME] [--enable|--disable]
meridian voice-hubs delete HUB_ID

meridian voices list HUB_ID
meridian voices create HUB_ID --voice-key KEY --backend-voice-id ID [--display-name N] [--language L] [--gender G]
meridian voices update VOICE_ID [--display-name N] [--language L] [--enable|--disable]
meridian voices delete VOICE_ID

meridian projects voices PROJECT_ID             # every voice the project's org has, flagged available/reason

meridian synthesize PROJECT_ID --text "..." (--agent-id N | --voice-id ID) --out out.mp3
                                                 # --agent-id resolves through the agent's effective voice
                                                 # (agent default -> project default); --voice-id is the
                                                 # numeric llmr_voices.id from `meridian voices list` - a
                                                 # voice_key string is rejected (422), numeric only. No
                                                 # cross-engine failover - a down/disallowed hub is a clean
                                                 # error, never a substitution.

meridian keys list [--json]
meridian keys create [--name NAME]
meridian keys revoke KEY_ID

meridian catalog
meridian logout [--revoke]

meridian python-path     # print the interpreter this command runs under —
                          # has `meridian` importable even inside a pipx venv.
                          # For a host program that wants `from meridian import
                          # Meridian` directly instead of shelling out: run this
                          # once to find the right interpreter, don't parse the
                          # `meridian` executable's shebang to guess it.

meridian chat [--agent NAME] [--code-agent NAME] [--project-id ID] [--max-tokens N]
meridian chat --one-shot "message" [--json] [--max-tokens N]
meridian chat --daemon [--host HOST] [--port PORT] [--refresh-interval SECS]
```

Every data-returning command without a dedicated human-readable format
(`explain`, `audit`, `catalog`, `projects list`, `agents list`) prints raw
JSON — pipe into `jq`.

### `chat`

Per-turn flow with `--dispatch local` (and as the fallback): `resolve(agent)` -> catalog/hubs
join -> dispatch to the chosen hub -> `audit`. By default Meridian does all of that itself
(see *Who calls the model*). Routing, scoring and governance all live in
Meridian; `chat` just drives the loop. Dispatch is keyed on the hub's own
wire protocol (`hub_type`), not which company trained the model
(`provider`) — an Anthropic-family model served through OpenRouter or
Cheaper-Inference is genuinely OpenAI-compatible and dispatches that way.

Supported today: any OpenAI-compatible hub (on-prem vLLM/Ollama,
OpenRouter, Cheaper-Inference), AWS Bedrock, and direct Anthropic. Bedrock
and Anthropic need their own extras (`pip install
'meridian-governance-cli[bedrock]'` / `[anthropic]`) — langchain-aws/
langchain-anthropic, the same libraries MTA's own production gateway uses.
Bedrock uses boto3's default credential chain; Anthropic reads
`ANTHROPIC_API_KEY` from the environment. Neither has `--max-tokens`
honored as precisely as the OpenAI-compat path (LangChain's streaming
doesn't report real usage either — both estimate token counts at char/4).
`azure-foundry` is a known, separate gap — some of its deployments speak
OpenAI's shape and some speak Anthropic's, at a non-generic URL path — and
OpenRouter/Cheaper-Inference dispatch sends no Authorization header yet
(a different, pre-existing gap noticed but not fixed here).

- No args: interactive REPL. `/help` inside it for slash commands
  (`/catalog`, `/hubs`, `/refresh`, `/history`, `/export`, `/window`, …).
- **Three REPL modes**, switched with `/chat`, `/code`, `/manage` (default `chat`):
  - `chat` — plain conversation, `resolve(--agent)` (default agent name
    `concierge` — every org gets a default project + a `concierge` agent
    provisioned automatically on signup, so this works immediately with
    no setup).
  - `code` — same loop, different binding: `resolve(--code-agent)` (default
    agent name `code`) plus a one-time system preamble. Its own history,
    separate from `chat` mode's. This is *not* a tool-using coding agent —
    Meridian's dispatch layer never sends `tools` to the hub, so this is "a
    different agent/model to resolve against," nothing more. A real
    tool-execution loop would be new dispatch-layer work, not a REPL mode.
  - `manage` — no LLM calls at all: `/projects`, `/agents`, `/keys` (list/create,
    `/keys revoke ID`) over the account you're logged into. Same functions
    `meridian projects`/`meridian agents`/`meridian keys` call outside the REPL
    (`meridian_cli/manage.py`) — one implementation, not two that can drift.
  - `/project [ID]` works in any mode: with no argument, shows the active
    project and lists your org's projects; with an ID, switches to it
    (validated against your org's actual projects first). Affects the next
    `resolve()` call in `chat`/`code` mode immediately.
- `--one-shot "message"`: single turn, prints the response, exits.
  `--json` emits structured output (`response`, `model`, `hub`,
  `routing_log_id`, `latency_ms`, `usage`) instead of plain text. Exit
  code: `0` an answer was produced (including a token-budget-exhausted
  message — that's a completed, audited call, just an unhelpful one),
  `1` a real failure (`resolve()` failed, or dispatch returned an error —
  unreachable hub, bad model id, HTTP error), `2` misuse (`--daemon` and
  `--one-shot` together — mutually exclusive, now rejected instead of
  silently running the daemon and dropping `--one-shot`).
- `--daemon`: long-lived local OpenAI-compatible endpoint (`POST
  /v1/chat/completions`, `GET /v1/models`, `GET /health`) — point an
  existing OpenAI-SDK-based app at `http://127.0.0.1:8700` and it works
  unchanged, with Meridian's governance and audit trail in the middle. The
  F9 "broker" shape from Local-AI's feedback. Stateless across requests,
  same as the real OpenAI API: your app holds history and sends the full
  `messages` array each call.
- `--max-tokens`: reasoning models can need a *much* larger budget than the
  default (8192) just to reach visible content — confirmed live against a
  real deployment where the same five-word prompt burned anywhere from
  ~2400 to the full 8192-token budget purely on reasoning, before any
  answer. If a response comes back as a token-budget notice instead of
  text, raise this — unless the prompt matches the pattern below, where
  raising it won't help.
- **Exact-count / constraint-satisfaction prompts can make reasoning never
  converge, at any budget.** Isolated live against `qwen3.6:35b`: `"Say
  hello in exactly five words."` burned the *entire* reasoning budget at
  8192, then again at 16384 — raising `--max-tokens` didn't make it
  converge faster, it just filled whatever ceiling it was given. The same
  model answers the unconstrained version (`"Say hello."`) normally in 186
  reasoning tokens, and a substantive non-counting prompt normally in ~700.
  So this isn't the model's reasoning budget being too small — it's a
  specific model failure mode where exact-count constraints seem to trap it
  in verifying the count. Not a Meridian or CLI bug; a model characteristic
  to know about before raising `--max-tokens` in response to a stuck
  "exactly N words/items" prompt — raising it will not fix that case.

### `hubs discover`

Probes `localhost` for a local Ollama (`:11434/api/tags`) or vLLM
(`:8000/v1/models`), proposes registering what it finds (models included),
and asks for confirmation before actually registering anything — it never
writes to your org's catalog without that confirmation. If nothing
responds on localhost, it falls back to prompting for a provider + URL
manually, probes that instead, and asks for confirmation the same way.
Same wizard from `meridian hubs discover` and `/discover` inside `meridian chat`'s
manage mode (`meridian_cli/manage.py` + `chat.py`'s `cmd_manage_discover`)
— one implementation either way.

Deliberately only probes `localhost`, never a LAN subnet: unlike a
single-household tool that can hardcode its own known boxes' IPs,
Meridian is multi-tenant — there's no fixed list of "this customer's
boxes" to guess at. `localhost` is the one address that means the same
thing for every caller; anything else goes through the manual-entry
fallback instead of a scan.

Also why this is a client-side probe at all, not a call to the backend's
own `/discover` endpoint: on a SaaS instance, "localhost" from the
*server's* perspective means the server's own container, not your
laptop. Discovery and model-listing both happen in the CLI process so
they can actually reach `localhost` on the machine `meridian` is running on;
the resulting model list is registered directly via `register_models`,
never by asking the server to re-discover something it structurally
cannot reach.

## What this deliberately doesn't do

- `hubs discover` only knows Ollama and vLLM, and only probes `localhost`.
  No cloud-hub registration commands (bedrock/anthropic/openrouter/etc.) —
  those need credentials entered deliberately, not something to probe for.
  Console-only for now.

## Colours (themes)

The chat prompt has named colour themes, like the profiles in a terminal app. In the chat, `/theme` lists them
(`default`, `wine`, `ocean`, `forest`, `amber`, `violet`, `mono`, `contrast`), `/theme wine` switches and remembers
it, and `/theme #8b2c4a` makes a variant of the current theme with that accent. `MERIDIAN_THEME=wine` sets it for one
run, and `NO_COLOR=1` turns colour off.

Your own themes go in `~/.meridian/themes.json`; anything you leave out comes from the default:

```json
{"harbour": {"accent": "#2f6f8f", "rule": "#33475b", "hint": "#6f8a96"}}
```

The colours are `accent` (the prompt, the highlighted menu entry, the dot before replies, the title), `rule`, `hint`,
`footer`, `menu_meta` and `suggestion`. A colour is `#rrggbb`, an ANSI name such as `ansicyan`, or `default` (the
terminal's own). The font and its size belong to your terminal's profile; a theme can only set colour and weight.
