@infernetprotocol/cli 0.1.22

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.
Files changed (50) hide show
  1. package/LICENSE +15 -0
  2. package/commands/chat.js +268 -0
  3. package/commands/console.js +229 -0
  4. package/commands/debug.js +222 -0
  5. package/commands/deploy.js +524 -0
  6. package/commands/doctor.js +501 -0
  7. package/commands/firewall.js +39 -0
  8. package/commands/gpu.js +130 -0
  9. package/commands/help.js +54 -0
  10. package/commands/init.js +304 -0
  11. package/commands/login.js +305 -0
  12. package/commands/logs.js +93 -0
  13. package/commands/model.js +359 -0
  14. package/commands/payments.js +92 -0
  15. package/commands/payout.js +128 -0
  16. package/commands/pubkey.js +116 -0
  17. package/commands/register.js +304 -0
  18. package/commands/remove.js +230 -0
  19. package/commands/service.js +255 -0
  20. package/commands/setup.js +869 -0
  21. package/commands/start.js +903 -0
  22. package/commands/stats.js +85 -0
  23. package/commands/status.js +116 -0
  24. package/commands/stop.js +81 -0
  25. package/commands/train.js +563 -0
  26. package/commands/tui.js +285 -0
  27. package/commands/uncensored.js +222 -0
  28. package/commands/update.js +80 -0
  29. package/commands/upgrade.js +2 -0
  30. package/examples/app.js +153 -0
  31. package/index.js +207 -0
  32. package/lib/chat-executor.js +232 -0
  33. package/lib/config.js +148 -0
  34. package/lib/daemonize.js +46 -0
  35. package/lib/firewall.js +190 -0
  36. package/lib/hf-model.js +166 -0
  37. package/lib/identity.js +18 -0
  38. package/lib/ipc.js +114 -0
  39. package/lib/model-fit.js +67 -0
  40. package/lib/model-key.js +52 -0
  41. package/lib/network.js +240 -0
  42. package/lib/nip44.js +130 -0
  43. package/lib/node-client.js +152 -0
  44. package/lib/peers.js +133 -0
  45. package/lib/prompt.js +49 -0
  46. package/lib/remote-chat.js +115 -0
  47. package/lib/route.js +44 -0
  48. package/lib/runtime-config.js +130 -0
  49. package/lib/version.js +32 -0
  50. package/package.json +57 -0
