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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/aot-inputs.ts +21 -2
  2. package/build.ts +241 -60
  3. package/check/bundle.ts +265 -0
  4. package/check/codes.ts +19 -0
  5. package/check/command.ts +5 -3
  6. package/check/graph.ts +3 -1
  7. package/check/index.ts +54 -2
  8. package/check/program.ts +26 -6
  9. package/cli/aot-build.ts +10 -7
  10. package/cli/build-app.ts +37 -8
  11. package/cli/config.ts +2 -2
  12. package/cli/create.ts +31 -8
  13. package/cli/dev.ts +109 -19
  14. package/cli/effects.ts +162 -0
  15. package/cli/elf.ts +3 -2
  16. package/cli/help.ts +56 -147
  17. package/cli/host-fetch.ts +33 -10
  18. package/cli/host.ts +43 -33
  19. package/cli/sk.ts +437 -234
  20. package/cli/skpk.ts +2 -0
  21. package/cli/stamp.ts +2 -2
  22. package/cli/term.ts +169 -38
  23. package/cli/workload-cache.ts +258 -0
  24. package/devtools/commands.ts +25 -0
  25. package/effects/compile.ts +1081 -0
  26. package/effects/redslangc.json +23 -0
  27. package/effects/redslangc.ts +220 -0
  28. package/effects/sk.slang +882 -0
  29. package/package.json +10 -4
  30. package/prod.ts +40 -7
  31. package/svelte.ts +76 -0
  32. package/templates/icon.png +0 -0
  33. package/templates/minimal/src/App.vue +2 -2
  34. package/templates/showcase/assets/textures/golden.png +0 -0
  35. package/templates/showcase/assets/textures/hammered.png +0 -0
  36. package/templates/showcase/assets/textures/noir.png +0 -0
  37. package/templates/showcase/assets/textures/reeded.png +0 -0
  38. package/templates/showcase/assets/textures/teal-orange.png +0 -0
  39. package/templates/showcase/shaders/dissolve.slang +40 -0
  40. package/templates/showcase/shaders/fireflies.slang +58 -0
  41. package/templates/showcase/shaders/glass.slang +31 -0
  42. package/templates/showcase/shaders/grade.slang +34 -0
  43. package/templates/showcase/shaders/halftone.slang +42 -0
  44. package/templates/showcase/shaders/lens.slang +51 -0
  45. package/templates/showcase/shaders/nebula.slang +57 -0
  46. package/templates/showcase/shaders/orbit.slang +52 -0
  47. package/templates/showcase/shaders/pond.slang +76 -0
  48. package/templates/showcase/shaders/ripples.slang +71 -0
  49. package/templates/showcase/shaders/shatter.slang +116 -0
  50. package/templates/showcase/shaders/sheen.slang +23 -0
  51. package/templates/showcase/shaders/snow.slang +57 -0
  52. package/templates/showcase/shaders/spotlight.slang +52 -0
  53. package/templates/showcase/src/App.vue +11 -16
  54. package/templates/showcase/src/components/FullWindow.vue +77 -0
  55. package/templates/showcase/src/components/Page.vue +2 -0
  56. package/templates/showcase/src/fullwindow.ts +36 -0
  57. package/templates/showcase/src/icons.ts +2 -0
  58. package/templates/showcase/src/pages/GraphicsPage.vue +122 -0
  59. package/templates/showcase/src/pages/MotionPage.vue +71 -1
  60. package/templates/showcase/src/pages/ShadersPage.vue +443 -0
  61. package/templates/showcase/src/pages/StylesPage.vue +9 -1
  62. package/templates/showcase/src/router.ts +32 -1
  63. package/templates/showcase/src/styles.css +2 -2
  64. package/templates/svelte/.vscode/settings.json +3 -0
  65. package/templates/svelte/assets/hello.txt +1 -0
  66. package/templates/svelte/src/App.svelte +142 -0
  67. package/templates/svelte/src/main.ts +4 -0
  68. package/vitecompat.ts +2 -0
