nylorun 0.3.0-beta → 0.4.0-beta

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,47 @@
1
1
  # nylorun
2
2
 
3
+ ## 0.4.0-beta
4
+
5
+ ### Major Changes
6
+
7
+ - 5ca1923: **Clients for one Tenant per installation: a stack per project, nothing selects a Tenant.** Upgrade these with the Runtime; they speak protocol 5. Existing stacks are left as they are: see MIGRATION.md.
8
+
9
+ - **Breaking (`nylorun`): one stack per project.** `nylorun start` in a project creates the project's stack (named after the project directory, or `--name`; Host root `~/.nylorun/stacks/<name>/`, Compose project `nylorun-<name>`, its own free ports and volumes), waits for its Runtime to create the stack's Tenant, writes the Project link (`.nylorun/link.json` format 2: `stack`, `hostUrl`, `hostId`, `tenantId`) and `.nylorun/credentials.json` (the key of the derived principal `project`, derived from the stack's admin key), and seeds the model provider from the project's `.env`. `nylorun ls` lists the machine's stacks and `nylorun delete <name>` removes one with its volumes and Host root. `nylorun status` shows the stack's Tenant; `nylorun studio` opens it. The old single stack under `~/.nylorun` is never touched: `start` notes it, and `nylorun legacy stop|delete` handles it. Every stack command takes `--name <stack>` (or `NYLORUN_STACK`, or the Project link's stack); `start --no-link` starts a stack without linking the directory; `nylorun reset` resets the selected stack only. The runtime container's healthcheck is now `/health`, so a Tenant that cannot open is reported by `start` from the Admin status at once instead of after a 300 s wait. `NYLORUN_HOME` still overrides the Host root. Stacks start and stop only when you say so.
10
+ - **Breaking (`@nylorun/cli`): no Tenant commands.** `nylo tenant create|use|list|current|delete` are removed; `nylo status`, `nylo reset` and `nylo endpoints` replace `nylo tenant status|reset|endpoints` on the linked installation. `nylo env` prints `NYLORUN_RUNTIME_URL` and `NYLORUN_SERVER_KEY` only. `nylo` no longer writes Project links.
11
+ - **Breaking (`@nylorun/agents`): no Tenant to name.** The `tenant` option (`createClient`, `Transport`, `resolveConnection`, `createActionHandler({ runtime })`, `JwksCache`) and `NYLORUN_TENANT` are gone, and no request sends `Nylorun-Tenant`; a connection is a URL and a key. A Project link of format 0 or 1 is refused with `connection_missing`, naming `npx nylorun start`. `verifyDeliveryToken`'s `tenantId` is optional: without it any Tenant issuer is accepted, since the installation's keys bind it. `TENANT_HEADER` is no longer re-exported.
12
+ - **Breaking (`@nylorun/admin`): status only.** `createTenant`, `listTenants`, `getTenant` and `deleteTenant` are removed; `status().tenant` names the Host's Tenant, and `deriveTenantKey` / `deriveStudioToken` derive its keys. Local Host resolution reads the stack's Host root (`stack` option, `NYLORUN_STACK`, or the Project link's `stack`); `NYLORUN_HOME` and `home` still override it. `stackHostRoot(name)` is exported.
13
+ - **Breaking (`@nylorun/studio`): Studio serves its installation's Tenant.** The Tenant picker, list and create are gone, with `/_studio/tenants`; `/` opens `/tenants/<id>`. The `/tenants/:tenant` routes and the login token's `tenant` claim stay for embedders and must name that Tenant. The proxy sends no `Nylorun-Tenant`.
14
+ - **`@nylorun/create-agent`:** the next steps are `npx nylorun start`, then `npm run dev`.
15
+ - `@nylorun/core`: `ProjectLinkFileSchema` accepts format 2 with `stack`, and `tenantId` is optional; `ERROR_CODES` loses `tenant_conflict` and `active_work`.
16
+
17
+ ### Minor Changes
18
+
19
+ - ee9e471: **Only the gateway can read the vault key (F4.2).** `nylorun start` writes the Tenant's vault key to `<Host root>/keys/vault-kek`. Only the `gateway` container mounts `keys/`, read-only, and runs `--service gates,keys`. The runtime container covers `keys/` and `docker/` with empty read-only mounts, so it reads neither the vault key nor Restate's private key and `.env`. `nylorun reset` deletes the key with the Tenant's data.
20
+ - e3af093: **A stack's Docker Compose files live in `docker/`.** `compose.yaml`, `.env` and `restate-identity.pem` are written to `~/.nylorun/stacks/<name>/docker/` (or `$NYLORUN_HOME/docker/`), so the folder says what it holds: to change a port, edit `docker/.env`. The single stack of older releases keeps its `~/.nylorun/stack/`, which `nylorun legacy` reads as it is.
21
+ - 7bd38d6: **The local stack runs a gateway container: model calls leave the Runtime.** `nylorun up` now runs the Runtime image twice, the combined packing: `runtime` (`--service core,loop`: the APIs and the agent loop) and `gateway` (`--service gates,keys`: the Model Gate, the Tool Gate and the keys service). Every model call, remote MCP call and Action delivery of the loop crosses the gateway, which alone reads the Tenant's credentials and the vault key. A new stack starts with the gateway.
22
+
23
+ - **Breaking for hand-written Compose files:** in a container, a Runtime that runs `loop` refuses to start without `NYLORUN_GATES_URL` and `NYLORUN_GATES_TOKEN`. Run the image a second time with `--service gates,keys` (see `DEPLOYMENT.md`). The image's default command is now `--service core,loop`.
24
+ - The gateway has no published port, mounts only the Host's Tenant directory (`tenant/`) and `keys/`, both read-only, and reaches model servers on this machine at `host.docker.internal`. `docker/.env` holds `NYLORUN_GATES_TOKEN`, generated once and kept across starts.
25
+ - `nylorun status` shows a Gateway line, `nylorun doctor` fails when the gateway is unhealthy and names `nylorun logs gateway`, and `nylorun logs gateway` is accepted.
26
+ - An image set with `NYLORUN_RUNTIME_IMAGE` must be this release or newer: older Runtimes don't know `--service`.
27
+
28
+ - 31cfec0: **Action deliveries leave through the gateway (F4.1).** With the gates service, every delivery and endpoint ping is POSTed by the gateway (`POST /nylorun/v1/deliveries`) under the gateway's own `NYLORUN_ENDPOINT_*` policy. The delivery state machine is unchanged. A gateway that cannot be reached counts as a delivery that was not sent, so it is retried, and its failure code is `gateway.unreachable`.
29
+
30
+ - `nylorun`: the `gateway` container now sets `NYLORUN_ENDPOINT_LOOPBACK=docker-host`, so Action endpoints on this machine stay reachable.
31
+ - A process that runs only `core` also reads `NYLORUN_GATES_URL`, for endpoint pings.
32
+
33
+ ### Patch Changes
34
+
35
+ - Pin core to the tested release.
36
+ - Pin runtime to the tested release.
37
+ - Pin studio to the tested release.
38
+ - Updated dependencies [fed780d]
39
+ - Updated dependencies [fed780d]
40
+ - Updated dependencies [7f4c3f1]
41
+ - Updated dependencies [5ca1923]
42
+ - Updated dependencies [5ca1923]
43
+ - @nylorun/core@0.10.0-beta
44
+
3
45
  ## 0.3.0-beta
4
46
 
5
47
  ### Minor Changes
package/README.md CHANGED
@@ -1,17 +1,22 @@
1
1
  # nylorun
2
2
 
3
- Sets up and runs the local Nylorun stack: the Runtime and Studio, as a Docker
4
- Compose stack. It needs nothing in your project; run it with `npx`:
3
+ Sets up and runs local Nylorun stacks: the Runtime and Studio, as Docker
4
+ Compose stacks, one per project. It needs nothing in your project; run it with
5
+ `npx` in the project's directory:
5
6
 
6
7
  ```sh
7
- npx nylorun up # set up the stack on the first run, then start it
8
- npx nylorun down # stop it; volumes (and Tenants) are kept
8
+ npx nylorun start # create (first run) and start this project's stack, its Tenant and the Project link
9
+ npx nylorun stop # stop it; volumes (and the Tenant's data) are kept
9
10
  ```
10
11
 
11
- `nylorun` only manages the stack. It never creates Tenants: create one in
12
- Studio, or with the Runtime client, [`@nylorun/cli`](../cli/README.md) (command
13
- `nylo`), which also links a project to it. Depends on `@nylorun/core` only
14
- among Nylorun packages and never imports `@nylorun/runtime`. Vocabulary:
12
+ A stack is one installation: one Runtime with its own Postgres, Restate and
13
+ S2, serving exactly one Tenant. `nylorun start` in a project creates the
14
+ project's stack, the Runtime creates the stack's Tenant on its first start,
15
+ and `nylorun start` links the project to it. There are no Tenant commands:
16
+ projects that must not share agents, credentials or history run separate
17
+ stacks. Agents, sessions and model providers belong to the Runtime client,
18
+ [`@nylorun/cli`](../cli/README.md) (command `nylo`). Depends on `@nylorun/core`
19
+ only among Nylorun packages and never imports `@nylorun/runtime`. Vocabulary:
15
20
  [runtime/src/CONTEXT.md](../runtime/src/CONTEXT.md).
16
21
 
17
22
  Prerequisites, installed by the developer (nylorun never downloads them): Node
@@ -29,66 +34,119 @@ npx nylorun doctor # Node 24+, Docker, Compose v2, and the stack
29
34
  ## Commands
30
35
 
31
36
  ```sh
32
- nylorun up|start [--no-studio] [--no-open] [--allow-downgrade] [--studio-embed-origin <origin>]... [--studio-embed-origin-reset]
33
- # set up (first run) and start the stack; print the Runtime and Studio URLs; open Studio signed in
34
- nylorun down|stop # stop the containers; keep volumes
35
- nylorun status [--json] # services, endpoints, Runtime health
36
- nylorun logs [service] [-f] [--tail <n>] # postgres, restate, s2, runtime, studio
37
- nylorun studio [--no-open] # sign a browser in to Studio (on the linked Project's Tenant); starts the stack if needed
38
- nylorun reset [--yes] # delete the stack's volumes and every Tenant
37
+ nylorun up|start [--name <stack>] [--no-link] [--no-studio] [--no-open] [--allow-downgrade] [--studio-embed-origin <origin>]... [--studio-embed-origin-reset]
38
+ # create (first run) and start the stack; link the project; print the URLs; open Studio signed in
39
+ nylorun down|stop [--name <stack>] # stop the containers; keep volumes
40
+ nylorun status [--name <stack>] [--json] # the stack, its Host root and Tenant, services, endpoints, Runtime health
41
+ nylorun logs [service] [--name <stack>] [-f] [--tail <n>] # postgres, restate, s2, gateway, runtime, studio
42
+ nylorun studio [--name <stack>] [--no-open] # sign a browser in to Studio on the stack's Tenant; starts the stack if needed
43
+ nylorun reset [--name <stack>] [--yes] # delete the stack's volumes and Tenant directory; the next start creates a new Tenant
44
+ nylorun ls [--json] # the stacks on this machine
45
+ nylorun delete <stack> --yes # remove a stack: containers, volumes, Host root and vault key
46
+ nylorun legacy stop|delete [--yes] # the single stack of older releases
39
47
  nylorun doctor [--json] # prerequisites and stack health
40
48
  ```
41
49
 
42
50
  `up` and `down` are the Docker Compose spellings of `start` and `stop`: `down`
43
51
  stops the containers and keeps the volumes, so no Tenant data is lost.
44
- `nylorun stack <command>` still works as a hidden alias. Commands that act on a
45
- Tenant moved to the Runtime client and exit 2 naming the replacement:
46
- `nylorun dev`, `nylorun tenant …`, `nylorun configure`, `nylorun status --env`
47
- and `nylorun doctor sandbox`.
52
+ `nylorun stack <command>` still works as a hidden alias. Removed commands exit
53
+ 2 naming the replacement: `nylorun tenant …` (`nylorun start` creates the
54
+ Tenant; `nylorun status|reset`, or `nylo status|reset|endpoints`), `nylorun
55
+ dev`, `nylorun configure`, `nylorun status --env` and `nylorun doctor sandbox`.
56
+
57
+ ## Stacks
58
+
59
+ Every command acts on one stack, chosen in this order:
60
+
61
+ 1. `--name <stack>`;
62
+ 2. `NYLORUN_STACK`;
63
+ 3. the stack in the project's link (`.nylorun/link.json`, found from the
64
+ working directory upwards);
65
+ 4. for `start` in a project only: the project directory's name, lowercased,
66
+ with characters outside `[a-z0-9_-]` as `-`, and a suffix (`-2`, `-3`, …)
67
+ when a stack of that name was created for another project directory.
68
+
69
+ Outside a project, `start` needs `--name`, and the other commands need
70
+ `--name`, `NYLORUN_STACK` or a linked project. `nylorun ls` lists the stacks.
71
+
72
+ Each stack has its own Host root `~/.nylorun/stacks/<name>/`, Compose project
73
+ `nylorun-<name>` (`NYLORUN_STACK_PROJECT` overrides it), volumes, network and
74
+ ports. `NYLORUN_HOME` replaces the whole Host root (the stack's name then comes
75
+ from its `stack.json`, the project directory or the Host root's own name).
76
+
77
+ A stack refuses only a Runtime older than its own database: `start` records
78
+ the pinned Runtime version in `host.json` (`runtimeVersion`) and exits 5 when
79
+ this nylorun pins an older one. Update nylorun, or pass `--allow-downgrade`
80
+ when both versions use the same database schema (otherwise the Runtime reports
81
+ the Tenant unavailable, `schema-too-new`). With `NYLORUN_RUNTIME_IMAGE` set,
82
+ the image's version is unknown: `start` does not check it and keeps the
83
+ recorded version.
84
+
85
+ ## The Project link
86
+
87
+ `nylorun start` in a project waits until the stack's Tenant is open
88
+ (`/v1/admin/status`), then writes, in a `.nylorun/` directory (mode 0700, with
89
+ its own `.gitignore` of `*`):
90
+
91
+ - `link.json`: `{ "format": 2, "stack", "hostUrl", "hostId", "tenantId" }`.
92
+ The Tenant id is information only: nothing in a request selects a Tenant.
93
+ - `credentials.json` (mode 0600): the key of the derived principal `project`,
94
+ derived from the stack's admin key, and its id.
95
+
96
+ Later starts reuse the stack and rewrite the link only when the stack, its URL,
97
+ Host or Tenant changed (after `nylorun reset`, for example). When it writes a
98
+ new link, `start` seeds the Tenant from the project's `.env`: the sandbox
99
+ backend (`NYLORUN_SANDBOX=auto|virtual`) and the model credential
100
+ (`MODEL_PROVIDER`, `MODEL`, `MODEL_PROVIDER_API_KEY`, `MODEL_PROVIDER_BASE_URL`,
101
+ or `.nylorun/auth.json`), unless the Tenant has a model or
102
+ `NYLORUN_DEV_MODEL=fixture`. `.env` never configures the stack itself.
103
+
104
+ A fresh clone or a second worktree has no link: `nylorun start` there creates a
105
+ new stack, or `nylorun start --name <stack>` attaches it to an existing one so
106
+ both share the stack's Tenant. `--no-link` starts a stack without linking the
107
+ working directory (scripts). A link of format 0 or 1 named a Tenant on the
108
+ shared stack of an older Runtime: `start` says so, creates the project's own
109
+ stack and replaces the link.
110
+
111
+ The Runtime registers the derived principals of `NYLORUN_DERIVED_PRINCIPALS`
112
+ (comma-separated, from the environment of `nylorun start`, kept in the stack's
113
+ `.env`) when it creates the Tenant; `project` is always among them.
48
114
 
49
115
  ## The stack
50
116
 
51
- `nylorun up` writes `compose.yaml` and `.env` (mode 0600) under
52
- `<Host root>/stack/` on the first run and reuses them after that. It runs the
53
- Compose project `nylorun` (override with `NYLORUN_STACK_PROJECT`): `postgres`,
54
- `restate`, `s2`, `runtime` and `studio`. The Runtime and Studio images are
55
- pinned by this release (`package.json` `nylorun.runtime` and `nylorun.studio`);
117
+ `nylorun start` writes `compose.yaml` and `.env` (mode 0600) under
118
+ `~/.nylorun/stacks/<name>/docker/` on the first run and reuses them after that: `postgres`,
119
+ `restate`, `s2`, `gateway`, `runtime` and `studio`. Postgres initialises the
120
+ stack's database with C collation. The Runtime and Studio images are pinned by
121
+ this release (`package.json` `nylorun.runtime` and `nylorun.studio`);
56
122
  `NYLORUN_RUNTIME_IMAGE` and `NYLORUN_STUDIO_IMAGE` override them (local builds,
57
- CI). Ports publish on loopback only: the Runtime on `8787`, Studio on `4161`
58
- and the Restate UI on `9070`, or free ports chosen on the first start and kept
59
- in `.env`. While the Host has no Tenant, `up` says how to create one.
60
-
61
- `up` never downgrades the stack on its own. Every project and app on the
62
- machine shares it, and a Runtime older than a Tenant's schema quarantines that
63
- Tenant. `up` records the pinned Runtime version in `host.json`
64
- (`runtimeVersion`) and exits 5 when that version is older than the one recorded
65
- there or the one running. Update nylorun, or pass `--allow-downgrade` to start
66
- the older Runtime anyway. With `NYLORUN_RUNTIME_IMAGE` set, the image's version
67
- is unknown: `up` does not check it and keeps the recorded version.
68
-
69
- `up` prints Studio as `http://localhost:<port>`. Studio has no password: in a
70
- terminal (not in CI, and not with `--no-open`), `up` asks the Studio container
123
+ CI). Ports publish on loopback only: the Runtime on `8787`, its operator
124
+ listener (Admin API) on `8788`, Studio on `4161` and the Restate UI on `9070`,
125
+ or free ports chosen on the stack's first start, avoiding the ports other
126
+ stacks keep, and kept in its `.env`.
127
+
128
+ `start` prints Studio as `http://localhost:<port>`. Studio has no password: in a
129
+ terminal (not in CI, and not with `--no-open`), `start` asks the Studio container
71
130
  for a single-use login token with the admin key (`POST /_studio/login-tokens`)
72
- and opens `http://localhost:<port>/login?token=…` in the browser. That sets a
73
- session cookie for 30 days, which survives Studio restarts, so the printed URL
74
- keeps working in that browser. The token itself is never printed unless no
75
- browser starts. Otherwise `up` says to run `nylorun studio`, which signs a
76
- browser in the same way; `nylorun studio --no-open` prints the login URL (it
77
- works once, for two minutes) instead. Inside a linked project, `nylorun studio`
78
- reads `.nylorun/link.json` (never writes it) and lands on that project's Tenant.
131
+ and opens `http://localhost:<port>/login?token=…` on the stack's Tenant in the
132
+ browser. That sets a session cookie for 30 days, which survives Studio
133
+ restarts, so the printed URL keeps working in that browser. The token itself is
134
+ never printed unless no browser starts. Otherwise `start` says to run `nylorun
135
+ studio`, which signs a browser in the same way; `nylorun studio --no-open`
136
+ prints the login URL (it works once, for two minutes) instead.
79
137
 
80
138
  ### Embedding Studio in a desktop app
81
139
 
82
140
  A desktop app such as Babai Desktop can show Studio inside its own window, in
83
141
  an iframe loaded from Studio's URL (`studio.url` in `nylorun status --json`).
84
142
  Only exact origins listed in `NYLORUN_STUDIO_FRAME_ANCESTORS` (in
85
- `<Host root>/stack/.env`) may frame it. The default is Babai's
143
+ `~/.nylorun/stacks/<name>/docker/.env`) may frame it. The default is Babai's
86
144
  `nylorun://localhost http://nylorun.localhost`; `nylorun status` lists them
87
145
  under `Embeds`. While building such an app, add its dev server once with
88
146
  `nylorun start --studio-embed-origin http://localhost:1420`; the list is kept
89
147
  across starts until `--studio-embed-origin-reset`. Wildcards are refused.
90
148
 
91
- The app's backend mints a single-use login token limited to one Tenant with
149
+ The app's backend mints a single-use login token for the stack's Tenant with
92
150
  `mintStudioLoginToken` from `@nylorun/admin` (it needs the admin key), and its
93
151
  page passes the token to Studio by `postMessage`. The message contract is
94
152
  `@nylorun/agents/studio-embed`.
@@ -102,12 +160,29 @@ extra containers. It is not a VM or container boundary.
102
160
 
103
161
  ## Host root
104
162
 
105
- The **Host root** is `NYLORUN_HOME` or `~/.nylorun`. It is bind-mounted into the
106
- Runtime and Studio containers, and holds `host.json` (the client-facing host
107
- and port), `host-credentials.json` (the admin key, mode 0600), the stack files
108
- and each Tenant's directory. Tenant data lives in the stack's Postgres, Restate
109
- and S2 volumes. The stack is one per machine: every project on it shares it,
110
- each with its own Tenant.
163
+ The **Host root** is `~/.nylorun/stacks/<name>/`, or `NYLORUN_HOME`. It is
164
+ bind-mounted into the Runtime and Studio containers, and holds `stack.json`
165
+ (the stack's name and the project it was created for), `host.json` (the
166
+ client-facing host and port), `host-credentials.json` (the admin key, mode
167
+ 0600), the Docker Compose files in `docker/`, the Tenant directory `tenant/` (homes, logs) and
168
+ `keys/vault-kek`, the Tenant's vault key, which only the gateway container
169
+ mounts. The Tenant's data lives in the stack's Postgres, Restate and S2
170
+ volumes.
171
+
172
+ `nylorun reset` deletes the selected stack's volumes, `tenant/` and `keys/`, and keeps
173
+ its files and ports; the next start creates a new Tenant and relinks the
174
+ project. `nylorun delete <stack> --yes` removes the stack's containers,
175
+ volumes and Host root: the vault key (KEK) and all the Tenant's data go with it.
176
+
177
+ ## Upgrading from a shared stack
178
+
179
+ Older releases ran one stack per machine (Compose project `nylorun`, Host root
180
+ `~/.nylorun`) with a Tenant per project. This release starts fresh and leaves
181
+ that stack as it is: `nylorun start` mentions it once, and `nylorun ls` shows
182
+ it. `nylorun legacy stop` stops it; `nylorun legacy delete --yes` removes its
183
+ containers, volumes and files under `~/.nylorun` (never `~/.nylorun/stacks`).
184
+ Model credentials come from each project's `.env` (or Studio), and agents
185
+ register again (`npm run dev`). See [MIGRATION.md](../MIGRATION.md).
111
186
 
112
187
  ## Exit codes
113
188
 
@@ -115,11 +190,11 @@ each with its own Tenant.
115
190
  | --- | --- |
116
191
  | 0 | Success |
117
192
  | 1 | Generic failure, including a missing Docker or Compose v2 |
118
- | 2 | Usage error, or a removed or moved command |
119
- | 3 | `status`: the Runtime is not answering; `stop`/`logs`: no stack yet |
193
+ | 2 | Usage error (including no stack selected, or `delete` without `--yes`), or a removed or moved command |
194
+ | 3 | `status`: the Runtime is not answering; `stop`/`logs`: no stack yet; `delete`: no such stack |
120
195
  | 4 | The Runtime port is held by another Host |
121
- | 5 | `up`/`start`/`studio`: this nylorun pins a Runtime older than the one the Host last ran or is running; update nylorun, or `up --allow-downgrade` |
122
- | 7 | The stack or Studio did not become ready |
196
+ | 5 | `up`/`start`/`studio`: this nylorun pins a Runtime older than the one that last ran the stack; update nylorun, or `start --allow-downgrade` |
197
+ | 7 | The stack, its Tenant or Studio did not become ready (an unavailable Tenant's cause is printed) |
123
198
  | 130 / 143 | SIGINT / SIGTERM |
124
199
 
125
200
  ## Troubleshooting
@@ -127,9 +202,10 @@ each with its own Tenant.
127
202
  | Symptom | What to do |
128
203
  | --- | --- |
129
204
  | Docker missing or not running | Install or start Docker Desktop, OrbStack or Colima; `nylorun doctor` checks |
130
- | `426` from the Runtime | Upgrade nylorun (`npx nylorun@latest up`), or pin a matching older set |
131
- | `Refusing to downgrade` (exit 5) | Upgrade nylorun (`npx nylorun@latest up`); `--allow-downgrade` only if you accept quarantined Tenants |
132
- | Port conflict | Change `NYLORUN_PORT` / `NYLORUN_STUDIO_PORT` in `<Host root>/stack/.env` |
205
+ | `426` from the Runtime | Upgrade nylorun (`npx nylorun@latest start`), or pin a matching older set |
206
+ | `Refusing to start Runtime …` (exit 5) | Upgrade nylorun (`npx nylorun@latest start`); `--allow-downgrade` only when both Runtimes share the database schema |
207
+ | `The Tenant of stack … is unavailable` (exit 7) | Follow the repair it names; `nylorun logs runtime` |
208
+ | Port conflict | Change `NYLORUN_PORT` / `NYLORUN_STUDIO_PORT` in `~/.nylorun/stacks/<name>/docker/.env` |
133
209
  | Logs | `nylorun logs runtime -f` |
134
210
  | Studio login expired | `nylorun studio` |
135
211
 
package/dist/cli.js CHANGED
@@ -2,23 +2,26 @@
2
2
  import "./baseline.js";
3
3
  import { baselineEnv } from "./baseline.js";
4
4
  import { CliError } from "./errors.js";
5
- import { linkedTenantId } from "./project/link.js";
6
- import { isStackCommand, stackCommand, stackUsage, studioCommand, tenantStudioPath, } from "./stack/index.js";
7
- const usage = `nylorun <up|down|start|stop|status|logs|studio|reset|doctor>
5
+ import { isStackCommand, stackCommand, stackUsage, studioCommand, } from "./stack/index.js";
6
+ const usage = `nylorun <up|down|start|stop|status|logs|studio|reset|ls|delete|legacy|doctor>
8
7
 
9
- Local stack (Docker Compose):
8
+ Local stacks (Docker Compose), one per project:
10
9
  ${stackUsage}
11
10
  doctor [--json] check Node, Docker and Compose v2, and the stack's health
12
11
 
13
- nylorun sets up and runs the local stack. Tenants, Project links and model
12
+ A command acts on the stack --name or NYLORUN_STACK names, else the linked project's;
13
+ NYLORUN_HOME sets its Host root (default ~/.nylorun/stacks/<name>).
14
+
15
+ nylorun sets up and runs local stacks. "nylorun start" in a project creates the
16
+ project's stack, its one Tenant and the Project link. Agents, sessions and model
14
17
  providers belong to the Runtime client: npx @nylorun/cli --help`;
15
18
  const CLIENT = "npx @nylorun/cli";
16
- /** Commands that moved to the Runtime client (`@nylorun/cli`, command `nylo`). */
19
+ /** Commands that were removed, or moved to the Runtime client (`@nylorun/cli`, command `nylo`). */
17
20
  const MOVED_TO_CLIENT = {
18
- dev: `nylorun dev was removed: run \`${CLIENT} tenant create\` once in your project, then your project's \`npm run dev\`.`,
19
- tenant: `Tenant commands moved to the Runtime client: ${CLIENT} tenant …`,
21
+ dev: "nylorun dev was removed: run `npx nylorun start` in your project (it creates the project's stack, its Tenant and the Project link), then your project's `npm run dev`.",
22
+ tenant: `Tenant commands were removed: a stack serves one Tenant, which \`npx nylorun start\` in a project creates with the stack and the Project link. Use nylorun status|reset, or ${CLIENT} status|reset|endpoints.`,
20
23
  configure: `nylorun configure moved to the Runtime client: ${CLIENT} configure`,
21
- serve: "nylorun serve was removed. Use node dist/src/main.js with NYLORUN_RUNTIME_URL, NYLORUN_TENANT and NYLORUN_SERVER_KEY.",
24
+ serve: "nylorun serve was removed. Use node dist/src/main.js with NYLORUN_RUNTIME_URL and NYLORUN_SERVER_KEY.",
22
25
  runtime: "nylorun runtime was removed: the local Runtime runs in the Docker Compose stack. Use nylorun up|down|status|logs.",
23
26
  };
24
27
  const LOCAL_UI_REMOVED = "--local-ui was removed: Studio runs in the stack's studio container. Run nylorun studio.";
@@ -37,8 +40,7 @@ async function main() {
37
40
  if (command === "studio") {
38
41
  if (args.includes("--local-ui"))
39
42
  throw usageError(LOCAL_UI_REMOVED);
40
- const tenantId = await linkedTenantId();
41
- process.exitCode = await studioCommand(args, baselineEnv(), tenantId ? { next: tenantStudioPath(tenantId) } : {});
43
+ process.exitCode = await studioCommand(args, baselineEnv());
42
44
  return;
43
45
  }
44
46
  if (isStackCommand(command)) {
package/dist/doctor.d.ts CHANGED
@@ -6,7 +6,9 @@ export interface StackDoctorReport {
6
6
  };
7
7
  docker: Check;
8
8
  compose?: Check;
9
- stack?: Pick<StackStatus, "project" | "home" | "state" | "runtime" | "studio">;
9
+ stack?: Pick<StackStatus, "name" | "project" | "home" | "state" | "runtime" | "tenant" | "studio" | "gateway">;
10
+ /** Why no stack was checked: none is selected here (no link, NYLORUN_STACK or NYLORUN_HOME). */
11
+ noStack?: string;
10
12
  }
11
13
  /**
12
14
  * `nylorun doctor`: check the prerequisites of the local stack (Node 24+,
package/dist/doctor.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { CliError } from "./errors.js";
1
2
  import { checkDocker, defaultStackDeps, readStackStatus, } from "./stack/index.js";
2
3
  /** Oldest Node the stack's tooling and the developer's application run on. */
3
4
  const MIN_NODE_MAJOR = 24;
@@ -17,16 +18,29 @@ export async function doctorStack(options) {
17
18
  ...checks,
18
19
  };
19
20
  if (checks.docker.ok && checks.compose?.ok) {
20
- const status = await readStackStatus(deps);
21
- report.stack = {
22
- project: status.project,
23
- home: status.home,
24
- state: status.state,
25
- runtime: status.runtime,
26
- studio: status.studio,
27
- };
21
+ try {
22
+ const status = await readStackStatus(deps);
23
+ report.stack = {
24
+ name: status.name,
25
+ project: status.project,
26
+ home: status.home,
27
+ state: status.state,
28
+ runtime: status.runtime,
29
+ ...(status.tenant ? { tenant: status.tenant } : {}),
30
+ studio: status.studio,
31
+ gateway: status.gateway,
32
+ };
33
+ }
34
+ catch (error) {
35
+ if (!(error instanceof CliError) || error.exitCode !== 2)
36
+ throw error;
37
+ report.noStack = error.message;
38
+ }
28
39
  }
29
- const stackBroken = report.stack?.state === "running" && !report.stack.runtime.healthy;
40
+ const stackBroken = report.stack?.state === "running" &&
41
+ (!report.stack.runtime.healthy ||
42
+ !report.stack.gateway.healthy ||
43
+ report.stack.tenant?.cause !== undefined);
30
44
  const failed = !nodeOk || !checks.docker.ok || checks.compose?.ok === false || stackBroken;
31
45
  if (options.json) {
32
46
  log(JSON.stringify(report, null, 2));
@@ -48,16 +62,18 @@ export async function doctorStack(options) {
48
62
  ["compose", line(checks.compose)],
49
63
  ];
50
64
  const stack = report.stack;
65
+ if (report.noStack)
66
+ rows.push(["stack", `- ${report.noStack}`]);
51
67
  if (stack) {
52
68
  rows.push([
53
69
  "stack",
54
70
  stack.state === "absent"
55
- ? `- not created under ${stack.home}: run nylorun up`
71
+ ? `- ${stack.name} not created under ${stack.home}: run nylorun up`
56
72
  : stack.state === "stopped"
57
- ? `- stopped (project ${stack.project}): run nylorun up`
73
+ ? `- ${stack.name} stopped (Compose project ${stack.project}): run nylorun up`
58
74
  : stack.runtime.healthy
59
- ? `✓ running (project ${stack.project})`
60
- : `✗ running, but the Runtime does not answer: see nylorun status and nylorun logs runtime`,
75
+ ? `✓ ${stack.name} running (Compose project ${stack.project})`
76
+ : `✗ ${stack.name} running, but the Runtime does not answer: see nylorun status and nylorun logs runtime`,
61
77
  ]);
62
78
  if (stack.state === "running") {
63
79
  rows.push([
@@ -66,6 +82,19 @@ export async function doctorStack(options) {
66
82
  ? `✓ ${stack.runtime.url ?? "?"} · ${stack.runtime.version ?? "?"}`
67
83
  : `✗ ${stack.runtime.url ?? "?"} not answering`,
68
84
  ]);
85
+ rows.push([
86
+ "gateway",
87
+ stack.gateway.healthy
88
+ ? `✓ ${stack.gateway.state} · combined packing (runtime: core,loop; gateway: gates)`
89
+ : `✗ ${stack.gateway.state}: model calls fail; see nylorun logs gateway`,
90
+ ]);
91
+ if (stack.tenant)
92
+ rows.push([
93
+ "tenant",
94
+ stack.tenant.state === "open"
95
+ ? `✓ ${stack.tenant.id ?? "?"} open`
96
+ : `✗ ${stack.tenant.id ?? "?"} unavailable${stack.tenant.cause ? `: ${stack.tenant.cause.code}: ${stack.tenant.cause.repair}` : " (opening)"}`,
97
+ ]);
69
98
  rows.push(["studio", `${stack.studio.url ?? "?"} · ${stack.studio.state}`]);
70
99
  }
71
100
  }
@@ -0,0 +1,8 @@
1
+ /** The derived principal a Project uses; the stack's Runtime registers it on its Tenant. */
2
+ export declare const PROJECT_PRINCIPAL_ID = "project";
3
+ /**
4
+ * Key of a derived principal on the stack's Tenant, from the admin key. A copy of
5
+ * `deriveTenantKey` in `@nylorun/admin` (nylorun depends on `@nylorun/core` only); both are
6
+ * tested against the same fixed vector.
7
+ */
8
+ export declare function deriveTenantKey(adminKey: string, tenantId: string, principalId: string): string;
@@ -0,0 +1,18 @@
1
+ import { createHmac } from "node:crypto";
2
+ /** The derived principal a Project uses; the stack's Runtime registers it on its Tenant. */
3
+ export const PROJECT_PRINCIPAL_ID = "project";
4
+ /**
5
+ * Key of a derived principal on the stack's Tenant, from the admin key. A copy of
6
+ * `deriveTenantKey` in `@nylorun/admin` (nylorun depends on `@nylorun/core` only); both are
7
+ * tested against the same fixed vector.
8
+ */
9
+ export function deriveTenantKey(adminKey, tenantId, principalId) {
10
+ const message = Buffer.concat([
11
+ Buffer.from("nylorun/principal/v1", "utf8"),
12
+ Buffer.from([0]),
13
+ Buffer.from(principalId, "utf8"),
14
+ Buffer.from([0]),
15
+ Buffer.from(tenantId, "utf8"),
16
+ ]);
17
+ return createHmac("sha256", Buffer.from(adminKey, "utf8")).update(message).digest("hex");
18
+ }
@@ -1,6 +1,34 @@
1
1
  /**
2
- * The linked Project's Tenant id, read from `.nylorun/link.json`, or undefined
3
- * outside a linked Project. nylorun only reads the link: `@nylorun/cli` writes
4
- * it when it creates or chooses a Tenant.
2
+ * The Project link (`.nylorun/link.json`) and credentials (`.nylorun/credentials.json`).
3
+ * `nylorun start` writes both, format 2: the stack the Project uses, its URL and Host id, and
4
+ * the Tenant id as information (nothing selects a Tenant). Formats 0 and 1 named a Tenant on a
5
+ * multi-Tenant Host of an older Runtime.
5
6
  */
6
- export declare function linkedTenantId(cwd?: string): Promise<string | undefined>;
7
+ export interface ProjectLink {
8
+ format: 0 | 1 | 2;
9
+ /** The local stack (format 2). */
10
+ stack?: string;
11
+ hostUrl: string;
12
+ hostId: string;
13
+ tenantId?: string;
14
+ }
15
+ export declare function linkPath(projectRoot: string): string;
16
+ export declare function credentialsPath(projectRoot: string): string;
17
+ /** The Project's link, or undefined when it has none. An unreadable link is an error. */
18
+ export declare function readProjectLink(projectRoot: string): Promise<ProjectLink | undefined>;
19
+ export declare function writeProjectLink(projectRoot: string, link: {
20
+ stack: string;
21
+ hostUrl: string;
22
+ hostId: string;
23
+ tenantId: string;
24
+ }): Promise<void>;
25
+ /** The Project's application key and principal, or undefined when absent or unreadable. */
26
+ export declare function readProjectCredentials(projectRoot: string): Promise<{
27
+ applicationKey: string;
28
+ principalId: string;
29
+ } | undefined>;
30
+ /** `.nylorun/credentials.json` (format 1, mode 0600). */
31
+ export declare function writeProjectCredentials(projectRoot: string, credentials: {
32
+ applicationKey: string;
33
+ principalId: string;
34
+ }): Promise<void>;
@@ -1,21 +1,90 @@
1
- import { readFile } from "node:fs/promises";
1
+ import { randomBytes } from "node:crypto";
2
+ import { chmod, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
2
3
  import { join } from "node:path";
3
- import { isTenantId } from "@nylorun/core/compatibility";
4
- import { findProjectRoot } from "./root.js";
5
- /**
6
- * The linked Project's Tenant id, read from `.nylorun/link.json`, or undefined
7
- * outside a linked Project. nylorun only reads the link: `@nylorun/cli` writes
8
- * it when it creates or chooses a Tenant.
9
- */
10
- export async function linkedTenantId(cwd = process.cwd()) {
11
- const root = findProjectRoot(cwd);
12
- if (!root)
13
- return undefined;
4
+ import { ProjectLinkFileSchema } from "@nylorun/core/contracts";
5
+ import { CliError } from "../errors.js";
6
+ export function linkPath(projectRoot) {
7
+ return join(projectRoot, ".nylorun", "link.json");
8
+ }
9
+ export function credentialsPath(projectRoot) {
10
+ return join(projectRoot, ".nylorun", "credentials.json");
11
+ }
12
+ /** The Project's link, or undefined when it has none. An unreadable link is an error. */
13
+ export async function readProjectLink(projectRoot) {
14
+ let text;
15
+ try {
16
+ text = await readFile(linkPath(projectRoot), "utf8");
17
+ }
18
+ catch (error) {
19
+ if (error.code === "ENOENT")
20
+ return undefined;
21
+ throw error;
22
+ }
23
+ let value;
24
+ try {
25
+ value = JSON.parse(text);
26
+ }
27
+ catch {
28
+ value = undefined;
29
+ }
30
+ const parsed = ProjectLinkFileSchema.safeParse(value);
31
+ if (!parsed.success)
32
+ throw new CliError(`Invalid or newer Project link at ${linkPath(projectRoot)}. Upgrade nylorun, or remove the file and run "npx nylorun start" again.`, 1);
33
+ const link = parsed.data;
34
+ return {
35
+ format: link.format,
36
+ ...(link.stack ? { stack: link.stack } : {}),
37
+ hostUrl: link.hostUrl.replace(/\/$/, ""),
38
+ hostId: link.hostId,
39
+ ...(link.tenantId ? { tenantId: link.tenantId } : {}),
40
+ };
41
+ }
42
+ async function writePrivate(path, value) {
43
+ const temporary = `${path}.${randomBytes(8).toString("hex")}.tmp`;
14
44
  try {
15
- const link = JSON.parse(await readFile(join(root, ".nylorun", "link.json"), "utf8"));
16
- return isTenantId(link.tenantId) ? link.tenantId : undefined;
45
+ await writeFile(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600 });
46
+ await rename(temporary, path);
47
+ await chmod(path, 0o600);
48
+ }
49
+ finally {
50
+ await rm(temporary, { force: true });
51
+ }
52
+ }
53
+ /** `.nylorun/` mode 0700 with its own `.gitignore` of `*`; the Project's is never edited. */
54
+ async function ensureProjectDir(projectRoot) {
55
+ const dir = join(projectRoot, ".nylorun");
56
+ await mkdir(dir, { recursive: true, mode: 0o700 });
57
+ await chmod(dir, 0o700);
58
+ await writeFile(join(dir, ".gitignore"), "*\n", { mode: 0o600 });
59
+ }
60
+ export async function writeProjectLink(projectRoot, link) {
61
+ await ensureProjectDir(projectRoot);
62
+ await writePrivate(linkPath(projectRoot), {
63
+ format: 2,
64
+ stack: link.stack,
65
+ hostUrl: link.hostUrl.replace(/\/$/, ""),
66
+ hostId: link.hostId,
67
+ tenantId: link.tenantId,
68
+ });
69
+ }
70
+ /** The Project's application key and principal, or undefined when absent or unreadable. */
71
+ export async function readProjectCredentials(projectRoot) {
72
+ try {
73
+ const value = JSON.parse(await readFile(credentialsPath(projectRoot), "utf8"));
74
+ return typeof value.applicationKey === "string" && typeof value.principalId === "string"
75
+ ? { applicationKey: value.applicationKey, principalId: value.principalId }
76
+ : undefined;
17
77
  }
18
78
  catch {
19
79
  return undefined;
20
80
  }
21
81
  }
82
+ /** `.nylorun/credentials.json` (format 1, mode 0600). */
83
+ export async function writeProjectCredentials(projectRoot, credentials) {
84
+ await ensureProjectDir(projectRoot);
85
+ await writePrivate(credentialsPath(projectRoot), {
86
+ format: 1,
87
+ applicationKey: credentials.applicationKey,
88
+ principalId: credentials.principalId,
89
+ });
90
+ }