@skathi-native/cli 0.1.0-beta.3 → 0.1.0-beta.4

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/cli/host.ts CHANGED
@@ -2,17 +2,17 @@
2
2
  // --features prod` (the whole engine, no app), built once per Skathi version and variant: `standard`, or
3
3
  // `no-devtools` with the devtools compiled out.
4
4
  //
5
- // Resolution, first hit wins: 1. `--host <exe>` or `SK_HOST`; 2. in-repo
5
+ // Resolution, first hit wins: 1. `--workload <exe>` or `SK_HOST`; 2. in-repo
6
6
  // target/x86_64-pc-windows-msvc/release/sk-app.exe, when that is a prod host of this variant and
7
- // version; 3. the local cache (`sk host add <exe>`, `sk host build`, or a download from this
7
+ // version; 3. the local cache (`sk workload add <exe>`, `sk workload build`, or a download from this
8
8
  // version's GitHub release: host-fetch.ts); 4. an error naming them. Paths per OS are in platform.ts.
9
9
  //
10
- // A host for another OS cannot be run to ask what it is: only `--host` / `SK_HOST` names one, its
10
+ // A host for another OS cannot be run to ask what it is: only `--workload` / `SK_HOST` names one, its
11
11
  // format is sniffed, and what it is comes from a `host.json` beside it or is taken on trust, with a warning.
12
12
  //
13
13
  // A host and a bundle must come from the same Skathi version (the bundle carries the JS half of
14
14
  // the `__sk_*` protocol): the CLI refuses a host whose `--sk-host-info` disagrees
15
- // (`--allow-host-mismatch` is for maintainers).
15
+ // (`--allow-workload-mismatch` is for maintainers).
16
16
 
17
17
  import { spawnSync } from "node:child_process";
