@agent-play/cli 3.2.0 → 3.2.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.
package/README.md CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  Command-line tool for **Agent Play**: create a **main developer node** (platform signup), add **agent nodes**, **validate** those identities against the server, and manage agent registrations. The server must use a **Redis**-backed agent repository (`REDIS_URL` on the server).
4
4
 
5
- Authentication uses **`x-node-id`** and **`x-node-passw`** on every request **except** main-node creation, which sends hashed passphrase material in the JSON body to **`POST /api/nodes**.
5
+ Authentication uses **`x-node-id`** and **`x-node-passw`** (the locally-computed `passwHash`) on every request **except** main-node creation. **`POST /api/nodes`** is unauthenticated and expects a JSON body with **`nodeId`** and **`passwHash`** already derived on the client; the server stores `passwHash` only and never re-hashes anything it receives.
6
6
 
7
7
  ## Documentation
8
8
 
9
9
  - **[Repository](https://github.com/wilforlan/agent-play)**
10
10
  - **[CLI guide](https://github.com/wilforlan/agent-play/blob/main/docs/cli.md)** — full **Node setup** and **Node validation** sections
11
- - **[API reference](https://wilforlan.github.io/agent-play/)** — TypeDoc
11
+ - **[API reference](https://wilforlan.github.io/agent-play/)** — TypeDoc
12
12
 
13
13
  ## Install
14
14
 
@@ -16,50 +16,52 @@ Authentication uses **`x-node-id`** and **`x-node-passw`** on every request **ex
16
16
  npm install -g @agent-play/cli
17
17
  ```
18
18
 
19
- Binary name: **`agent-play`**.
19
+ Binary name: `**agent-play**`.
20
20
 
21
- Default server URL: **`http://127.0.0.1:3000`**, or override with **`AGENT_PLAY_SERVER_URL`**.
21
+ Default server URL: `**http://127.0.0.1:3000**`, or override with `**AGENT_PLAY_SERVER_URL**`.
22
22
 
23
- Root key for derivation: **`--root-file`**, **`AGENT_PLAY_ROOT_FILE_PATH`**, or a **`.root`** file under **`~/.agent-play/`** or the current working directory (must match the server’s `.root`).
23
+ Root key for derivation: `**--root-file**`, `**AGENT_PLAY_ROOT_FILE_PATH**`, or a `**.root**` file under `**~/.agent-play/**` or the current working directory (must match the server’s `.root`).
24
24
 
25
25
  ## Node setup
26
26
 
27
27
  1. **Server:** Redis (`REDIS_URL`) and a deployed web UI/API the CLI can reach (`AGENT_PLAY_SERVER_URL`).
28
28
  2. **Local `.root`:** Must match the server genesis root key (see resolution order above).
29
- 3. **`create-main-node`** (`bootstrap-node`): prompts for server URL, generates a passphrase, registers **`POST /api/nodes`**, writes **`~/.agent-play/credentials.json`** with **`serverUrl`**, **`nodeId`**, and the human passphrase.
30
- 4. **`create-agent-node`**: derives an agent node under your main node, **`POST /api/nodes/agent-node`**, appends to **`credentials.json``agentNodes`**.
31
- 5. **`inspect-node`**, **`list-agent-nodes`**, **`delete-*`**, **`clear-node-credentials`**: inspect or tear down registrations; see **`docs/cli.md`** for the full table.
29
+ 3. **`create-main-node`** (`bootstrap-node`): prompts for server URL, generates a passphrase and **`passwHash`** locally with `createNodeCredentialMaterial`, registers **`POST /api/nodes`** with `{ kind: "main", nodeId, passwHash }`, and writes **`~/.agent-play/credentials.json`** with **`serverUrl`**, **`nodeId`**, and the human passphrase.
30
+ 4. **`create-agent-node`**: derives an agent node locally with `createNodeCredentialMaterial`, calls **`POST /api/nodes/agent-node`** with `{ kind: "agent", parentNodeId, agentNodeId, agentNodePasswHash }`, and appends the result to **`credentials.json → agentNodes`**.
31
+ 5. `**inspect-node**`, `**list-agent-nodes**`, `**delete-***`, `**clear-node-credentials**`: inspect or tear down registrations; see `**docs/cli.md**` for the full table.
32
32
 