package/cli/help.ts CHANGED
@@ -1,159 +1,68 @@
1
- import { CLI_VERSION } from "./host";
1
+ // `sk --help` and `sk <command> --help`, laid out from the commander declarations in sk.ts: usage,
2
+ // what the command does, its subcommands, and its options under their group headings.
3
+
4
+ import type { Argument, CommandUnknownOpts, Help } from "@commander-js/extra-typings";
2
5
  import { paint, type Paint } from "./term";
3
6
 
4
- type Row = [string, string];
5
- type Section = { title: string; rows: Row[] };
7
+ export type Row = [string, string];
6
8
 
7
- const COMMANDS: Row[] = [
8
- ["create [dir]", "Start a new app"],
9
- ["dev [app]", "Run the app with hot reload"],
10
- ["build [app]", "Debug build: devtools on, not minified"],
11
- ["publish [app]", "Release build to ship"],
12
- ["run [app]", "Build, then start the app"],
13
- ["check [app]", "What breaks under AOT, and how well the code is typed"],
14
- ["explain <code>", "What a check code means and how to fix it"],
15
- ["host <command>", "Manage the prebuilt engine hosts"],
16
- ];
9
+ export function table(p: Paint, rows: Row[]): string[] {
10
+ const width = Math.max(...rows.map(([term]) => term.length));
11
+ return rows.map(([term, text]) => ` ${p.cyan(term.padEnd(width))} ${text}`);
12
+ }
17
13
 
18
- const BUILD: Section[] = [
19
- {
20
- title: "Options",
21
- rows: [
22
- ["--platform <os>", "windows, macos or linux (default: this OS)"],
23
- ["--out <dir>", "Output directory (default: <app>/dist/debug or dist/release)"],
24
- ["--define K=V", "A Vite-style define; repeatable"],
25
- ["--config <path>", "An sk.config.json outside the app"],
26
- ["--sign <identity>", "macOS: codesign identity (- for ad hoc)"],
27
- ["--no-sign", "macOS: leave the bundle unsigned"],
28
- ["--console", "Windows: keep the console window"],
29
- ["--aot", "Windows x64: compile the app to a native image (--no-aot: don't)"],
30
- ["--json", "Print the result as JSON"],
31
- ],
32
- },
33
- {
34
- title: "Advanced",
35
- rows: [
36
- ["--host <exe>", "Stamp this host instead of the cached one"],
37
- ["--payload-only", "Write dist/.sk/app.skpk and stop"],
38
- ["--aot-inputs", "Keep the typed sources for a later AOT compile"],
39
- ["--aot-compiler <exe>", "Compile native images with this sk-aot.exe (or SK_AOT_COMPILER)"],
40
- ],
41
- },
42
- ];
14
+ export const section = (p: Paint, title: string, rows: Row[]): string[] =>
15
+ rows.length ? ["", p.bold(title), ...table(p, rows)] : [];
43
16
 