18
18
  import {
@@ -57,6 +57,8 @@ export interface HostInfo {
57
57
  jscPin: string;
58
58
  payloadFormat: number;
59
59
  profile: string;
60
+ /** What a dev host reloads in place from `sk dev` besides JS modules; absent on older hosts. */
61
+ devReload?: string[];
60
62
  /** A host built with the native AOT loader: what an app image must be compiled against. */
61
63
  aot?: HostAot | null;
62
64
  }
@@ -69,7 +71,7 @@ export interface HostAot extends CompilerInfo {
69
71
  export interface ResolvedHost {
70
72
  exe: string;
71
73
  info: HostInfo;
72
- source: "--host" | "SK_HOST" | "repo" | "cache";
74
+ source: "--workload" | "SK_HOST" | "repo" | "cache";
73
75
  unverified?: string;
74
76
  }
75
77
 
@@ -91,12 +93,12 @@ function formatProblem(exe: string, platform: Platform): string | null {
91
93
  if (platform === "windows") return null;
92
94
  if (platform === "linux") {
93
95
  const machine = elfMachineOf(exe);
94
- if (!machine) return `${exe} is not an ELF executable — a Linux build needs a Linux sk-app`;
96
+ if (!machine) return `${exe} is not an ELF executable — a Linux build needs a Linux workload (sk-app)`;
95
97
  if (machine !== "x86_64" && machine !== "aarch64") return `${exe} is an ELF for ${machine}, not x86_64 or aarch64`;
96
98
  return null;
97
99
  }
98
100
  const archs = machOArchs(exe);
99
- if (!archs) return `${exe} is not a Mach-O executable — a macOS bundle needs a macOS sk-app`;
101
+ if (!archs) return `${exe} is not a Mach-O executable — a macOS bundle needs a macOS workload (sk-app)`;
100
102
  if (!archs.some((a) => a === "arm64" || a === "x86_64"))
101
103
  return `${exe} is a Mach-O for ${archs.join(", ")}, not arm64 or x86_64`;
102
104
  return null;
@@ -114,7 +116,10 @@ export function crossHostInfo(
114
116
  try {
115
117
  const info = JSON.parse(readFileSync(sidecar, "utf8")) as HostInfo;
116
118
  if (info.mode && info.skathi && info.variant) {
117
- return { info, unverified: `${platform} host described by ${sidecar}, not run (this is ${process.platform})` };
119
+ return {
120
+ info,
121
+ unverified: `${platform} workload described by ${sidecar}, not run (this is ${process.platform})`,
122
+ };
118
123
  }
119
124
  } catch {}
120
125
  }
@@ -133,7 +138,7 @@ export function crossHostInfo(
133
138
  return {
134
139
  info,
135
140
  unverified:
136
- `a ${platform} host cannot be run on ${process.platform} to check it — ${exe} is taken to be a prod ${variant} host ` +
141
+ `a ${platform} workload cannot be run on ${process.platform} to check it — ${exe} is taken to be a prod ${variant} workload ` +
137
142
  `of Skathi ${CLI_VERSION}. Put its \`--sk-host-info\` output in ${sidecar} to have it checked.`,
138
143
  };
139
144
  }
@@ -141,7 +146,7 @@ export function crossHostInfo(
141
146
  export function hostInfo(exe: string): HostInfo {
142
147
  if (!existsSync(exe)) throw new HostError(`${exe} does not exist`);
143
148
  if (isStamped(exe)) {
144
- throw new HostError(`${exe} is a packaged app, not a bare host (it already carries a SKPAYLOAD)`);
149
+ throw new HostError(`${exe} is a packaged app, not a bare workload (it already carries a SKPAYLOAD)`);
145
150
  }
146
151
  const r = spawnSync(exe, ["--sk-host-info"], { encoding: "utf8", timeout: 30_000, windowsHide: true });
147
152
  if (r.error) throw new HostError(`${exe} could not be run: ${r.error.message}`);
@@ -152,7 +157,7 @@ export function hostInfo(exe: string): HostInfo {
152
157
  return info;
153
158
  } catch {
154
159
  throw new HostError(
155
- `${exe} did not answer --sk-host-info (exit ${r.status}). Hosts older than this CLI do not know the flag — ` +
160
+ `${exe} did not answer --sk-host-info (exit ${r.status}). Workloads older than this CLI do not know the flag — ` +
156
161
  `rebuild it.\n${(r.stderr ?? "").trim().split(/\r?\n/).slice(-5).join("\n")}`,
157
162
  );
158
163
  }
@@ -172,20 +177,20 @@ export function checkHost(exe: string, info: HostInfo, variant: Variant | null,
172
177
  const mismatch =
173
178
  info.skathi !== CLI_VERSION && !allowMismatch
174
179
  ? `${exe} is Skathi ${info.skathi}, this CLI is ${CLI_VERSION} — the bundle carries the JS half of the ` +
175
- `host protocol, so the two must match (--allow-host-mismatch overrides, for maintainers)`
180
+ `workload protocol, so the two must match (--allow-workload-mismatch overrides, for maintainers)`
176
181
  : null;
177
182
  if (variant === DEV_HOST) {
178
183
  return info.mode === "dev"
179
184
  ? mismatch
180
- : `${exe} is a ${info.mode} host — sk dev needs one built without --features prod`;
185
+ : `${exe} is a ${info.mode} workload — sk dev needs one built without --features prod`;
181
186
  }
182
- if (info.mode !== "prod") return `${exe} is a ${info.mode} host — sk build needs one built with --features prod`;
187
+ if (info.mode !== "prod") return `${exe} is a ${info.mode} workload — sk build needs one built with --features prod`;
183
188
  if (variant && info.variant !== variant) return `${exe} is the ${info.variant} variant, not ${variant}`;
184
189
  if (!VARIANTS.includes(info.variant)) {
185
- return `${exe} is the ${info.variant} variant, which leaves engine parts out — sk build stamps only ${VARIANTS.join(" or ")} hosts`;
190
+ return `${exe} is the ${info.variant} variant, which leaves engine parts out — sk build stamps only ${VARIANTS.join(" or ")} workloads`;
186
191
  }
187
192
  const missing = ENGINE_FEATURES.filter((f) => !info.features?.includes(f));
188
- if (missing.length) return `${exe} lacks ${missing.join(", ")} — rebuild or replace the cached host`;
193
+ if (missing.length) return `${exe} lacks ${missing.join(", ")} — rebuild or replace the cached workload`;
189
194
  return mismatch;
190
195
  }
191
196
 
@@ -229,6 +234,7 @@ export interface ResolveOptions {
229
234
  allowMismatch?: boolean | undefined;
230
235
  platform?: Platform | undefined;
231
236
  log?: (line: string) => void;
237
+ onBytes?: ((done: number, total: number) => void) | undefined;
232
238
  }
233
239
 
234
240
  export function resolveHost(options: ResolveOptions): ResolvedHost {
@@ -239,11 +245,11 @@ export function resolveHost(options: ResolveOptions): ResolvedHost {
239
245
  const explicit = options.host ?? process.env.SK_HOST;
240
246
  if (explicit) {
241
247
  const exe = resolve(explicit);
242
- const source = options.host ? "--host" : "SK_HOST";
248
+ const source = options.host ? "--workload" : "SK_HOST";
243
249
  if (cross) {
244
250
  if (!existsSync(exe)) throw new HostError(`${exe} does not exist`);
245
251
  if (isStamped(exe))
246
- throw new HostError(`${exe} is a packaged app, not a bare host (it already carries an app payload)`);
252
+ throw new HostError(`${exe} is a packaged app, not a bare workload (it already carries an app payload)`);
247
253
  const { info, unverified } = crossHostInfo(exe, options.variant, platform);
248
254
  const problem = checkHost(exe, info, options.variant, allow);
249
255
  if (problem) throw new HostError(problem);
@@ -258,8 +264,8 @@ export function resolveHost(options: ResolveOptions): ResolvedHost {
258
264
  }
259
265
  if (cross) {
260
266
  throw new HostError(
261
- `a ${platform} build on ${process.platform} needs the host named: --host <path to a ${platform} sk-app> ` +
262
- `(or SK_HOST). This machine's checkout and cache hold ${currentPlatform()} hosts.`,
267
+ `a ${platform} build on ${process.platform} needs the workload named: --workload <path to a ${platform} sk-app> ` +
268
+ `(or SK_HOST). This machine's checkout and cache hold ${currentPlatform()} workloads.`,
263
269
  );
264
270
  }
265
271
 
@@ -272,7 +278,7 @@ export function resolveHost(options: ResolveOptions): ResolvedHost {
272
278
  if (statSync(REPO_RELEASE_EXE).mtimeMs < newestHostSource()) {
273
279
  log(
274
280
  `warning: ${REPO_RELEASE_EXE} is older than the sources it is built from — ` +
275
- "`bun packages/cli/cli/sk.ts host build` rebuilds it",
281
+ "`bun packages/cli/cli/sk.ts workload build` rebuilds it",
276
282
  );
277
283
  }
278
284
  return { exe: REPO_RELEASE_EXE, info, source: "repo" };
@@ -295,18 +301,20 @@ export function resolveHost(options: ResolveOptions): ResolvedHost {
295
301
  tried.push(`cache: ${cached} does not exist`);
296
302
  }
297
303
 
304
+ const remedies: [string, string][] = [
305
+ [`--workload <${hostsFor(platform).exeFile}>`, "(or SK_HOST=<exe>) a prod workload built from this version"],
306
+ [`sk workload install ${options.variant}`, `download it from the Skathi ${CLI_VERSION} release`],
307
+ ["sk workload add <exe>", "import one into the local cache"],
308
+ ...(REPO_ROOT
309
+ ? [[`sk workload build ${options.variant}`, "build it from this checkout (cargo)"] as [string, string]]
310
+ : []),
311
+ ];
312
+ const width = Math.max(...remedies.map(([how]) => how.length));
298
313
  throw new HostError(
299
- `no ${options.variant} Skathi ${CLI_VERSION} host found.\n` +
314
+ `no ${options.variant} Skathi ${CLI_VERSION} workload found.\n` +
300
315
  tried.map((t) => ` - ${t}`).join("\n") +
301
316
  "\nSupply one of:\n" +
302
- ` ${`--host <${hostsFor(platform).exeFile}>`.padEnd(21)}(or SK_HOST=<exe>) a prod host built from this version\n` +
303
- ` sk host fetch download it from the Skathi ${CLI_VERSION} release\n` +
304
- " sk host add <exe> import one into the local cache\n" +
305
- (REPO_ROOT
306
- ? options.variant === "standard" || options.variant === "no-devtools"
307
- ? " sk host build build both variants from this checkout (cargo)\n"
308
- : ` sk host build --variant ${options.variant} build this one from this checkout (cargo)\n`
309
- : ""),
317
+ remedies.map(([how, what]) => ` ${how.padEnd(width)} ${what}\n`).join(""),
310
318
  );
311
319
  }
312
320
 
@@ -324,7 +332,7 @@ export function addHost(exe: string, log: (line: string) => void = () => {}): {
324
332
  rmSync(dest, { force: true });
325
333
  renameSync(tmp, dest);
326
334
  writeFileSync(join(dirname(dest), "host.json"), JSON.stringify(info, null, 2) + "\n");
327
- log(`cached ${info.variant} host ${info.skathi} (${info.profile}) → ${dest}`);
335
+ log(`cached ${info.variant} workload ${info.skathi} (${info.profile}) → ${dest}`);
328
336
  return { path: dest, info };
329
337
  }
330
338
 
@@ -334,7 +342,7 @@ function cargo(): string {
334
342
  const home = process.env.CARGO_HOME ?? join(process.env.USERPROFILE ?? homedir(), ".cargo");
335
343
  const exe = join(home, "bin", process.platform === "win32" ? "cargo.exe" : "cargo");
336
344
  if (existsSync(exe)) return exe;
337
- throw new HostError("cargo is not on PATH — building a host needs the Rust toolchain (sk build does not)");
345
+ throw new HostError("cargo is not on PATH — building a workload needs the Rust toolchain (sk build does not)");
338
346
  }
339
347
 
340
348
  /** The cargo command line for `variant`, plus `extra` features (`native-inspector` for a release host). */
@@ -360,7 +368,9 @@ export function cargoBuildHost(
360
368
  extras: CargoExtras = {},
361
369
  ): { exe: string; ms: number } {
362
370
  if (!REPO_ROOT || !REPO_RELEASE_EXE) {
363
- throw new HostError("sk host build runs from a Skathi checkout; elsewhere, use sk host fetch or sk host add <exe>");
371
+ throw new HostError(
372
+ "sk workload build runs from a Skathi checkout; elsewhere, use sk workload install or sk workload add <exe>",
373
+ );
364
374
  }
365
375
  const args = hostCargoArgs(variant, extras.features);
366
376
  log(`cargo ${args.join(" ")}`);