33
- > **@deprecated** **`POST /api/agents`** does not create agent **node** identity. Use **`POST /api/nodes/agent-node`**, then attach runtime data with **`world.addPlayer`**.
33
+ > **@deprecated** `**POST /api/agents`** does not create agent **node** identity. Use `**POST /api/nodes/agent-node`**, then attach runtime data with `**world.addPlayer**`.
34
34
 
35
35
  ## Node validation
36
36
 
37
- - **`validate-main-node`** — calls **`POST /api/nodes/validate`** for your main node id (uses **`credentials.json`** + **`.root`**).
38
- - **`validate-agent-node --all`** — validates every id in **`credentials.json` → `agentNodes`** (includes **`mainNodeId`** in the validate body).
39
- - **`validate-agent-node --agent-node-ids id1,id2`** — same for explicit ids.
37
+ - `**validate-main-node**` — calls `**POST /api/nodes/validate**` for your main node id (uses `**credentials.json**` + `**.root**`).
38
+ - `**validate-agent-node --all**` — validates every id in `**credentials.json` → `agentNodes**` (includes `**mainNodeId**` in the validate body).
39
+ - `**validate-agent-node --agent-node-ids id1,id2**` — same for explicit ids.
40
40
 
41
- For Redis-direct checks (ops/CI), use **`node-tools`** script **`scripts/validate-node-derivative.mjs`**; details in **`docs/cli.md`** and **`docs/notes/node-id-v1-migration.md`**.
41
+ For Redis-direct checks (ops/CI), use `**node-tools**` script `**scripts/validate-node-derivative.mjs**`; details in `**docs/cli.md**` and `**docs/notes/node-id-v1-migration.md**`.
42
42
 
43
43
  ## Commands
44
44
 
45
- | Command | Aliases | What it does |
46
- |--------|---------|----------------|
47
- | **`create-main-node`** | `bootstrap-node` | Sign up a **main** node: **`POST /api/nodes`** (no node headers), save **`~/.agent-play/credentials.json`**. Optional **`--root-file`**. |
48
- | **`inspect-node`** | | **GET /api/nodes** genesis id, main node, **agent node ids** (`create-agent-node`), and **runtime** agent rows (SDK metadata) if present. |
49
- | **`create-agent-node`** | `create` | **POST /api/nodes/agent-node** — new agent node under your main node. |
50
- | **`list-agent-nodes`** | `list` | **GET /api/agents** — lists registered agents. |
51
- | **`delete-agent-node`** | `delete`, `remove` | **DELETE /api/agents** — optional **`[agent-id]`**; if omitted, prompts. |
52
- | **`delete-main-node`** | | **DELETE /api/nodes** — confirm by typing main node id; cascades. |
53
- | **`validate-main-node`** | — | **POST /api/nodes/validate** for main node id. |
54
- | **`validate-agent-node`** | — | **`--all`** or **`--agent-node-ids id1,id2,...`** — validate agent node ids. |
55
- | **`initialize`** | `init` | Interactive scaffold for a starter agent codebase, optional node bootstrap, asks for agent count (1-2), and writes env-variable node ids into `.env` when bootstrapped. |
56
- | **`clear-node-credentials`** | | Removes **`~/.agent-play/credentials.json`**. |
45
+
46
+ | Command | Aliases | What it does |
47
+ | ---------------------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
48
+ | `**create-main-node**` | `bootstrap-node` | Sign up a **main** node: `**POST /api/nodes`** (no node headers), save `**~/.agent-play/credentials.json**`. Optional `**--root-file**`. |
49
+ | `**inspect-node**` | | **GET /api/nodes** — genesis id, main node, **agent node ids** (`create-agent-node`), and **runtime** agent rows (SDK metadata) if present. |
50
+ | `**create-agent-node`** | `create` | **POST /api/nodes/agent-node** — new agent node under your main node. |
51
+ | `**list-agent-nodes`** | `list` | **GET /api/agents** — lists registered agents. |
52
+ | `**delete-agent-node`** | `delete`, `remove` | **DELETE /api/agents** — optional `**[agent-id]`**; if omitted, prompts. |
53
+ | `**delete-main-node**` | — | **DELETE /api/nodes** confirm by typing main node id; cascades. |
54
+ | `**validate-main-node`** | — | **POST /api/nodes/validate** for main node id. |
55
+ | `**validate-agent-node`** | | `**--all**` or `**--agent-node-ids id1,id2,...**` validate agent node ids. |
56
+ | `**initialize**` | `init` | Interactive scaffold for a starter agent codebase, optional node bootstrap, asks for agent count (1-2), and writes env-variable node ids into `.env` when bootstrapped. |
57
+ | `**clear-node-credentials**` | — | Removes `**~/.agent-play/credentials.json**`. |
58
+
57
59
 
