nylorun 0.0.0-bootstrap → 0.1.1-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.
Files changed (44) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +192 -0
  3. package/README.md +98 -0
  4. package/dist/baseline.d.ts +2 -0
  5. package/dist/baseline.js +10 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +78 -0
  8. package/dist/doctor.d.ts +23 -0
  9. package/dist/doctor.js +76 -0
  10. package/dist/errors.d.ts +5 -0
  11. package/dist/errors.js +9 -0
  12. package/dist/home.d.ts +6 -0
  13. package/dist/home.js +15 -0
  14. package/dist/project/link.d.ts +6 -0
  15. package/dist/project/link.js +21 -0
  16. package/dist/project/root.d.ts +7 -0
  17. package/dist/project/root.js +44 -0
  18. package/dist/stack/commands.d.ts +103 -0
  19. package/dist/stack/commands.js +478 -0
  20. package/dist/stack/compose-file.d.ts +14 -0
  21. package/dist/stack/compose-file.js +128 -0
  22. package/dist/stack/docker.d.ts +38 -0
  23. package/dist/stack/docker.js +101 -0
  24. package/dist/stack/env-file.d.ts +32 -0
  25. package/dist/stack/env-file.js +93 -0
  26. package/dist/stack/host-files.d.ts +36 -0
  27. package/dist/stack/host-files.js +93 -0
  28. package/dist/stack/images.d.ts +22 -0
  29. package/dist/stack/images.js +28 -0
  30. package/dist/stack/index.d.ts +13 -0
  31. package/dist/stack/index.js +75 -0
  32. package/dist/stack/paths.d.ts +20 -0
  33. package/dist/stack/paths.js +18 -0
  34. package/dist/stack/ports.d.ts +18 -0
  35. package/dist/stack/ports.js +45 -0
  36. package/dist/stack/prepare.d.ts +28 -0
  37. package/dist/stack/prepare.js +65 -0
  38. package/dist/stack/restate-identity.d.ts +28 -0
  39. package/dist/stack/restate-identity.js +92 -0
  40. package/dist/stack/studio-login.d.ts +14 -0
  41. package/dist/stack/studio-login.js +37 -0
  42. package/dist/stack/versions.d.ts +9 -0
  43. package/dist/stack/versions.js +28 -0
  44. package/package.json +43 -3
