Metadata-Version: 2.4
Name: xian-tech-cli
Version: 0.2.3
Summary: Operator CLI for Xian networks and nodes
Author: Xian Core Team
License-Expression: MIT
Project-URL: Repository, https://github.com/xian-technology/xian-cli
Keywords: blockchain,cometbft,cli,operator,xian
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: System Administrators
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.14
Requires-Python: <3.15,>=3.14
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pynacl<2,>=1.6.2
Requires-Dist: xian-tech-abci<0.11,>=0.10.0
Requires-Dist: xian-tech-compiler-core<0.3,>=0.2.1
Requires-Dist: xian-tech-py<0.6,>=0.5.4
Dynamic: license-file

# xian-cli

`xian-cli` is the operator-facing and automation-facing control plane for
Xian. It owns manifests, node profiles, lifecycle commands, health checks,
local bootstrap flows, and JSON-first client commands without turning
`xian-abci`, `xian-py`, or `xian-stack` into user-facing tools.

The published PyPI package is `xian-tech-cli`. The installed console command
remains `xian`. Runtime-heavy commands expect access to `xian-stack` and
canonical manifests from `xian-configs`, either through the default sibling
workspace layout or explicit `--stack-dir` and `--configs-dir` flags.

## Control Plane

```mermaid
flowchart LR
  Operator["Operator or automation"] --> CLI["xian CLI"]
  CLI --> Configs["xian-configs manifests and templates"]
  CLI --> Stack["xian-stack backend"]
  CLI --> SDK["xian-py client"]
  Configs --> Profiles["Network and node profiles"]
  Stack --> Runtime["Local node runtime"]
  SDK --> Node["Running Xian node"]
  Runtime --> Node
```

## Quick Start

Local development in a sibling-repo workspace:

```bash
uv sync --group dev
uv run xian --help
```

Isolated operator install from a published release:

```bash
uv tool install xian-tech-cli
xian --help
```

Bootstrap installer (requires `uv`):

```bash
curl -fsSL https://raw.githubusercontent.com/xian-technology/xian-cli/main/scripts/install.sh | sh
```

Windows PowerShell:

```powershell
irm https://raw.githubusercontent.com/xian-technology/xian-cli/main/scripts/install.ps1 | iex
```

Set `XIAN_CLI_VERSION` before either installer to pin a specific release.

### Common Workflows

Guided node setup:

```bash
uv run xian setup node
```

For scripted review without changing files:

```bash
uv run xian setup node --mode join --network mainnet --name validator-1 --plan
```

Validator key generation validates both output files before writing either.
Existing key or metadata files require `--force`; unsafe secret-file permissions
or symlinks are refused before replacing any key material.

Create a local network from a template:

```bash
uv run xian network template list
uv run xian network create local-dev --chain-id xian-local-1 \
  --template single-node-dev --generate-validator-key --init-node
uv run xian node start local-dev
uv run xian node status local-dev
```

`single-node-dev` is the full self-contained development profile. It enables
BDS/Postgres, the read-only GraphQL endpoint and GraphiQL browser UI, the node
dashboard, Prometheus, and Grafana. Host-facing endpoints stay on loopback;
inspect their effective URLs with `xian node endpoints local-dev`. Periodic
five-second blocks keep contract time advancing while the node is idle.

A profile's `advanced.metrics.host` and `advanced.metrics.port` are the host
address and port the stack publishes the node's app metrics on
(`XIAN_APP_METRICS_HOST`/`XIAN_APP_METRICS_PORT`, default `127.0.0.1:9108`, so
local only). Inside the container the node always listens on `0.0.0.0:9108`. A
non-loopback host needs the stack's public-metrics opt-in.

The transaction fee policy is chain state chosen at genesis, not node
configuration. Every fee mode carries hard chi caps: `--max-tx-chi` (default
200,000) bounds `chi_supplied` per transaction and `--max-block-chi` (default
500,000) bounds the block's total. For a metered 0-fee local network, pass
`--tx-fee-mode free_metered` to `network create` or `setup node --mode local`;
the cap flags work the same in both modes. A bundle network records
the policy as `fee_policy` in its manifest and every `node init` builds it into
genesis; a generated genesis carries it directly. Joining nodes cannot choose
it, and node profiles or `xian.toml` that set fee keys are rejected.

