@plitzi/sdk-server 0.38.15 → 0.38.16

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/CHANGELOG.md CHANGED
@@ -1,5 +1,70 @@
1
1
  # @plitzi/sdk-server
2
2
 
3
+ ## 0.38.16
4
+
5
+ ### Patch Changes
6
+
7
+ - 9cfdccb: ## Security
8
+
9
+ - **A site's credential reads nothing of the space over MCP** (`@plitzi/sdk-mcp`): the `render` token every published
10
+ page embeds — and a self-hosting `host` key — resolved to a grant naming the space, and the MCP served every read
11
+ under it: the unpublished draft, the change history with who made each change and every value before and after, the
12
+ functions' source, the space's private data, its action documents and connectors. Only an `agent` grant attaches a
13
+ space now; any other is a connection with no space (`plitzi_render` and the public guides), told so in the words
14
+ `NO_SPACE_ATTACHED` already uses. A deployment whose `getGrant` answered other scopes for reading must issue agent
15
+ grants for them.
16
+
17
+ ## Agents
18
+ - **`plitzi space watch`** (`@plitzi/cli`): the space read again on every save of `src/space/`, `src/plugins/`,
19
+ `src/data/` or `public/data/`, and only what changed said — what the save did to the space element by element, the
20
+ findings and warnings it brought and fixed (one that only moved down its file is the same one), a save that changed
21
+ nothing, or that the space stopped authoring and why. `--json` is one event a line (`ready`, `pass`, `refused`,
22
+ `error`), for an agent to run in the background instead of `author` and `space lint` after every edit. Each pass reads
23
+ the space in a process of its own (`space watch-pass`, hidden). `space lint`'s reading is `spaceFindings`, shared.
24
+ - **A space's activity, followed** (`@plitzi/sdk-shared`, `@plitzi/sdk-mcp`, `@plitzi/cli`): what happened on a space
25
+ after a cursor — its draft changed (a person in the builder, an agent, the autofix), a version went out, a server
26
+ action failed or was refused — and, with nothing yet, waited for, up to 50 s. One vocabulary,
27
+ `@plitzi/sdk-shared/activity` (`SpaceActivity`, `SpaceActivityPage`, `activityLine`, `isSpaceActivityPage`, the
28
+ limits); the reader's own writes left out and counted (`skippedMine`), `mine` keeps them.
29
+ - **`plitzi_activity { after, wait, limit, mine }`** (`@plitzi/sdk-mcp`), on the new `getActivity` adapter
30
+ (`SSRAdapters`). The listing budget is 78k (was 77k) for it.
31
+ - **`plitzi space activity [--follow] [--after <cursor>] [--mine] [--limit <n>] [--json]`** (`@plitzi/cli`), over
32
+ the platform's `GET /spaces/:spaceId/activity`; `--follow` stays, one page a line with `--json`, and asks again
33
+ when the platform does not answer.
34
+ - **The people in the builder see the agent work** (`@plitzi/sdk-server`, `@plitzi/sdk-shared`, `@plitzi/sdk-mcp`,
35
+ `@plitzi/plitzi-builder`): an agent grant carries the application the member connected (`Grant.client`,
36
+ `StoredSpaceToken.client`, `SSRGrant.client`), and every MCP write `SSRWriteContext.client` — the history's
37
+ `client` for an agent, which was never set. A collaborator may be an agent (`SubscriptionCollaborator.agent`): the
38
+ builder draws it as a robot, names it `Claude · for ana` (`collaboratorTitle`) in the header, on the canvas and in
39
+ its notices. The deployment announces it — Plitzi's joins it on a write, selects what it changed, and lets it go
40
+ after a minute of nothing. `activityLine` names it the same way (`Claude for ana over the MCP, …`), so
41
+ `plitzi space activity` says which application wrote.
42
+ - A tool may declare `documents: false` (`ToolSpec`): the host loads none of the space for it, and passes the call's
43
+ abort signal through `ToolContext.activity`.
44
+
45
+ ## Authoring
46
+ - **A file that does not parse is said at its line under any loader** (`@plitzi/sdk-authoring`): `moduleProblem` read
47
+ the first line of the error, and an esbuild transform (tsx, vitest) puts only `Transform failed with 1 error:` there
48
+ — the file, line and what is wrong are on the next. A line of the message that points at a file of the project is
49
+ now the problem (`src/space/hero.ts:139: Expected "}" but found ";"`), the project's root matched as given and as it
50
+ is on disk (`/var/…` and `/private/var/…` on macOS).
51
+
52
+ ## Testing
53
+ - **`unusedPort` is chosen where the system never hands one out** (`@plitzi/sdk-server`): it answered a port the system
54
+ had just handed out (`listen(0)`), from the ephemeral range every outgoing connection takes its local port from — so
55
+ another worker's request could take it before the test listened, and CI failed `runtime.test.ts` with `EADDRINUSE`
56
+ (the page server then ends the process). It is a free port below that range now, at random, checked first.
57
+
58
+ ## Docs
59
+ - **A self-hosted runtime's endpoints go in `data`**, as 0.38.15 moved them: `docs/en/runtimes.md`, the
60
+ `10-runtime` example and the website still put `served.stage` in `preAuth`, before the cross-site guard.
61
+ - New: `docs/en/activity.md`; `space watch` in `docs/en/agent-tooling.md`'s loop; the CLI README, the CLI skill, the
62
+ generated project's `AGENTS.md`, the MCP guide and README.
63
+
64
+ - Updated dependencies [9cfdccb]
65
+ - @plitzi/plitzi-sdk@0.38.16
66
+ - @plitzi/sdk-shared@0.38.16
67
+
3
68
  ## 0.38.15