package/CHANGELOG.md ADDED
@@ -0,0 +1,37 @@
1
+ # nylorun
2
+
3
+ ## 0.1.1-beta
4
+
5
+ ### Patch Changes
6
+
7
+ - Pin core to the tested release.
8
+ - Pin runtime to the tested release.
9
+ - Pin studio to the tested release.
10
+ - Updated dependencies [a322696]
11
+ - Updated dependencies [844bff3]
12
+ - Updated dependencies [a322696]
13
+ - @nylorun/core@0.7.0-beta
14
+
15
+ ## 0.1.0-beta
16
+
17
+ ### Minor Changes
18
+
19
+ - ba1b239: **`nylorun` sets up the local stack; `@nylorun/cli` becomes the Runtime client `nylo` (breaking beta).**
20
+
21
+ - New unscoped package **`nylorun`**: `npx nylorun up` sets up the Docker stack on the first run and starts it after that, from any directory; `npx nylorun down` stops it (volumes are kept). `up` and `down` are aliases of `start` and `stop`. It also owns `status`, `logs`, `studio`, `reset` and `doctor`, pins the Runtime and Studio images (`package.json` `nylorun.runtime` / `nylorun.studio`), depends on `@nylorun/core` only, and never creates Tenants.
22
+ - **`@nylorun/cli`** is the Runtime client with the command **`nylo`**: `nylo tenant create [name]` (creates the Tenant; in a project, writes the Project link and seeds the model provider and sandbox from `.env`), `nylo tenant current|list|use|status|reset|delete`, `nylo configure`, `nylo env` (was `nylorun status --env`) and `nylo doctor sandbox`. It no longer provides the `nylorun` command or the stack commands.
23
+ - **Removed:** `nylorun dev` and `nylorun dev --ephemeral`. Link once with `nylo tenant create`, then run the project's own `npm run dev`. Moved commands exit 2 and name their replacement.
24
+ - **Starter:** the generated project depends on `@nylorun/agents` only (no Nylorun devDependency); `dev` is `tsx watch --env-file-if-exists=.env src/main.ts`. `npm create @nylorun/agent` installs the project and prints the next steps (`npx nylorun up`, `npx @nylorun/cli tenant create`, `npm run dev`) instead of starting development; `--no-open` is accepted and ignored.
25
+ - `connectAgents` names those steps when it finds no Runtime connection. Runtime repair hints, model errors and core's sandbox message name `nylo` and `nylorun up`.
26
+
27
+ ### Patch Changes
28
+
29
+ - Pin core to the tested release.
30
+ - Pin runtime to the tested release.
31
+ - Pin studio to the tested release.
32
+ - Updated dependencies [bf1c2da]
33
+ - Updated dependencies [ba1b239]
34
+ - Updated dependencies [bf1c2da]
35
+ - Updated dependencies [bf1c2da]
36
+ - Updated dependencies [bf1c2da]
37
+ - @nylorun/core@0.6.0-beta
package/LICENSE ADDED
@@ -0,0 +1,192 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ Copyright 2026 Nylo
181
+
182
+ Licensed under the Apache License, Version 2.0 (the "License");
183
+ you may not use this file except in compliance with the License.
184
+ You may obtain a copy of the License at
185
+
186
+ http://www.apache.org/licenses/LICENSE-2.0
187
+
188
+ Unless required by applicable law or agreed to in writing, software
189
+ distributed under the License is distributed on an "AS IS" BASIS,
190
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
191
+ See the License for the specific language governing permissions and
192
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # nylorun
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`:
5
+
6
+ ```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
9
+ ```
10
+
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:
15
+ [runtime/src/CONTEXT.md](../runtime/src/CONTEXT.md).
16
+
17
+ Prerequisites, installed by the developer (nylorun never downloads them): Node
18
+ 24 or newer, and Docker with Compose v2 ([Docker
19
+ Desktop](https://www.docker.com/products/docker-desktop/),
20
+ [OrbStack](https://orbstack.dev), [Colima](https://github.com/abiosoft/colima) or
21
+ another engine). On Windows, install them inside
22
+ [WSL2](https://learn.microsoft.com/windows/wsl/install); native Windows is not
23
+ supported.
24
+
25
+ ```sh
26
+ npx nylorun doctor # Node 24+, Docker, Compose v2, and the stack's health
27
+ ```
28
+
29
+ ## Commands
30
+
31
+ ```sh
32
+ nylorun up|start [--no-studio] # set up (first run) and start the stack; print the Runtime URL and a Studio login URL
33
+ nylorun down|stop # stop the containers; keep volumes
34
+ nylorun status [--json] # services, endpoints, Runtime health
35
+ nylorun logs [service] [-f] [--tail <n>] # postgres, restate, s2, runtime, studio
36
+ nylorun studio [--no-open] # fresh Studio login (on the linked Project's Tenant); starts the stack if needed
37
+ nylorun reset [--yes] # delete the stack's volumes and every Tenant
38
+ nylorun doctor [--json] # prerequisites and stack health
39
+ ```
40
+
41
+ `up` and `down` are the Docker Compose spellings of `start` and `stop`: `down`
42
+ stops the containers and keeps the volumes, so no Tenant data is lost.
43
+ `nylorun stack <command>` still works as a hidden alias. Commands that act on a
44
+ Tenant moved to the Runtime client and exit 2 naming the replacement:
45
+ `nylorun dev`, `nylorun tenant …`, `nylorun configure`, `nylorun status --env`
46
+ and `nylorun doctor sandbox`.
47
+
48
+ ## The stack
49
+
50
+ `nylorun up` writes `compose.yaml` and `.env` (mode 0600) under
51
+ `<Host root>/stack/` on the first run and reuses them after that. It runs the
52
+ Compose project `nylorun` (override with `NYLORUN_STACK_PROJECT`): `postgres`,
53
+ `restate`, `s2`, `runtime` and `studio`. The Runtime and Studio images are
54
+ pinned by this release (`package.json` `nylorun.runtime` and `nylorun.studio`);
55
+ `NYLORUN_RUNTIME_IMAGE` and `NYLORUN_STUDIO_IMAGE` override them (local builds,
56
+ CI). Ports publish on loopback only: the Runtime on `8787`, Studio on `4161`
57
+ and the Restate UI on `9070`, or free ports chosen on the first start and kept
58
+ in `.env`. While the Host has no Tenant, `up` says how to create one.
59
+
60
+ Studio has no password: nylorun asks the Studio container for a single-use
61
+ login token with the admin key (`POST /_studio/login-tokens`) and opens
62
+ `http://localhost:<port>/login?token=…`, which sets a session cookie. The
63
+ token expires after two minutes; `nylorun studio` mints a fresh one. Inside a
64
+ linked project, `nylorun studio` reads `.nylorun/link.json` (never writes it)
65
+ and lands on that project's Tenant.
66
+
67
+ ## Host root
68
+
69
+ The **Host root** is `NYLORUN_HOME` or `~/.nylorun`. It is bind-mounted into the
70
+ Runtime and Studio containers, and holds `host.json` (the client-facing host
71
+ and port), `host-credentials.json` (the admin key, mode 0600), the stack files
72
+ and each Tenant's directory. Tenant data lives in the stack's Postgres, Restate
73
+ and S2 volumes. The stack is one per machine: every project on it shares it,
74
+ each with its own Tenant.
75
+
76
+ ## Exit codes
77
+
78
+ | Code | Meaning |
79
+ | --- | --- |
80
+ | 0 | Success |
81
+ | 1 | Generic failure, including a missing Docker or Compose v2 |
82
+ | 2 | Usage error, or a removed or moved command |
83
+ | 3 | `status`: the Runtime is not answering; `stop`/`logs`: no stack yet |
84
+ | 4 | The Runtime port is held by another Host |
85
+ | 7 | The stack or Studio did not become ready |
86
+ | 130 / 143 | SIGINT / SIGTERM |
87
+
88
+ ## Troubleshooting
89
+
90
+ | Symptom | What to do |
91
+ | --- | --- |
92
+ | Docker missing or not running | Install or start Docker Desktop, OrbStack or Colima; `nylorun doctor` checks |
93
+ | `426` from the Runtime | Upgrade nylorun (`npx nylorun@latest up`), or pin a matching older set |
94
+ | Port conflict | Change `NYLORUN_PORT` / `NYLORUN_STUDIO_PORT` in `<Host root>/stack/.env` |
95
+ | Logs | `nylorun logs runtime -f` |
96
+ | Studio login expired | `nylorun studio` |
97
+
98
+ See [MIGRATION.md](../MIGRATION.md).
@@ -0,0 +1,2 @@
1
+ /** Frozen map captured when this module first loads. */
2
+ export declare function baselineEnv(): Readonly<Record<string, string | undefined>>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Snapshot of the process environment at CLI module load.
3
+ */
4
+ const snapshot = Object.freeze({
5
+ ...process.env,
6
+ });
7
+ /** Frozen map captured when this module first loads. */
8
+ export function baselineEnv() {
9
+ return snapshot;
10
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import "./baseline.js";
package/dist/cli.js ADDED
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env node
2
+ import "./baseline.js";
3
+ import { baselineEnv } from "./baseline.js";
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>
8
+
9
+ Local stack (Docker Compose):
10
+ ${stackUsage}
11
+ doctor [--json] check Node, Docker and Compose v2, and the stack's health
12
+
13
+ nylorun sets up and runs the local stack. Tenants, Project links and model
14
+ providers belong to the Runtime client: npx @nylorun/cli --help`;
15
+ const CLIENT = "npx @nylorun/cli";
16
+ /** Commands that moved to the Runtime client (`@nylorun/cli`, command `nylo`). */
17
+ 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 …`,
20
+ 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.",
22
+ runtime: "nylorun runtime was removed: the local Runtime runs in the Docker Compose stack. Use nylorun up|down|status|logs.",
23
+ };
24
+ const LOCAL_UI_REMOVED = "--local-ui was removed: Studio runs in the stack's studio container. Run nylorun studio.";
25
+ const usageError = (message) => new CliError(message, 2);
26
+ async function main() {
27
+ const [command, ...args] = process.argv.slice(2);
28
+ if (!command || command === "--help" || command === "-h")
29
+ return void console.log(usage);
30
+ if (process.platform === "win32")
31
+ throw new CliError("Nylorun does not run on native Windows. Use WSL2: install Node 24 and Docker (Docker Desktop's WSL integration) inside your WSL distribution and run nylorun there (https://learn.microsoft.com/windows/wsl/install).", 1);
32
+ const moved = MOVED_TO_CLIENT[command];
33
+ if (moved)
34
+ throw usageError(moved);
35
+ if (command === "status" && args.includes("--env"))
36
+ throw usageError(`nylorun status --env moved to the Runtime client: ${CLIENT} env`);
37
+ if (command === "studio") {
38
+ if (args.includes("--local-ui"))
39
+ throw usageError(LOCAL_UI_REMOVED);
40
+ const tenantId = await linkedTenantId();
41
+ process.exitCode = await studioCommand(args, baselineEnv(), tenantId ? { next: tenantStudioPath(tenantId) } : {});
42
+ return;
43
+ }
44
+ if (isStackCommand(command)) {
45
+ process.exitCode = await stackCommand(command, args, baselineEnv());
46
+ return;
47
+ }
48
+ // `nylorun stack <command>`: the Wave 1 spelling, kept as a hidden alias.
49
+ if (command === "stack") {
50
+ const [name, ...rest] = args;
51
+ if (!isStackCommand(name))
52
+ throw usageError(usage);
53
+ process.exitCode = await stackCommand(name, rest, baselineEnv());
54
+ return;
55
+ }
56
+ if (command === "doctor") {
57
+ // `doctor stack` and `doctor runtime` are older spellings of `doctor`.
58
+ const options = args[0] === "stack" || args[0] === "runtime" ? args.slice(1) : args;
59
+ if (args[0] === "sandbox")
60
+ throw usageError(`nylorun doctor sandbox moved to the Runtime client: ${CLIENT} doctor sandbox`);
61
+ if (options.some((option) => option !== "--json"))
62
+ throw usageError("Usage: nylorun doctor [--json]");
63
+ const { doctorStack } = await import("./doctor.js");
64
+ process.exitCode = await doctorStack({ json: options.includes("--json"), env: baselineEnv() });
65
+ return;
66
+ }
67
+ throw usageError(usage);
68
+ }
69
+ async function finish(code) {
70
+ process.exitCode = code;
71
+ for (const stream of [process.stdout, process.stderr])
72
+ await new Promise((resolve) => stream.write("", () => resolve()));
73
+ process.exit(code);
74
+ }
75
+ void main().then(() => finish(process.exitCode === undefined ? 0 : Number(process.exitCode)), (error) => {
76
+ console.error(error instanceof Error ? error.message : String(error));
77
+ return finish(error instanceof CliError ? error.exitCode : 1);
78
+ });
@@ -0,0 +1,23 @@
1
+ import { type Check, type StackDeps, type StackStatus } from "./stack/index.js";
2
+ export interface StackDoctorReport {
3
+ node: {
4
+ version: string;
5
+ ok: boolean;
6
+ };
7
+ docker: Check;
8
+ compose?: Check;
9
+ stack?: Pick<StackStatus, "project" | "home" | "state" | "runtime" | "studio">;
10
+ }
11
+ /**
12
+ * `nylorun doctor`: check the prerequisites of the local stack (Node 24+,
13
+ * Docker, Compose v2) and, when they pass, the stack's health. Prints the fix
14
+ * for each problem and returns 1 when a prerequisite is missing or a running
15
+ * stack is unhealthy; installs and starts nothing.
16
+ */
17
+ export declare function doctorStack(options: {
18
+ json: boolean;
19
+ env?: Readonly<Record<string, string | undefined>>;
20
+ /** Stack dependencies (tests). */
21
+ deps?: StackDeps;
22
+ log?: (line: string) => void;
23
+ }): Promise<number>;
package/dist/doctor.js ADDED
@@ -0,0 +1,76 @@
1
+ import { checkDocker, defaultStackDeps, readStackStatus, } from "./stack/index.js";
2
+ /** Oldest Node the stack's tooling and the developer's application run on. */
3
+ const MIN_NODE_MAJOR = 24;
4
+ /**
5
+ * `nylorun doctor`: check the prerequisites of the local stack (Node 24+,
6
+ * Docker, Compose v2) and, when they pass, the stack's health. Prints the fix
7
+ * for each problem and returns 1 when a prerequisite is missing or a running
8
+ * stack is unhealthy; installs and starts nothing.
9
+ */
10
+ export async function doctorStack(options) {
11
+ const log = options.log ?? ((line) => console.log(line));
12
+ const deps = options.deps ?? defaultStackDeps(options.env ?? process.env);
13
+ const nodeOk = Number(process.versions.node.split(".")[0]) >= MIN_NODE_MAJOR;
14
+ const checks = await checkDocker(deps.docker);
15
+ const report = {
16
+ node: { version: process.versions.node, ok: nodeOk },
17
+ ...checks,
18
+ };
19
+ 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
+ };
28
+ }
29
+ const stackBroken = report.stack?.state === "running" && !report.stack.runtime.healthy;
30
+ const failed = !nodeOk || !checks.docker.ok || checks.compose?.ok === false || stackBroken;
31
+ if (options.json) {
32
+ log(JSON.stringify(report, null, 2));
33
+ return failed ? 1 : 0;
34
+ }
35
+ const line = (check) => check === undefined
36
+ ? "- not checked"
37
+ : check.ok
38
+ ? `✓ ${check.version}`
39
+ : `✗ ${check.problem}`;
40
+ const rows = [
41
+ [
42
+ "node",
43
+ nodeOk
44
+ ? `✓ ${process.versions.node}`
45
+ : `✗ ${process.versions.node}: install Node ${MIN_NODE_MAJOR} or newer`,
46
+ ],
47
+ ["docker", line(checks.docker)],
48
+ ["compose", line(checks.compose)],
49
+ ];
50
+ const stack = report.stack;
51
+ if (stack) {
52
+ rows.push([
53
+ "stack",
54
+ stack.state === "absent"
55
+ ? `- not created under ${stack.home}: run nylorun up`
56
+ : stack.state === "stopped"
57
+ ? `- stopped (project ${stack.project}): run nylorun up`
58
+ : stack.runtime.healthy
59
+ ? `✓ running (project ${stack.project})`
60
+ : `✗ running, but the Runtime does not answer: see nylorun status and nylorun logs runtime`,
61
+ ]);
62
+ if (stack.state === "running") {
63
+ rows.push([
64
+ "runtime",
65
+ stack.runtime.healthy
66
+ ? `✓ ${stack.runtime.url ?? "?"} · ${stack.runtime.version ?? "?"}`
67
+ : `✗ ${stack.runtime.url ?? "?"} not answering`,
68
+ ]);
69
+ rows.push(["studio", `${stack.studio.url ?? "?"} · ${stack.studio.state}`]);
70
+ }
71
+ }
72
+ const width = Math.max(...rows.map(([key]) => key.length)) + 2;
73
+ for (const [key, value] of rows)
74
+ log(` ${key.padEnd(width)}${value}`);
75
+ return failed ? 1 : 0;
76
+ }
@@ -0,0 +1,5 @@
1
+ /** Exit codes are part of the CLI contract; see cli/README.md. */
2
+ export declare class CliError extends Error {
3
+ readonly exitCode: number;
4
+ constructor(message: string, exitCode?: number);
5
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,9 @@
1
+ /** Exit codes are part of the CLI contract; see cli/README.md. */
2
+ export class CliError extends Error {
3
+ exitCode;
4
+ constructor(message, exitCode = 1) {
5
+ super(message);
6
+ this.exitCode = exitCode;
7
+ this.name = "CliError";
8
+ }
9
+ }
package/dist/home.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The Host root: an explicit home, `NYLORUN_HOME`, or `~/.nylorun`. The stack
3
+ * bind-mounts it into the Runtime and Studio containers, and `@nylorun/admin`
4
+ * reads `host.json` and the admin key from it.
5
+ */
6
+ export declare function resolveHome(home?: string, env?: Readonly<Record<string, string | undefined>>): string;
package/dist/home.js ADDED
@@ -0,0 +1,15 @@
1
+ import { homedir } from "node:os";
2
+ import { join, resolve } from "node:path";
3
+ /**
4
+ * The Host root: an explicit home, `NYLORUN_HOME`, or `~/.nylorun`. The stack
5
+ * bind-mounts it into the Runtime and Studio containers, and `@nylorun/admin`
6
+ * reads `host.json` and the admin key from it.
7
+ */
8
+ export function resolveHome(home, env = process.env) {
9
+ if (home !== undefined && home.trim() !== "")
10
+ return resolve(home);
11
+ const fromEnv = env.NYLORUN_HOME?.trim();
12
+ if (fromEnv)
13
+ return resolve(fromEnv);
14
+ return resolve(join(homedir(), ".nylorun"));
15
+ }
@@ -0,0 +1,6 @@
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.
5
+ */
6
+ export declare function linkedTenantId(cwd?: string): Promise<string | undefined>;
@@ -0,0 +1,21 @@
1
+ import { readFile } from "node:fs/promises";
2
+ 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;
14
+ try {
15
+ const link = JSON.parse(await readFile(join(root, ".nylorun", "link.json"), "utf8"));
16
+ return isTenantId(link.tenantId) ? link.tenantId : undefined;
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The nearest `.nylorun` wins so an initialised Project keeps working from a
3
+ * subdirectory; otherwise the nearest package.json defines the Project. The
4
+ * walk stops at the home directory because `~/.nylorun` is the Host root, never
5
+ * a Project root.
6
+ */
7
+ export declare function findProjectRoot(cwd?: string): string | undefined;
@@ -0,0 +1,44 @@
1
+ import { existsSync, realpathSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { dirname, join, parse, resolve } from "node:path";
4
+ /**
5
+ * The nearest `.nylorun` wins so an initialised Project keeps working from a
6
+ * subdirectory; otherwise the nearest package.json defines the Project. The
7
+ * walk stops at the home directory because `~/.nylorun` is the Host root, never
8
+ * a Project root.
9
+ */
10
+ export function findProjectRoot(cwd = process.cwd()) {
11
+ const stop = (() => {
12
+ try {
13
+ return realpathSync(homedir());
14
+ }
15
+ catch {
16
+ return homedir();
17
+ }
18
+ })();
19
+ let directory = resolve(cwd);
20
+ try {
21
+ directory = realpathSync(directory);
22
+ }
23
+ catch {
24
+ /* unresolvable cwd falls through */
25
+ }
26
+ const root = parse(directory).root;
27
+ let fallback;
28
+ for (;;) {
29
+ // The home directory is never a Project, but a package.json below it is.
30
+ if (directory === stop)
31
+ return fallback;
32
+ if (existsSync(join(directory, ".nylorun")))
33
+ return directory;
34
+ if (!fallback && existsSync(join(directory, "package.json")))
35
+ fallback = directory;
36
+ if (directory === root)
37
+ break;
38
+ const parent = dirname(directory);
39
+ if (parent === directory)
40
+ break;
41
+ directory = parent;
42
+ }
43
+ return fallback;
44
+ }