Node profiles start with the shared node defaults, apply template choices and
explicit flags, and save the resolved values. Existing explicit profile values
stay fixed; fields omitted from a profile receive the installed release's defaults.

Block production defaults come from the selected network template or manifest.
For on-demand local development, use `--block-policy-mode on_demand`; for
scheduled empty blocks, pass both a mode and empty-block interval:

```bash
uv run xian setup node --mode local --network local-dev \
  --block-policy-mode periodic --block-policy-interval 1s
```

The interval controls CometBFT empty-block scheduling. It is not an exact
finalized block-time target: observed cadence is still bounded by normal
CometBFT consensus timing, especially `timeout_commit`, and block execution
time.

Join a manifest-backed shared network with the lean `validator` template (the
node and monitoring; BDS, GraphQL and the dashboard stay off):

```bash
uv run xian network join mainnet-node --network mainnet \
  --template validator --generate-validator-key \
  --init-node
uv run xian node start mainnet-node
uv run xian node health mainnet-node
uv run xian node endpoints mainnet-node
```

Package a clean operator handoff bundle for a network manifest:

```bash
uv run xian network package-operator-bundle mainnet \
  --bootstrap-seed '<node_id>@<public-host>:26656' \
  --archive
```

The bundle pins the shipped genesis with `genesis_sha256` (manifest,
`operator-bundle.json`, README); `node init` refuses any genesis whose
installed `config/genesis.json` hashes differently. Publish that value through
a separate channel so participants can check the bundle they received.

Inspect or recover a configured node:

```bash
uv run xian doctor mainnet-node
uv run xian doctor mainnet-node --skip-live-checks
uv run xian snapshot restore mainnet-node
```

Application logs default to seven-day retention, 50 MiB segments and a
250 MiB total budget. Use `--app-log-max-file-mb` and
`--app-log-max-total-mb` on setup/create/join to override the local node profile.
The total must be at least the segment limit; disk pressure from logging may
remove older records before seven days. See the node logging guide in
`xian-docs-web/node/managing.md` for diagnostic and container-log boundaries.

Advanced runtime settings cover CometBFT and application metrics. Numeric
timing and ratio options in node profiles and templates must be finite.

Xian uses unmodified upstream CometBFT. Bootstrap through ordinary replay from
genesis or a verified full-node-store snapshot. `node init` and `node start`
require P2P application state sync to be disabled in the installed CometBFT
configuration. `--skip-health-check` skips the startup RPC wait and still
validates this configuration. `node health` and `doctor` report validation
under `cometbft_config`.

Generated profiles omit `advanced.statesync`. An existing disabled section is
accepted and ignored. `node health` and `doctor` report incompatible legacy
settings under `profile_config`. You can stop or inspect the node and export or
restore full-store snapshots while you correct its profile.

`xian snapshot restore` and `node init --restore-snapshot` consume a signed
full-node-store manifest from `snapshot_url`, verified against the configured
trusted `snapshot_signing_keys`. The node verifier binds its chain and genesis,
application root and height, and complete CometBFT stores/checkpoint before
publishing data. Recipient node/validator keys and signing state stay local.
This bootstrap trusts the configured snapshot signer; it is not independent
replay of every block. Application-only `xian-state-snapshot` exports are offline
data APIs and cannot bootstrap a node.

Release provenance preserves upstream `cometbft_source_commit`, source URL and
SHA256. It does not require a custom CometBFT patch or attest a running binary.

Create a signed full-store archive from a stopped nonvalidator home:

```bash
uv run xian node stop snapshot-source
uv run xian snapshot export snapshot-source \
  --archive-output ./node-store.tar.gz \
  --manifest-output ./node-store.manifest.json \
  --snapshot-url https://snapshots.example/node-store.tar.gz \
  --signing-key-file /private/publisher.key
```

