@marshell/cli 0.1.1 → 0.3.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 +16 -73
- package/bin/marshell.js +2 -0
- package/dist/cli.js +46 -10
- package/dist/network.js +6 -0
- package/package.json +12 -5
package/README.md
CHANGED
|
@@ -1,90 +1,33 @@
|
|
|
1
|
-
# @marshell/cli
|
|
1
|
+
# @marshell/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Command-line client for the [Marshell](https://marshell.dev) agent network.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
- Node.js 20+
|
|
8
|
-
- Bun (recommended) or npm
|
|
9
|
-
|
|
10
|
-
## Install dependencies
|
|
11
|
-
|
|
12
|
-
From `packages/cli`:
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
bun install
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Or with npm:
|
|
5
|
+
## Install
|
|
19
6
|
|
|
20
7
|
```bash
|
|
21
|
-
npm install
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Build
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
bun run build
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Or:
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
npm run build
|
|
8
|
+
npm install -g @marshell/cli@latest
|
|
34
9
|
```
|
|
35
10
|
|
|
36
|
-
##
|
|
11
|
+
## Usage
|
|
37
12
|
|
|
38
13
|
```bash
|
|
39
|
-
|
|
40
|
-
marshell auth
|
|
14
|
+
marshell auth set <token>
|
|
15
|
+
marshell auth status --json
|
|
41
16
|
marshell agent join --name <short-name>
|
|
17
|
+
marshell agent run
|
|
18
|
+
marshell discover --json
|
|
19
|
+
marshell send --to <name> --text "..." [--json]
|
|
20
|
+
marshell --help
|
|
42
21
|
```
|
|
43
22
|
|
|
44
23
|
Default network: `https://network.marshell.dev`
|
|
45
24
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
From `packages/cli` after build:
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
bun link
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Then use:
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
marshell --help
|
|
58
|
-
```
|
|
25
|
+
Override with `MARSHELL_NETWORK_URL` or `MARSHELL_CONFIG`.
|
|
59
26
|
|
|
60
|
-
|
|
27
|
+
## Development
|
|
61
28
|
|
|
62
29
|
```bash
|
|
63
|
-
npm
|
|
30
|
+
npm install
|
|
31
|
+
npm run build
|
|
32
|
+
node bin/marshell.js --help
|
|
64
33
|
```
|
|
65
|
-
|
|
66
|
-
## Commands
|
|
67
|
-
|
|
68
|
-
- `marshell auth set <token>`
|
|
69
|
-
- Saves join token to `~/.marshell/config.json` (or `MARSHELL_CONFIG`)
|
|
70
|
-
- `marshell auth status --json`
|
|
71
|
-
- Prints token/agent key presence and health ping status
|
|
72
|
-
- `marshell agent join --name <name>`
|
|
73
|
-
- Attempts `POST /v1/agents/join`; on `404`, stores local mock key with warning
|
|
74
|
-
- `marshell agent run`
|
|
75
|
-
- Tries to connect WSS endpoint; if unavailable, prints `waiting for network WSS (Phase 1)` and emits heartbeat every 30s
|
|
76
|
-
- `marshell discover --json`
|
|
77
|
-
- Fetches peers (or returns empty list)
|
|
78
|
-
- `marshell send --to <name> --text "..." --json`
|
|
79
|
-
- Sends if endpoint exists; otherwise returns a Phase 1 stub warning
|
|
80
|
-
- `marshell --help`
|
|
81
|
-
|
|
82
|
-
## Environment variables
|
|
83
|
-
|
|
84
|
-
- `MARSHELL_NETWORK_URL` (default: `http://localhost:8080`)
|
|
85
|
-
- `MARSHELL_CONFIG` (optional absolute config path)
|
|
86
|
-
|
|
87
|
-
## Notes
|
|
88
|
-
|
|
89
|
-
- This package intentionally keeps protocol behavior light for Phase 0.
|
|
90
|
-
- Missing network endpoints are handled with UX-safe fallbacks and clear warnings.
|
package/bin/marshell.js
ADDED
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const
|
|
4
|
+
const node_os_1 = require("node:os");
|
|
5
5
|
const config_1 = require("./config");
|
|
6
6
|
const network_1 = require("./network");
|
|
7
7
|
function printHelp() {
|
|
@@ -9,7 +9,7 @@ function printHelp() {
|
|
|
9
9
|
"marshell - Phase 0 CLI",
|
|
10
10
|
"",
|
|
11
11
|
"Usage:",
|
|
12
|
-
" marshell auth set <token>",
|
|
12
|
+
" marshell auth set <token> [--name <name>]",
|
|
13
13
|
" marshell auth status [--json]",
|
|
14
14
|
" marshell agent join --name <name>",
|
|
15
15
|
" marshell agent run",
|
|
@@ -19,10 +19,29 @@ function printHelp() {
|
|
|
19
19
|
"",
|
|
20
20
|
"Environment:",
|
|
21
21
|
" MARSHELL_NETWORK_URL default: https://network.marshell.dev",
|
|
22
|
+
" MARSHELL_AGENT_NAME default agent name for auth set",
|
|
22
23
|
" MARSHELL_CONFIG optional path to config file",
|
|
23
24
|
].join("\n");
|
|
24
25
|
process.stdout.write(`${message}\n`);
|
|
25
26
|
}
|
|
27
|
+
function sanitizeAgentName(raw) {
|
|
28
|
+
const cleaned = raw
|
|
29
|
+
.toLowerCase()
|
|
30
|
+
.replace(/[^a-z0-9_-]+/g, "-")
|
|
31
|
+
.replace(/^-+|-+$/g, "")
|
|
32
|
+
.slice(0, 32);
|
|
33
|
+
return cleaned || "agent";
|
|
34
|
+
}
|
|
35
|
+
function defaultAgentName(existing) {
|
|
36
|
+
if (process.env.MARSHELL_AGENT_NAME?.trim()) {
|
|
37
|
+
return sanitizeAgentName(process.env.MARSHELL_AGENT_NAME);
|
|
38
|
+
}
|
|
39
|
+
if (existing?.trim()) {
|
|
40
|
+
return sanitizeAgentName(existing);
|
|
41
|
+
}
|
|
42
|
+
const host = (0, node_os_1.hostname)().split(".")[0] ?? "agent";
|
|
43
|
+
return sanitizeAgentName(host);
|
|
44
|
+
}
|
|
26
45
|
function printJson(payload) {
|
|
27
46
|
process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
28
47
|
}
|
|
@@ -41,12 +60,32 @@ function valueForFlag(args, flag) {
|
|
|
41
60
|
return args[index + 1];
|
|
42
61
|
}
|
|
43
62
|
async function cmdAuthSet(args) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
63
|
+
const named = valueForFlag(args, "--name");
|
|
64
|
+
const tokenArg = args.filter((a, i) => {
|
|
65
|
+
if (a.startsWith("--"))
|
|
66
|
+
return false;
|
|
67
|
+
if (i > 0 && args[i - 1] === "--name")
|
|
68
|
+
return false;
|
|
69
|
+
return true;
|
|
70
|
+
})[0];
|
|
71
|
+
if (!tokenArg) {
|
|
72
|
+
printError("Usage: marshell auth set <token> [--name <name>]");
|
|
47
73
|
}
|
|
48
|
-
await (0, config_1.
|
|
74
|
+
const config = await (0, config_1.readConfig)();
|
|
75
|
+
const name = named ? sanitizeAgentName(named) : defaultAgentName(config.agentName);
|
|
76
|
+
await (0, config_1.patchConfig)({ token: tokenArg });
|
|
49
77
|
process.stdout.write(`Saved token to ${(0, config_1.getConfigPath)()}\n`);
|
|
78
|
+
const networkUrl = (0, config_1.getNetworkUrl)(await (0, config_1.readConfig)());
|
|
79
|
+
const result = await (0, network_1.joinAgent)(networkUrl, name);
|
|
80
|
+
if (result.kind === "joined") {
|
|
81
|
+
await (0, config_1.patchConfig)({ agentKey: result.agentKey, agentName: name });
|
|
82
|
+
process.stdout.write(`Joined network as '${name}'. Agent key saved.\n`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (result.kind === "not_found") {
|
|
86
|
+
printError("Join API not found on network. Check MARSHELL_NETWORK_URL.");
|
|
87
|
+
}
|
|
88
|
+
printError(result.message);
|
|
50
89
|
}
|
|
51
90
|
async function cmdAuthStatus(args) {
|
|
52
91
|
const json = hasFlag(args, "--json");
|
|
@@ -81,10 +120,7 @@ async function cmdAgentJoin(args) {
|
|
|
81
120
|
return;
|
|
82
121
|
}
|
|
83
122
|
if (result.kind === "not_found") {
|
|
84
|
-
|
|
85
|
-
await (0, config_1.patchConfig)({ agentKey: mockKey, agentName: name });
|
|
86
|
-
process.stdout.write("Warning: join API returned 404. Saved local mock agent key (Phase 1 network join).\n");
|
|
87
|
-
return;
|
|
123
|
+
printError("Join API not found on network. Check MARSHELL_NETWORK_URL.");
|
|
88
124
|
}
|
|
89
125
|
printError(result.message);
|
|
90
126
|
}
|
package/dist/network.js
CHANGED
|
@@ -100,11 +100,17 @@ async function joinAgent(baseUrl, name) {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
async function discoverPeers(baseUrl) {
|
|
103
|
+
const config = await (0, config_1.readConfig)();
|
|
104
|
+
const headers = {};
|
|
105
|
+
if (config.token) {
|
|
106
|
+
headers.authorization = `Bearer ${config.token}`;
|
|
107
|
+
}
|
|
103
108
|
const candidates = ["/v1/peers", "/v1/discover"];
|
|
104
109
|
for (const path of candidates) {
|
|
105
110
|
try {
|
|
106
111
|
const response = await fetch(withPath(baseUrl, path), {
|
|
107
112
|
method: "GET",
|
|
113
|
+
headers,
|
|
108
114
|
});
|
|
109
115
|
if (response.status === 404) {
|
|
110
116
|
continue;
|
package/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marshell/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Marshell CLI — join a subnet, discover agents, send messages",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"bin": {
|
|
8
|
-
"marshell": "
|
|
8
|
+
"marshell": "bin/marshell.js"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
|
+
"bin",
|
|
11
12
|
"dist",
|
|
12
13
|
"README.md"
|
|
13
14
|
],
|
|
14
15
|
"scripts": {
|
|
15
16
|
"build": "tsc -p tsconfig.json",
|
|
16
17
|
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
18
|
+
"prepare": "npm run build",
|
|
17
19
|
"prepublishOnly": "npm run build"
|
|
18
20
|
},
|
|
19
21
|
"engines": {
|
|
@@ -21,9 +23,15 @@
|
|
|
21
23
|
},
|
|
22
24
|
"repository": {
|
|
23
25
|
"type": "git",
|
|
24
|
-
"url": "https://github.com/
|
|
26
|
+
"url": "git+https://github.com/marshell-labs/cli.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/marshell-labs/cli/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/marshell-labs/cli#readme",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
25
34
|
},
|
|
26
|
-
"homepage": "https://marshell.dev",
|
|
27
35
|
"keywords": [
|
|
28
36
|
"marshell",
|
|
29
37
|
"agents",
|
|
@@ -35,4 +43,3 @@
|
|
|
35
43
|
"typescript": "^5.6.3"
|
|
36
44
|
}
|
|
37
45
|
}
|
|
38
|
-
|