58
60
  ## Genesis and main node
59
61
 
60
- Every **main node id** is derived from passphrase material and the platform **root key** (the **genesis** identity). **`inspect-node`** and **`create-main-node`** output should agree with **`.root`** when both sides use the same key.
62
+ Every **main node id** is derived from passphrase material and the platform **root key** (the **genesis** identity). `**inspect-node`** and `**create-main-node**` output should agree with `**.root**` when both sides use the same key.
61
63
 
62
- Node kinds: **`root` → `main` → `agent`**. Root has no passphrase; main and agent persist hashed material server-side.
64
+ Node kinds: `**root` → `main` → `agent**`. Root has no passphrase; main and agent persist hashed material server-side.
63
65
 
64
66
  ## Usage examples
65
67
 
@@ -77,7 +79,7 @@ npx agent-play delete-main-node
77
79
  npx agent-play clear-node-credentials
78
80
  ```
79
81
 
80
- For SDK usage after bootstrap, use **`RemotePlayWorld`** and register players with **`mainNodeId`** and **`agentId`** from the CLI output.
82
+ For SDK usage after bootstrap, use `**RemotePlayWorld**` and register players with `**mainNodeId**` and `**agentId**` from the CLI output.
81
83
 
82
84
  ## Initialize quick start
83
85
 
@@ -89,3 +91,4 @@ For SDK usage after bootstrap, use **`RemotePlayWorld`** and register players wi
89
91
  - `AGENT_PLAY_AGENT_NODE_ID_2` (when requested)
90
92
  into generated `.env`.
91
93
  - Generated code references these env vars directly (no hardcoded ids).
94
+
package/dist/README.md CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  Command-line tool for **Agent Play**: create a **main developer node** (platform signup), add **agent nodes**, **validate** those identities against the server, and manage agent registrations. The server must use a **Redis**-backed agent repository (`REDIS_URL` on the server).
4
4
 
5
- Authentication uses **`x-node-id`** and **`x-node-passw`** on every request **except** main-node creation, which sends hashed passphrase material in the JSON body to **`POST /api/nodes**.
5
+ Authentication uses **`x-node-id`** and **`x-node-passw`** (the locally-computed `passwHash`) on every request **except** main-node creation. **`POST /api/nodes`** is unauthenticated and expects a JSON body with **`nodeId`** and **`passwHash`** already derived on the client; the server stores `passwHash` only and never re-hashes anything it receives.
6
6
 
7
7
  ## Documentation
8
8
 