The signing file contains the publisher's 32-byte hexadecimal private key and
uses mode `0600`. Export writes the archive and signed manifest locally; it
does not upload them. It uses the profile's current node image for native
store inspection, so a host Go binary is not required. Both export and restore
require a successful stopped-runtime status check; unknown status, paused or
restarting containers are refused. A known-empty
fresh home can be restored after its own genesis/configuration/keys are initialized.

Existing `recovery apply` plans may supply an independently trusted archive
SHA256 as a lower-level alternative to a signed manifest. The canonical verifier
still requires complete full-store/genesis/application/native-history/resource
checks; an archive's self-declared hash is not authorization. `--skip-stop`
skips issuing the stop command, not the stopped-runtime proof.

Recovery plans keep an explicit manual incident policy: `target_height`,
`trusted_block_hash`, and `trusted_app_hash` are not automatically compared to
the restored checkpoint. The plan layer checks chain consistency and, when
live RPC is available, that the live height is at least the target. The canonical
verifier checks the archive's own full-store checkpoint and trust inputs.
Operators must compare that checkpoint with the incident plan before using
`--yes` or starting the restored node; JSON output retains
`requires_manual_hash_confirmation: true` and the manual hash fields.

Wallet, query, and transaction automation against a running node:

```bash
uv run xian client wallet generate --private-key-out ./wallet.key
uv run xian client query nonce --node-url http://127.0.0.1:26657 <address>
uv run xian client query indexed-tx --node-url http://127.0.0.1:26657 <tx-hash>
uv run xian client tx transfer \
  --node-url http://127.0.0.1:26657 \
  --private-key-env XIAN_PRIVATE_KEY \
  <recipient> 1.25
```

## Operator Journeys

Use `xian-cli` when you want a stable human-facing command surface. The CLI
reads committed assets from `xian-configs`, delegates runtime-heavy local
operations to `xian-stack`, and uses `xian-py` for wallet / RPC automation.

| Goal | Primary commands | Backing repo |
| --- | --- | --- |
| Create a local network | `xian network template ...`, `xian network create ...` | `xian-configs`, `xian-abci` |
| Join an existing network | `xian network join ...` | `xian-configs`, `xian-stack` |
| Guided node setup | `xian setup node` | `xian-cli`, `xian-configs`, `xian-stack` |
| Package operator handoff | `xian network package-operator-bundle ...` | `xian-cli`, `xian-configs` |
| Operate a node | `xian node start/status/health/endpoints/stop ...` | `xian-stack` |
| Diagnose a setup | `xian doctor ...`, `xian snapshot restore ...` | `xian-stack`, `xian-abci` |
| Validate deployment bundles | `xian contract bundle validate ...` | product or contract repos |
| Submit contract source | `xian client tx submit-source ...` | product or contract repos, `xian-py` |
| Script chain interactions | `xian client query/call/simulate/tx ...` | `xian-py` |

Product repos own product bootstrap. Use the CLI for generic bundle and
transaction helpers, then run the product repo's installer:

```bash
uv run xian contract bundle validate ../xian-dex/contract-bundle.json
cd ../xian-dex
uv run python scripts/bootstrap_dex.py --recipe local-demo
```

Validate a hash-pinned contract bundle directly:

```bash
uv run xian contract bundle validate ../xian-dex/contract-bundle.json
```

Build Xian VM artifacts from source for offline inspection or CI checks:

```bash
uv run xian contract build-artifacts ./contracts/con_counter.s.py \
  --output ./dist/con_counter.artifacts.json
```

The command calls the Rust compiler core (`xian_compiler_core`, package
`xian-tech-compiler-core`) directly, so its output is byte-identical to
`xian_compiler_core.compile_contract_artifact` and to the WASM
`@xian-tech/compiler` used by the IDE. The compiler always applies its lint
rules; they are part of admission.

Artifact inspection defaults to the fresh chain's `xian_vm_v2` profile.
Select `--vm-profile xian_vm_v1` to reproduce an archived V1 test artifact. Client calls,
simulations, transfers and deployments use V2. In `--kwargs-json` and
`--args-json`, fractional JSON numbers are read directly as decimals. Use a
quoted `--kwargs-json '{"amount":0.000000000000000000000000000001}'` to
preserve each source digit. Typed `__fixed__` wrappers are also accepted.

