@diagonal-hq/cli 0.45.0 → 0.45.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,6 +11,15 @@ This package is the authoring SDK for file-based workspaces. A workspace reposit
11
11
  - The `diagonal assets upload` and `diagonal assets list` commands. They upload Application Assets, update `assets.ts`, and list immutable references.
12
12
  - The `diagonal workflows`, `diagonal run`, and `diagonal logs` commands. They list the deployed workflows, run a workflow by its file path, and print recent runs with the error of each failed run.
13
13
 
14
+ ## Get help
15
+
16
+ ```bash
17
+ npx diagonal help
18
+ npx diagonal help run
19
+ ```
20
+
21
+ `diagonal help`, `diagonal --help`, and `diagonal` without a command list each command with one line about it. `diagonal help <command>` and `diagonal <command> --help` print the usage, a description, the arguments, the options, and examples of one command. `diagonal help assets` prints both asset commands.
22
+
14
23
  ## Check a workspace
15
24
 
16
25
  ```bash
@@ -3,7 +3,7 @@ const require = __diagonalCreateRequire(import.meta.url);
3
3
  import {
4
4
  WORKFLOW_STAGE,
5
5
  stripTypes
6
- } from "./cli-chunk-I2TWWQ3W.mjs";
6
+ } from "./cli-chunk-XXHASLSH.mjs";
7
7
  import {
8
8
  scriptSdkRuntimeFiles
9
9
  } from "./cli-chunk-6HPUF67L.mjs";
package/dist/cli.mjs CHANGED
@@ -58,7 +58,7 @@ import {
58
58
  workflowConfigObject,
59
59
  workflowMetadata,
60
60
  workspaceBuildNeeds
61
- } from "./cli-chunk-I2TWWQ3W.mjs";
61
+ } from "./cli-chunk-XXHASLSH.mjs";
62
62
  import {
63
63
  GENERATED_NOTIFICATION_TYPES_MODULE,
64
64
  GENERATED_WORKFLOWS_MODULE,
@@ -3938,43 +3938,470 @@ import { existsSync as existsSync4, readdirSync as readdirSync4, statSync as sta
3938
3938
  import { join as join7, resolve as resolve2 } from "node:path";
3939
3939
  import { fileURLToPath } from "node:url";
3940
3940
 
3941
+ // scripts/lib/runtime-build/migration-cli.mjs
3942
+ import { mkdirSync, readdirSync, statSync, writeFileSync } from "node:fs";
3943
+ import { join } from "node:path";
3944
+
3945
+ // scripts/lib/runtime-build/migration-file.mjs
3946
+ var MIGRATION_ID = /^(?=.{1,100}$)(\d{14})_[a-z0-9][a-z0-9_]*$/;
3947
+ function migrationTimestamp(id) {
3948
+ const timestamp = MIGRATION_ID.exec(id)?.[1];
3949
+ if (timestamp === void 0) return null;
3950
+ const iso = `${timestamp.slice(0, 4)}-${timestamp.slice(4, 6)}-${timestamp.slice(6, 8)}T${timestamp.slice(8, 10)}:${timestamp.slice(10, 12)}:${timestamp.slice(12, 14)}.000Z`;
3951
+ const date = new Date(iso);
3952
+ return Number.isNaN(date.getTime()) || date.toISOString() !== iso ? null : timestamp;
3953
+ }
3954
+ function formatMigrationTimestamp(date) {
3955
+ return date.toISOString().replace(/\D/g, "").slice(0, 14);
3956
+ }
3957
+
3958
+ // scripts/lib/runtime-build/migration-cli.mjs
3959
+ var MIGRATION_USAGE = "Usage: diagonal make:migration <name>";
3960
+ var NAME = /^[a-z0-9][a-z0-9_]{0,84}$/;
3961
+ function makeMigration(args, { cwd, stdout, stderr }) {
3962
+ if (args.length !== 1 || !NAME.test(args[0])) {
3963
+ stderr.write(
3964
+ `Give one lowercase migration name with letters, digits, and underscores (at most 85 characters).
3965
+ ${MIGRATION_USAGE}
3966
+ `
3967
+ );
3968
+ return 2;
3969
+ }
3970
+ if (!statSync(join(cwd, "diagonal.config.ts"), { throwIfNoEntry: false })?.isFile()) {
3971
+ stderr.write("Run this command in a workspace directory with diagonal.config.ts.\n");
3972
+ return 2;
3973
+ }
3974
+ const name = args[0];
3975
+ const directory = join(cwd, "migrations");
3976
+ mkdirSync(directory, { recursive: true });
3977
+ const used = new Set(
3978
+ readdirSync(directory).filter((file) => file.endsWith(".ts") && !file.endsWith(".test.ts")).map((file) => migrationTimestamp(file.slice(0, -3))).filter((timestamp2) => timestamp2 !== null)
3979
+ );
3980
+ const date = /* @__PURE__ */ new Date();
3981
+ let timestamp = formatMigrationTimestamp(date);
3982
+ while (used.has(timestamp)) {
3983
+ date.setUTCSeconds(date.getUTCSeconds() + 1);
3984
+ timestamp = formatMigrationTimestamp(date);
3985
+ }
3986
+ const path = `migrations/${timestamp}_${name}.ts`;
3987
+ const label = name.replaceAll("_", " ");
3988
+ const source = `import { defineWorkflow } from '@diagonal/workflow';
3989
+
3990
+ export default defineWorkflow(
3991
+ {
3992
+ name: '${label}',
3993
+ trigger: { type: 'manual' },
3994
+ runAs: 'system'
3995
+ },
3996
+ async () => {}
3997
+ );
3998
+ `;
3999
+ writeFileSync(join(cwd, path), source, { flag: "wx" });
4000
+ stdout.write(`Created ${path}
4001
+ `);
4002
+ return 0;
4003
+ }
4004
+
4005
+ // scripts/lib/runtime-build/update-cli.mjs
4006
+ import { execFileSync, spawnSync } from "node:child_process";
4007
+ import { existsSync, readdirSync as readdirSync2, readFileSync, rmSync, statSync as statSync2, writeFileSync as writeFileSync2 } from "node:fs";
4008
+ import { basename, dirname, isAbsolute, join as join2, relative, resolve } from "node:path";
4009
+ var UPDATE_USAGE = "Usage: diagonal update";
4010
+ var SCOPE = "@diagonal-hq/";
4011
+ var COMPILER_SCOPE = "@diagonal-hq/workflow-script-compiler-";
4012
+ var SECTIONS = ["dependencies", "devDependencies"];
4013
+ var FILE = "file:";
4014
+ function newestTarball(name, directory) {
4015
+ const prefix = tarballName(name, "").slice(0, -".tgz".length);
4016
+ let newest = null;
4017
+ for (const file of readdirSync2(directory)) {
4018
+ if (!file.startsWith(prefix) || !file.endsWith(".tgz")) {
4019
+ continue;
4020
+ }
4021
+ const version = file.slice(prefix.length, -".tgz".length);
4022
+ if (isVersion(version) && (newest === null || compareVersions(version, newest) > 0)) {
4023
+ newest = version;
4024
+ }
4025
+ }
4026
+ return newest === null ? null : join2(directory, tarballName(name, newest));
4027
+ }
4028
+ function fileSpecifier(cwd, path, absolute) {
4029
+ return `${FILE}${absolute ? path : relative(cwd, path)}`;
4030
+ }
4031
+ function replaceCompilerOverrides(manifest, compilerOverrides) {
4032
+ const overrides = { ...manifest.overrides };
4033
+ for (const name of Object.keys(overrides)) {
4034
+ if (name.startsWith(COMPILER_SCOPE)) {
4035
+ delete overrides[name];
4036
+ }
4037
+ }
4038
+ Object.assign(overrides, compilerOverrides);
4039
+ if (Object.keys(overrides).length > 0) {
4040
+ manifest.overrides = overrides;
4041
+ } else {
4042
+ delete manifest.overrides;
4043
+ }
4044
+ }
4045
+ function packedCliCompilerOverrides(cliTarball, cwd, absolute) {
4046
+ const cli = JSON.parse(
4047
+ execFileSync("tar", ["-xOzf", cliTarball, "package/package.json"], { encoding: "utf8" })
4048
+ );
4049
+ const overrides = {};
4050
+ for (const [name, version] of Object.entries(cli.optionalDependencies ?? {})) {
4051
+ const tarball = join2(dirname(cliTarball), tarballName(name, version));
4052
+ if (name.startsWith(COMPILER_SCOPE) && existsSync(tarball)) {
4053
+ overrides[name] = fileSpecifier(cwd, tarball, absolute);
4054
+ }
4055
+ }
4056
+ return overrides;
4057
+ }
4058
+ function forgetInstalledPackages(cwd) {
4059
+ const lockPath = join2(cwd, "package-lock.json");
4060
+ if (existsSync(lockPath)) {
4061
+ const lock = JSON.parse(readFileSync(lockPath, "utf8"));
4062
+ for (const path of Object.keys(lock.packages ?? {})) {
4063
+ if (path.startsWith(`node_modules/${SCOPE}`)) {
4064
+ delete lock.packages[path];
4065
+ }
4066
+ }
4067
+ writeFileSync2(lockPath, `${JSON.stringify(lock, null, 2)}
4068
+ `);
4069
+ }
4070
+ rmSync(join2(cwd, "node_modules", SCOPE), { recursive: true, force: true });
4071
+ }
4072
+ function updatePackages(args, { cwd, env, stdout, stderr }) {
4073
+ if (args.length > 0) {
4074
+ stderr.write(`${UPDATE_USAGE}
4075
+ `);
4076
+ return 2;
4077
+ }
4078
+ const manifestPath = join2(cwd, "package.json");
4079
+ if (!statSync2(manifestPath, { throwIfNoEntry: false })?.isFile()) {
4080
+ stderr.write("Run this command in a workspace directory with package.json.\n");
4081
+ return 2;
4082
+ }
4083
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
4084
+ const latest = [];
4085
+ let packed = false;
4086
+ for (const section of SECTIONS) {
4087
+ for (const [name, specifier] of Object.entries(manifest[section] ?? {})) {
4088
+ if (!name.startsWith(SCOPE) || name.startsWith(COMPILER_SCOPE)) {
4089
+ continue;
4090
+ }
4091
+ if (!specifier.startsWith(FILE)) {
4092
+ latest.push(`${name}@latest`);
4093
+ continue;
4094
+ }
4095
+ packed = true;
4096
+ const path = specifier.slice(FILE.length);
4097
+ if (!path.endsWith(".tgz")) {
4098
+ stdout.write(`${name}: reinstalling ${path}
4099
+ `);
4100
+ continue;
4101
+ }
4102
+ const current = resolve(cwd, path);
4103
+ const directory = dirname(current);
4104
+ const newest = statSync2(directory, { throwIfNoEntry: false })?.isDirectory() ? newestTarball(name, directory) : null;
4105
+ if (newest === null) {
4106
+ stderr.write(`No ${tarballName(name, "<version>")} exists in ${directory}.
4107
+ `);
4108
+ return 1;
4109
+ }
4110
+ manifest[section][name] = fileSpecifier(cwd, newest, isAbsolute(path));
4111
+ stdout.write(`${name}: ${basename(current)} -> ${basename(newest)}
4112
+ `);
4113
+ if (name === `${SCOPE}cli`) {
4114
+ replaceCompilerOverrides(
4115
+ manifest,
4116
+ packedCliCompilerOverrides(newest, cwd, isAbsolute(path))
4117
+ );
4118
+ }
4119
+ }
4120
+ }
4121
+ if (!packed && latest.length === 0) {
4122
+ stderr.write("package.json has no @diagonal-hq packages.\n");
4123
+ return 1;
4124
+ }
4125
+ if (packed) {
4126
+ writeFileSync2(manifestPath, `${JSON.stringify(manifest, null, 2)}
4127
+ `);
4128
+ forgetInstalledPackages(cwd);
4129
+ }
4130
+ for (const spec of latest) {
4131
+ stdout.write(`${spec.slice(0, -"@latest".length)}: installing the latest version from npm
4132
+ `);
4133
+ }
4134
+ const install = spawnSync("npm", ["install", "--no-audit", "--no-fund", ...latest], {
4135
+ cwd,
4136
+ env,
4137
+ stdio: "inherit"
4138
+ });
4139
+ if (install.status !== 0) {
4140
+ stderr.write(`npm install failed${install.error ? `: ${install.error.message}` : ""}.
4141
+ `);
4142
+ return 1;
4143
+ }
4144
+ return 0;
4145
+ }
4146
+
4147
+ // scripts/lib/runtime-build/cli-help.mjs
4148
+ var CHECK_USAGE = "Usage: diagonal check [dir] [--json] [--fix]";
4149
+ var WIDTH = 80;
4150
+ var OFFLINE = "Local commands";
4151
+ var API = "Workspace API commands (need DIAGONAL_URL and DIAGONAL_API_KEY)";
4152
+ var API_CREDENTIALS = "Reads DIAGONAL_URL and DIAGONAL_API_KEY from the environment. When the environment sets neither, reads both from .env in the current folder.";
4153
+ var COMMANDS = [
4154
+ {
4155
+ name: "check",
4156
+ group: OFFLINE,
4157
+ synopsis: "check [dir]",
4158
+ summary: "Build and check the workspace, as a deploy does.",
4159
+ usage: CHECK_USAGE,
4160
+ description: [
4161
+ "Runs the same build and checks that a platform deploy runs, including the workflow and migration tests. Writes the generated/ modules, which give your editor the types of Resources, Pages, Workflows, Assets, and the other definitions. Writes a uid into each definition that has none.",
4162
+ "Exits with 1 when an error exists, with 2 for a usage error, and with 0 otherwise."
4163
+ ],
4164
+ arguments: [["dir", "The workspace root. The default is the current folder."]],
4165
+ options: [
4166
+ ["--fix", "Also rewrite the deprecated page options to bindings and seo."],
4167
+ ["--json", 'Print { "ok": boolean, "diagnostics": [...] } instead of text.']
4168
+ ],
4169
+ examples: ["diagonal check", "diagonal check --fix"]
4170
+ },
4171
+ {
4172
+ name: "make:migration",
4173
+ group: OFFLINE,
4174
+ synopsis: "make:migration <name>",
4175
+ summary: "Create a data migration workflow in migrations/.",
4176
+ usage: MIGRATION_USAGE,
4177
+ description: [
4178
+ "Creates migrations/<timestamp>_<name>.ts, an ordinary workflow that runs as system once, at the first deploy that holds it. Run it in the workspace root. Edit the workflow, then run diagonal check before you commit. Do not change a migration after a deploy: create a new one for a correction."
4179
+ ],
4180
+ arguments: [["name", "Lowercase letters, digits, and underscores, at most 85 characters."]],
4181
+ options: [],
4182
+ examples: ["diagonal make:migration backfill_post_slug"]
4183
+ },
4184
+ {
4185
+ name: "update",
4186
+ group: OFFLINE,
4187
+ synopsis: "update",
4188
+ summary: "Update the @diagonal-hq packages and run npm install.",
4189
+ usage: UPDATE_USAGE,
4190
+ description: [
4191
+ "Moves each @diagonal-hq package of package.json to its latest npm version, or a file: tarball to the newest tarball in its folder. Then runs npm install. Run diagonal check after an update."
4192
+ ],
4193
+ arguments: [],
4194
+ options: [],
4195
+ examples: ["diagonal update"]
4196
+ },
4197
+ {
4198
+ name: "workflows",
4199
+ group: API,
4200
+ synopsis: "workflows",
4201
+ summary: "List the workflows of the active deployment.",
4202
+ usage: WORKFLOWS_USAGE,
4203
+ description: [
4204
+ "Prints the path, the trigger type, and the title of each workflow of the active deployment. Needs the manage_workflows permission.",
4205
+ API_CREDENTIALS
4206
+ ],
4207
+ arguments: [],
4208
+ options: [["--json", "Print the API response, with each workflow id and version id."]],
4209
+ examples: ["diagonal workflows"]
4210
+ },
4211
+ {
4212
+ name: "run",
4213
+ group: API,
4214
+ synopsis: "run <path>",
4215
+ summary: "Run a deployed workflow and print its result.",
4216
+ usage: RUN_USAGE,
4217
+ description: [
4218
+ "Runs the workflow at <path> in the active deployment, waits for it, and prints the status, the execution id, and the output. A workflow with executionMode: async does not wait: the command prints the execution id, and diagonal logs <execution id> shows the result. A record workflow runs against the record whose id --input gives as record. Needs the manage_workflows permission.",
4219
+ API_CREDENTIALS
4220
+ ],
4221
+ arguments: [["path", "The workflow file, for example workflows/seed-catalog.ts."]],
4222
+ options: [
4223
+ ["--input <json>", "The workflow input, as a JSON object."],
4224
+ ["--json", "Print the API response."]
4225
+ ],
4226
+ examples: [
4227
+ "diagonal run workflows/seed-catalog.ts",
4228
+ `diagonal run workflows/send-reminder.ts --input '{"record":"<record id>"}'`
4229
+ ]
4230
+ },
4231
+ {
4232
+ name: "logs",
4233
+ group: API,
4234
+ synopsis: "logs [path | id]",
4235
+ summary: "Show recent workflow runs and the error of each failed run.",
4236
+ usage: LOGS_USAGE,
4237
+ description: [
4238
+ "Prints the recent runs of the deployed workflows, oldest first: the start time, the status, the path, the trigger, the duration, and the execution id. Under a failed run it prints the error. A path shows only the runs of that workflow. An execution id shows one run with its full error or its output. Needs the manage_workflows permission.",
4239
+ API_CREDENTIALS
4240
+ ],
4241
+ arguments: [
4242
+ ["path", "Show only the runs of this workflow file."],
4243
+ ["id", "Show one run, with its full error or its output."]
4244
+ ],
4245
+ options: [
4246
+ [
4247
+ "--status <status>",
4248
+ "Show only runs with this status: success, error (a declared failure or an exception), exception, started, or pending."
4249
+ ],
4250
+ ["--limit <1-100>", "The number of runs. The default is 20."],
4251
+ ["--json", "Print the API response."]
4252
+ ],
4253
+ examples: [
4254
+ "diagonal logs",
4255
+ "diagonal logs workflows/seed-catalog.ts --status error",
4256
+ "diagonal logs <execution id>"
4257
+ ]
4258
+ },
4259
+ {
4260
+ name: "assets upload",
4261
+ group: API,
4262
+ synopsis: "assets upload <file>",
4263
+ summary: "Upload an application asset and add it to assets.ts.",
4264
+ usage: ASSETS_UPLOAD_USAGE,
4265
+ description: [
4266
+ "Uploads the file and writes its version reference to the --key entry of assets.ts. A new key creates an asset. An existing key adds a version to its asset, and identical bytes reuse the latest version. Needs the manage_workspace_settings permission.",
4267
+ API_CREDENTIALS
4268
+ ],
4269
+ arguments: [["file", "The file to upload."]],
4270
+ options: [
4271
+ ["--key <key>", "The entry of assets.ts. Required unless --no-write is given."],
4272
+ ["--no-write", "Write nothing, and print only the version reference."],
4273
+ ["--json", "Print { key, written, asset, version }."]
4274
+ ],
4275
+ examples: ["diagonal assets upload hero.png --key hero"]
4276
+ },
4277
+ {
4278
+ name: "assets list",
4279
+ group: API,
4280
+ synopsis: "assets list",
4281
+ summary: "List the application assets and their latest versions.",
4282
+ usage: ASSETS_LIST_USAGE,
4283
+ description: [
4284
+ "Prints each application asset of the workspace with its latest version. Needs the manage_workspace_settings permission.",
4285
+ API_CREDENTIALS
4286
+ ],
4287
+ arguments: [],
4288
+ options: [
4289
+ ["--search <text>", "Show only assets whose name or latest file name has this text."],
4290
+ ["--versions", "Also print the newest 100 versions of each asset."],
4291
+ ["--json", "Print { data: [...] }."]
4292
+ ],
4293
+ examples: ["diagonal assets list", "diagonal assets list --search hero --versions"]
4294
+ }
4295
+ ];
4296
+ function wrap(text, indent) {
4297
+ const lines = [];
4298
+ let line = "";
4299
+ for (const word of text.split(" ")) {
4300
+ if (line !== "" && indent.length + line.length + 1 + word.length > WIDTH) {
4301
+ lines.push(indent + line);
4302
+ line = word;
4303
+ } else {
4304
+ line = line === "" ? word : `${line} ${word}`;
4305
+ }
4306
+ }
4307
+ lines.push(indent + line);
4308
+ return lines;
4309
+ }
4310
+ function table(rows) {
4311
+ const column = Math.max(...rows.map(([label]) => label.length)) + 4;
4312
+ const lines = [];
4313
+ for (const [label, text] of rows) {
4314
+ const [first, ...rest] = wrap(text, " ".repeat(column));
4315
+ lines.push(` ${label.padEnd(column - 2)}${first.slice(column)}`, ...rest);
4316
+ }
4317
+ return lines;
4318
+ }
4319
+ function commandList() {
4320
+ const lines = [
4321
+ "diagonal builds, checks, and runs a file-based Diagonal workspace.",
4322
+ "",
4323
+ "Usage: diagonal <command> [options]"
4324
+ ];
4325
+ const groups = [...new Set(COMMANDS.map((command) => command.group))];
4326
+ const column = Math.max(...COMMANDS.map((command) => command.synopsis.length)) + 4;
4327
+ for (const group of groups) {
4328
+ lines.push("", group);
4329
+ for (const command of COMMANDS.filter((each) => each.group === group)) {
4330
+ lines.push(` ${command.synopsis.padEnd(column - 2)}${command.summary}`);
4331
+ }
4332
+ }
4333
+ lines.push(
4334
+ "",
4335
+ "Run diagonal help <command>, or diagonal <command> --help, for the options of a command."
4336
+ );
4337
+ return `${lines.join("\n")}
4338
+ `;
4339
+ }
4340
+ function commandHelp(topic) {
4341
+ const commands = COMMANDS.filter(
4342
+ (command) => command.name === topic || command.name.startsWith(`${topic} `)
4343
+ );
4344
+ if (commands.length === 0) {
4345
+ return null;
4346
+ }
4347
+ return commands.map(helpOf).join("\n");
4348
+ }
4349
+ function helpOf(command) {
4350
+ const lines = [command.usage, ""];
4351
+ for (const paragraph of command.description) {
4352
+ lines.push(...wrap(paragraph, ""), "");
4353
+ }
4354
+ if (command.arguments.length > 0) {
4355
+ lines.push("Arguments", ...table(command.arguments), "");
4356
+ }
4357
+ if (command.options.length > 0) {
4358
+ lines.push("Options", ...table(command.options), "");
4359
+ }
4360
+ lines.push("Examples", ...command.examples.map((example) => ` ${example}`));
4361
+ return `${lines.join("\n")}
4362
+ `;
4363
+ }
4364
+ function asksForHelp(args) {
4365
+ return args.includes("--help") || args.includes("-h");
4366
+ }
4367
+
3941
4368
  // scripts/lib/runtime-build/installed-packages.mjs
3942
4369
  import {
3943
4370
  cpSync,
3944
- existsSync as existsSync2,
3945
- mkdirSync,
4371
+ existsSync as existsSync3,
4372
+ mkdirSync as mkdirSync2,
3946
4373
  mkdtempSync,
3947
- readFileSync as readFileSync3,
3948
- rmSync,
3949
- statSync,
4374
+ readFileSync as readFileSync4,
4375
+ rmSync as rmSync2,
4376
+ statSync as statSync3,
3950
4377
  symlinkSync,
3951
- writeFileSync
4378
+ writeFileSync as writeFileSync3
3952
4379
  } from "node:fs";
3953
4380
  var import_npm_package_arg = __toESM(require_npa(), 1);
3954
4381
  var import_semver = __toESM(require_semver2(), 1);
3955
4382
  import { tmpdir } from "node:os";
3956
- import { basename as basename5, dirname as dirname2, isAbsolute, join as join4, relative as relative2, sep as sep2 } from "node:path";
4383
+ import { basename as basename6, dirname as dirname3, isAbsolute as isAbsolute2, join as join6, relative as relative3, sep as sep2 } from "node:path";
3957
4384
 
3958
4385
  // scripts/lib/runtime-build/checkout-files.mjs
3959
- import { readdirSync } from "node:fs";
3960
- import { join, relative, sep } from "node:path";
4386
+ import { readdirSync as readdirSync3 } from "node:fs";
4387
+ import { join as join3, relative as relative2, sep } from "node:path";
3961
4388
  var PACKAGE_DIRECTORY = "node_modules";
3962
4389
  function listCheckoutFiles(root, skippedRootDirectories) {
3963
4390
  const files = [];
3964
4391
  const pending = [root];
3965
4392
  while (pending.length > 0) {
3966
4393
  const directory = pending.pop();
3967
- for (const entry2 of readdirSync(directory, { withFileTypes: true })) {
4394
+ for (const entry2 of readdirSync3(directory, { withFileTypes: true })) {
3968
4395
  if (entry2.name.startsWith(".")) {
3969
4396
  continue;
3970
4397
  }
3971
4398
  if (entry2.isDirectory()) {
3972
4399
  const skipped = entry2.name === PACKAGE_DIRECTORY || directory === root && skippedRootDirectories.has(entry2.name);
3973
4400
  if (!skipped) {
3974
- pending.push(join(directory, entry2.name));
4401
+ pending.push(join3(directory, entry2.name));
3975
4402
  }
3976
4403
  } else if (entry2.isFile()) {
3977
- files.push(relative(root, join(directory, entry2.name)).split(sep).join("/"));
4404
+ files.push(relative2(root, join3(directory, entry2.name)).split(sep).join("/"));
3978
4405
  }
3979
4406
  }
3980
4407
  }
@@ -3982,7 +4409,7 @@ function listCheckoutFiles(root, skippedRootDirectories) {
3982
4409
  }
3983
4410
 
3984
4411
  // scripts/lib/runtime-build/brand-kit.mjs
3985
- var SECTIONS = ["colors", "typography", "shadows", "logos", "favicon", "seo", "design_profile"];
4412
+ var SECTIONS2 = ["colors", "typography", "shadows", "logos", "favicon", "seo", "design_profile"];
3986
4413
  var SHADOW_PRESETS = Object.keys(Object.values(brand_kit_catalog_default.shadows)[0]);
3987
4414
  var COLOR_PATTERN = new RegExp(brand_kit_catalog_default.color_pattern);
3988
4415
  function readBrandKit(brand, node) {
@@ -3994,9 +4421,9 @@ function readBrandKit(brand, node) {
3994
4421
  }
3995
4422
  const reader = new BrandKitReader();
3996
4423
  for (const key of Object.keys(brand)) {
3997
- if (!SECTIONS.includes(key)) {
4424
+ if (!SECTIONS2.includes(key)) {
3998
4425
  throw new SourceError(
3999
- `Unknown Brand Kit section "brand.${key}". Use one of: ${SECTIONS.join(", ")}`,
4426
+ `Unknown Brand Kit section "brand.${key}". Use one of: ${SECTIONS2.join(", ")}`,
4000
4427
  propertyNode(node, key)
4001
4428
  );
4002
4429
  }
@@ -7613,8 +8040,8 @@ var packageInputsAdapter = Object.freeze({
7613
8040
  import { posix as posix3 } from "node:path";
7614
8041
 
7615
8042
  // scripts/lib/runtime-build/package-input-bindings.mjs
7616
- import { readFileSync } from "node:fs";
7617
- import { basename, join as join2 } from "node:path";
8043
+ import { readFileSync as readFileSync2 } from "node:fs";
8044
+ import { basename as basename2, join as join4 } from "node:path";
7618
8045
 
7619
8046
  // scripts/lib/workflow-code/workflow-evaluator.mjs
7620
8047
  function textTemplateFields(template, variables) {
@@ -7697,14 +8124,14 @@ function targetsByUid(root, sources) {
7697
8124
  continue;
7698
8125
  }
7699
8126
  try {
7700
- const ast = parseSource(readFileSync(join2(root, source), "utf8"), { jsx: false });
8127
+ const ast = parseSource(readFileSync2(join4(root, source), "utf8"), { jsx: false });
7701
8128
  const uid = readUid(KINDS[kind].argument(ast));
7702
8129
  if (uid === null) {
7703
8130
  continue;
7704
8131
  }
7705
8132
  const key = `${kind}:${uid}`;
7706
8133
  const folder = kind === "resource" ? resourceFolderOf(path) : null;
7707
- const name = studlyName(folder ?? basename(withoutDevInfix(path), ".ts"));
8134
+ const name = studlyName(folder ?? basename2(withoutDevInfix(path), ".ts"));
7708
8135
  const entries = targets.get(key) ?? [];
7709
8136
  entries.push({ kind, uid, name, path, folder });
7710
8137
  targets.set(key, entries);
@@ -7768,7 +8195,7 @@ function resolvePackageInputBindings(root, workspaceManifest, choices, candidate
7768
8195
  continue;
7769
8196
  }
7770
8197
  try {
7771
- validatePackageFieldSource(input, readFileSync(join2(root, source), "utf8"));
8198
+ validatePackageFieldSource(input, readFileSync2(join4(root, source), "utf8"));
7772
8199
  resolved.push({ input, selected: resolvePackageFieldInput(input, selected[key]) });
7773
8200
  } catch (error) {
7774
8201
  if (!(error instanceof SourceError)) throw error;
@@ -11324,7 +11751,7 @@ var skillAdapter = Object.freeze({
11324
11751
  });
11325
11752
 
11326
11753
  // scripts/lib/runtime-build/test-suites.mjs
11327
- import { basename as basename2, dirname } from "node:path";
11754
+ import { basename as basename3, dirname as dirname2 } from "node:path";
11328
11755
  var TEST_SUITE_DEFINE = "defineTestSuite";
11329
11756
  var TEST_DEFINE = "defineTest";
11330
11757
  var TEST_FILE_PATTERN = /^tests\/[^/]+\/([^/]+)\.ts$/;
@@ -11426,7 +11853,7 @@ function readSuite(file, report) {
11426
11853
  }
11427
11854
  const read = readConfig(
11428
11855
  node,
11429
- { allowed: SUITE_PROPERTIES, noun: "test suite", fallbackName: basename2(dirname(file.path)) },
11856
+ { allowed: SUITE_PROPERTIES, noun: "test suite", fallbackName: basename3(dirname2(file.path)) },
11430
11857
  report
11431
11858
  );
11432
11859
  if (read === null) {
@@ -11780,7 +12207,7 @@ var testSuiteAdapter = Object.freeze({
11780
12207
  });
11781
12208
 
11782
12209
  // scripts/lib/runtime-build/workflow-config-file.mjs
11783
- import { basename as basename3 } from "node:path";
12210
+ import { basename as basename4 } from "node:path";
11784
12211
  var WORKFLOW_PATH = /^workflows\/[^/]+\.ts$/;
11785
12212
  var HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
11786
12213
  var RECORD_EVENTS = ["created", "updated", "deleted", "restored", "saved"];
@@ -12042,7 +12469,7 @@ function referenceWriter(ast, resources, permissions) {
12042
12469
  }
12043
12470
  const name = pathName(
12044
12471
  value.path,
12045
- basename3(withoutDevInfix(value.path), ".ts"),
12472
+ basename4(withoutDevInfix(value.path), ".ts"),
12046
12473
  { exportName: WORKFLOWS_EXPORT, label: "workflow" },
12047
12474
  []
12048
12475
  );
@@ -12734,7 +13161,7 @@ var workspaceDomainsAdapter = Object.freeze({
12734
13161
  });
12735
13162
 
12736
13163
  // scripts/lib/runtime-build/source-adapters/workspace-field.mjs
12737
- import { basename as basename4 } from "node:path";
13164
+ import { basename as basename5 } from "node:path";
12738
13165
  var fields = ["uid", "key", "type", "label", "description", "guard", "settings", "section", "definition", "value"];
12739
13166
  function entry(source) {
12740
13167
  const node = defineWorkspaceFieldArgument(parseSource(source, { jsx: false }));
@@ -12790,7 +13217,7 @@ var workspaceFieldAdapter = Object.freeze({
12790
13217
  const node = entry(source);
12791
13218
  const uid = property(node, "uid");
12792
13219
  const key = property(node, "key");
12793
- const fieldKey = key ? staticValue(key.value) : basename4(path, ".ts");
13220
+ const fieldKey = key ? staticValue(key.value) : basename5(path, ".ts");
12794
13221
  const definition = property(node, "definition")?.value;
12795
13222
  const { metadata } = readWorkspaceFieldDefinition(
12796
13223
  fieldKey,
@@ -13180,16 +13607,16 @@ function transformField(op, path, source, data) {
13180
13607
  }
13181
13608
 
13182
13609
  // scripts/lib/runtime-build/sdk-packages.mjs
13183
- import { existsSync, readFileSync as readFileSync2 } from "node:fs";
13184
- import { join as join3 } from "node:path";
13610
+ import { existsSync as existsSync2, readFileSync as readFileSync3 } from "node:fs";
13611
+ import { join as join5 } from "node:path";
13185
13612
  var DIAGONAL_PACKAGE = /^@diagonal(-hq)?\//;
13186
13613
  function readPackageFiles(root, diagnostics) {
13187
13614
  const read = (path) => {
13188
- if (!existsSync(join3(root, path))) {
13615
+ if (!existsSync2(join5(root, path))) {
13189
13616
  return null;
13190
13617
  }
13191
13618
  try {
13192
- return JSON.parse(readFileSync2(join3(root, path), "utf8"));
13619
+ return JSON.parse(readFileSync3(join5(root, path), "utf8"));
13193
13620
  } catch (error) {
13194
13621
  if (!(error instanceof SyntaxError)) {
13195
13622
  throw error;
@@ -13214,15 +13641,15 @@ function composePackages(root) {
13214
13641
  const packages = [];
13215
13642
  const files = /* @__PURE__ */ new Map();
13216
13643
  const dependencies = /* @__PURE__ */ new Set();
13217
- const manifest = readJson(join4(root, "package.json"));
13644
+ const manifest = readJson(join6(root, "package.json"));
13218
13645
  const declared = Object.entries(manifest?.dependencies ?? {}).filter(([name, specifier]) => PACKAGE_NAME2.test(name) && typeof specifier === "string").toSorted(([left], [right]) => left < right ? -1 : left > right ? 1 : 0);
13219
- const overridePaths = isDirectory(join4(root, "vendor")) ? listCheckoutFiles(join4(root, "vendor"), /* @__PURE__ */ new Set()).map((path) => `vendor/${path}`) : [];
13646
+ const overridePaths = isDirectory(join6(root, "vendor")) ? listCheckoutFiles(join6(root, "vendor"), /* @__PURE__ */ new Set()).map((path) => `vendor/${path}`) : [];
13220
13647
  const localSources = overridePaths.length === 0 ? /* @__PURE__ */ new Set() : localPackageSources(root, manifest);
13221
13648
  let choices = {};
13222
- const configPath = join4(root, "diagonal.config.ts");
13223
- if (existsSync2(configPath)) {
13649
+ const configPath = join6(root, "diagonal.config.ts");
13650
+ if (existsSync3(configPath)) {
13224
13651
  try {
13225
- choices = readConfigPackages(readFileSync3(configPath, "utf8"));
13652
+ choices = readConfigPackages(readFileSync4(configPath, "utf8"));
13226
13653
  } catch (error) {
13227
13654
  if (!(error instanceof SourceError || error instanceof SyntaxError)) throw error;
13228
13655
  diagnostics.push(diagnosticFromError("diagonal.config.ts", error));
@@ -13236,10 +13663,10 @@ function composePackages(root) {
13236
13663
  const candidates = [];
13237
13664
  const ordinary = /* @__PURE__ */ new Set();
13238
13665
  for (const [name] of declared) {
13239
- const installed = join4(root, "node_modules", name);
13240
- const overrides = join4(root, "vendor", name);
13666
+ const installed = join6(root, "node_modules", name);
13667
+ const overrides = join6(root, "vendor", name);
13241
13668
  const hasOverrides = isDirectory(overrides);
13242
- const installedManifest = readJson(join4(installed, "package.json"));
13669
+ const installedManifest = readJson(join6(installed, "package.json"));
13243
13670
  if (installedManifest === null) {
13244
13671
  if (!DIAGONAL_PACKAGE.test(name)) {
13245
13672
  const problem2 = diagnosticAt("package.json", null, `The dependency "${name}" is missing or has an invalid installed package.json. Run npm install with a valid lockfile`);
@@ -13341,7 +13768,7 @@ function composePackages(root) {
13341
13768
  function packageInputDiagnostics(root) {
13342
13769
  const files = /* @__PURE__ */ new Map();
13343
13770
  for (const path of ["package.json", "package-lock.json", "npm-shrinkwrap.json"]) {
13344
- if (existsSync2(join4(root, path))) files.set(path, readFileSync3(join4(root, path), "utf8"));
13771
+ if (existsSync3(join6(root, path))) files.set(path, readFileSync4(join6(root, path), "utf8"));
13345
13772
  }
13346
13773
  return packageInputDiagnosticsFromFiles(files);
13347
13774
  }
@@ -13431,7 +13858,7 @@ function localPackageDirectory(specifier, directory) {
13431
13858
  }
13432
13859
  return dependency.type === "directory" ? dependency.fetchSpec : null;
13433
13860
  }
13434
- function localPackageSources(root, manifest = readJson(join4(root, "package.json")), readManifest = (directory) => readJson(join4(directory, "package.json"))) {
13861
+ function localPackageSources(root, manifest = readJson(join6(root, "package.json")), readManifest = (directory) => readJson(join6(directory, "package.json"))) {
13435
13862
  const paths = /* @__PURE__ */ new Set();
13436
13863
  const visited = /* @__PURE__ */ new Set([root]);
13437
13864
  const pending = [{ directory: root, manifest }];
@@ -13442,8 +13869,8 @@ function localPackageSources(root, manifest = readJson(join4(root, "package.json
13442
13869
  if (directory === null) {
13443
13870
  continue;
13444
13871
  }
13445
- const path = relative2(root, directory);
13446
- if (visited.has(directory) || path === ".." || path.startsWith(`..${sep2}`) || isAbsolute(path)) {
13872
+ const path = relative3(root, directory);
13873
+ if (visited.has(directory) || path === ".." || path.startsWith(`..${sep2}`) || isAbsolute2(path)) {
13447
13874
  continue;
13448
13875
  }
13449
13876
  visited.add(directory);
@@ -13503,7 +13930,7 @@ function packageRequirementProblems(candidates) {
13503
13930
  return diagnostics;
13504
13931
  }
13505
13932
  function packageBuildSource(root, path, source, bindings) {
13506
- const content = readFileSync3(join4(root, source));
13933
+ const content = readFileSync4(join6(root, source));
13507
13934
  if (bindings.length === 0 || !/\.[jt]sx?$/.test(source)) {
13508
13935
  return content;
13509
13936
  }
@@ -13511,29 +13938,29 @@ function packageBuildSource(root, path, source, bindings) {
13511
13938
  }
13512
13939
  function materializePackages(root, plan) {
13513
13940
  for (const [path, { source, name }] of plan.files) {
13514
- const target = join4(root, path);
13515
- mkdirSync(dirname2(target), { recursive: true });
13516
- writeFileSync(target, packageBuildSource(root, path, source, plan.bindings.get(name) ?? []));
13941
+ const target = join6(root, path);
13942
+ mkdirSync2(dirname3(target), { recursive: true });
13943
+ writeFileSync3(target, packageBuildSource(root, path, source, plan.bindings.get(name) ?? []));
13517
13944
  }
13518
13945
  }
13519
13946
  function buildComposedCheckout(root, plan, options, build) {
13520
- const composed = mkdtempSync(join4(tmpdir(), "diagonal-packages-"));
13947
+ const composed = mkdtempSync(join6(tmpdir(), "diagonal-packages-"));
13521
13948
  try {
13522
13949
  cpSync(root, composed, {
13523
13950
  recursive: true,
13524
13951
  filter: (source) => {
13525
- const path = relative2(root, source);
13952
+ const path = relative3(root, source);
13526
13953
  return path !== "node_modules" && path !== ".git";
13527
13954
  }
13528
13955
  });
13529
- if (existsSync2(join4(root, "node_modules"))) {
13530
- symlinkSync(join4(root, "node_modules"), join4(composed, "node_modules"), "dir");
13956
+ if (existsSync3(join6(root, "node_modules"))) {
13957
+ symlinkSync(join6(root, "node_modules"), join6(composed, "node_modules"), "dir");
13531
13958
  }
13532
13959
  materializePackages(composed, plan);
13533
13960
  const result = build(composed, plan, options);
13534
13961
  for (const path of listCheckoutFiles(composed, /* @__PURE__ */ new Set())) {
13535
13962
  const owner = plan.files.get(path);
13536
- const content = readFileSync3(join4(composed, path));
13963
+ const content = readFileSync4(join6(composed, path));
13537
13964
  if (owner !== void 0) {
13538
13965
  if (!content.equals(packageBuildSource(root, path, owner.source, plan.bindings.get(owner.name) ?? []))) {
13539
13966
  result.diagnostics.push(
@@ -13549,24 +13976,24 @@ function buildComposedCheckout(root, plan, options, build) {
13549
13976
  if (options.writeSource !== true) {
13550
13977
  continue;
13551
13978
  }
13552
- const target = join4(root, path);
13553
- if (!existsSync2(target) || !readFileSync3(target).equals(content)) {
13554
- mkdirSync(dirname2(target), { recursive: true });
13555
- writeFileSync(target, content);
13979
+ const target = join6(root, path);
13980
+ if (!existsSync3(target) || !readFileSync4(target).equals(content)) {
13981
+ mkdirSync2(dirname3(target), { recursive: true });
13982
+ writeFileSync3(target, content);
13556
13983
  }
13557
13984
  }
13558
13985
  result.ok = !hasErrors(result.diagnostics);
13559
13986
  result.diagnostics = sortDiagnostics(result.diagnostics);
13560
13987
  return result;
13561
13988
  } finally {
13562
- rmSync(composed, { recursive: true, force: true });
13989
+ rmSync2(composed, { recursive: true, force: true });
13563
13990
  }
13564
13991
  }
13565
13992
  var TYPESCRIPT_CONFIG = "tsconfig.json";
13566
13993
  var APP_PATH_PATTERN = "@app/*";
13567
13994
  var PACKAGE_TREE = /^\.\/(?:vendor|node_modules)\/.+/;
13568
13995
  function writeTypeScriptConfig(root, plan) {
13569
- const path = join4(root, TYPESCRIPT_CONFIG);
13996
+ const path = join6(root, TYPESCRIPT_CONFIG);
13570
13997
  const config2 = readJson(path);
13571
13998
  if (config2 === null) {
13572
13999
  return false;
@@ -13597,21 +14024,21 @@ function writeTypeScriptConfig(root, plan) {
13597
14024
  }
13598
14025
  const text = `${JSON.stringify(next, null, 2)}
