@netnodeag/kraftwerk 0.76.0 → 0.77.0

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 (45) hide show
  1. package/README.md +33 -27
  2. package/dist/cli/cloud.d.ts +2 -0
  3. package/dist/cli/cloud.js +262 -0
  4. package/dist/cli/daemon.js +9 -0
  5. package/dist/cli/doctor.js +16 -8
  6. package/dist/cli/init.js +2 -2
  7. package/dist/cli/kraftwerk.js +4 -0
  8. package/dist/client/routes.d.ts +4 -0
  9. package/dist/client/routes.js +4 -0
  10. package/dist/config.d.ts +15 -28
  11. package/dist/config.js +5 -19
  12. package/dist/core/cloud.d.ts +115 -0
  13. package/dist/core/cloud.js +94 -0
  14. package/dist/server/api/cloud.d.ts +72 -0
  15. package/dist/server/api/cloud.js +38 -0
  16. package/dist/server/api/devices.d.ts +8 -8
  17. package/dist/server/api/index.d.ts +88 -10
  18. package/dist/server/api/index.js +2 -0
  19. package/dist/server/api/workspace.d.ts +16 -1
  20. package/dist/server/api/workspace.js +2 -1
  21. package/dist/server/cloud.d.ts +65 -33
  22. package/dist/server/cloud.js +207 -188
  23. package/dist/server/hub-context.d.ts +1 -1
  24. package/dist/server/hub-context.js +3 -3
  25. package/dist/server/relay.d.ts +13 -0
  26. package/dist/server/relay.js +29 -1
  27. package/dist/server/server.d.ts +3 -2
  28. package/dist/server/server.js +6 -6
  29. package/package.json +1 -1
  30. package/schema/kraftwerk.schema.json +4 -4
  31. package/web/dist/assets/{dist-T1sNLC62.js → dist-BGHweZKi.js} +1 -1
  32. package/web/dist/assets/{dist-DFXmaDc5.js → dist-BVPxOqcx.js} +1 -1
  33. package/web/dist/assets/{dist-BYkcY-Vl.js → dist-CCNyRSAA.js} +1 -1
  34. package/web/dist/assets/{dist-flnLXEzU.js → dist-CXoAMU1b.js} +1 -1
  35. package/web/dist/assets/{dist-l7foWlFx.js → dist-DCFREMXk.js} +1 -1
  36. package/web/dist/assets/{dist-BQpWYkxm.js → dist-DT2Tjvwx.js} +1 -1
  37. package/web/dist/assets/{dist-BwIca_Uj.js → dist-DdA5PoVJ.js} +1 -1
  38. package/web/dist/assets/{dist-fgB7OEJy.js → dist-DoD3qX1P.js} +1 -1
  39. package/web/dist/assets/{dist-vuciRCSz.js → dist-FFA4-S6d.js} +1 -1
  40. package/web/dist/assets/{dist-BTVP-6On.js → dist-yGx0qYbw.js} +1 -1
  41. package/web/dist/assets/dist-zjUUP5a9.js +1 -0
  42. package/web/dist/assets/{editor-C6Ok8NPo.js → editor-CyWapLQr.js} +3 -3
  43. package/web/dist/assets/{index-z4tpCCzk.js → index-CNXcNoKJ.js} +4 -4
  44. package/web/dist/index.html +1 -1
  45. package/web/dist/assets/dist-BURf1l-A.js +0 -1
package/README.md CHANGED
@@ -296,8 +296,8 @@ fields are optional. `workflows:` sets the workflows root, `output:` the
296
296
  run-artifact directory (default `output/`), `knowledge:` the OKF bundle root