Submit contract source through the same signed transaction surface as other
client automation:

```bash
uv run xian client tx submit-source ./contracts/con_counter.s.py \
  --node-url http://127.0.0.1:26657 \
  --private-key-env XIAN_PRIVATE_KEY \
  --mode commit
```

For scripts and CI, prefer commands that emit JSON and avoid parsing human
status text. `xian client tx ...` always prints its JSON result and exits 1
when the node refused the transaction, when it executed and failed (its fee is
still paid), or when a `--mode commit` wait ended without finalization:

```bash
uv run xian client query balance \
  --node-url http://127.0.0.1:26657 \
  <address>
```

## Principles

- **Operator UX lives here.** Deterministic node logic stays in `xian-abci`,
  and local runtime orchestration stays in `xian-stack`. This repo is the
  control plane that ties them together.
- **Explicit artifacts, not hidden state.** Manifests and node profiles are
  human-readable files. The CLI inspects, generates, and updates them; it
  does not invent state outside them.
- **Templates accelerate, never lock in.** Templates shorten common network
  setups, but an operator who knows what they are doing should still be able to
  work directly with manifests, profiles, and node homes.
- **Diagnostics are first-class.** Health, endpoint discovery, and `doctor`
  paths are core features, not afterthoughts.
- **JSON-first for automation.** Client commands and inspection commands emit
  machine-readable output suitable for scripts and CI.

## Key Directories

- `src/xian_cli/` — commands, models, manifest handling, and backend
  integration.
  - `cli.py`, `parser.py` — argument parsing and command dispatch.
  - `client/` — wallet, query, call, simulate, and transaction commands.
  - `config_repo.py`, `models.py` — manifest and profile schemas.
  - `abci_bridge.py`, `runtime.py` — node-runtime integration.
  - `contract_bundles.py` — hash-pinned contract-bundle validation.
- `scripts/` — install / packaging helpers (e.g. `install.sh`, `install.ps1`).
- `tests/` — CLI behavior and manifest / profile validation coverage.
- `docs/` — architecture, lifecycle contract, distribution notes, backlog.

## Capabilities

- key generation and validator material
- network template discovery
- network creation and network join flows
- node initialization, start, stop, and status
- endpoint and health discovery, including optional dashboard, monitoring,
  and stack-managed `xian-intentkit` / `xian-dex-automation`
- snapshot restore and doctor diagnostics
- Xian VM artifact generation from contract source for offline inspection
- hash-pinned contract-bundle validation
- wallet, query, call / simulate, and transaction automation via `xian-py`

## Command Groups

- `xian keys ...` — generate validator and account material
- `xian setup node` — guided wrapper for local node creation or network join
- `xian network template ...` — inspect reusable network templates
- `xian network create ...` — create a local / operator-managed network profile
- `xian network join ...` — join an existing manifest-backed or remote network
- `xian network package-operator-bundle ...` — package a shareable operator handoff
- `xian node ...` — initialize, start, stop, inspect, and recover a node profile
- `xian client ...` — wallet, query, call / simulate, and transaction automation
  including source-backed contract submission
- `xian contract build-artifacts ...` — build Xian VM artifacts for inspection
- `xian contract bundle ...` — validate hash-pinned contract bundles
- `xian doctor ...` — run broader local diagnostics

## Validation

```bash
uv sync --group dev
uv run ruff check .
uv run ruff format --check .
uv run pytest
```

## Related Docs

- [AGENTS.md](AGENTS.md) — repo-specific guidance for AI agents and contributors
- [docs/README.md](docs/README.md) — index of internal docs
- [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) — major components and dependency direction
- [docs/BACKLOG.md](docs/BACKLOG.md) — open work and follow-ups
- [docs/LIFECYCLE_CONTRACT.md](docs/LIFECYCLE_CONTRACT.md) — node-lifecycle contract that the CLI enforces
- [docs/DISTRIBUTION.md](docs/DISTRIBUTION.md) — packaging, install paths, and release-channel rules