13599
14026
  `;
13600
- if (readFileSync3(path, "utf8") === text) {
14027
+ if (readFileSync4(path, "utf8") === text) {
13601
14028
  return false;
13602
14029
  }
13603
- writeFileSync(path, text);
14030
+ writeFileSync3(path, text);
13604
14031
  return true;
13605
14032
  }
13606
14033
  function isDiagonalPackage(manifest) {
13607
14034
  return isPlainObject(manifest[DIAGONAL_PACKAGE_FIELD]);
13608
14035
  }
13609
14036
  function readJson(path) {
13610
- if (!existsSync2(path)) {
14037
+ if (!existsSync3(path)) {
13611
14038
  return null;
13612
14039
  }
13613
14040
  try {
13614
- const value = JSON.parse(readFileSync3(path, "utf8"));
14041
+ const value = JSON.parse(readFileSync4(path, "utf8"));
13615
14042
  return isPlainObject(value) ? value : null;
13616
14043
  } catch (error) {
13617
14044
  if (error instanceof SyntaxError) {
@@ -13621,213 +14048,7 @@ function readJson(path) {
13621
14048
  }
13622
14049
  }
13623
14050
  function isDirectory(path) {
13624
- return existsSync2(path) && statSync(path).isDirectory();
13625
- }
13626
-
13627
- // scripts/lib/runtime-build/migration-cli.mjs
13628
- import { mkdirSync as mkdirSync2, readdirSync as readdirSync2, statSync as statSync2, writeFileSync as writeFileSync2 } from "node:fs";
13629
- import { join as join5 } from "node:path";
13630
-
13631
- // scripts/lib/runtime-build/migration-file.mjs
13632
- var MIGRATION_ID = /^(?=.{1,100}$)(\d{14})_[a-z0-9][a-z0-9_]*$/;
13633
- function migrationTimestamp(id) {
13634
- const timestamp = MIGRATION_ID.exec(id)?.[1];
13635
- if (timestamp === void 0) return null;
13636
- const iso = `${timestamp.slice(0, 4)}-${timestamp.slice(4, 6)}-${timestamp.slice(6, 8)}T${timestamp.slice(8, 10)}:${timestamp.slice(10, 12)}:${timestamp.slice(12, 14)}.000Z`;
13637
- const date = new Date(iso);
13638
- return Number.isNaN(date.getTime()) || date.toISOString() !== iso ? null : timestamp;
13639
- }
13640
- function formatMigrationTimestamp(date) {
13641
- return date.toISOString().replace(/\D/g, "").slice(0, 14);
13642
- }
13643
-
13644
- // scripts/lib/runtime-build/migration-cli.mjs
13645
- var MIGRATION_USAGE = "Usage: diagonal make:migration <name>";
13646
- var NAME = /^[a-z0-9][a-z0-9_]{0,84}$/;
13647
- function makeMigration(args, { cwd, stdout, stderr }) {
13648
- if (args.length !== 1 || !NAME.test(args[0])) {
13649
- stderr.write(
13650
- `Give one lowercase migration name with letters, digits, and underscores (at most 85 characters).
13651
- ${MIGRATION_USAGE}
13652
- `
13653
- );
13654
- return 2;
13655
- }
13656
- if (!statSync2(join5(cwd, "diagonal.config.ts"), { throwIfNoEntry: false })?.isFile()) {
13657
- stderr.write("Run this command in a workspace directory with diagonal.config.ts.\n");
13658
- return 2;
13659
- }
13660
- const name = args[0];
13661
- const directory = join5(cwd, "migrations");
13662
- mkdirSync2(directory, { recursive: true });
13663
- const used = new Set(
13664
- readdirSync2(directory).filter((file) => file.endsWith(".ts") && !file.endsWith(".test.ts")).map((file) => migrationTimestamp(file.slice(0, -3))).filter((timestamp2) => timestamp2 !== null)
13665
- );
13666
- const date = /* @__PURE__ */ new Date();
13667
- let timestamp = formatMigrationTimestamp(date);
13668
- while (used.has(timestamp)) {
13669
- date.setUTCSeconds(date.getUTCSeconds() + 1);
13670
- timestamp = formatMigrationTimestamp(date);
13671
- }
13672
- const path = `migrations/${timestamp}_${name}.ts`;
13673
- const label = name.replaceAll("_", " ");
13674
- const source = `import { defineWorkflow } from '@diagonal/workflow';
13675
-
13676
- export default defineWorkflow(
13677
- {
13678
- name: '${label}',
13679
- trigger: { type: 'manual' },
13680
- runAs: 'system'
13681
- },
13682
- async () => {}
13683
- );
13684
- `;
13685
- writeFileSync2(join5(cwd, path), source, { flag: "wx" });
13686
- stdout.write(`Created ${path}
13687
- `);
13688
- return 0;
13689
- }
13690
-
13691
- // scripts/lib/runtime-build/update-cli.mjs
13692
- import { execFileSync, spawnSync } from "node:child_process";
13693
- import { existsSync as existsSync3, readdirSync as readdirSync3, readFileSync as readFileSync4, rmSync as rmSync2, statSync as statSync3, writeFileSync as writeFileSync3 } from "node:fs";
13694
- import { basename as basename6, dirname as dirname3, isAbsolute as isAbsolute2, join as join6, relative as relative3, resolve } from "node:path";
13695
- var UPDATE_USAGE = "Usage: diagonal update";
13696
- var SCOPE = "@diagonal-hq/";
13697
- var COMPILER_SCOPE = "@diagonal-hq/workflow-script-compiler-";
13698
- var SECTIONS2 = ["dependencies", "devDependencies"];
13699
- var FILE = "file:";
13700
- function newestTarball(name, directory) {
13701
- const prefix = tarballName(name, "").slice(0, -".tgz".length);
13702
- let newest = null;
13703
- for (const file of readdirSync3(directory)) {
13704
- if (!file.startsWith(prefix) || !file.endsWith(".tgz")) {
13705
- continue;
13706
- }
13707
- const version = file.slice(prefix.length, -".tgz".length);
13708
- if (isVersion(version) && (newest === null || compareVersions(version, newest) > 0)) {
13709
- newest = version;
13710
- }
13711
- }
13712
- return newest === null ? null : join6(directory, tarballName(name, newest));
13713
- }
13714
- function fileSpecifier(cwd, path, absolute) {
13715
- return `${FILE}${absolute ? path : relative3(cwd, path)}`;
13716
- }
13717
- function replaceCompilerOverrides(manifest, compilerOverrides) {
13718
- const overrides = { ...manifest.overrides };
13719
- for (const name of Object.keys(overrides)) {
13720
- if (name.startsWith(COMPILER_SCOPE)) {
13721
- delete overrides[name];
13722
- }
13723
- }
13724
- Object.assign(overrides, compilerOverrides);
13725
- if (Object.keys(overrides).length > 0) {
13726
- manifest.overrides = overrides;
13727
- } else {
13728
- delete manifest.overrides;
13729
- }
13730
- }
13731
- function packedCliCompilerOverrides(cliTarball, cwd, absolute) {
13732
- const cli = JSON.parse(
13733
- execFileSync("tar", ["-xOzf", cliTarball, "package/package.json"], { encoding: "utf8" })
13734
- );
13735
- const overrides = {};
13736
- for (const [name, version] of Object.entries(cli.optionalDependencies ?? {})) {
13737
- const tarball = join6(dirname3(cliTarball), tarballName(name, version));
13738
- if (name.startsWith(COMPILER_SCOPE) && existsSync3(tarball)) {
13739
- overrides[name] = fileSpecifier(cwd, tarball, absolute);
13740
- }
13741
- }
13742
- return overrides;
13743
- }
13744
- function forgetInstalledPackages(cwd) {
13745
- const lockPath = join6(cwd, "package-lock.json");
13746
- if (existsSync3(lockPath)) {
13747
- const lock = JSON.parse(readFileSync4(lockPath, "utf8"));
13748
- for (const path of Object.keys(lock.packages ?? {})) {
13749
- if (path.startsWith(`node_modules/${SCOPE}`)) {
13750
- delete lock.packages[path];
13751
- }
13752
- }
13753
- writeFileSync3(lockPath, `${JSON.stringify(lock, null, 2)}
13754
- `);
13755
- }
13756
- rmSync2(join6(cwd, "node_modules", SCOPE), { recursive: true, force: true });
13757
- }
13758
- function updatePackages(args, { cwd, env, stdout, stderr }) {
13759
- if (args.length > 0) {
13760
- stderr.write(`${UPDATE_USAGE}
13761
- `);
13762
- return 2;
13763
- }
13764
- const manifestPath = join6(cwd, "package.json");
13765
- if (!statSync3(manifestPath, { throwIfNoEntry: false })?.isFile()) {
13766
- stderr.write("Run this command in a workspace directory with package.json.\n");
13767
- return 2;
13768
- }
13769
- const manifest = JSON.parse(readFileSync4(manifestPath, "utf8"));
13770
- const latest = [];
13771
- let packed = false;
13772
- for (const section of SECTIONS2) {
13773
- for (const [name, specifier] of Object.entries(manifest[section] ?? {})) {
13774
- if (!name.startsWith(SCOPE) || name.startsWith(COMPILER_SCOPE)) {
13775
- continue;
13776
- }
13777
- if (!specifier.startsWith(FILE)) {
13778
- latest.push(`${name}@latest`);
13779
- continue;
13780
- }
13781
- packed = true;
13782
- const path = specifier.slice(FILE.length);
13783
- if (!path.endsWith(".tgz")) {
13784
- stdout.write(`${name}: reinstalling ${path}
13785
- `);
13786
- continue;
13787
- }
13788
- const current = resolve(cwd, path);
13789
- const directory = dirname3(current);
13790
- const newest = statSync3(directory, { throwIfNoEntry: false })?.isDirectory() ? newestTarball(name, directory) : null;
13791
- if (newest === null) {
13792
- stderr.write(`No ${tarballName(name, "<version>")} exists in ${directory}.
13793
- `);
13794
- return 1;
13795
- }
13796
- manifest[section][name] = fileSpecifier(cwd, newest, isAbsolute2(path));
13797
- stdout.write(`${name}: ${basename6(current)} -> ${basename6(newest)}
13798
- `);
13799
- if (name === `${SCOPE}cli`) {
13800
- replaceCompilerOverrides(
13801
- manifest,
13802
- packedCliCompilerOverrides(newest, cwd, isAbsolute2(path))
13803
- );
13804
- }
13805
- }
13806
- }
13807
- if (!packed && latest.length === 0) {
13808
- stderr.write("package.json has no @diagonal-hq packages.\n");
13809
- return 1;
13810
- }
13811
- if (packed) {
13812
- writeFileSync3(manifestPath, `${JSON.stringify(manifest, null, 2)}
13813
- `);
13814
- forgetInstalledPackages(cwd);
13815
- }
13816
- for (const spec of latest) {
13817
- stdout.write(`${spec.slice(0, -"@latest".length)}: installing the latest version from npm
13818
- `);
13819
- }
13820
- const install = spawnSync("npm", ["install", "--no-audit", "--no-fund", ...latest], {
13821
- cwd,
13822
- env,
13823
- stdio: "inherit"
13824
- });
13825
- if (install.status !== 0) {
13826
- stderr.write(`npm install failed${install.error ? `: ${install.error.message}` : ""}.
13827
- `);
13828
- return 1;
13829
- }
13830
- return 0;
14051
+ return existsSync3(path) && statSync3(path).isDirectory();
13831
14052
  }
13832
14053
 
13833
14054
  // scripts/lib/runtime-build/workspace-build.mjs
@@ -13895,18 +14116,7 @@ function finishedDiagnostics(diagnostics, plan) {
13895
14116
  // scripts/lib/runtime-build/check-cli.mjs
13896
14117
  var DATA_FILE = fileURLToPath(new URL("./check-data.json", import.meta.url));
13897
14118
  var SDK_FILE = fileURLToPath(new URL("./script-sdk.json", import.meta.url));
13898
- var CHECK_USAGE = "Usage: diagonal check [dir] [--json] [--fix]";
13899
14119
  var CHECK_FLAGS = /* @__PURE__ */ new Set(["--json", "--fix"]);
13900
- var USAGE = [
13901
- CHECK_USAGE,
13902
- MIGRATION_USAGE,
13903
- UPDATE_USAGE,
13904
- WORKFLOWS_USAGE,
13905
- RUN_USAGE,
13906
- LOGS_USAGE,
13907
- ASSETS_UPLOAD_USAGE,
13908
- ASSETS_LIST_USAGE
13909
- ].join("\n");
13910
14120
  function plural(count, word) {
13911
14121
  return `${count} ${word}${count === 1 ? "" : "s"}`;
13912
14122
  }
@@ -13955,7 +14165,7 @@ function holdsSkills(root, plan) {
13955
14165
  async function checkCheckout(root, options) {
13956
14166
  const sources = await checkSources();
13957
14167
  const plan = composePackages(root);
13958
- const testRunner = async () => (await import("./cli-workflows-HBMQQ4SP.mjs")).runBuildTests;
14168
+ const testRunner = async () => (await import("./cli-workflows-TQAVRQ7O.mjs")).runBuildTests;
13959
14169
  const skillReader = async () => (await import("./cli-skill-file-C2WAUJGV.mjs")).skillFrontMatter;
13960
14170
  const finish = (checkoutRoot, buildPlan, answer, runTests2) => {
13961
14171
  const run = hasScriptTests(answer) ? runTests2(checkoutRoot, answer.tests) : null;
@@ -14010,7 +14220,10 @@ ${CHECK_USAGE}
14010
14220
  `);