297
297
  (default `knowledge/`), and `agents:` the agent-definition root (default
298
298
  `agents/`). `repos:` turns on the [repositories](#repositories) folder.
299
- `cloud:` tunes (or turns off) the registration with the
300
- [kraftwerk cloud](#inspector-in-the-kraftwerk-cloud), which is on by default.
299
+ `cloud: { enabled: false }` leaves the workspace out of this machine's
300
+ record in the [kraftwerk cloud](#this-machine-in-the-kraftwerk-cloud).
301
301
 
302
302
  `name:` is the title shown in the UI and can change freely. `slug:` is the
303
303
  workspace's address on this machine. It defaults to the folder name
@@ -486,38 +486,44 @@ repo. Agent logins made inside the container persist in the `agent-home`
486
486
  volume. This is a different image from the `kraftwerk-runner` sandbox
487
487
  (`runner/Dockerfile`) used by `run --sandbox`.
488
488
 
489
- ### Inspector in the kraftwerk cloud
489
+ ### This machine in the kraftwerk cloud
490
490
 
491
491
  The kraftwerk cloud is the `~/.kraftwerk` registry made reachable over the
492
- internet: every `kraftwerk ui` registers there when it starts and sends a
493
- heartbeat while it runs, so you can see from anywhere which of your
494
- workspaces are up, on which machine, with which agents — and an admin sees
495
- every instance at once. **This is on by default.** The record carries the
496
- workspace name, icon and colour, the machine, the root, the version, and
497
- the agent and channel roster. Registration
498
- is best-effort: a cloud that is down never affects the UI.
499
-
500
- No key goes into kraftwerk.yml. The cloud hands the instance an identity
501
- (kept under `~/.kraftwerk/cloud/`, so a restart updates the record) and a
502
- **claim code**, shown under Settings → Cloud in the UI. Sign in at the
503
- cloud, type the code (or follow the "claim in the cloud" link), and the
504
- workspace appears under *My instances*; the instance learns about the claim
505
- with its next heartbeat.
492
+ internet: the daemon (`kraftwerk daemon`) registers **this machine** once
493
+ when it starts and sends a heartbeat while it runs; the workspaces it serves
494
+ ride along as children of that record, so you can see from anywhere which
495
+ of your workspaces are up, and where. **This is on by default.** A
496
+ standalone `kraftwerk ui` never registers. Registration is best-effort: a
497
+ cloud that is down never affects the UI.
498
+
499
+ The machine's id is its relay id (the key in `~/.kraftwerk/relay.json`,
500
+ created at the daemon's first start with the relay still off), proven with
501
+ the relay secret. Until someone claims the machine it registers
502
+ anonymously: workspace names, slugs and ids only, no paths. Claiming
503
+ happens in the browser — no password passes through the CLI:
504
+
505
+ ```bash
506
+ kraftwerk login --open # prints (and opens) the claim link and code, waits for the claim
507
+ kraftwerk cloud # registered? claimed? url, machine id, last heartbeat
508
+ kraftwerk logout # release the machine; a fresh claim code follows
509
+ kraftwerk cloud off # turn it off for this machine (the daemon says goodbye); `on [--url]` back on
510
+ ```
511
+
512
+ The claim code is also shown under Settings → Cloud. The switch and the
513
+ cloud's origin live in `~/.kraftwerk/cloud.json` (`{ "enabled": false,
514
+ "url": "…" }`); `KRAFTWERK_CLOUD_URL` in the environment wins (`off` turns
515
+ the feature off — what the test suites set). In kraftwerk.yml, `cloud:` is
516
+ a per-workspace veto only:
506
517
 
507
518
  ```yaml
508
519
  cloud:
509
- url: https://srv.kraftwerk-cloud.netnode.cloud # default
510
- interval: 60 # seconds between heartbeats (default 60)
511
- enabled: false # opt out of the cloud for this workspace
520
+ enabled: false # leave this workspace out of the machine's record
512
521
  ```
513
522
 
514
- `KRAFTWERK_CLOUD_URL` in the environment wins over the file (`off` turns the
515
- feature off everywhere — what the test suites set). A server that starts
516
- unattended and should register under an account without a claim puts an
517
- account token from the cloud UI into `.env` as `KRAFTWERK_CLOUD_TOKEN`; a
518
- `token:` key in kraftwerk.yml is refused. `/api/meta` reports the
519
- connection state and the claim code; `kraftwerk doctor` prints what the
520
- block will do.
523
+ (`cloud.url` there is deprecated — honored with a warning when the machine
524
+ names no origin — and `cloud.interval` is ignored: the cloud sets the
525
+ cadence.) `/api/meta` and `/api/cloud` report the machine's state and claim
526
+ code; `kraftwerk doctor` prints what happens to the workspace.
521
527
 
522
528
  ## Projects
523
529
 
@@ -0,0 +1,2 @@
1
+ import type { Command } from "commander";
2
+ export declare function registerCloudCommands(program: Command): void;
@@ -0,0 +1,262 @@
1
+ import { spawn } from "node:child_process";
2
+ import os from "node:os";
3
+ import chalk from "chalk";
4
+ import { CloudError, claimUrlFor, envCloudOff, machineCloud, machineGoodbye, machineHeartbeat, machineRegister, machineUnlink, writeCloudFile, } from "../core/cloud.js";
5
+ import { findDaemon } from "../core/daemon.js";
6
+ import { identityString, readIdentity } from "../core/identity.js";
7
+ import { relayId, fromBase64Url } from "../client/relay.js";
8
+ import { machineCredentials, readRelaySettings } from "../server/relay.js";
9
+ import { getPkgVersion } from "../server/version.js";
10
+ const POLL_MS = 2000;
11
+ async function daemonCloud(port, method, route, body) {
12
+ const r = await fetch(`http://127.0.0.1:${port}${route}`, {
13
+ method,
14
+ headers: body ? { "content-type": "application/json" } : {},
15
+ ...(body ? { body: JSON.stringify(body) } : {}),
16
+ signal: AbortSignal.timeout(15_000),
17
+ });
18
+ const data = (await r.json().catch(() => ({})));
19
+ if (!r.ok)
20
+ throw new Error(data.error ?? `${r.status} from the daemon`);
21
+ return data;
22
+ }
23
+ const fail = (message, code = 1) => {
24
+ console.error(chalk.red(`✖ ${message}`));
25
+ process.exit(code);
26
+ };
27
+ function openBrowser(url) {
28
+ const [cmd, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
29
+ try {
30
+ spawn(cmd, args, { stdio: "ignore", detached: true }).unref();
31
+ }
32
+ catch { }
33
+ }
34
+ /** The machine's id without creating a key: null before the daemon's first start (or `kraftwerk login`). */
35
+ async function machineIdIfAny() {
36
+ const s = await readRelaySettings();
37
+ return s ? relayId(fromBase64Url(s.publicKey)) : null;
38
+ }
39
+ async function hello() {
40
+ const id = await readIdentity();
41
+ return { name: id.machine, handle: id.handle, hostname: os.hostname(), platform: `${process.platform}-${process.arch}`, version: await getPkgVersion() };
42
+ }
43
+ function printClaim(st) {
44
+ if (!st.claimCode)
45
+ return;
46
+ console.log(` claim code ${chalk.bold(st.claimCode)}`);
47
+ console.log(` claim link ${chalk.cyan(st.claimUrl ?? claimUrlFor(st.url, st.claimCode) ?? "")}`);
48
+ }
49
+ async function showStatus(opts) {
50
+ const [cloud, identity, id, daemon] = await Promise.all([machineCloud(), readIdentity(), machineIdIfAny(), findDaemon()]);
51
+ const live = daemon ? await daemonCloud(daemon.port, "GET", "/api/cloud").catch(() => null) : null;
52
+ const out = {
53
+ enabled: cloud.enabled,
54
+ url: cloud.url,
55
+ source: cloud.source,
56
+ ...(cloud.reason ? { reason: cloud.reason } : {}),
57
+ machine: identityString(identity),
58
+ id,
59
+ daemon: !!daemon,
60
+ state: live?.state ?? "off",
61
+ registered: live?.state === "connected",
62
+ claimed: !!live?.account,
63
+ account: live?.account ?? null,
64
+ claimCode: live?.claimCode ?? null,
65
+ claimUrl: live?.claimUrl ?? null,
66
+ lastSeen: live?.lastSeen ?? null,
67
+ interval: live?.interval ?? null,
68
+ workspaces: live?.workspaces ?? null,
69
+ ...(live?.error ? { error: live.error } : {}),
70
+ };
71
+ if (opts.json)
72
+ return void console.log(JSON.stringify(out, null, 2));
73
+ const dot = !cloud.enabled ? chalk.dim("○") : out.claimed ? chalk.green("●") : out.registered ? chalk.yellow("●") : chalk.dim("●");
74
+ console.log(`${dot} kraftwerk cloud ${cloud.enabled ? chalk.green("on") : chalk.dim("off")} ${chalk.dim(`${cloud.url} (${cloud.source})`)}`);
75
+ if (!cloud.enabled)
76
+ console.log(chalk.dim(` ${cloud.reason}`));
77
+ console.log(` machine ${identityString(identity)} ${chalk.dim(id ?? "no id yet — created at the daemon's first start")}`);
78
+ if (!cloud.enabled)
79
+ return;
80
+ if (!daemon) {
81
+ console.log(` state ${chalk.dim("not reporting — the daemon registers this machine (`kraftwerk daemon start`)")}`);
82
+ return;
83
+ }
84
+ if (!live)
85
+ return void console.log(` state ${chalk.yellow("the daemon did not answer")}`);
86
+ if (live.state === "error")
87
+ console.log(` state ${chalk.red("error")} ${chalk.dim(live.error ?? "")}`);
88
+ else if (live.state !== "connected")
89
+ console.log(` state ${live.state}`);
90
+ else if (live.account)
91
+ console.log(` state ${chalk.green("claimed")} by ${chalk.bold(live.account)}`);
92
+ else
93
+ console.log(` state ${chalk.yellow("registered, unclaimed")} ${chalk.dim("— `kraftwerk login` claims it")}`);
94
+ if (live.state === "connected" && !live.account)
95
+ printClaim(live);
96
+ if (live.lastSeen)
97
+ console.log(` heartbeat ${new Date(live.lastSeen).toLocaleTimeString()} ${chalk.dim(`every ${live.interval ?? 60}s · ${live.workspaces ?? 0} workspace${live.workspaces === 1 ? "" : "s"} reported`)}`);
98
+ }
99
+ async function setEnabled(enabled, url) {
100
+ if (url && !/^https?:\/\/[^/?#]+\/?$/.test(url))
101
+ fail("--url is the cloud's origin, e.g. https://srv.kraftwerk-cloud.netnode.cloud", 2);
102
+ await writeCloudFile({ enabled, url });
103
+ const cloud = await machineCloud();
104
+ const daemon = await findDaemon();
105
+ // The daemon follows at once (off: goodbye); best-effort — the file is what counts at its next start.
106
+ const live = daemon ? await daemonCloud(daemon.port, "POST", "/api/cloud", { enabled, ...(url ? { url } : {}) }).catch(() => null) : null;
107
+ if (!enabled) {
108
+ console.log(`${chalk.green("✔")} cloud off for this machine ${chalk.dim(daemon ? (live ? "— the daemon said goodbye" : "— the daemon did not answer; it stops reporting at its next start") : "")}`);
109
+ return;
110
+ }
111
+ if (envCloudOff())
112
+ console.log(chalk.yellow("⚠ KRAFTWERK_CLOUD_URL=off in this environment keeps it off here"));
113
+ console.log(`${chalk.green("✔")} cloud on for this machine: ${chalk.cyan(cloud.url)}`);
114
+ if (!daemon)
115
+ console.log(chalk.dim(" the daemon registers this machine when it runs (`kraftwerk daemon start`); `kraftwerk login` claims it"));
116
+ else if (live?.state === "connected")
117
+ console.log(chalk.dim(live.account ? ` registered, claimed by ${live.account}` : " registered — `kraftwerk login` claims it"));
118
+ else if (live?.state === "error")
119
+ console.log(chalk.yellow(` the cloud did not answer: ${live.error ?? ""} (the daemon retries)`));
120
+ }
121
+ async function session() {
122
+ const daemon = await findDaemon();
123
+ if (daemon) {
124
+ const port = daemon.port;
125
+ // Off in the daemon (it read cloud.json before `login` turned it on): turning it on registers.
126
+ let first = true;
127
+ return {
128
+ status: async () => {
129
+ const st = first ? await daemonCloud(port, "POST", "/api/cloud", { enabled: true }) : await daemonCloud(port, "POST", "/api/cloud/sync");
130
+ first = false;
131
+ return st;
132
+ },
133
+ end: async () => { },
134
+ };
135
+ }
136
+ const cloud = await machineCloud();
137
+ const version = await getPkgVersion();
138
+ const creds = await machineCredentials();
139
+ let registered = false;
140
+ return {
141
+ status: async () => {
142
+ try {
143
+ const r = registered ? await machineHeartbeat(cloud.url, creds, { version }) : await machineRegister(cloud.url, creds, await hello(), []);
144
+ registered = true;
145
+ return { state: "connected", url: cloud.url, account: r.account, claimCode: r.claimCode, claimUrl: claimUrlFor(cloud.url, r.claimCode) };
146
+ }
147
+ catch (err) {
148
+ if (err instanceof CloudError && err.status === 403)
149
+ throw new Error(`${cloud.url} refuses this machine's secret (403) — another machine holds this id`);
150
+ return { state: "error", url: cloud.url, error: err.message };
151
+ }
152
+ },
153
+ // Without a daemon nothing reports afterwards: the record says so now instead of after the grace period.
154
+ end: async () => {
155
+ if (registered)
156
+ await machineGoodbye(cloud.url, creds, version).catch(() => { });
157
+ },
158
+ };
159
+ }
160
+ async function login(opts) {
161
+ if (envCloudOff())
162
+ fail("KRAFTWERK_CLOUD_URL=off in this environment — unset it to log in", 2);
163
+ const timeout = Number(opts.timeout ?? 600);
164
+ if (!Number.isFinite(timeout) || timeout <= 0)
165
+ fail("--timeout must be a positive number of seconds", 2);
166
+ const before = await machineCloud();
167
+ if (!before.enabled) {
168
+ await writeCloudFile({ enabled: true });
169
+ console.log(chalk.dim("cloud turned on for this machine (`kraftwerk cloud off` turns it off)"));
170
+ }
171
+ const s = await session().catch((err) => fail(err.message));
172
+ try {
173
+ let st = await s.status();
174
+ if (st.state === "off")
175
+ fail(`the daemon keeps the cloud off: ${st.reason ?? "off"}`);
176
+ if (st.state !== "connected")
177
+ fail(`could not reach ${st.url}: ${st.error ?? st.state}`);
178
+ if (st.account) {
179
+ console.log(`${chalk.green("✔")} already logged in as ${chalk.bold(st.account)} ${chalk.dim(`(${st.url}) — \`kraftwerk logout\` releases this machine`)}`);
180
+ return;
181
+ }
182
+ if (!st.claimCode)
183
+ fail(`${st.url} handed out no claim code`);
184
+ console.log(`Sign in (or sign up) in the browser and claim this machine:`);
185
+ printClaim(st);
186
+ if (opts.open && st.claimUrl)
187
+ openBrowser(st.claimUrl);
188
+ console.log(chalk.dim(`waiting for the claim … (Ctrl-C stops; the code stays valid)`));
189
+ const until = Date.now() + timeout * 1000;
190
+ while (Date.now() < until) {
191
+ await new Promise((r) => setTimeout(r, Math.min(POLL_MS, Math.max(0, until - Date.now()))));
192
+ st = await s.status().catch((err) => ({ ...st, state: "error", error: err.message }));
193
+ if (st.account) {
194
+ console.log(`${chalk.green("✔")} logged in as ${chalk.bold(st.account)} ${chalk.dim(`— this machine is in your account at ${st.url}`)}`);
195
+ return;
196
+ }
197
+ }
198
+ fail(`not claimed within ${timeout}s — the code stays valid; \`kraftwerk login\` waits again`);
199
+ }
200
+ finally {
201
+ await s.end();
202
+ }
203
+ }
204
+ async function logout() {
205
+ if (envCloudOff())
206
+ fail("KRAFTWERK_CLOUD_URL=off in this environment", 2);
207
+ const cloud = await machineCloud();
208
+ if (!cloud.enabled)
209
+ fail(`the cloud is off for this machine — ${cloud.reason}`, 2);
210
+ const daemon = await findDaemon();
211
+ let st;
212
+ if (daemon) {
213
+ st = await daemonCloud(daemon.port, "POST", "/api/cloud/unlink").catch((err) => fail(err.message));
214
+ }
215
+ else {
216
+ const creds = await machineCredentials();
217
+ const r = await machineUnlink(cloud.url, creds, await getPkgVersion()).catch((err) => fail(err instanceof CloudError && err.status === 404 ? `this machine is not registered at ${cloud.url}` : `${cloud.url}: ${err.message}`));
218
+ st = { url: cloud.url, claimCode: r.claimCode, claimUrl: claimUrlFor(cloud.url, r.claimCode) };
219
+ }
220
+ console.log(`${chalk.green("✔")} logged out — this machine is unclaimed at ${st.url}`);
221
+ printClaim(st);
222
+ console.log(chalk.dim(" `kraftwerk login` claims it again"));
223
+ }
224
+ export function registerCloudCommands(program) {
225
+ const cloud = program
226
+ .command("cloud")
227
+ .description("This machine in the kraftwerk cloud: status, on, off (`kraftwerk login` claims it)")
228
+ .option("--json", "Machine-readable output")
229
+ .addHelpText("after", `
230
+ The daemon registers this machine once; its open workspaces ride along.
231
+ kraftwerk cloud registered? claimed? url, machine id, last heartbeat
232
+ kraftwerk cloud on [--url <u>] turn it on (~/.kraftwerk/cloud.json); the daemon follows at once
233
+ kraftwerk cloud off turn it off; the running daemon says goodbye
234
+ kraftwerk login [--open] claim this machine into your account (in the browser)
235
+ kraftwerk logout release it
236
+ A workspace stays out with \`cloud: { enabled: false }\` in its kraftwerk.yml.`)
237
+ .action(async (opts) => showStatus(opts));
238
+ cloud
239
+ .command("status")
240
+ .description("Registered? claimed? url, machine id, last heartbeat")
241
+ .option("--json", "Machine-readable output")
242
+ .action(async (opts) => showStatus({ json: opts.json ?? cloud.opts().json }));
243
+ cloud
244
+ .command("on")
245
+ .description("Turn the cloud on for this machine (the running daemon registers at once)")
246
+ .option("--url <url>", "The cloud's origin (default: the kraftwerk cloud)")
247
+ .action(async (opts) => setEnabled(true, opts.url));
248
+ cloud
249
+ .command("off")
250
+ .description("Turn the cloud off for this machine (the running daemon says goodbye)")
251
+ .action(async () => setEnabled(false));
252
+ program
253
+ .command("login")
254
+ .description("Claim this machine into your kraftwerk cloud account: prints the claim link and code, waits for the claim")
255
+ .option("--open", "Open the claim link in the browser")
256
+ .option("--timeout <seconds>", "How long to wait for the claim", "600")
257
+ .action(async (opts) => login(opts));
258
+ program
259
+ .command("logout")
260
+ .description("Release this machine from its kraftwerk cloud account (a fresh claim code follows)")
261
+ .action(async () => logout());
262
+ }
@@ -2,6 +2,7 @@ import chalk from "chalk";
2
2
  import { DAEMON_PORT, daemonState, lastOpenRoots, setDaemonVersion, writeDaemonFile } from "../core/daemon.js";
3
3
  import { tildify } from "../core/instances.js";
4
4
  import { networkUrls } from "../server/bind.js";
5
+ import { startMachineCloud } from "../server/cloud.js";
5
6
  import { startPushWatcher } from "../server/push.js";
6
7
  import { applyRelay, relayPush } from "../server/relay.js";
7
8
  import { startHub } from "../server/server.js";
@@ -51,6 +52,14 @@ export async function runDaemon(opts) {
51
52
  console.log(` ${chalk.cyan(o.url)} ${chalk.dim(o.name)}${o.aliasPort ? chalk.dim(` · also :${o.aliasPort}`) : ""}`);
52
53
  if (!hub.list().length)
53
54
  console.log(chalk.dim(" no workspace open yet — `kraftwerk ui` in a workspace folder opens it here"));
55
+ // The machine in the kraftwerk cloud: registered once, the open workspaces as its children (`kraftwerk cloud`, `kraftwerk login`).
56
+ const cloud = await startMachineCloud({ version: await getPkgVersion(), workspaces: () => hub.list(), owner: hub });
57
+ if (cloud.state === "connected") {
58
+ console.log(`${chalk.green("✔")} Cloud: ${chalk.cyan(cloud.url)} ${chalk.dim(cloud.account ? `(claimed by ${cloud.account})` : `(unclaimed — \`kraftwerk login\` claims this machine)`)}`);
59
+ }
60
+ else if (cloud.state === "error") {
61
+ console.log(`${chalk.yellow("⚠")} Cloud: ${cloud.url} unreachable — ${cloud.error ?? "no answer"} ${chalk.dim("(retrying; nothing else depends on it)")}`);
62
+ }
54
63
  // The relay (`kraftwerk remote on`): devices reach this machine from anywhere, end to end encrypted.
55
64
  const relay = await applyRelay(hub.port, await getPkgVersion(), (line) => console.log(chalk.dim(line)));
56
65
  // What needs you, pushed to the phones that asked (through the relay, sealed per device).
@@ -2,7 +2,8 @@ import { spawnSync } from "node:child_process";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import chalk from "chalk";
5
- import { addWorkspaceId, cloudFor, ignoreEntryFor, isDir, reposRootFor, resolveWorkspace, workspaceSlug } from "../config.js";
5
+ import { machineCloud } from "../core/cloud.js";
6
+ import { addWorkspaceId, ignoreEntryFor, isDir, reposRootFor, resolveWorkspace, workspaceSlug } from "../config.js";
6
7
  import { discoverWorkflows } from "../discover.js";
7
8
  import { missingEnv } from "../yaml.js";
8
9
  import { applyDotenv, DOTENV_FILE } from "../dotenv.js";
@@ -177,15 +178,22 @@ export async function runDoctor(cwd, opts = {}) {
177
178
  report("warn", `${these.length} routine(s) name the retired identity ${old}`, `${names(these)} · \`kraftwerk doctor --fix\` moves them to ${me} and commits`);
178
179
  }
179
180
  }
180
- // Cloud manager: registration is best-effort at runtime, so doctor only says what would happen.
181
- const cloud = cloudFor(project);
182
- if (cloud) {
183
- report("ok", `cloud: ${cloud.url}`, cloud.token
184
- ? `registers under your kraftwerk account (KRAFTWERK_CLOUD_TOKEN), heartbeat every ${cloud.interval}s`
185
- : `on by default — the UI shows a claim code under Settings → Cloud; opt out with cloud.enabled: false`);
181
+ // The kraftwerk cloud: the daemon registers the machine; doctor only says what would happen to this workspace.
182
+ const ymlCloud = project.config.cloud;
183
+ const cloud = await machineCloud(ymlCloud?.url ? [ymlCloud.url] : []);
184
+ if (ymlCloud?.enabled === false) {
185
+ report("info", "cloud: this workspace is left out", "cloud.enabled: false in kraftwerk.yml — the machine's cloud record does not list it");
186
+ }
187
+ else if (!cloud.enabled) {
188
+ report("info", "cloud: off", cloud.reason ?? "");
186
189
  }
187
190
  else {
188
- report("info", "cloud: off", process.env.KRAFTWERK_CLOUD_URL?.trim().toLowerCase() === "off" ? "KRAFTWERK_CLOUD_URL=off" : "cloud.enabled: false in kraftwerk.yml");
191
+ report("ok", `cloud: ${cloud.url}`, "the daemon registers this machine and lists this workspace; `kraftwerk login` claims it, `kraftwerk cloud off` opts out");
192
+ }
193
+ if (ymlCloud?.url) {
194
+ report("warn", "kraftwerk.yml cloud.url is deprecated", cloud.source === "kraftwerk.yml"
195
+ ? `the cloud is the machine's now — \`kraftwerk cloud on --url ${ymlCloud.url}\`, then remove it from kraftwerk.yml`
196
+ : `ignored: the machine's cloud is ${cloud.url} (${cloud.source}) — remove it from kraftwerk.yml`);
189
197
  }
190
198
  const found = project.workflowsRoot ? await discoverWorkflows(cwd) : [];
191
199
  if (!project.workflowsRoot) {
package/dist/cli/init.js CHANGED
@@ -31,8 +31,8 @@ skills: ${DATA_DIR}/skills # workspace skills (shared instruction packag
31
31
  # root: ${DATA_DIR}/repos # clones land here (git-ignored); a bare \`repos:\` uses repos/ instead
32
32
  # vibeables: # small apps built live in a chat with a preview pane (uncomment to enable; one folder per app under ${DATA_DIR}/vibeables, versioned with the workspace)
33
33
  # projects: # goal-scoped folders — brief, systems of record, links to knowledge/vibeables/repos/workflows/agents — that chats work in (uncomment to enable; one folder per project under ${DATA_DIR}/projects)
34
- # cloud: # the kraftwerk cloud is ON BY DEFAULT: \`kraftwerk ui\` registers this workspace there and shows a claim code under Settings → Cloud
35
- # enabled: false # uncomment both lines to keep this workspace out of the cloud (or set KRAFTWERK_CLOUD_URL=off for the whole machine)
34
+ # cloud: # the daemon registers this MACHINE with the kraftwerk cloud and lists this workspace (\`kraftwerk login\` claims the machine)
35
+ # enabled: false # uncomment both lines to leave this workspace out (\`kraftwerk cloud off\` turns the cloud off for the whole machine)
36
36
  `;
37
37
  const WORKFLOW_TEMPLATE = `# yaml-language-server: $schema=${SCHEMA_URL}
38
38
  name: hello
@@ -22,6 +22,7 @@ import { registerDaemonCommand } from "./daemon.js";
22
22
  import { registerRemoteCommand } from "./remote.js";
23
23
  import { registerJournalCommands } from "./journal.js";
24
24
  import { registerWhoamiCommand } from "./whoami.js";
25
+ import { registerCloudCommands } from "./cloud.js";
25
26
  import { applyDotenv } from "../dotenv.js";
26
27
  import { resolveWorkspace } from "../config.js";
27
28
  import { registerRoutineCommands } from "./routines.js";
@@ -46,6 +47,8 @@ import { runUi } from "./ui.js";
46
47
  * kraftwerk trash ... what was deleted: list, restore, purge, empty
47
48
  * kraftwerk devices ... paired devices: list, pair one, revoke one
48
49
  * kraftwerk daemon the machine's kraftwerk: every open workspace at <slug>.localhost
50
+ * kraftwerk cloud [on|off|status] this machine in the kraftwerk cloud (the daemon registers it)
51
+ * kraftwerk login / logout claim this machine into your cloud account (in the browser) / release it
49
52
  * kraftwerk doctor [--fix] preflight: harness CLIs, docker, workflows, env, routine runners
50
53
  * kraftwerk validate [paths...] validate without executing
51
54
  *
@@ -302,6 +305,7 @@ registerDaemonCommand(program);
302
305
  registerRemoteCommand(program);
303
306
  registerJournalCommands(program);
304
307
  registerWhoamiCommand(program);
308
+ registerCloudCommands(program);
305
309
  program
306
310
  .command("ui")
307
311
  .description("Start the inspector web UI for this project's runs and workflows")
@@ -45,6 +45,10 @@ export declare const ROUTES: {
45
45
  readonly "chats.setVibeable": readonly ["POST", "/api/chats/:id/vibeable"];
46
46
  readonly "chats.steer": readonly ["POST", "/api/chats/:id/steer"];
47
47
  readonly "chats.stopTask": readonly ["POST", "/api/chats/:id/task-stop"];
48
+ readonly "cloud.set": readonly ["POST", "/api/cloud"];
49
+ readonly "cloud.status": readonly ["GET", "/api/cloud"];
50
+ readonly "cloud.sync": readonly ["POST", "/api/cloud/sync"];
51
+ readonly "cloud.unlink": readonly ["POST", "/api/cloud/unlink"];
48
52
  readonly "devices.code": readonly ["POST", "/api/devices/code"];
49
53
  readonly "devices.dropPush": readonly ["DELETE", "/api/devices/push"];
50
54
  readonly "devices.list": readonly ["GET", "/api/devices"];
@@ -46,6 +46,10 @@ export const ROUTES = {
46
46
  "chats.setVibeable": ["POST", "/api/chats/:id/vibeable"],
47
47
  "chats.steer": ["POST", "/api/chats/:id/steer"],
48
48
  "chats.stopTask": ["POST", "/api/chats/:id/task-stop"],
49
+ "cloud.set": ["POST", "/api/cloud"],
50
+ "cloud.status": ["GET", "/api/cloud"],
51
+ "cloud.sync": ["POST", "/api/cloud/sync"],
52
+ "cloud.unlink": ["POST", "/api/cloud/unlink"],
49
53
  "devices.code": ["POST", "/api/devices/code"],
50
54
  "devices.dropPush": ["DELETE", "/api/devices/push"],
51
55
  "devices.list": ["GET", "/api/devices"],
package/dist/config.d.ts CHANGED
@@ -34,11 +34,10 @@
34
34
  * root: apps # one folder per app, part of the workspace. Default: kraftwerk-data/vibeables
35
35
  * projects: # goal-scoped folders (brief, systems of record, links) that chats work in (absent = off, bare key = on)
36
36
  * root: kraftwerk-data/projects # one folder per project, part of the workspace. Default: kraftwerk-data/projects
37
- * cloud: # kraftwerk cloud manager — ON BY DEFAULT, `enabled: false` opts out
38
- * url: https://srv.kraftwerk-cloud.netnode.cloud # where the cloud answers (default). KRAFTWERK_CLOUD_URL env wins; "off" disables
39
- * interval: 60 # seconds between heartbeats. Default: 60
40
- * # No key here: the cloud hands the instance its identity and a claim code (Settings → Cloud in the UI);
41
- * # a server that should register under an account unattended puts KRAFTWERK_CLOUD_TOKEN into .env.
37
+ * cloud: # the machine's kraftwerk cloud record lists this workspace — `enabled: false` leaves it out
38
+ * enabled: false # a per-workspace veto; the machine's switch is `kraftwerk cloud on|off` (~/.kraftwerk/cloud.json)
39
+ * # No key here: the daemon registers the MACHINE (its relay id) and `kraftwerk login` claims it.
40
+ * # `url` and `interval` are deprecated: the cloud's origin is the machine's (cloud.json / KRAFTWERK_CLOUD_URL).
42
41
  */
43
42
  /** Stable, versionless URL of the workflow JSON schema (editor validation). */
44
43
  export declare const SCHEMA_URL = "https://raw.githubusercontent.com/NETNODEAG/kraftwerk/main/kraftwerk/schema/workflow.schema.json";
@@ -123,35 +122,23 @@ export declare const PROJECTS_DEFAULT_ROOT = "kraftwerk-data/projects";
123
122
  /** Absolute projects root when the feature is on, undefined otherwise. */
124
123
  export declare function projectsRootFor(project: ResolvedWorkspace): string | undefined;
125
124
  /**
126
- * Cloud manager: the kraftwerk cloud is ~/.kraftwerk made reachable over
127
- * the internet — a registry of instances across machines. Every inspector
128
- * registers on start and heartbeats while it runs, so the cloud's global
129
- * view shows this workspace, where it runs, and whether it is live; the
130
- * user claims it into their account with the code the UI shows. On by
131
- * default: an absent block is the same as a bare one, `enabled: false`
132
- * opts out, and so does KRAFTWERK_CLOUD_URL=off in the environment (what
133
- * the tests and CI set). No credential lives in kraftwerk.yml — the
134
- * identity comes from the cloud, and an account token for unattended
135
- * servers is KRAFTWERK_CLOUD_TOKEN in .env.
125
+ * kraftwerk.yml `cloud:` — since the cloud knows machines (core/cloud.ts,
126
+ * server/cloud.ts), this block only vetoes: `enabled: false` leaves the
127
+ * workspace out of the machine's reports. The machine's switch and the
128
+ * cloud's origin are ~/.kraftwerk/cloud.json (`kraftwerk cloud on|off`) and
129
+ * KRAFTWERK_CLOUD_URL. `url` is still honored for one release (with a
130
+ * warning) when the machine names none; `interval` is ignored — the cloud
131
+ * sets the cadence.
136
132
  */
137
133
  export interface CloudConfig {
138
- /** false turns the feature off. Default: true. */
134
+ /** false leaves this workspace out of the machine's cloud record. Default: true. */
139
135
  enabled?: boolean;
140
- /** Origin of the cloud manager. Default: https://srv.kraftwerk-cloud.netnode.cloud */
136
+ /** @deprecated The machine's (cloud.json / KRAFTWERK_CLOUD_URL); used only when the machine names none. */
141
137
  url?: string;
142
- /** Seconds between heartbeats. Default: 60 (the cloud may raise it). */
138
+ /** @deprecated Ignored: the cloud sets the heartbeat interval. */
143
139
  interval?: number;
144
140
  }
145
141
  export declare const CLOUD_DEFAULT_URL = "https://srv.kraftwerk-cloud.netnode.cloud";
146
- export declare const CLOUD_DEFAULT_INTERVAL = 60;
147
- export interface CloudSettings {
148
- url: string;
149
- interval: number;
150
- /** KRAFTWERK_CLOUD_TOKEN from the environment (.env), when set. */
151
- token?: string;
152
- }
153
- /** The effective cloud settings when the feature is on; undefined when kraftwerk.yml or the environment turned it off. */
154
- export declare function cloudFor(project: ResolvedWorkspace): CloudSettings | undefined;
155
142
  /** A directory as a .gitignore entry: relative, forward slashes, no trailing slash; undefined outside the root. */
156
143
  export declare function ignoreEntryFor(projectRoot: string, dir: string): string | undefined;
157
144
  /** True when .gitignore text already covers the entry (with or without a leading or trailing slash). */
@@ -206,7 +193,7 @@ export interface WorkspaceConfig {
206
193
  vibeables?: VibeablesConfig;
207
194
  /** Projects: goal-scoped folders the chats work in. Absent = off. */
208
195
  projects?: ProjectsConfig;
209
- /** kraftwerk cloud manager this instance registers with. Absent = on with defaults; `enabled: false` opts out. */
196
+ /** The machine's cloud record lists this workspace. Absent = listed; `enabled: false` leaves it out. */
210
197
  cloud?: CloudConfig;
211
198
  }
212
199
  export interface ResolvedWorkspace {
package/dist/config.js CHANGED
@@ -39,11 +39,10 @@ import { parse } from "yaml";
39
39
  * root: apps # one folder per app, part of the workspace. Default: kraftwerk-data/vibeables
40
40
  * projects: # goal-scoped folders (brief, systems of record, links) that chats work in (absent = off, bare key = on)
41
41
  * root: kraftwerk-data/projects # one folder per project, part of the workspace. Default: kraftwerk-data/projects
42
- * cloud: # kraftwerk cloud manager — ON BY DEFAULT, `enabled: false` opts out
43
- * url: https://srv.kraftwerk-cloud.netnode.cloud # where the cloud answers (default). KRAFTWERK_CLOUD_URL env wins; "off" disables
44
- * interval: 60 # seconds between heartbeats. Default: 60
45
- * # No key here: the cloud hands the instance its identity and a claim code (Settings → Cloud in the UI);
46
- * # a server that should register under an account unattended puts KRAFTWERK_CLOUD_TOKEN into .env.
42
+ * cloud: # the machine's kraftwerk cloud record lists this workspace — `enabled: false` leaves it out
43
+ * enabled: false # a per-workspace veto; the machine's switch is `kraftwerk cloud on|off` (~/.kraftwerk/cloud.json)
44
+ * # No key here: the daemon registers the MACHINE (its relay id) and `kraftwerk login` claims it.
45
+ * # `url` and `interval` are deprecated: the cloud's origin is the machine's (cloud.json / KRAFTWERK_CLOUD_URL).
47
46
  */
48
47
  /** Stable, versionless URL of the workflow JSON schema (editor validation). */
49
48
  export const SCHEMA_URL = "https://raw.githubusercontent.com/NETNODEAG/kraftwerk/main/kraftwerk/schema/workflow.schema.json";
@@ -98,19 +97,6 @@ export function projectsRootFor(project) {
98
97
  return path.resolve(project.root, p.root ?? PROJECTS_DEFAULT_ROOT);
99
98
  }
100
99
  export const CLOUD_DEFAULT_URL = "https://srv.kraftwerk-cloud.netnode.cloud";
101
- export const CLOUD_DEFAULT_INTERVAL = 60;
102
- /** The effective cloud settings when the feature is on; undefined when kraftwerk.yml or the environment turned it off. */
103
- export function cloudFor(project) {
104
- const c = project.config.cloud ?? {};
105
- const envUrl = process.env.KRAFTWERK_CLOUD_URL?.trim();
106
- if (c.enabled === false || envUrl?.toLowerCase() === "off")
107
- return undefined;
108
- return {
109
- url: (envUrl || c.url || CLOUD_DEFAULT_URL).replace(/\/+$/, ""),
110
- interval: c.interval ?? CLOUD_DEFAULT_INTERVAL,
111
- token: process.env.KRAFTWERK_CLOUD_TOKEN?.trim() || undefined,
112
- };
113
- }
114
100
  /** A directory as a .gitignore entry: relative, forward slashes, no trailing slash; undefined outside the root. */
115
101
  export function ignoreEntryFor(projectRoot, dir) {
116
102
  const rel = path.relative(projectRoot, path.resolve(projectRoot, dir)).split(path.sep).join("/");
@@ -337,7 +323,7 @@ function validateCloud(configPath, value) {
337
323
  const c = value;
338
324
  for (const key of Object.keys(c)) {
339
325
  if (key === "token") {
340
- throw new Error(`${file}: cloud.token does not belong in kraftwerk.yml — put KRAFTWERK_CLOUD_TOKEN into .env (and only for unattended servers; a workspace with a UI is claimed with its code)`);
326
+ throw new Error(`${file}: cloud.token does not belong in kraftwerk.yml — the cloud knows the machine, and \`kraftwerk login\` claims it`);
341
327
  }
342
328
  if (!["enabled", "url", "interval"].includes(key)) {
343
329
  throw new Error(`${file}: cloud.${key} is unknown (allowed: enabled, url, interval)`);