4
69
 
5
70
  ### Patch Changes
package/README.md CHANGED
@@ -450,10 +450,10 @@ Beside the page adapters it offers `getSchema` and `getStyle`, read from the sam
450
450
  path, or a function that may answer one — `saveSchema` and `saveStyle`, each writing its document back into the file. So an MCP server
451
451
  ([`@plitzi/sdk-mcp`](../mcp/README.md#adapters)) can run over it, with a `getGrant` of yours beside it.
452
452
 
453
- In a test, listen on `await unusedPort()`: a port the system has just handed out, never a fixed number — one in the
454
- system's ephemeral range can be taken by any outgoing connection of a test running beside it, and the listen fails with
455
- `EADDRINUSE` on a run with nothing wrong. (`freePort(8080)` is the development server's: the next free one from a port
456
- people expect.)
453
+ In a test, listen on `await unusedPort()`: a free port below the system's ephemeral range, never a fixed number nor
454
+ one the system hands out (`listen(0)`) — a port of that range can be taken by any outgoing connection of a test running
455
+ beside it between the moment it is chosen and the listen, which fails with `EADDRINUSE` on a run with nothing wrong.
456
+ (`freePort(8080)` is the development server's: the next free one from a port people expect.)
457
457
 
458
458
  ### `JsonAdaptersConfig`
459
459
 
@@ -23,6 +23,8 @@ export interface Grant {
23
23
  spaceId: number;
24
24
  scope: SpaceScope;
25
25
  userId?: number;
26
+ /** For an `agent` grant, the application the member connected, as it registered (`Claude`): who writes for them. */
27
+ client?: string;
26
28
  origins: string[];
27
29
  }
28
30
  /** What an account may do inside ONE space. */
@@ -37,6 +39,8 @@ export interface StoredSpaceToken {
37
39
  spaceId: number;
38
40
  scope: SpaceScope;
39
41
  userId?: number;
42
+ /** For an `agent` grant, the application the member connected (`Claude`). */
43
+ client?: string;
40
44
  }
41
45
  /**
42
46
  * What identity resolution cannot work out on its own: where accounts, space tokens and memberships are kept. This
@@ -63,6 +63,7 @@ var createIdentity = ({ tokens, carriers, adapters, config = {}, presentedOrigin
63
63
  spaceId,
64
64
  scope,
65
65
  userId: stored.userId,
66
+ ...stored.client === void 0 ? {} : { client: stored.client },
66
67
  origins
67
68
  };
68
69
  if (scope === "render" && host !== void 0 && !domainAllowed(host, origins, platformHosts)) {
@@ -1,3 +1,7 @@
1
+ /** Whether something already answers at `port` — the one test that sees a listener on every address, not just `host`. */
2
+ export declare const portAnswers: (port: number, host: string) => Promise<boolean>;
3
+ /** Whether this process could listen at `port` on `host`. */
4
+ export declare const portBindable: (port: number, host: string) => Promise<boolean>;
1
5
  /**
2
6
  * The first port from `preferred` up that nothing uses — for a development server, which should start beside
3
7
  * whatever else is running rather than refuse to.
@@ -1,7 +1,7 @@
1
1
  import { connect, createServer } from "node:net";
2
2
  //#region src/core/freePort.ts
3
3
  /** Whether something already answers at `port` — the one test that sees a listener on every address, not just `host`. */
4
- var answers = (port, host) => new Promise((resolve) => {
4
+ var portAnswers = (port, host) => new Promise((resolve) => {
5
5
  const socket = connect({
6
6
  port,
7
7
  host
@@ -13,7 +13,7 @@ var answers = (port, host) => new Promise((resolve) => {
13
13
  socket.once("error", () => resolve(false));
14
14
  });
15
15
  /** Whether this process could listen at `port` on `host`. */
16
- var bindable = (port, host) => new Promise((resolve) => {
16
+ var portBindable = (port, host) => new Promise((resolve) => {
17
17
  const probe = createServer();
18
18
  probe.once("error", () => resolve(false));
19
19
  probe.once("listening", () => probe.close(() => resolve(true)));
@@ -29,8 +29,8 @@ var bindable = (port, host) => new Promise((resolve) => {
29
29
  * this: a fixed port that is taken is an error worth stopping for.
30
30
  */
31
31
  var freePort = async (preferred, host = "127.0.0.1", attempts = 20) => {
32
- for (let port = preferred; port < preferred + attempts; port += 1) if (!await answers(port, host) && await bindable(port, host)) return port;
32
+ for (let port = preferred; port < preferred + attempts; port += 1) if (!await portAnswers(port, host) && await portBindable(port, host)) return port;
33
33
  throw new Error(`No free port between ${preferred} and ${preferred + attempts - 1} on ${host}. Set PORT to one.`);
34
34
  };
35
35
  //#endregion
36
- export { freePort };
36
+ export { freePort, portAnswers, portBindable };
@@ -1,6 +1,10 @@
1
1
  /**
2
- * A port the system has just handed out and nobody holds — what a test listens on. Never a fixed number: one in the
3
- * system's ephemeral range (above 32768 on Linux) can be taken by any outgoing connection of a test running beside it,
4
- * and the listen fails with `EADDRINUSE` on a run that has nothing wrong with it.
2
+ * A port nobody holds, for a test to listen on — chosen where the system never hands one out by itself.
3
+ *
4
+ * Not one the system hands out (`listen(0)`): that range is the one every outgoing connection takes its local port
5
+ * from, so between the moment a port is handed out and the moment the test listens on it, a request of a test running
6
+ * beside it — another worker's `fetch`, a database connection — can take it, and the listen fails with `EADDRINUSE` on
7
+ * a run that has nothing wrong with it. Below that range only a port somebody chose explicitly is ever taken, and it is
8
+ * looked at first: one that answers, or that this process may not listen on, is passed over.
5
9
  */
6
10
  export declare const unusedPort: (host?: string) => Promise<number>;
@@ -1,20 +1,38 @@
1
- import { createServer } from "node:net";
1
+ import { portAnswers, portBindable } from "./freePort.js";
2
+ import { readFileSync } from "node:fs";
2
3
  //#region src/core/unusedPort.ts
4
+ /** The lowest port handed out: above the well-known and the registered ones most local services sit on. */
5
+ var LOWEST = 1e4;
6
+ /** Below it, as far as a system lets a port be chosen for nobody: Linux's default, and below macOS's and Windows's. */
7
+ var EPHEMERAL_DEFAULT = 32768;
8
+ var ATTEMPTS = 50;
3
9
  /**
4
- * A port the system has just handed out and nobody holds — what a test listens on. Never a fixed number: one in the
5
- * system's ephemeral range (above 32768 on Linux) can be taken by any outgoing connection of a test running beside it,
6
- * and the listen fails with `EADDRINUSE` on a run that has nothing wrong with it.
10
+ * Where the system starts handing out ports by itself — to every outgoing connection and every `listen(0)`. Linux says
11
+ * where in `/proc`; macOS and Windows start at 49152, above Linux's default.
7
12
  */
8
- var unusedPort = (host = "127.0.0.1") => new Promise((resolve, reject) => {
9
- const probe = createServer();
10
- probe.once("error", reject);
11
- probe.listen(0, host, () => {
12
- const address = probe.address();
13
- probe.close(() => {
14
- if (typeof address === "object" && address) resolve(address.port);
15
- else reject(/* @__PURE__ */ new Error(`The system gave no port on ${host}`));
16
- });
17
- });
18
- });
13
+ var ephemeralStart = () => {
14
+ try {
15
+ const [low] = readFileSync("/proc/sys/net/ipv4/ip_local_port_range", "utf-8").trim().split(/\s+/).map(Number);
16
+ if (Number.isInteger(low) && low > 10050) return Math.min(low, EPHEMERAL_DEFAULT);
17
+ } catch {}
18
+ return EPHEMERAL_DEFAULT;
19
+ };
20
+ /**
21
+ * A port nobody holds, for a test to listen on — chosen where the system never hands one out by itself.
22
+ *
23
+ * Not one the system hands out (`listen(0)`): that range is the one every outgoing connection takes its local port
24
+ * from, so between the moment a port is handed out and the moment the test listens on it, a request of a test running
25
+ * beside it — another worker's `fetch`, a database connection — can take it, and the listen fails with `EADDRINUSE` on
26
+ * a run that has nothing wrong with it. Below that range only a port somebody chose explicitly is ever taken, and it is
27
+ * looked at first: one that answers, or that this process may not listen on, is passed over.
28
+ */
29
+ var unusedPort = async (host = "127.0.0.1") => {
30
+ const span = ephemeralStart() - LOWEST;
31
+ for (let attempt = 0; attempt < ATTEMPTS; attempt += 1) {
32
+ const port = LOWEST + Math.floor(Math.random() * span);
33
+ if (!await portAnswers(port, host) && await portBindable(port, host)) return port;
34
+ }
35
+ throw new Error(`No free port between ${String(LOWEST)} and ${String(LOWEST + span)} on ${host} after ${String(ATTEMPTS)} tries`);
36
+ };
19
37
  //#endregion
20
38
  export { unusedPort };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-server",
3
- "version": "0.38.15",
3
+ "version": "0.38.16",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist",
@@ -96,8 +96,8 @@
96
96
  "./dist/env.js"
97
97
  ],
98
98
  "dependencies": {
99
- "@plitzi/plitzi-sdk": "0.38.15",
100
- "@plitzi/sdk-shared": "0.38.15",
99
+ "@plitzi/plitzi-sdk": "0.38.16",
100
+ "@plitzi/sdk-shared": "0.38.16",
101
101
  "ejs": "^6.0.1",
102
102
  "esbuild": "^0.28.2",
103
103
  "jsonwebtoken": "^9.0.3",