@netnodeag/kraftwerk 0.100.0 → 0.100.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.
@@ -3,7 +3,7 @@ import { DAEMON_PORT, daemonState, lastOpenRoots, setDaemonVersion, writeDaemonF
3
3
  import { tildify } from "../core/instances.js";
4
4
  import { log } from "../core/log.js";
5
5
  import { networkUrls } from "../server/bind.js";
6
- import { startMachineCloud } from "../server/cloud.js";
6
+ import { cloudStatus, startMachineCloud, syncMachineCloud } from "../server/cloud.js";
7
7
  import { startPushWatcher } from "../server/push.js";
8
8
  import { applyRelay, relayPush } from "../server/relay.js";
9
9
  import { startHub } from "../server/server.js";
@@ -37,7 +37,13 @@ export async function runDaemon(opts) {
37
37
  port,
38
38
  staticDir: ensureBuilt(),
39
39
  daemon: true,
40
- onChange: (h) => writeDaemonFile(h.port, h.list().map((o) => o.root)),
40
+ onChange: async (h) => {
41
+ await writeDaemonFile(h.port, h.list().map((o) => o.root));
42
+ // A workspace opened or closed: the cloud hears it now, not with the next heartbeat (up to a minute) —
43
+ // until then its cloud boards and git answer "this machine does not host that workspace".
44
+ if (cloudStatus().state === "connected")
45
+ void syncMachineCloud().catch(() => { });
46
+ },
41
47
  });
42
48
  await writeDaemonFile(hub.port, []);
43
49
  for (const root of reopen) {
@@ -2,7 +2,7 @@ import { resolveWorkspace, usersMode } from "../config.js";
2
2
  import { readAccountFile } from "../core/cloud.js";
3
3
  import { workspaceRoot } from "../core/context.js";
4
4
  import { ApiError } from "./api/router.js";
5
- import { machineLink } from "./cloud.js";
5
+ import { machineLink, syncMachineCloud } from "./cloud.js";
6
6
  import { personOf } from "./person.js";
7
7
  const REMOTE_TIMEOUT_MS = 10_000;
8
8
  /** Reads wait less: the boards list asks on every poll. */
@@ -49,21 +49,28 @@ export async function remoteCall(trust, call) {
49
49
  const actor = call.actor && !call.actor.trim().startsWith("human:") ? call.actor.trim() : undefined;
50
50
  if (down && down.until > Date.now())
51
51
  throw offline(down.why);
52
+ const send = () => fetch(`${link.url}/api/workspaces/${encodeURIComponent(wsId)}/${call.path}`, {
53
+ method: call.method,
54
+ headers: {
55
+ "user-agent": `kraftwerk/${link.version}`,
56
+ "x-kw-machine-id": link.creds.id,
57
+ "x-kw-machine-secret": link.creds.secret,
58
+ ...(as ? { "x-kw-user": as } : {}),
59
+ ...(actor ? { "x-kw-actor": actor } : {}),
60
+ ...(call.body !== undefined ? { "content-type": "application/json" } : {}),
61
+ },
62
+ body: call.body !== undefined ? JSON.stringify(call.body) : undefined,
63
+ signal: AbortSignal.timeout(call.method === "GET" ? READ_TIMEOUT_MS : REMOTE_TIMEOUT_MS),
64
+ });
52
65
  let r;
53
66
  try {
54
- r = await fetch(`${link.url}/api/workspaces/${encodeURIComponent(wsId)}/${call.path}`, {
55
- method: call.method,
56
- headers: {
57
- "user-agent": `kraftwerk/${link.version}`,
58
- "x-kw-machine-id": link.creds.id,
59
- "x-kw-machine-secret": link.creds.secret,
60
- ...(as ? { "x-kw-user": as } : {}),
61
- ...(actor ? { "x-kw-actor": actor } : {}),
62
- ...(call.body !== undefined ? { "content-type": "application/json" } : {}),
63
- },
64
- body: call.body !== undefined ? JSON.stringify(call.body) : undefined,
65
- signal: AbortSignal.timeout(call.method === "GET" ? READ_TIMEOUT_MS : REMOTE_TIMEOUT_MS),
66
- });
67
+ r = await send();
68
+ // The cloud has not heard of this workspace on this machine yet (opened since the last heartbeat):
69
+ // tell it now and ask once more.
70
+ if (r.status === 403 && /does not host/.test(await r.clone().text())) {
71
+ await syncMachineCloud().catch(() => { });
72
+ r = await send();
73
+ }
67
74
  }
68
75
  catch (err) {
69
76
  const why = `kraftwerk cloud does not answer (${err.message})`;
@@ -82,7 +89,10 @@ export async function remoteCall(trust, call) {
82
89
  if (r.status >= 500)
83
90
  throw offline(String(data.error ?? `kraftwerk cloud answered ${r.status}`));
84
91
  if (!r.ok) {
85
- const error = String(data.error ?? `kraftwerk cloud answered ${r.status}`);
92
+ let error = String(data.error ?? `kraftwerk cloud answered ${r.status}`);
93
+ // Still unknown after telling it: the account on this machine is not on the workspace (removed, or never invited).
94
+ if (r.status === 403 && /does not host/.test(error))
95
+ error = "kraftwerk cloud does not let this machine into this workspace — its account is not (or no longer) a member; ask an owner for an invite";
86
96
  // A person who signed in before the cloud kept sign-ins must sign in once more.
87
97
  const signin = r.status === 403 && /may act only for/.test(error) && as ? { signin: true } : {};
88
98
  throw new ApiError(r.status, error, { error, ...signin });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netnodeag/kraftwerk",
3
- "version": "0.100.0",
3
+ "version": "0.100.1",
4
4
  "description": "Open-source agentic workspace for teams — where people and AI agents get work done together: agents (Claude Code, Codex, Pi), skills, shared knowledge, repeatable workflows, and deterministic verification",
5
5
  "keywords": [
6
6
  "agents",