@nylorun/create-agent 0.2.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 ADDED
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0-beta
4
+
5
+ ### Minor Changes
6
+
7
+ - 54ab304: Configure the provider and model after project installation and before development
8
+ starts. Add --skip-config for deferred setup and require it for noninteractive
9
+ creation. Retain the project with recovery instructions when setup fails or is
10
+ cancelled, and cancel pending prompts, authentication, and child processes on
11
+ shutdown.
12
+
13
+ ### Patch Changes
14
+
15
+ - 54ab304: Group generated npm scripts by workflow and remove the redundant `dev:host` alias.
16
+ Use `npm run dev -- --no-studio` for headless development.
17
+ - 54ab304: Support portable Runtime protocol version 2 while retaining legacy Studio
18
+ manifest support. Move the Studio CLI into Runtime: use `nylorun studio
19
+ --agent-url <url>` instead of `nylo studio`. Applications should install Runtime
20
+ directly and keep Studio as a development dependency.
21
+
22
+ Retain session lists and media across development reloads, and recognize agent
23
+ file changes on Windows. Validate noninteractive creator startup during release
24
+ verification with deferred provider configuration.
25
+
26
+ Include Harness in this release so the creator does not rely on an unpublished
27
+ compatibility pin. Ship and verify all four packages together.
28
+
29
+ - Update the tested Harness, Runtime, and Studio compatibility combination.
30
+
31
+ Release notes are maintained with Changesets.
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,55 @@
1
+ # @nylorun/create-agent
2
+
3
+ ```sh
4
+ npm create @nylorun/agent@beta my-agent
5
+ ```
6
+
7
+ Creates a project that directly installs Harness and Runtime, with Studio as a development dependency. The project owns its ordinary `agent/` code and composes the packages in `nylorun.config.ts`. No server or provider implementation is copied into the project.
8
+
9
+ Creation installs dependencies, runs Runtime’s provider/model configuration wizard in the same terminal, then starts development. Pass `-- --no-studio` for a headless project or `-- --no-open` to suppress the browser. `nylorun configure` connects a provider without importing the agent graph.
10
+
11
+ ## Configuration and recovery
12
+
13
+ Use `-- --skip-config` to start development without configuring a provider:
14
+
15
+ ```sh
16
+ npm create @nylorun/agent@beta my-agent -- --skip-config
17
+ ```
18
+
19
+ Without interactive stdin and stdout, creation requires `--skip-config` and fails
20
+ before creating files when it is missing. `--yes` only affects installation; it
21
+ does not skip configuration. After skipping, run `npm run configure` inside the
22
+ project in another terminal before sending a message. Development and Studio
23
+ start immediately; provider configuration takes effect without restarting them.
24
+
25
+ If configuration fails or is cancelled, development does not start and the
26
+ created project is retained. Resume from its directory:
27
+
28
+ ```sh
29
+ cd my-agent
30
+ npm run configure
31
+ npm run dev
32
+ ```
33
+
34
+ If installation failed, run `npm install` first. Ctrl-C exits with status 130;
35
+ SIGTERM exits with status 143. Cancelling setup also cancels pending authentication.
36
+ Configuration saves the provider selection and credentials; it does not make a
37
+ model request to validate connectivity.
38
+
39
+ ## Maintaining examples
40
+
41
+ `starter/` is the canonical project template. `compatibility.json` pins tested Harness, Runtime, and Studio versions. `examples.recipe.json` explicitly adds the eleven-agent registry, local package references, persistence/media configuration, and test dependencies.
42
+
43
+ From the repository root:
44
+
45
+ ```sh
46
+ npm run examples:sync
47
+ npm install --prefix examples
48
+ npm run examples:check
49
+ ```
50
+
51
+ The renderer is shared by project creation, the isolated starter development runner, and examples synchronization. Sync owns shell files listed in `examples/.scaffold-manifest.json`; it never edits `agent/`, tests, local model selection, credentials, or `.data/`. Edit generated configuration in the recipe or template. Conflicts with manual generated-file edits fail before any writes. CI checks the rendered shell and runs examples against the current stack. Package changes can require explicit adaptations in authored code; sync does not rewrite TypeScript imports.
52
+
53
+ `npm run dev:starter` from the repository root previews a fresh project using local packages, including unpublished changes. Each preview has its own retained directory and provider configuration.
54
+
55
+ Repository development: [contributing](../CONTRIBUTING.md). Package publication: [releasing](../RELEASING.md).
@@ -0,0 +1,5 @@
1
+ {
2
+ "harness": "0.11.0-beta",
3
+ "studio": "0.4.0-beta",
4
+ "runtime": "0.1.1-beta"
5
+ }
@@ -0,0 +1,3 @@
1
+ import type { CreateOptions } from "./contracts.js";
2
+ export declare const usage = "Usage: npm create @nylorun/agent@beta <directory> [--no-studio] [--no-open] [--skip-config] [--yes]";
3
+ export declare function parse(argv: readonly string[]): CreateOptions;
@@ -0,0 +1,21 @@
1
+ export const usage = "Usage: npm create @nylorun/agent@beta <directory> [--no-studio] [--no-open] [--skip-config] [--yes]";
2
+ export function parse(argv) {
3
+ const [directory, ...flags] = argv;
4
+ if (!directory || directory.startsWith("-"))
5
+ throw new Error(usage);
6
+ if (flags.some((flag) => ![
7
+ "--studio",
8
+ "--no-studio",
9
+ "--no-open",
10
+ "--skip-config",
11
+ "--yes",
12
+ ].includes(flag)))
13
+ throw new Error(usage);
14
+ return Object.freeze({
15
+ directory,
16
+ studio: !flags.includes("--no-studio"),
17
+ open: !flags.includes("--no-open"),
18
+ yes: flags.includes("--yes"),
19
+ skipConfig: flags.includes("--skip-config"),
20
+ });
21
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ import { mkdir, rename, rm, writeFile, readFile } from "node:fs/promises";
3
+ import { existsSync } from "node:fs";
4
+ import { fileURLToPath } from "node:url";
5
+ import { dirname, join } from "node:path";
6
+ import { createProject, CreationError } from "./project.js";
7
+ import { parse, usage } from "./arguments.js";
8
+ import { CreationCancelled, runCommand } from "./process.js";
9
+ async function main() {
10
+ const argv = process.argv.slice(2);
11
+ if (argv.length === 1 && ["--help", "-h"].includes(argv[0])) {
12
+ console.log(usage);
13
+ return;
14
+ }
15
+ const options = parse(argv);
16
+ const [major, minor] = process.versions.node.split(".").map(Number);
17
+ if (!(major > 22 || (major === 22 && minor >= 19)))
18
+ throw new Error("Nylorun project creation requires Node.js 22.19 or newer.");
19
+ const controller = new AbortController();
20
+ const onInt = () => controller.abort(new CreationCancelled("SIGINT"));
21
+ const onTerm = () => controller.abort(new CreationCancelled("SIGTERM"));
22
+ process.on("SIGINT", onInt);
23
+ process.on("SIGTERM", onTerm);
24
+ try {
25
+ const dependencies = {
26
+ currentDirectory: () => process.cwd(),
27
+ isInteractive: () => Boolean(process.stdin.isTTY && process.stdout.isTTY),
28
+ log: (message) => console.log(message),
29
+ signal: controller.signal,
30
+ exists: async (path) => existsSync(path),
31
+ makeDirectory: async (path) => {
32
+ await mkdir(path, { recursive: true });
33
+ },
34
+ rename,
35
+ remove: async (path) => rm(path, { recursive: true, force: true }),
36
+ write: async (path, content) => writeFile(path, content),
37
+ run: (command, args, directory) => runCommand(command, args, directory, controller.signal),
38
+ };
39
+ const compatibility = JSON.parse(await readFile(join(dirname(fileURLToPath(import.meta.url)), "compatibility.json"), "utf8"));
40
+ await createProject(options, compatibility, dependencies);
41
+ }
42
+ finally {
43
+ process.removeListener("SIGINT", onInt);
44
+ process.removeListener("SIGTERM", onTerm);
45
+ }
46
+ }
47
+ void main().catch((error) => {
48
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
49
+ process.exitCode =
50
+ error instanceof CreationError || error instanceof CreationCancelled
51
+ ? error.exitCode
52
+ : 1;
53
+ });
@@ -0,0 +1,5 @@
1
+ {
2
+ "harness": "0.11.0-beta",
3
+ "studio": "0.4.0-beta",
4
+ "runtime": "0.1.1-beta"
5
+ }
@@ -0,0 +1,28 @@
1
+ export type Compatibility = Readonly<{
2
+ harness: string;
3
+ studio: string;
4
+ runtime: string;
5
+ }>;
6
+ export type CreateOptions = Readonly<{
7
+ directory: string;
8
+ studio: boolean;
9
+ open: boolean;
10
+ yes: boolean;
11
+ skipConfig?: boolean;
12
+ }>;
13
+ export type Process = Readonly<{
14
+ status: number | null;
15
+ signal?: NodeJS.Signals | null;
16
+ }>;
17
+ export type CreatorDependencies = Readonly<{
18
+ currentDirectory: () => string;
19
+ isInteractive: () => boolean;
20
+ log: (message: string) => void;
21
+ signal?: AbortSignal;
22
+ exists: (path: string) => Promise<boolean>;
23
+ makeDirectory: (path: string) => Promise<void>;
24
+ rename: (from: string, to: string) => Promise<void>;
25
+ remove: (path: string) => Promise<void>;
26
+ write: (path: string, content: string) => Promise<void>;
27
+ run: (command: string, args: readonly string[], directory: string) => Promise<Process>;
28
+ }>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { Process } from "./contracts.js";
2
+ export declare class CreationCancelled extends Error {
3
+ readonly signal: NodeJS.Signals;
4
+ readonly exitCode: number;
5
+ constructor(signal: NodeJS.Signals);
6
+ }
7
+ /** Own npm and its descendants, including authentication started by a script. */
8
+ export declare function runCommand(command: string, args: readonly string[], directory: string, signal: AbortSignal): Promise<Process>;
@@ -0,0 +1,102 @@
1
+ import { spawn } from "node:child_process";
2
+ import { setTimeout as delay } from "node:timers/promises";
3
+ export class CreationCancelled extends Error {
4
+ signal;
5
+ exitCode;
6
+ constructor(signal) {
7
+ super(`Creation cancelled (${signal}).`);
8
+ this.signal = signal;
9
+ this.exitCode = signal === "SIGINT" ? 130 : 143;
10
+ }
11
+ }
12
+ /**
13
+ * Run the npm that launched this creator. `npm create` sets npm_execpath, which
14
+ * avoids the Windows `.cmd` shim (Node rejects spawning it without a shell).
15
+ * Arguments are fixed literals, so the shell fallback carries no injection risk.
16
+ */
17
+ function npmInvocation(args) {
18
+ const execPath = process.env.npm_execpath;
19
+ if (execPath && /\.[cm]?js$/u.test(execPath))
20
+ return {
21
+ command: process.execPath,
22
+ args: [execPath, ...args],
23
+ shell: false,
24
+ };
25
+ if (process.platform === "win32")
26
+ return { command: "npm.cmd", args: [...args], shell: true };
27
+ return { command: "npm", args: [...args], shell: false };
28
+ }
29
+ /** Own npm and its descendants, including authentication started by a script. */
30
+ export async function runCommand(command, args, directory, signal) {
31
+ signal.throwIfAborted();
32
+ const invocation = command === "npm"
33
+ ? npmInvocation(args)
34
+ : { command, args: [...args], shell: false };
35
+ const child = spawn(invocation.command, invocation.args, {
36
+ cwd: directory,
37
+ stdio: "inherit",
38
+ detached: process.platform !== "win32",
39
+ shell: invocation.shell,
40
+ });
41
+ let shutdown;
42
+ const stop = (requested) => {
43
+ shutdown ??= stopTree(requested);
44
+ // Await cleanup below, but observe early failures while npm is still exiting.
45
+ void shutdown.catch(() => undefined);
46
+ };
47
+ const onAbort = () => stop(signal.reason instanceof CreationCancelled
48
+ ? signal.reason.signal
49
+ : "SIGTERM");
50
+ signal.addEventListener("abort", onAbort, { once: true });
51
+ if (signal.aborted)
52
+ onAbort();
53
+ try {
54
+ const result = await new Promise((resolve, reject) => {
55
+ child.once("error", reject);
56
+ child.once("close", (status, endedBy) => resolve({ status, signal: endedBy }));
57
+ });
58
+ if (result.signal || result.status === 130 || result.status === 143)
59
+ stop(result.signal ?? (result.status === 130 ? "SIGINT" : "SIGTERM"));
60
+ await shutdown;
61
+ signal.throwIfAborted();
62
+ return result;
63
+ }
64
+ finally {
65
+ signal.removeEventListener("abort", onAbort);
66
+ await shutdown;
67
+ }
68
+ async function stopTree(requested) {
69
+ if (!child.pid)
70
+ return;
71
+ if (process.platform === "win32") {
72
+ await new Promise((resolve) => {
73
+ const killer = spawn("taskkill", ["/pid", String(child.pid), "/T", "/F"], { stdio: "ignore" });
74
+ killer.once("error", () => resolve());
75
+ killer.once("close", () => resolve());
76
+ });
77
+ return;
78
+ }
79
+ const send = (value) => {
80
+ try {
81
+ process.kill(-child.pid, value);
82
+ return true;
83
+ }
84
+ catch (error) {
85
+ if (error.code === "ESRCH")
86
+ return false;
87
+ // EPERM on a liveness probe means the group still exists. Recheck while
88
+ // exiting descendants are reaped; actual signal failures still propagate.
89
+ if (value === 0 && error.code === "EPERM")
90
+ return true;
91
+ throw error;
92
+ }
93
+ };
94
+ if (!send(requested))
95
+ return;
96
+ const deadline = Date.now() + 5000;
97
+ while (send(0) && Date.now() < deadline)
98
+ await delay(25);
99
+ if (send(0))
100
+ send("SIGKILL");
101
+ }
102
+ }
@@ -0,0 +1,6 @@
1
+ import type { Compatibility, CreateOptions, CreatorDependencies } from "./contracts.js";
2
+ export declare class CreationError extends Error {
3
+ readonly exitCode: number;
4
+ constructor(message: string, exitCode?: number);
5
+ }
6
+ export declare function createProject(options: CreateOptions, compatibility: Compatibility, dependencies: CreatorDependencies): Promise<void>;
@@ -0,0 +1,88 @@
1
+ import { basename, dirname, isAbsolute, join, relative, resolve, } from "node:path";
2
+ import { randomUUID } from "node:crypto";
3
+ import { starterFiles } from "./scaffold.js";
4
+ import { CreationCancelled } from "./process.js";
5
+ export class CreationError extends Error {
6
+ exitCode;
7
+ constructor(message, exitCode = 1) {
8
+ super(message);
9
+ this.exitCode = exitCode;
10
+ }
11
+ }
12
+ export async function createProject(options, compatibility, dependencies) {
13
+ const currentDirectory = resolve(dependencies.currentDirectory());
14
+ const destination = resolve(currentDirectory, options.directory);
15
+ const pathFromCurrentDirectory = relative(currentDirectory, destination);
16
+ if (isAbsolute(options.directory) ||
17
+ pathFromCurrentDirectory === "" ||
18
+ pathFromCurrentDirectory === ".." ||
19
+ pathFromCurrentDirectory.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`))
20
+ throw new Error("Target directory must be a new child of the current directory.");
21
+ if (await dependencies.exists(destination))
22
+ throw new Error(`Target directory already exists: ${destination}`);
23
+ if (!options.skipConfig && !dependencies.isInteractive())
24
+ throw new Error("Provider configuration requires interactive stdin and stdout. " +
25
+ `To configure later, run: npm create @nylorun/agent@beta ${quote(options.directory)} -- --skip-config`);
26
+ dependencies.signal?.throwIfAborted();
27
+ const temporary = join(dirname(destination), `.${basename(destination)}-${randomUUID()}`);
28
+ await dependencies.makeDirectory(temporary);
29
+ try {
30
+ for (const [relative, content] of Object.entries(await starterFiles(compatibility, options.studio))) {
31
+ const file = join(temporary, relative);
32
+ await dependencies.makeDirectory(dirname(file));
33
+ await dependencies.write(file, content);
34
+ dependencies.signal?.throwIfAborted();
35
+ }
36
+ await dependencies.rename(temporary, destination);
37
+ }
38
+ catch (error) {
39
+ await dependencies.remove(temporary);
40
+ throw error;
41
+ }
42
+ dependencies.log("Installing dependencies...");
43
+ await stage("Installation", ["install", ...(options.yes ? ["--yes"] : [])]);
44
+ if (options.skipConfig) {
45
+ dependencies.log(`Provider configuration skipped. Configure later in another terminal:\ncd ${quote(destination)}\nnpm run configure`);
46
+ }
47
+ else {
48
+ dependencies.log("Configuring your provider and model...");
49
+ await stage("Provider configuration", ["run", "configure"]);
50
+ }
51
+ dependencies.log("Starting development...");
52
+ await stage("Development", [
53
+ "run",
54
+ "dev",
55
+ ...(options.open ? [] : ["--", "--no-open"]),
56
+ ]);
57
+ async function stage(name, args) {
58
+ try {
59
+ dependencies.signal?.throwIfAborted();
60
+ const result = await dependencies.run("npm", args, destination);
61
+ dependencies.signal?.throwIfAborted();
62
+ if (result.signal === "SIGINT" || result.status === 130)
63
+ throw new CreationCancelled("SIGINT");
64
+ if (result.signal === "SIGTERM" || result.status === 143)
65
+ throw new CreationCancelled("SIGTERM");
66
+ if (result.status !== 0 || result.signal)
67
+ throw new Error(`${name} failed.`);
68
+ }
69
+ catch (error) {
70
+ const cancelled = error instanceof CreationCancelled;
71
+ const configured = name === "Development" && !options.skipConfig;
72
+ const recovery = [
73
+ `cd ${quote(destination)}`,
74
+ ...(name === "Installation" ? ["npm install"] : []),
75
+ ...(configured ? [] : ["npm run configure"]),
76
+ "npm run dev",
77
+ ].join("\n");
78
+ throw new CreationError(`${cancelled ? error.message : `${name} failed.`} The generated project was kept.\n${name === "Development" ? "Restart" : "Resume"} with:\n${recovery}`, cancelled ? error.exitCode : 1);
79
+ }
80
+ }
81
+ }
82
+ function quote(value) {
83
+ if (/^[a-zA-Z0-9_./-]+$/.test(value))
84
+ return value;
85
+ return process.platform === "win32"
86
+ ? `"${value.replaceAll('"', '""')}"`
87
+ : `'${value.replaceAll("'", "'\\''")}'`;
88
+ }
@@ -0,0 +1,2 @@
1
+ import type { Compatibility } from "./contracts.js";
2
+ export declare function starterFiles(compatibility: Compatibility, studio: boolean): Promise<Readonly<Record<string, string>>>;
@@ -0,0 +1,40 @@
1
+ import { readdir, readFile } from "node:fs/promises";
2
+ import { fileURLToPath } from "node:url";
3
+ import { join, relative, sep } from "node:path";
4
+ /** The only renderer used by creation, development, and examples synchronization. */
5
+ /**
6
+ * npm never packs files named `.gitignore` and treats them as ignore rules for
7
+ * their directory, so the template stores them as `_gitignore`.
8
+ */
9
+ function templatePath(path) {
10
+ return path
11
+ .split(sep)
12
+ .map((segment) => (segment === "_gitignore" ? ".gitignore" : segment))
13
+ .join("/");
14
+ }
15
+ export async function starterFiles(compatibility, studio) {
16
+ const root = fileURLToPath(new URL("./starter/", import.meta.url));
17
+ const files = {};
18
+ async function walk(directory) {
19
+ for (const entry of (await readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
20
+ const absolute = join(directory, entry.name);
21
+ if (entry.isDirectory())
22
+ await walk(absolute);
23
+ else
24
+ files[templatePath(relative(root, absolute))] = (await readFile(absolute, "utf8"))
25
+ .replaceAll("{{HARNESS_VERSION}}", compatibility.harness)
26
+ .replaceAll("{{RUNTIME_VERSION}}", compatibility.runtime)
27
+ .replaceAll("{{STUDIO_VERSION}}", compatibility.studio);
28
+ }
29
+ }
30
+ await walk(root);
31
+ if (!("." + "gitignore" in files))
32
+ throw new Error("Starter template is missing its .gitignore.");
33
+ if (!studio) {
34
+ const manifest = JSON.parse(files["package.json"]);
35
+ delete manifest.devDependencies["@nylorun/studio"];
36
+ manifest.scripts.dev = "nylorun dev --no-studio";
37
+ files["package.json"] = JSON.stringify(manifest, null, 2) + "\n";
38
+ }
39
+ return Object.freeze(files);
40
+ }
@@ -0,0 +1,4 @@
1
+ # Project credentials
2
+
3
+ Run `npm run configure`. Provider credentials are stored in `auth.json`.
4
+ Do not commit credentials. Optional integration environment variables belong in `integrations.env`.
@@ -0,0 +1,3 @@
1
+ *
2
+ !.gitignore
3
+ !README.md
@@ -0,0 +1,6 @@
1
+ # My agent
2
+
3
+ The creator configures a provider before starting development. For later sessions, run `npm run dev`. If setup was skipped with `--skip-config` or interrupted, run `npm run configure` first, then `npm run dev`.
4
+ Edit agents under `agent/` and compose Runtime in `nylorun.config.ts`.
5
+
6
+ `npm run dev -- --no-studio` starts without Studio. `npm run build` creates `dist/`; deploy it alongside `package.json`, installed production dependencies, and private project configuration, then run `npm start`.
@@ -0,0 +1,7 @@
1
+ node_modules/
2
+ dist/
3
+ .data/
4
+ .env/*
5
+ !.env/.gitignore
6
+ !.env/README.md
7
+ config/model.json
@@ -0,0 +1,10 @@
1
+ import { Agent } from "@nylorun/harness";
2
+ import { piModel } from "@nylorun/runtime";
3
+
4
+ export const assistant = Agent({
5
+ id: "assistant",
6
+ name: "Assistant",
7
+ instructions: ["You are helpful."],
8
+ })
9
+ .with(piModel())
10
+ .build();
@@ -0,0 +1,3 @@
1
+ import { assistant } from "./assistant/agent.js";
2
+
3
+ export const agents = [assistant];
@@ -0,0 +1,4 @@
1
+ import { defineRuntime } from "@nylorun/runtime";
2
+ import { agents } from "./agent/registry.js";
3
+
4
+ export default defineRuntime({ agents });
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "my-nylorun-agent",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=22.19.0"
8
+ },
9
+ "scripts": {
10
+ "configure": "nylorun configure",
11
+ "dev": "nylorun dev",
12
+ "inspect": "nylorun inspect",
13
+ "build": "nylorun build",
14
+ "start": "nylorun start",
15
+ "check": "tsc --noEmit"
16
+ },
17
+ "dependencies": {
18
+ "@nylorun/harness": "{{HARNESS_VERSION}}",
19
+ "@nylorun/runtime": "{{RUNTIME_VERSION}}",
20
+ "zod": "^4.1.12"
21
+ },
22
+ "devDependencies": {
23
+ "@nylorun/studio": "{{STUDIO_VERSION}}",
24
+ "@types/node": "^22.18.0",
25
+ "typescript": "^5.9.3"
26
+ }
27
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2024",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "strict": true,
7
+ "verbatimModuleSyntax": true,
8
+ "skipLibCheck": true,
9
+ "noEmit": true,
10
+ "types": ["node"]
11
+ },
12
+ "include": ["agent/**/*.ts", "nylorun.config.ts"]
13
+ }
package/dist/sync.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { Compatibility } from "./contracts.js";
2
+ export interface ExamplesRecipe {
3
+ name: string;
4
+ dependencies: Record<string, string>;
5
+ devDependencies: Record<string, string>;
6
+ scripts: Record<string, string>;
7
+ configuration: string;
8
+ }
9
+ export declare function examplesFiles(compatibility: Compatibility, recipe: ExamplesRecipe): Promise<{
10
+ [k: string]: string;
11
+ }>;
12
+ /** Preflight the whole tree before edits. Authored paths and local state are never eligible. */
13
+ export declare function synchronize(root: string, files: Readonly<Record<string, string>>, compatibility: Compatibility, options: {
14
+ check?: boolean;
15
+ adopt?: boolean;
16
+ creatorVersion: string;
17
+ }): Promise<readonly string[]>;
package/dist/sync.js ADDED
@@ -0,0 +1,137 @@
1
+ import { createHash } from "node:crypto";
2
+ import { lstat, mkdir, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { starterFiles } from "./scaffold.js";
5
+ export async function examplesFiles(compatibility, recipe) {
6
+ const rendered = await starterFiles(compatibility, true);
7
+ const files = Object.fromEntries(Object.entries(rendered).filter(([path]) => managed(path)));
8
+ const manifest = JSON.parse(files["package.json"]);
9
+ manifest.name = recipe.name;
10
+ for (const field of ["dependencies", "devDependencies", "scripts"])
11
+ manifest[field] = { ...manifest[field], ...recipe[field] };
12
+ // Recipe additions belong beside the corresponding starter commands.
13
+ const scriptOrder = [
14
+ "configure",
15
+ "dev",
16
+ "inspect",
17
+ "studio",
18
+ "build",
19
+ "start",
20
+ "check",
21
+ "test",
22
+ ];
23
+ const rank = (name) => {
24
+ const index = scriptOrder.indexOf(name);
25
+ return index < 0 ? scriptOrder.length : index;
26
+ };
27
+ manifest.scripts = Object.fromEntries(Object.entries(manifest.scripts).sort(([left], [right]) => rank(left) - rank(right) || left.localeCompare(right)));
28
+ files["package.json"] = JSON.stringify(manifest, null, 2) + "\n";
29
+ files["nylorun.config.ts"] = recipe.configuration;
30
+ const tsconfig = JSON.parse(files["tsconfig.json"]);
31
+ tsconfig.include.push("test/**/*.ts");
32
+ files["tsconfig.json"] = JSON.stringify(tsconfig, null, 2) + "\n";
33
+ return files;
34
+ }
35
+ function managed(path) {
36
+ return (!path.startsWith("agent/") &&
37
+ !path.startsWith("config/") &&
38
+ path !== "README.md");
39
+ }
40
+ const manifestPath = ".scaffold-manifest.json";
41
+ const hash = (value) => createHash("sha256").update(value).digest("hex");
42
+ /** Preflight the whole tree before edits. Authored paths and local state are never eligible. */
43
+ export async function synchronize(root, files, compatibility, options) {
44
+ root = resolve(root);
45
+ async function pathFor(path) {
46
+ if (!path ||
47
+ path.includes("\\") ||
48
+ path.split("/").some((part) => !part || part === "." || part === "..") ||
49
+ !managed(path) ||
50
+ path.startsWith("test/") ||
51
+ path.startsWith("scripts/") ||
52
+ path.startsWith(".data/") ||
53
+ path.startsWith("node_modules/") ||
54
+ (path.startsWith(".env/") &&
55
+ ![".env/README.md", ".env/.gitignore"].includes(path)))
56
+ throw new Error(`Refusing unmanaged path: ${path}`);
57
+ let current = root;
58
+ for (const part of path.split("/")) {
59
+ current = join(current, part);
60
+ try {
61
+ const stat = await lstat(current);
62
+ if (stat.isSymbolicLink())
63
+ throw new Error(`Refusing symlink: ${path}`);
64
+ if (current !== join(root, path) && !stat.isDirectory())
65
+ throw new Error(`Cannot write ${path}: relocate the legacy .env file before syncing; its contents will not be changed.`);
66
+ }
67
+ catch (error) {
68
+ if (error.code !== "ENOENT")
69
+ throw error;
70
+ }
71
+ }
72
+ return join(root, path);
73
+ }
74
+ async function read(path) {
75
+ try {
76
+ return await readFile(await pathFor(path), "utf8");
77
+ }
78
+ catch (error) {
79
+ if (error.code === "ENOENT")
80
+ return undefined;
81
+ throw error;
82
+ }
83
+ }
84
+ const priorText = await read(manifestPath);
85
+ const prior = priorText
86
+ ? JSON.parse(priorText)
87
+ : undefined;
88
+ if (prior &&
89
+ (prior.version !== 1 || !prior.files || typeof prior.files !== "object"))
90
+ throw new Error("Invalid scaffold manifest.");
91
+ const hashes = Object.fromEntries(Object.keys(files)
92
+ .sort()
93
+ .map((path) => [path, hash(files[path])]));
94
+ const provenance = {
95
+ version: 1,
96
+ creatorVersion: options.creatorVersion,
97
+ compatibility,
98
+ templateHash: hash(JSON.stringify(hashes)),
99
+ files: hashes,
100
+ };
101
+ const changes = [];
102
+ const writes = new Map();
103
+ const removals = [];
104
+ for (const path of new Set([
105
+ ...Object.keys(prior?.files ?? {}),
106
+ ...Object.keys(files),
107
+ ])) {
108
+ const existing = await read(path);
109
+ const desired = files[path];
110
+ if (existing === desired)
111
+ continue;
112
+ changes.push(path);
113
+ if (!options.check &&
114
+ existing !== undefined &&
115
+ hash(existing) !== prior?.files[path] &&
116
+ !(options.adopt && !prior))
117
+ throw new Error(`Generated-file conflict: ${path}. Move the intended change into the creator template or recipe before syncing.`);
118
+ if (desired === undefined)
119
+ removals.push(path);
120
+ else
121
+ writes.set(path, desired);
122
+ }
123
+ const next = JSON.stringify(provenance, null, 2) + "\n";
124
+ if (priorText !== next)
125
+ changes.push(manifestPath);
126
+ if (options.check)
127
+ return changes;
128
+ for (const [path, content] of writes) {
129
+ const file = await pathFor(path);
130
+ await mkdir(dirname(file), { recursive: true });
131
+ await writeFile(file, content);
132
+ }
133
+ for (const path of removals)
134
+ await rm(await pathFor(path));
135
+ await writeFile(await pathFor(manifestPath), next);
136
+ return changes;
137
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@nylorun/create-agent",
3
+ "version": "0.2.0-beta",
4
+ "description": "Create a local Nylorun Harness agent project.",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/nylorun/harness.git",
10
+ "directory": "create-agent"
11
+ },
12
+ "homepage": "https://github.com/nylorun/harness",
13
+ "bugs": "https://github.com/nylorun/harness/issues",
14
+ "bin": {
15
+ "create-agent": "dist/cli.js"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "compatibility.json",
20
+ "README.md",
21
+ "LICENSE",
22
+ "CHANGELOG.md"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public",
26
+ "provenance": true
27
+ },
28
+ "engines": {
29
+ "node": ">=22.19.0"
30
+ },
31
+ "scripts": {
32
+ "build": "npm run clean && node ../scripts/check-typescript-version.mjs && tsc -p tsconfig.json && node scripts/copy-compatibility.mjs",
33
+ "check": "npm run build && npm run test:types && npm test && node scripts/check-package.mjs",
34
+ "test": "vitest run",
35
+ "test:types": "tsc -p test/tsconfig.json",
36
+ "examples:sync": "npm run build && node scripts/examples.mjs",
37
+ "examples:check": "npm run build && node scripts/examples.mjs --check",
38
+ "clean": "node -e \"import('node:fs').then(({rmSync})=>rmSync('dist',{recursive:true,force:true}))\"",
39
+ "prepack": "npm run build"
40
+ },
41
+ "devDependencies": {
42
+ "@nylorun/harness": "file:../harness",
43
+ "@nylorun/runtime": "file:../runtime",
44
+ "@types/node": "^22.18.0",
45
+ "@typescript/native": "npm:typescript@^7.0.2",
46
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
47
+ "vitest": "^4.1.11",
48
+ "zod": "^4.1.12"
49
+ }
50
+ }