44
- const HELP: Record<string, { usage: string; about: string; sections: Section[] }> = {
45
- create: {
46
- usage: "sk create [dir] [options]",
47
- about: "Start a new app. In a terminal it asks for whatever the options leave open.",
48
- sections: [
49
- {
50
- title: "Options",
51
- rows: [
52
- ["--name <name>", "The app's name (default: the directory's)"],
53
- ["--template <name>", "showcase (every feature) or minimal"],
54
- ["--os <list>", "What to package for: windows, macos, linux"],
55
- ["--devtools", "Keep devtools (F12) in published builds"],
56
- ["--pm <name>", "bun, npm, pnpm or yarn"],
57
- ["-y, --yes", "Ask nothing, take the defaults"],
58
- ],
59
- },
60
- ],
61
- },
62
- dev: {
63
- usage: "sk dev [app] [options]",
64
- about: "Run the app with hot reload: edits to .vue, .ts and .css apply without a restart.",
65
- sections: [{ title: "Options", rows: [["--exe <host>", "Run this dev host instead of the cached one"]] }],
66
- },
67
- build: {
68
- usage: "sk build [app] [options]",
69
- about: "A debug build in <app>/dist/debug: devtools (F12) on, the bundle not minified.",
70
- sections: BUILD,
71
- },
72
- publish: {
73
- usage: "sk publish [app] [options]",
74
- about:
75
- 'The release build in <app>/dist/release: minified, devtools only with "publishDevtools": true in sk.config.json.',
76
- sections: BUILD,
77
- },
78
- run: {
79
- usage: "sk run [app] [options] [-- app args]",
80
- about: "sk build, then start the app with its output in this terminal.",
81
- sections: BUILD,
82
- },
83
- check: {
84
- usage: "sk check [app] [options]",
85
- about: "What in the bundle, app code and node_modules, breaks or slows down under AOT, and how well it is typed.",
86
- sections: [
87
- {
88
- title: "Options",
89
- rows: [
90
- ["--format json", "One JSON report on stdout (schema skathi.check)"],
91
- ["--deny-warnings", "Fail on warnings too"],
92
- ["--no-deps", "Only the app's own code"],
93
- ["--config <path>", "An sk.config.json outside the app"],
94
- ],
95
- },
96
- {
97
- title: "Exit codes",
98
- rows: [
99
- ["0", "Clean"],
100
- ["1", "Errors (or warnings with --deny-warnings)"],
101
- ["2", "Bad usage or config, or the check failed"],
102
- ],
103
- },
104
- ],
105
- },
106
- explain: {
107
- usage: "sk explain <code> | --list",
108
- about: "What a check code means, an example, and how to fix it.",
109
- sections: [{ title: "Options", rows: [["--list", "Every code"]] }],
110
- },
111
- host: {
112
- usage: "sk host <command>",
113
- about: "The engine host is the prebuilt executable an app is packed into. sk build fetches it on demand.",
114
- sections: [
115
- {
116
- title: "Commands",
117
- rows: [
118
- ["fetch", "Download this version's hosts into the local cache"],
119
- ["path", "Which host sk build would use"],
120
- ["info [exe]", "What a host says about itself"],
121
- ["add <exe>", "Verify a host and add it to the cache"],
122
- ["build", "In a Skathi checkout: build the hosts with cargo"],
123
- ],
124
- },
125
- ],
126
- },
17
+ const argTerm = (a: Argument) => {
18
+ const name = `${a.name()}${a.variadic ? "..." : ""}`;
19
+ return a.required ? `<${name}>` : `[${name}]`;
127
20
  };
128
21
 
129
- function rows(p: Paint, list: Row[]): string[] {
130
- const width = Math.max(...list.map(([name]) => name.length));
131
- return list.map(([name, text]) => ` ${p.cyan(name.padEnd(width))} ${text}`);
132
- }
133
-
134
- function sections(p: Paint, list: Section[]): string[] {
135
- return list.flatMap((s) => ["", p.bold(s.title), ...rows(p, s.rows)]);
22
+ function path(cmd: CommandUnknownOpts): string {
23
+ const names: string[] = [];
24
+ for (let c: CommandUnknownOpts | null = cmd; c; c = c.parent) names.unshift(c.name());
25
+ return names.join(" ");
136
26
  }
137
27
 
138
- const head = (p: Paint) => `${p.bold("sk")} ${p.dim(CLI_VERSION)} Skathi apps for Windows, macOS and Linux`;
139
-
140
- export function topHelp(color: boolean): string {
141
- const p = paint(color);
142
- return [
143
- head(p),
144
- "",
145
- `${p.bold("Usage")} sk <command> [app] [options]`,
146
- "",
147
- p.bold("Commands"),
148
- ...rows(p, COMMANDS),
149
- "",
150
- p.dim("Run sk <command> --help for its options. [app] is a directory (default: .)."),
151
- ].join("\n");
152
- }
28
+ const visible = (helper: Help, cmd: CommandUnknownOpts) =>
29
+ helper.visibleCommands(cmd).filter((c) => c.name() !== "help");
153
30
 
154
- export function commandHelp(command: string, color: boolean): string | null {
155
- const help = HELP[command];
156
- if (!help) return null;
31
+ export function helpFormat(color: boolean): Partial<Help> {
157
32
  const p = paint(color);
158
- return [`${p.bold("Usage")} ${help.usage}`, "", help.about, ...sections(p, help.sections)].join("\n");
33
+ return {
34
+ formatHelp(cmd, helper) {
35
+ const commands = visible(helper, cmd);
36
+ const options = helper.visibleOptions(cmd);
37
+ const usage = [
38
+ path(cmd),
39
+ ...cmd.registeredArguments.map(argTerm),
40
+ ...(commands.length ? ["<command>"] : []),
41
+ ...(options.length ? ["[options]"] : []),
42
+ ].join(" ");
43
+ const lines: string[] = [];
44
+ if (!cmd.parent) lines.push(`${p.bold(cmd.name())} ${p.dim(cmd.version() ?? "")} ${cmd.description()}`, "");
45
+ lines.push(`${p.bold("Usage")} ${usage}`);
46
+ if (cmd.parent && cmd.description()) lines.push("", cmd.description());
47
+ lines.push(
48
+ ...section(
49
+ p,
50
+ "Commands",
51
+ commands.map((c) => [
52
+ [c.name(), ...c.registeredArguments.map(argTerm), ...(visible(helper, c).length ? ["<command>"] : [])].join(
53
+ " ",
54
+ ),
55
+ c.summary() || c.description(),
56
+ ]),
57
+ ),
58
+ );
59
+ const groups = new Map<string, Row[]>();
60
+ for (const o of options) {
61
+ const title = (o.helpGroupHeading ?? "Options").replace(/:$/, "");
62
+ groups.set(title, [...(groups.get(title) ?? []), [o.flags, o.description]]);
63
+ }
64
+ for (const [title, rows] of groups) lines.push(...section(p, title, rows));
65
+ return `${lines.join("\n")}\n`;
66
+ },
67
+ };
159
68
  }
package/cli/host-fetch.ts CHANGED
@@ -77,6 +77,7 @@ export interface FetchOptions {
77
77
  platform?: Platform;
78
78
  arch?: string;
79
79
  log?: (line: string) => void;
80
+ onBytes?: OnBytes | undefined;
80
81
  }
81
82
 
82
83
  function source() {
@@ -88,10 +89,31 @@ function source() {
88
89
  return { repo, api, headers };
89
90
  }
90
91
 
91
- async function download(asset: ReleaseAsset, headers: Record<string, string>): Promise<Uint8Array<ArrayBuffer>> {
92
+ export type OnBytes = (done: number, total: number) => void;
93
+
94
+ async function download(
95
+ asset: ReleaseAsset,
96
+ headers: Record<string, string>,
97
+ onBytes?: OnBytes,
98
+ ): Promise<Uint8Array<ArrayBuffer>> {
92
99
  const res = await fetch(asset.url, { headers: { ...headers, Accept: "application/octet-stream" } });
93
100
  if (!res.ok) throw new HostError(`downloading ${asset.name}: HTTP ${res.status}`);
94
- return new Uint8Array(await res.arrayBuffer());
101
+ if (!onBytes || !res.body) return new Uint8Array(await res.arrayBuffer());
102
+ const total = Number(res.headers.get("content-length")) || asset.size;
103
+ const chunks: Uint8Array[] = [];
104
+ let done = 0;
105
+ for await (const chunk of res.body) {
106
+ chunks.push(chunk);
107
+ done += chunk.length;
108
+ onBytes(done, total);
109
+ }
110
+ const bytes = new Uint8Array(done);
111
+ let at = 0;
112
+ for (const chunk of chunks) {
113
+ bytes.set(chunk, at);
114
+ at += chunk.length;
115
+ }
116
+ return bytes;
95
117
  }
96
118
 
97
119
  interface Release {
@@ -132,11 +154,12 @@ async function cacheAsset(
132
154
  digest: string,
133
155
  dest: string,
134
156
  log: (line: string) => void,
157
+ onBytes?: OnBytes,
135
158
  ): Promise<void> {
136
159
  const asset = release.asset(name);
137
160
  if (!asset) throw new HostError(`release ${release.tag} lists ${name} in ${MANIFEST_NAME} but does not carry it`);
138
161
  log(`downloading ${name} (${(asset.size / 1048576).toFixed(1)} MB) from github.com/${release.repo} ${release.tag}`);
139
- const bytes = Bun.gunzipSync(await download(asset, release.headers));
162
+ const bytes = Bun.gunzipSync(await download(asset, release.headers, onBytes));
140
163
  if (bytes.length !== size || sha256(bytes) !== digest) {
141
164
  throw new HostError(`${name} does not match the sha256 in ${MANIFEST_NAME}; nothing was cached`);
142
165
  }
@@ -148,7 +171,7 @@ async function cacheAsset(
148
171
  renameSync(tmp, dest);
149
172
  }
150
173
 
151
- /** Downloads the host for `variant` from the release of `version` into the local cache, checked against `hosts.json`. */
174
+ /** Downloads the workload for `variant` from the release of `version` into the local cache, checked against `hosts.json`. */
152
175
  export async function fetchHost(options: FetchOptions): Promise<{ path: string; info: HostInfo }> {
153
176
  const version = options.version ?? CLI_VERSION;
154
177
  const platform = options.platform ?? currentPlatform();
@@ -163,14 +186,14 @@ export async function fetchHost(options: FetchOptions): Promise<{ path: string;
163
186
  .map((h) => h.variant)
164
187
  .join(", ");
165
188
  throw new HostError(
166
- `release ${tag} has no ${options.variant} host for ${platform}-${arch}` +
167
- (offered ? ` (it has: ${offered}); other variants are built from a checkout with sk host build` : ""),
189
+ `release ${tag} has no ${options.variant} workload for ${platform}-${arch}` +
190
+ (offered ? ` (it has: ${offered}); other variants are built from a checkout with sk workload build` : ""),
168
191
  );
169
192
  }
170
193
  const dest = cachedHost(version, options.variant, platform);
171
- await cacheAsset(release, entry.file, entry.size, entry.sha256, dest, log);
194
+ await cacheAsset(release, entry.file, entry.size, entry.sha256, dest, log, options.onBytes);
172
195
  writeFileSync(join(dirname(dest), "host.json"), JSON.stringify(entry.info, null, 2) + "\n");
173
- log(`cached ${options.variant} host ${version} → ${dest}`);
196
+ log(`cached ${options.variant} workload ${version} → ${dest}`);
174
197
  return { path: dest, info: entry.info };
175
198
  }
176
199
 
@@ -190,7 +213,7 @@ export async function fetchAotCompiler(
190
213
  const entry = release.manifest.aot?.find((c) => c.platform === platform && c.arch === arch);
191
214
  if (!entry) throw new HostError(`release ${release.tag} has no sk-aot for ${platform}-${arch}`);
192
215
  const dest = cachedAotCompiler(version, platform);
193
- await cacheAsset(release, entry.file, entry.size, entry.sha256, dest, log);
216
+ await cacheAsset(release, entry.file, entry.size, entry.sha256, dest, log, options.onBytes);
194
217
  writeFileSync(join(dirname(dest), "compiler.json"), JSON.stringify(entry.info, null, 2) + "\n");
195
218
  log(`cached sk-aot ${version} → ${dest}`);
196
219
  return { path: dest, info: entry.info };
@@ -208,7 +231,7 @@ export async function resolveOrFetchHost(options: ResolveOptions): Promise<Resol
208
231
  const cross = (options.platform ?? currentPlatform()) !== currentPlatform();
209
232
  if (!(e instanceof HostError) || named || cross || process.env.SK_HOST_OFFLINE === "1") throw e;
210
233
  try {
211
- await fetchHost({ variant: options.variant, ...(options.log && { log: options.log }) });
234
+ await fetchHost({ variant: options.variant, onBytes: options.onBytes, ...(options.log && { log: options.log }) });
212
235
  } catch (f) {
213
236
  throw new HostError(`${e.message}\n(downloading it failed too: ${(f as Error).message})`);
214
237
  }
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(" ")}`);