cli
CLI (agent-play)
The workspace package @agent-play/cli builds an agent-play binary (also exposed from the repo root package.json bin after npm run build:cli).
Node setup
This section describes how to provision main and agent nodes from the CLI and what must be true on the server and on your machine.
Prerequisites
| Requirement | Why it matters |
|---|---|
| Web UI / API reachable | Set AGENT_PLAY_SERVER_URL (default http://127.0.0.1:3000) to your Agent Play server. |
| Redis on the server | Node and agent records live in Redis; set REDIS_URL on the server (not necessarily on the CLI host). |
Matching .root file |
The platform root key (genesis identity) comes from .root. The CLI resolves it via --root-file, AGENT_PLAY_ROOT_FILE_PATH, ~/.agent-play/.root, or ./.root (first match). It must match the server’s root key or derived node ids will not line up. |
First-time main node (create-main-node / bootstrap-node)
- Run
agent-play create-main-node(orbootstrap-node). The CLI prompts for server URL (presets 1–3, 4 for a custom third-party / self-hosted base URL, or paste anhttp(s)://…URL), unless you pass--server-url <https://…>to skip the prompt. - The CLI generates a 10-word passphrase (
createNodeCredentialMaterial), hashes it locally topasswHash, derives your main node id under the active root key, and callsPOST /api/nodeswith{ "kind": "main", "nodeId": "<derived>", "passwHash": "<hashed material>" }. The server storespasswHashonly and never re-hashes the supplied material. Nox-node-id/x-node-passwheaders are sent for this call. - Credentials are saved to
~/.agent-play/credentials.json:serverUrl,nodeId(main), and the human-readable passphrase (for you to store safely). Losing the phrase means losing access to that node identity. - The CLI prints the genesis / root key string and your main node id; the genesis value should match
.rootwhen both sides use the same file.
Optional: --root-file /path/to/.root if your root file is not in the default search paths. Optional: --server-url https://your-host for a non-default Agent Play deployment (skips the URL prompt).
Hierarchy (mental model)
Node kinds are fixed: root → main → agent.
rootexists on the server only (from.root); it has no passphrase.mainis your developer account node (what you create withcreate-main-node).agentnodes are children of your main node; you add them withcreate-agent-node.
Agent nodes (create-agent-node / create)
- Requires a successful
create-main-nodesocredentials.jsonexists. - The CLI generates a new credential locally with
createNodeCredentialMaterial, hashes the phrase, derives an agent node id, and callsPOST /api/nodes/agent-nodewithkind: "agent",parentNodeIdset to your main node id,agentNodeId, andagentNodePasswHash(the locally-hashed material). Requests usex-node-id/x-node-passw(see Auth model). - Agent entries are merged into
credentials.jsonunderagentNodes(per-agentnodeId,passw,createdAt).
Inspect and lifecycle
| Action | Command | Notes |
|---|---|---|
| Show genesis id, main node, agent node ids, and runtime agent rows | inspect-node |
GET /api/nodes: mainNode.agentNodeIds (from create-agent-node) plus agentNodes (SDK StoredAgentRecord list, if any). |
| List agents (SDK registrations) | list-agent-nodes |
GET /api/agents. |
| Remove one agent registration | delete-agent-node [agent-id] |
DELETE /api/agents; can prompt if id omitted. |
| Remove main node and cascade | delete-main-node |
DELETE /api/nodes; requires typing your main node id; then consider clear-node-credentials. |
| Drop local file only | clear-node-credentials |
Does not delete server-side nodes. |
@deprecated
POST /api/agentsdoes not create agent identities. Register agent nodes withPOST /api/nodes/agent-node; runtime tool/metadata is attached viaworld.addPlayerin your app.
Node validation
Use these when you want to confirm that stored server state still matches the root-key derivative rules for your main node or agent nodes—without guessing ids by hand.
CLI validation commands
| Command | Purpose |
|---|---|
validate-main-node |
Checks your main node id from credentials.json against the server via POST /api/nodes/validate (body includes nodeId, rootKey from .root). Uses saved credentials for x-node-id / x-node-passw. |
validate-agent-node --all |
Validates every agent node id listed under credentials.json → agentNodes, with mainNodeId set to your main node id so parent checks apply. |
validate-agent-node --agent-node-ids id1,id2,... |
Same checks for an explicit comma-separated list of agent node ids. |
Requirements: run create-main-node first so credentials.json and the passphrase exist; use the same .root resolution as for setup. If --all finds no agentNodes, the CLI reports that there is nothing to validate (exit success).
What “passing” means
The server’s validateNodeIdentity implementation confirms (among other things) that the nodeId is derivable from the stored hashed material under the given rootKey, and for agents that parentNodeId matches the given mainNodeId when provided.
Ops / CI: node-tools script
For validation that reads directly from Redis (same host/namespace as the server), build @agent-play/node-tools and run:
node packages/node-tools/scripts/validate-node-derivative.mjs \
--root-key <hex> \
--node-id <id> \
--redis-url <url> \
[--host-id <id>] \
[--main-node-id <main-id>]
Use --main-node-id when validating an agent node id. See docs/notes/node-id-v1-migration.md for key layout and field semantics.
Deprecated for new work: buffer.txt-only flows and validateNodeDerivativeFromBufferFile.
Commands (summary)
create-main-node(aliasbootstrap-node) — sign up main node; optional--root-file,--server-url. Saves~/.agent-play/credentials.json.inspect-node—GET /api/nodes(authenticated).create-agent-node(aliascreate) —POST /api/nodes/agent-node.list-agent-nodes(aliaslist) —GET /api/agents.delete-agent-node(aliasesdelete,remove) —DELETE /api/agents.delete-main-node—DELETE /api/nodeswith confirmation.validate-main-node— server validation for main node (see Node validation).validate-agent-node—--allor--agent-node-ids id1,id2,...(see Node validation).initialize(aliasinit) — interactive starter scaffold, optional node bootstrap, prompts for agent count (max2), and hydrates.envnode-id env vars when bootstrapped.clear-node-credentials— remove local credentials file.
Auth model
POST /api/nodes(create main node) does not require node auth headers; it expects a JSON body withnodeIdandpasswHash(both computed by the client). The server storespasswHashonly and verifies thatnodeIdderives from it under the active root key.- All other node/agent management requests use:
x-node-id(the locally-derived node id)x-node-passw(the locally-computedpasswHash, i.e.nodeCredentialsMaterialFromHumanPassphrase(passw); the server compares against the stored hash without re-hashing)
Genesis and root key
- The platform genesis identity is the root key from
.root(exposed as genesis node id ininspect-node). - Main and agent node ids are derivatives of passphrase material + that root key.
- Keep CLI
.rootdiscovery aligned with the server so local derivation and server validation agree.
Usage
From the repository root after npm install and npm run build:cli:
npx agent-play create-main-node
npx agent-play create-main-node --server-url https://my-agent-play.example.com
npx agent-play initialize
npx agent-play validate-main-node
npx agent-play inspect-node
npx agent-play create-agent-node
npx agent-play validate-agent-node --all
npx agent-play list-agent-nodes
npx agent-play delete-agent-node
npx agent-play delete-main-node
npx agent-play clear-node-credentials
When registering players in code, use mainNodeId, agent agentId, and node credentials with RemotePlayWorld / addPlayer as described in the SDK docs.
Initialize quick start
npx agent-play initialize creates a starter agent repository skeleton and asks:
- which environment to target (
development,test,production) - server runtime to scaffold (
bareorexpress) - whether to bootstrap node identities now
- how many agent nodes to prepare (
1or2)
When bootstrap is selected, generated .env is hydrated with:
AGENT_PLAY_WEB_UI_URL(derived from selected environment)AGENT_PLAY_MAIN_NODE_IDAGENT_PLAY_AGENT_NODE_ID_1AGENT_PLAY_AGENT_NODE_ID_2(if2agents selected)
The scaffolded runtime reads these env vars directly, so node IDs stay configurable per environment.
For a full end-to-end walkthrough (initializer prompts, bootstrap paths, generated project layout, and troubleshooting), see Initialize agent server and template.