@@ -0,0 +1,222 @@
1
+ /**
2
+ * `infernet debug` — one command that dumps everything you'd want to
3
+ * paste into a bug report or support chat. Bundles:
4
+ *
5
+ * - CLI version + control-plane commit + timestamp
6
+ * - Sanitized config (bearer tokens + private keys redacted)
7
+ * - Daemon status + stats (uptime, heartbeat counters, last error)
8
+ * - Last 60 lines of the daemon log
9
+ * - Local Ollama state (models pulled, version)
10
+ * - Control-plane "self" row from /api/v1/node/me (signed)
11
+ * - This node's entry in /api/peers (last_seen, served_models, etc.)
12
+ * - `infernet doctor --skip-e2e` summary
13
+ *
14
+ * Sensitive values redacted:
15
+ * - auth.bearerToken
16
+ * - node.privateKey
17
+ * - public IP + port (the daemon advertises these on the network so
18
+ * they're not really secret, but we redact anyway because someone
19
+ * pasting `infernet debug` in a public chat may not realize)
20
+ */
21
+
22
+ import fs from "node:fs/promises";
23
+ import { getDaemonLogPath, getConfigPath, loadConfig } from "../lib/config.js";
24
+ import { isDaemonAlive, sendToDaemon } from "../lib/ipc.js";
25
+ import { createNodeClient } from "../lib/node-client.js";
26
+ import doctor from "./doctor.js";
27
+
28
+ const HELP = `infernet debug — dump diagnostic bundle for support / bug reports
29
+
30
+ Usage:
31
+ infernet debug [flags]
32
+
33
+ Flags:
34
+ --no-redact Don't redact tokens / private keys / public address.
35
+ Use ONLY when sharing privately. Default: redact.
36
+ --log-lines <n> Daemon log tail size (default 60).
37
+ --help
38
+
39
+ What it does:
40
+ Runs every diagnostic at once and prints a single Markdown-formatted
41
+ bundle you can copy-paste into a bug report. Sensitive values are
42
+ redacted by default. Nothing is uploaded — output is local stdout.
43
+ `;
44
+
45
+ const REDACTED = "<redacted>";
46
+
47
+ function section(title) {
48
+ process.stdout.write(`\n## ${title}\n\n`);
49
+ }
50
+
51
+ function codeBlock(lang, body) {
52
+ process.stdout.write("```");
53
+ process.stdout.write(lang ?? "");
54
+ process.stdout.write("\n");
55
+ process.stdout.write(body.replace(/\n$/, ""));
56
+ process.stdout.write("\n```\n");
57
+ }
58
+
59
+ function jsonBlock(obj) {
60
+ codeBlock("json", JSON.stringify(obj, null, 2));
61
+ }
62
+
63
+ function sanitizeConfig(cfg, redact) {
64
+ if (!cfg) return cfg;
65
+ if (!redact) return cfg;
66
+ const out = JSON.parse(JSON.stringify(cfg));
67
+ if (out.auth?.bearerToken) out.auth.bearerToken = REDACTED;
68
+ if (out.node?.privateKey) out.node.privateKey = REDACTED;
69
+ if (out.node?.address) out.node.address = REDACTED;
70
+ if (typeof out.node?.port === "number") out.node.port = "<redacted>";
71
+ return out;
72
+ }
73
+
74
+ async function probeHealth(baseUrl) {
75
+ if (!baseUrl) return { error: "no controlPlane.url in config" };
76
+ try {
77
+ const res = await fetch(new URL("/api/health", baseUrl), {
78
+ signal: AbortSignal.timeout?.(5000)
79
+ });
80
+ if (!res.ok) return { http: res.status };
81
+ return await res.json();
82
+ } catch (err) {
83
+ return { error: err?.message ?? String(err) };
84
+ }
85
+ }
86
+
87
+ async function probeOllama(host) {
88
+ if (!host) return { error: "no engine.ollamaHost in config" };
89
+ try {
90
+ const res = await fetch(new URL("/api/tags", host), {
91
+ signal: AbortSignal.timeout?.(3000)
92
+ });
93
+ if (!res.ok) return { http: res.status };
94
+ const json = await res.json();
95
+ return {
96
+ models: (json.models ?? []).map((m) => ({
97
+ name: m.name ?? m.model,
98
+ size_gb: typeof m.size === "number" ? +(m.size / 1024 / 1024 / 1024).toFixed(2) : null
99
+ }))
100
+ };
101
+ } catch (err) {
102
+ return { error: err?.message ?? String(err) };
103
+ }
104
+ }
105
+
106
+ async function probeSelfRow(config) {
107
+ if (!config?.controlPlane?.url || !config?.node?.publicKey) {
108
+ return { skipped: "no control-plane URL or pubkey in config" };
109
+ }
110
+ try {
111
+ const client = createNodeClient({
112
+ url: config.controlPlane.url,
113
+ publicKey: config.node.publicKey,
114
+ privateKey: config.node.privateKey,
115
+ role: config.node.role ?? "provider",
116
+ timeoutMs: 5000
117
+ });
118
+ const resp = await client.me();
119
+ return resp?.row ?? { row: null };
120
+ } catch (err) {
121
+ return { error: err?.message ?? String(err), status: err?.status };
122
+ }
123
+ }
124
+
125
+ async function probePeerEntry(config) {
126
+ if (!config?.controlPlane?.url || !config?.node?.publicKey) {
127
+ return { skipped: "no control-plane URL or pubkey" };
128
+ }
129
+ try {
130
+ const res = await fetch(
131
+ new URL("/api/peers?limit=100", config.controlPlane.url),
132
+ { signal: AbortSignal.timeout?.(5000) }
133
+ );
134
+ if (!res.ok) return { http: res.status };
135
+ const body = await res.json();
136
+ const me = (body.data ?? []).find((p) => p.pubkey === config.node.publicKey);
137
+ return me ?? { not_in_peer_list: true, total_peers: (body.data ?? []).length };
138
+ } catch (err) {
139
+ return { error: err?.message ?? String(err) };
140
+ }
141
+ }
142
+
143
+ async function probeDaemonSnapshot() {
144
+ const alive = await isDaemonAlive(500);
145
+ if (!alive) return { running: false };
146
+ try {
147
+ const reply = await sendToDaemon({ kind: "snapshot" }, 1500);
148
+ return { running: true, snapshot: reply };
149
+ } catch (err) {
150
+ return { running: true, error: err?.message ?? String(err) };
151
+ }
152
+ }
153
+
154
+ async function tailLog(path, n) {
155
+ try {
156
+ const text = await fs.readFile(path, "utf8");
157
+ const lines = text.split("\n");
158
+ return lines.slice(-n).join("\n");
159
+ } catch (err) {
160
+ return `(no log at ${path}: ${err?.message ?? err})`;
161
+ }
162
+ }
163
+
164
+ export default async function debugCommand(args) {
165
+ if (args.has("help") || args.has("h")) {
166
+ process.stdout.write(HELP);
167
+ return 0;
168
+ }
169
+
170
+ const redact = !args.has("no-redact");
171
+ const logLines = Number.parseInt(args.get("log-lines") ?? "60", 10) || 60;
172
+
173
+ const config = (await loadConfig()) ?? {};
174
+ const baseUrl = config?.controlPlane?.url ?? null;
175
+
176
+ process.stdout.write(`# infernet debug bundle\n`);
177
+ process.stdout.write(`generated: ${new Date().toISOString()}\n`);
178
+ process.stdout.write(`config: ${getConfigPath()}\n`);
179
+ process.stdout.write(`redacted: ${redact ? "yes (use --no-redact in private channels)" : "NO — values are visible"}\n`);
180
+
181
+ section("Control plane");
182
+ jsonBlock(await probeHealth(baseUrl));
183
+
184
+ section("Local config (sanitized)");
185
+ jsonBlock(sanitizeConfig(config, redact));
186
+
187
+ section("Daemon snapshot");
188
+ jsonBlock(await probeDaemonSnapshot());
189
+
190
+ section("Daemon log (last " + logLines + " lines)");
191
+ codeBlock("", await tailLog(getDaemonLogPath(), logLines));
192
+
193
+ section("Local Ollama");
194
+ jsonBlock(await probeOllama(config?.engine?.ollamaHost));
195
+
196
+ section("Self row on control plane (signed /api/v1/node/me)");
197
+ jsonBlock(await probeSelfRow(config));
198
+
199
+ section("Self entry in /api/peers");
200
+ jsonBlock(await probePeerEntry(config));
201
+
202
+ section("Doctor (skip-e2e, json)");
203
+ process.stdout.write("```\n");
204
+ // Re-use doctor with --skip-e2e --json so the bundle stays parseable.
205
+ const fakeArgs = {
206
+ positional: [],
207
+ flags: new Map([["skip-e2e", true], ["json", true]]),
208
+ has(name) { return this.flags.has(name); },
209
+ get(name) { const v = this.flags.get(name); return v === true ? undefined : v; }
210
+ };
211
+ try {
212
+ await doctor(fakeArgs);
213
+ } catch (err) {
214
+ process.stdout.write(`doctor threw: ${err?.message ?? err}\n`);
215
+ }
216
+ process.stdout.write("```\n");
217
+
218
+ process.stdout.write(`\n---\nEnd of bundle. Paste this into a bug report or support chat.\n`);
219
+ return 0;
220
+ }
221
+
222
+ export { HELP };