9
9
  - **[Repository](https://github.com/wilforlan/agent-play)**
10
10
  - **[CLI guide](https://github.com/wilforlan/agent-play/blob/main/docs/cli.md)** — full **Node setup** and **Node validation** sections
11
- - **[API reference](https://wilforlan.github.io/agent-play/)** — TypeDoc
11
+ - **[API reference](https://wilforlan.github.io/agent-play/)** — TypeDoc
12
12
 
13
13
  ## Install
14
14
 
@@ -16,50 +16,52 @@ Authentication uses **`x-node-id`** and **`x-node-passw`** on every request **ex
16
16
  npm install -g @agent-play/cli
17
17
  ```
18
18
 
19
- Binary name: **`agent-play`**.
19
+ Binary name: `**agent-play**`.
20
20
 
21
- Default server URL: **`http://127.0.0.1:3000`**, or override with **`AGENT_PLAY_SERVER_URL`**.
21
+ Default server URL: `**http://127.0.0.1:3000**`, or override with `**AGENT_PLAY_SERVER_URL**`.
22
22
 
23
- Root key for derivation: **`--root-file`**, **`AGENT_PLAY_ROOT_FILE_PATH`**, or a **`.root`** file under **`~/.agent-play/`** or the current working directory (must match the server’s `.root`).
23
+ Root key for derivation: `**--root-file**`, `**AGENT_PLAY_ROOT_FILE_PATH**`, or a `**.root**` file under `**~/.agent-play/**` or the current working directory (must match the server’s `.root`).
24
24
 
25
25
  ## Node setup
26
26
 
27
27
  1. **Server:** Redis (`REDIS_URL`) and a deployed web UI/API the CLI can reach (`AGENT_PLAY_SERVER_URL`).
28
28
  2. **Local `.root`:** Must match the server genesis root key (see resolution order above).
29
- 3. **`create-main-node`** (`bootstrap-node`): prompts for server URL, generates a passphrase, registers **`POST /api/nodes`**, writes **`~/.agent-play/credentials.json`** with **`serverUrl`**, **`nodeId`**, and the human passphrase.
30
- 4. **`create-agent-node`**: derives an agent node under your main node, **`POST /api/nodes/agent-node`**, appends to **`credentials.json``agentNodes`**.
31
- 5. **`inspect-node`**, **`list-agent-nodes`**, **`delete-*`**, **`clear-node-credentials`**: inspect or tear down registrations; see **`docs/cli.md`** for the full table.
29
+ 3. **`create-main-node`** (`bootstrap-node`): prompts for server URL, generates a passphrase and **`passwHash`** locally with `createNodeCredentialMaterial`, registers **`POST /api/nodes`** with `{ kind: "main", nodeId, passwHash }`, and writes **`~/.agent-play/credentials.json`** with **`serverUrl`**, **`nodeId`**, and the human passphrase.
30
+ 4. **`create-agent-node`**: derives an agent node locally with `createNodeCredentialMaterial`, calls **`POST /api/nodes/agent-node`** with `{ kind: "agent", parentNodeId, agentNodeId, agentNodePasswHash }`, and appends the result to **`credentials.json → agentNodes`**.
31
+ 5. `**inspect-node**`, `**list-agent-nodes**`, `**delete-***`, `**clear-node-credentials**`: inspect or tear down registrations; see `**docs/cli.md**` for the full table.
32
32
 
33
- > **@deprecated** **`POST /api/agents`** does not create agent **node** identity. Use **`POST /api/nodes/agent-node`**, then attach runtime data with **`world.addPlayer`**.
33
+ > **@deprecated** `**POST /api/agents`** does not create agent **node** identity. Use `**POST /api/nodes/agent-node`**, then attach runtime data with `**world.addPlayer**`.
34
34
 
35
35
  ## Node validation
36
36
 
37
- - **`validate-main-node`** — calls **`POST /api/nodes/validate`** for your main node id (uses **`credentials.json`** + **`.root`**).
38
- - **`validate-agent-node --all`** — validates every id in **`credentials.json` → `agentNodes`** (includes **`mainNodeId`** in the validate body).
39
- - **`validate-agent-node --agent-node-ids id1,id2`** — same for explicit ids.
37
+ - `**validate-main-node**` — calls `**POST /api/nodes/validate**` for your main node id (uses `**credentials.json**` + `**.root**`).
38
+ - `**validate-agent-node --all**` — validates every id in `**credentials.json` → `agentNodes**` (includes `**mainNodeId**` in the validate body).
39
+ - `**validate-agent-node --agent-node-ids id1,id2**` — same for explicit ids.
40
40
 
41
- For Redis-direct checks (ops/CI), use **`node-tools`** script **`scripts/validate-node-derivative.mjs`**; details in **`docs/cli.md`** and **`docs/notes/node-id-v1-migration.md`**.
41
+ For Redis-direct checks (ops/CI), use `**node-tools**` script `**scripts/validate-node-derivative.mjs**`; details in `**docs/cli.md**` and `**docs/notes/node-id-v1-migration.md**`.
42
42
 
43
43
  ## Commands
44
44
 
45
- | Command | Aliases | What it does |
46
- |--------|---------|----------------|
47
- | **`create-main-node`** | `bootstrap-node` | Sign up a **main** node: **`POST /api/nodes`** (no node headers), save **`~/.agent-play/credentials.json`**. Optional **`--root-file`**. |
48
- | **`inspect-node`** | | **GET /api/nodes** genesis id, main node, **agent node ids** (`create-agent-node`), and **runtime** agent rows (SDK metadata) if present. |
49
- | **`create-agent-node`** | `create` | **POST /api/nodes/agent-node** — new agent node under your main node. |
50
- | **`list-agent-nodes`** | `list` | **GET /api/agents** — lists registered agents. |
51
- | **`delete-agent-node`** | `delete`, `remove` | **DELETE /api/agents** — optional **`[agent-id]`**; if omitted, prompts. |
52
- | **`delete-main-node`** | | **DELETE /api/nodes** — confirm by typing main node id; cascades. |
53
- | **`validate-main-node`** | — | **POST /api/nodes/validate** for main node id. |
54
- | **`validate-agent-node`** | — | **`--all`** or **`--agent-node-ids id1,id2,...`** — validate agent node ids. |
55
- | **`initialize`** | `init` | Interactive scaffold for a starter agent codebase, optional node bootstrap, asks for agent count (1-2), and writes env-variable node ids into `.env` when bootstrapped. |
56
- | **`clear-node-credentials`** | | Removes **`~/.agent-play/credentials.json`**. |
45
+
46
+ | Command | Aliases | What it does |
47
+ | ---------------------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
48
+ | `**create-main-node**` | `bootstrap-node` | Sign up a **main** node: `**POST /api/nodes`** (no node headers), save `**~/.agent-play/credentials.json**`. Optional `**--root-file**`. |
49
+ | `**inspect-node**` | | **GET /api/nodes** — genesis id, main node, **agent node ids** (`create-agent-node`), and **runtime** agent rows (SDK metadata) if present. |
50
+ | `**create-agent-node`** | `create` | **POST /api/nodes/agent-node** — new agent node under your main node. |
51
+ | `**list-agent-nodes`** | `list` | **GET /api/agents** — lists registered agents. |
52
+ | `**delete-agent-node`** | `delete`, `remove` | **DELETE /api/agents** — optional `**[agent-id]`**; if omitted, prompts. |
53
+ | `**delete-main-node**` | — | **DELETE /api/nodes** confirm by typing main node id; cascades. |
54
+ | `**validate-main-node`** | — | **POST /api/nodes/validate** for main node id. |
55
+ | `**validate-agent-node`** | | `**--all**` or `**--agent-node-ids id1,id2,...**` validate agent node ids. |
56
+ | `**initialize**` | `init` | Interactive scaffold for a starter agent codebase, optional node bootstrap, asks for agent count (1-2), and writes env-variable node ids into `.env` when bootstrapped. |
57
+ | `**clear-node-credentials**` | — | Removes `**~/.agent-play/credentials.json**`. |
58
+
57
59
 
58
60
  ## Genesis and main node
59
61
 
60
- Every **main node id** is derived from passphrase material and the platform **root key** (the **genesis** identity). **`inspect-node`** and **`create-main-node`** output should agree with **`.root`** when both sides use the same key.
62
+ Every **main node id** is derived from passphrase material and the platform **root key** (the **genesis** identity). `**inspect-node`** and `**create-main-node**` output should agree with `**.root**` when both sides use the same key.
61
63
 
62
- Node kinds: **`root` → `main` → `agent`**. Root has no passphrase; main and agent persist hashed material server-side.
64
+ Node kinds: `**root` → `main` → `agent**`. Root has no passphrase; main and agent persist hashed material server-side.
63
65
 
64
66
  ## Usage examples
65
67
 
@@ -77,7 +79,7 @@ npx agent-play delete-main-node
77
79
  npx agent-play clear-node-credentials
78
80
  ```
79
81
 
80
- For SDK usage after bootstrap, use **`RemotePlayWorld`** and register players with **`mainNodeId`** and **`agentId`** from the CLI output.
82
+ For SDK usage after bootstrap, use `**RemotePlayWorld**` and register players with `**mainNodeId**` and `**agentId**` from the CLI output.
81
83
 
82
84
  ## Initialize quick start
83
85
 
@@ -89,3 +91,4 @@ For SDK usage after bootstrap, use **`RemotePlayWorld`** and register players wi
89
91
  - `AGENT_PLAY_AGENT_NODE_ID_2` (when requested)
90
92
  into generated `.env`.
91
93
  - Generated code references these env vars directly (no hardcoded ids).
94
+
package/dist/cli.js CHANGED
@@ -8,12 +8,10 @@ import { join as join2, resolve as resolve2 } from "path";
8
8
  import { createInterface } from "readline/promises";
9
9
  import { stdin as input, stdout as output } from "process";
10
10
  import {
11
- createNodeCredentialFromPassw,
12
- deriveNodeIdFromPassword,
13
- generateNodePassw,
14
- hashNodePassword,
11
+ createNodeCredentialMaterial,
15
12
  loadAgentPlayCredentialsFileFromPath,
16
- loadRootKey
13
+ loadRootKey,
14
+ nodeCredentialsMaterialFromHumanPassphrase
17
15
  } from "@agent-play/node-tools";
18
16
 
19
17
  // src/initialize.ts
@@ -259,7 +257,7 @@ function basenameFromPath(pathValue) {
259
257
  function nodeAuthHeaders(cred) {
260
258
  return {
261
259
  "x-node-id": cred.nodeId,
262
- "x-node-passw": hashNodePassword(cred.passw)
260
+ "x-node-passw": nodeCredentialsMaterialFromHumanPassphrase(cred.passw)
263
261
  };
264
262
  }
265
263
  function parseAgentRows(agentsRaw) {
@@ -492,11 +490,11 @@ function resolveAgentPlayRootPath(options) {
492
490
  "Agent Play root key not found. Pass --root-file <path>, set AGENT_PLAY_ROOT_FILE_PATH, or place .root in ~/.agent-play/ or the project directory."
493
491
  );
494
492
  }
495
- async function registerNodeOnServer(serverUrl, passw, expectedNodeId) {
493
+ async function registerNodeOnServer(serverUrl, nodeId, passwHash) {
496
494
  const res = await fetch(`${serverUrl}/api/nodes`, {
497
495
  method: "POST",
498
496
  headers: { "content-type": "application/json" },
499
- body: JSON.stringify({ kind: "main", passw })
497
+ body: JSON.stringify({ kind: "main", nodeId, passwHash })
500
498
  });
501
499
  const text = await res.text();
502
500
  if (res.status === 409) {
@@ -519,9 +517,7 @@ async function registerNodeOnServer(serverUrl, passw, expectedNodeId) {
519
517
  if (typeof json.nodeId !== "string") {
520
518
  throw new Error("Invalid response from server.");
521
519
  }
522
- if (json.nodeId !== expectedNodeId) {
523
- console.log("json", json);
524
- console.log("expectedNodeId", expectedNodeId);
520
+ if (json.nodeId !== nodeId) {
525
521
  throw new Error(
526
522
  "Server node id does not match local derivation; check root file and server configuration."
527
523
  );
@@ -537,20 +533,18 @@ async function cmdBootstrapNode(argv) {
537
533
  const rootKey = loadRootKey(rootPath);
538
534
  const dir = join2(homedir(), ".agent-play");
539
535
  await mkdir2(dir, { recursive: true });
540
- const generatedPassw = generateNodePassw();
541
- const hashedPassw = hashNodePassword(generatedPassw);
542
- const credential = createNodeCredentialFromPassw({ passw: hashedPassw, rootKey });
543
- await registerNodeOnServer(serverUrl, hashedPassw, credential.nodeId);
536
+ const credential = createNodeCredentialMaterial({ rootKey });
537
+ await registerNodeOnServer(serverUrl, credential.nodeId, credential.passwHash);
544
538
  await saveCredentials({
545
539
  serverUrl,
546
540
  nodeId: credential.nodeId,
547
- passw: generatedPassw
541
+ passw: credential.phrase
548
542
  });
549
543
  console.log(
550
544
  `genesisNodeId (platform root key from .root; all main nodes derive under this): ${rootKey}`
551
545
  );
552
546
  console.log(`mainNodeId (your developer node): ${credential.nodeId}`);
553
- console.log(`passw: ${generatedPassw}`);
547
+ console.log(`passw: ${credential.phrase}`);
554
548
  console.log("Keep this material safe. Losing it means losing access.");
555
549
  }
556
550
  async function cmdClearNodeCredentials() {
@@ -592,12 +586,7 @@ async function cmdCreateAgentNode() {
592
586
  return;
593
587
  }
594
588
  const rootKey = loadRootKey(resolveAgentPlayRootPath({}));
595
- const agentPassw = generateNodePassw();
596
- const hashedAgentPassw = hashNodePassword(agentPassw);
597
- const agentNodeId = deriveNodeIdFromPassword({
598
- password: hashedAgentPassw,
599
- rootKey
600
- });
589
+ const agentCredential = createNodeCredentialMaterial({ rootKey });
601
590
  const res = await fetch(`${cred.serverUrl}/api/nodes/agent-node`, {
602
591
  method: "POST",
603
592
  headers: {
@@ -607,8 +596,8 @@ async function cmdCreateAgentNode() {
607
596
  body: JSON.stringify({
608
597
  kind: "agent",
609
598
  parentNodeId: cred.nodeId,
610
- agentNodeId,
611
- agentNodePassw: hashedAgentPassw
599
+ agentNodeId: agentCredential.nodeId,
600
+ agentNodePasswHash: agentCredential.passwHash
612
601
  })
613
602
  });
614
603
  const text = await res.text();
@@ -629,7 +618,7 @@ async function cmdCreateAgentNode() {
629
618
  process.exitCode = 1;
630
619
  return;
631
620
  }
632
- if (json.agentId !== agentNodeId) {
621
+ if (json.agentId !== agentCredential.nodeId) {
633
622
  console.error(
634
623
  "Server returned a different agent node id than the locally derived one."
635
624
  );
@@ -637,10 +626,10 @@ async function cmdCreateAgentNode() {
637
626
  return;
638
627
  }
639
628
  const nextAgentNodes = [
640
- ...(cred.agentNodes ?? []).filter((n) => n.nodeId !== agentNodeId),
629
+ ...(cred.agentNodes ?? []).filter((n) => n.nodeId !== agentCredential.nodeId),
641
630
  {
642
- nodeId: agentNodeId,
643
- passw: agentPassw,
631
+ nodeId: agentCredential.nodeId,
632
+ passw: agentCredential.phrase,
644
633
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
645
634
  }
646
635
  ];
@@ -650,7 +639,7 @@ async function cmdCreateAgentNode() {
650
639
  });
651
640
  printAgentPlayIntegrationGuide();
652
641
  console.log(`Created agent node id: ${json.agentId}`);
653
- console.log(`Agent node passw: ${agentPassw}`);
642
+ console.log(`Agent node passw: ${agentCredential.phrase}`);
654
643
  console.log(
655
644
  `Saved agent node credentials to ${credentialsPath()} (agentNodes).`
656
645
  );
@@ -663,26 +652,19 @@ async function ensureMainCredentialsForInitialize(serverUrl) {
663
652
  return existing;
664
653
  }
665
654
  const rootKey = loadRootKey(resolveAgentPlayRootPath({}));
666
- const generatedPassw = generateNodePassw();
667
- const hashedPassw = hashNodePassword(generatedPassw);
668
- const credential = createNodeCredentialFromPassw({ passw: hashedPassw, rootKey });
669
- await registerNodeOnServer(serverUrl, hashedPassw, credential.nodeId);
655
+ const credential = createNodeCredentialMaterial({ rootKey });
656
+ await registerNodeOnServer(serverUrl, credential.nodeId, credential.passwHash);
670
657
  const created = {
671
658
  serverUrl,
672
659
  nodeId: credential.nodeId,
673
- passw: generatedPassw
660
+ passw: credential.phrase
674
661
  };
675
662
  await saveCredentials(created);
676
663
  return created;
677
664
  }
678
665
  async function createAgentNodeForInitialize(cred) {
679
666
  const rootKey = loadRootKey(resolveAgentPlayRootPath({}));
680
- const agentPassw = generateNodePassw();
681
- const hashedAgentPassw = hashNodePassword(agentPassw);
682
- const agentNodeId = deriveNodeIdFromPassword({
683
- password: hashedAgentPassw,
684
- rootKey
685
- });
667
+ const agentCredential = createNodeCredentialMaterial({ rootKey });
686
668
  const res = await fetch(`${cred.serverUrl}/api/nodes/agent-node`, {
687
669
  method: "POST",
688
670
  headers: {
@@ -692,8 +674,8 @@ async function createAgentNodeForInitialize(cred) {
692
674
  body: JSON.stringify({
693
675
  kind: "agent",
694
676
  parentNodeId: cred.nodeId,
695
- agentNodeId,
696
- agentNodePassw: hashedAgentPassw
677
+ agentNodeId: agentCredential.nodeId,
678
+ agentNodePasswHash: agentCredential.passwHash
697
679
  })
698
680
  });
699
681
  const text = await res.text();
@@ -701,14 +683,14 @@ async function createAgentNodeForInitialize(cred) {
701
683
  throw new Error(`Create failed (${String(res.status)}): ${text}`);
702
684
  }
703
685
  const json = JSON.parse(text);
704
- if (typeof json.agentId !== "string" || json.agentId !== agentNodeId) {
686
+ if (typeof json.agentId !== "string" || json.agentId !== agentCredential.nodeId) {
705
687
  throw new Error("Invalid agent creation response.");
706
688
  }
707
689
  const nextAgentNodes = [
708
- ...(cred.agentNodes ?? []).filter((n) => n.nodeId !== agentNodeId),
690
+ ...(cred.agentNodes ?? []).filter((n) => n.nodeId !== agentCredential.nodeId),
709
691
  {
710
- nodeId: agentNodeId,
711
- passw: agentPassw,
692
+ nodeId: agentCredential.nodeId,
693
+ passw: agentCredential.phrase,
712
694
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
713
695
  }
714
696
  ];
@@ -716,7 +698,7 @@ async function createAgentNodeForInitialize(cred) {
716
698
  ...cred,
717
699
  agentNodes: nextAgentNodes
718
700
  });
719
- return agentNodeId;
701
+ return agentCredential.nodeId;
720
702
  }
721
703
  async function cmdInspectNode() {
722
704
  const cred = await loadCredentials();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-play/cli",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "Command-line tool for Agent Play: node configurations, agent starter kit, and agent registration against the web UI.",
5
5
  "private": false,
6
6
  "type": "module",