14011
14221
  return 2;
14012
14222
  }
14013
- const result = await checkCheckout(root, { writeSource: true, fixSource: parsed.fix });
14223
+ const result = await checkCheckout(root, {
14224
+ writeSource: true,
14225
+ fixSource: parsed.fix
14226
+ });
14014
14227
  if (parsed.json) {
14015
14228
  stdout.write(
14016
14229
  `${JSON.stringify({ ok: result.ok, diagnostics: result.diagnostics }, null, 2)}
@@ -14031,6 +14244,13 @@ ${CHECK_USAGE}
14031
14244
  }
14032
14245
  async function main(argv, io) {
14033
14246
  const [command, ...args] = argv;
14247
+ if (command === void 0 || command === "help" || command === "--help" || command === "-h") {
14248
+ return help(args, io);
14249
+ }
14250
+ if (asksForHelp(args)) {
14251
+ const topic = command === "assets" && ["upload", "list"].includes(args[0]) ? `assets ${args[0]}` : command;
14252
+ return help([topic], io);
14253
+ }
14034
14254
  switch (command) {
14035
14255
  case "make:migration":
14036
14256
  return makeMigration(args, io);
@@ -14044,9 +14264,7 @@ async function main(argv, io) {
14044
14264
  return (await import("./cli-assets-cli-QIFVUAWF.mjs")).uploadAsset(assetArgs, withWorkspaceEnv(io));
14045
14265
  if (subcommand === "list")
14046
14266
  return (await import("./cli-assets-cli-QIFVUAWF.mjs")).listAssets(assetArgs, withWorkspaceEnv(io));
14047
- io.stderr.write(`${ASSETS_UPLOAD_USAGE}
14048
- ${ASSETS_LIST_USAGE}
14049
- `);
14267
+ io.stderr.write(commandHelp("assets"));
14050
14268
  return 2;
14051
14269
  }
14052
14270
  case "workflows":
@@ -14056,11 +14274,28 @@ ${ASSETS_LIST_USAGE}
14056
14274
  case "logs":
14057
14275
  return showLogs(args, withWorkspaceEnv(io));
14058
14276
  default:
14059
- io.stderr.write(`${USAGE}
14060
- `);
14277
+ io.stderr.write(`Unknown command ${command}
14278
+
14279
+ ${commandList()}`);
14061
14280
  return 2;
14062
14281
  }
14063
14282
  }
14283
+ function help(args, { stdout, stderr }) {
14284
+ if (args.length === 0) {
14285
+ stdout.write(commandList());
14286
+ return 0;
14287
+ }
14288
+ const topic = args.join(" ");
14289
+ const text = commandHelp(topic);
14290
+ if (text === null) {
14291
+ stderr.write(`Unknown command ${topic}
14292
+
14293
+ ${commandList()}`);
14294
+ return 2;
14295
+ }
14296
+ stdout.write(text);
14297
+ return 0;
14298
+ }
14064
14299
  export {
14065
14300
  main
14066
14301
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/cli",
3
- "version": "0.45.0",
3
+ "version": "0.45.1",
4
4
  "description": "The diagonal CLI and the configuration helpers for file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -489,14 +489,14 @@ function runCompilerAsync(input, args) {
489
489
  }
490
490
 
491
491
  export {
492
+ tarballName,
493
+ isVersion,
494
+ compareVersions,
492
495
  WORKFLOW_STAGE,
493
496
  TRIGGER_TYPES,
494
497
  workflowConfigObject,
495
498
  workflowMetadata,
496
499
  editableInputSchema,
497
- tarballName,
498
- isVersion,
499
- compareVersions,
500
500
  stripTypes,
501
501
  runWorkspaceBuild,
502
502
  runWorkspaceBuildAsync,