@zuke-build/cli 0.0.0-stage → 2.7.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 (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +353 -2
  3. package/mod.d.ts +102 -0
  4. package/mod.js +931 -0
  5. package/package.json +35 -4
  6. package/src/binary_launcher.d.ts +49 -0
  7. package/src/binary_launcher.js +325 -0
  8. package/src/binary_pin.d.ts +47 -0
  9. package/src/binary_pin.js +117 -0
  10. package/src/build_file.d.ts +25 -0
  11. package/src/build_file.js +58 -0
  12. package/src/cache.d.ts +23 -0
  13. package/src/cache.js +26 -0
  14. package/src/deno_isolated.d.ts +14 -0
  15. package/src/deno_isolated.js +70 -0
  16. package/src/deno_path.d.ts +115 -0
  17. package/src/deno_path.js +205 -0
  18. package/src/deno_pin.d.ts +37 -0
  19. package/src/deno_pin.js +32 -0
  20. package/src/dependencies.d.ts +48 -0
  21. package/src/dependencies.js +80 -0
  22. package/src/dispatch.d.ts +229 -0
  23. package/src/dispatch.js +549 -0
  24. package/src/embedded_engine.d.ts +28 -0
  25. package/src/embedded_engine.js +21 -0
  26. package/src/engine_pin.d.ts +56 -0
  27. package/src/engine_pin.js +196 -0
  28. package/src/fs.d.ts +14 -0
  29. package/src/fs.js +25 -0
  30. package/src/import.d.ts +132 -0
  31. package/src/import.js +289 -0
  32. package/src/install_source.d.ts +79 -0
  33. package/src/install_source.js +104 -0
  34. package/src/launcher.d.ts +37 -0
  35. package/src/launcher.js +405 -0
  36. package/src/launcher_shared.d.ts +25 -0
  37. package/src/launcher_shared.js +91 -0
  38. package/src/mcp_config.d.ts +71 -0
  39. package/src/mcp_config.js +96 -0
  40. package/src/node_launcher.d.ts +19 -0
  41. package/src/node_launcher.js +416 -0
  42. package/src/node_pin.d.ts +25 -0
  43. package/src/node_pin.js +30 -0
  44. package/src/output.d.ts +38 -0
  45. package/src/output.js +43 -0
  46. package/src/paint.d.ts +42 -0
  47. package/src/paint.js +38 -0
  48. package/src/project.d.ts +69 -0
  49. package/src/project.js +132 -0
  50. package/src/pyproject.d.ts +30 -0
  51. package/src/pyproject.js +156 -0
  52. package/src/python_build.d.ts +27 -0
  53. package/src/python_build.js +197 -0
  54. package/src/records.d.ts +18 -0
  55. package/src/records.js +31 -0
  56. package/src/relock.d.ts +11 -0
  57. package/src/relock.js +182 -0
  58. package/src/runtime_field.d.ts +15 -0
  59. package/src/runtime_field.js +29 -0
  60. package/src/setup.d.ts +259 -0
  61. package/src/setup.js +693 -0
  62. package/src/star.d.ts +44 -0
  63. package/src/star.js +100 -0
  64. package/src/starter.d.ts +64 -0
  65. package/src/starter.js +138 -0
  66. package/src/toml.d.ts +32 -0
  67. package/src/toml.js +354 -0
  68. package/src/translate.d.ts +69 -0
  69. package/src/translate.js +198 -0
  70. package/src/upgrade.d.ts +113 -0
  71. package/src/upgrade.js +344 -0
  72. package/src/version.d.ts +11 -0
  73. package/src/version.js +13 -0
  74. package/src/version_report.d.ts +55 -0
  75. package/src/version_report.js +187 -0
  76. package/zuke.js +8 -0
@@ -0,0 +1,91 @@
1
+ // Copyright (c) 2026 the Zuke contributors
2
+ // SPDX-License-Identifier: MIT
3
+ /**
4
+ * The pieces the bootstrapping launchers share: the license header, and the
5
+ * download-with-retry and SHA-256 verification of a pinned archive. One
6
+ * implementation, so the Deno and Node launchers cannot drift on how a
7
+ * download is retried or verified.
8
+ *
9
+ * @module
10
+ */
11
+ /** The MIT notice every generated launcher opens with (after its shebang). */
12
+ export const LICENSE_HEADER = `# Copyright (c) 2026 the Zuke contributors
13
+ # SPDX-License-Identifier: MIT`;
14
+ /* cspell:disable */
15
+ /**
16
+ * The bash steps that fetch `$download_url` into `$archive` (inside a fresh
17
+ * `$work_dir`, removed on exit) with retries, then check its SHA-256 against
18
+ * `$expected_sha256`, exiting 1 on a mismatch. Expects `asset`,
19
+ * `download_url` and `expected_sha256` to be set, and is indented for use
20
+ * inside an `if` block. `name` is the tool, for messages.
21
+ */
22
+ export function bashFetchVerified(name) {
23
+ return ` work_dir="$(mktemp -d)"
24
+ trap 'rm -rf "$work_dir"' EXIT
25
+ archive="$work_dir/$asset"
26
+
27
+ # The download fetches over the network, which is occasionally flaky (e.g. a
28
+ # transient 5xx from the CDN). Retry a few times with backoff so a blip
29
+ # doesn't fail the whole run.
30
+ download_${name.toLowerCase()}() {
31
+ curl -fsSL -o "$archive" "$download_url"
32
+ }
33
+ attempt=1
34
+ max_attempts=4
35
+ until download_${name.toLowerCase()}; do
36
+ if [ "$attempt" -ge "$max_attempts" ]; then
37
+ echo "zuke: failed to download ${name} after $max_attempts attempts." >&2
38
+ exit 1
39
+ fi
40
+ delay=$((attempt * 3))
41
+ echo "zuke: ${name} download failed (attempt $attempt/$max_attempts); retrying in \${delay}s..." >&2
42
+ sleep "$delay"
43
+ attempt=$((attempt + 1))
44
+ done
45
+
46
+ if command -v sha256sum >/dev/null 2>&1; then
47
+ actual_sha256="$(sha256sum "$archive" | awk '{print $1}')"
48
+ elif command -v shasum >/dev/null 2>&1; then
49
+ actual_sha256="$(shasum -a 256 "$archive" | awk '{print $1}')"
50
+ else
51
+ echo "zuke: neither sha256sum nor shasum is available to verify the download." >&2
52
+ exit 1
53
+ fi
54
+ if [ "$actual_sha256" != "$expected_sha256" ]; then
55
+ echo "zuke: checksum mismatch for $asset:" >&2
56
+ echo " expected $expected_sha256" >&2
57
+ echo " got $actual_sha256" >&2
58
+ exit 1
59
+ fi`;
60
+ }
61
+ /**
62
+ * The PowerShell steps that fetch `$downloadUrl` into `$archive` with
63
+ * retries, then check its SHA-256 against `$expectedSha256`, throwing on a
64
+ * mismatch. Indented for use inside a `try` block; `name` is the tool, for
65
+ * messages.
66
+ */
67
+ export function pwshFetchVerified(name) {
68
+ return ` # The download fetches over the network, which is occasionally flaky (e.g.
69
+ # a transient 5xx from the CDN). Retry a few times with backoff so a blip
70
+ # doesn't fail the whole run.
71
+ $maxAttempts = 4
72
+ for ($attempt = 1; $attempt -le $maxAttempts; $attempt++) {
73
+ try {
74
+ Invoke-WebRequest -Uri $downloadUrl -OutFile $archive
75
+ break
76
+ } catch {
77
+ if ($attempt -ge $maxAttempts) {
78
+ throw "zuke: failed to download ${name} after $maxAttempts attempts: $_"
79
+ }
80
+ $delay = $attempt * 3
81
+ Write-Host "zuke: ${name} download failed (attempt $attempt/$maxAttempts); retrying in \${delay}s..."
82
+ Start-Sleep -Seconds $delay
83
+ }
84
+ }
85
+
86
+ $actualSha256 = (Get-FileHash -Path $archive -Algorithm SHA256).Hash.ToLowerInvariant()
87
+ if ($actualSha256 -ne $expectedSha256.ToLowerInvariant()) {
88
+ throw "zuke: checksum mismatch for \${asset}: expected $expectedSha256, got $actualSha256"
89
+ }`;
90
+ }
91
+ /* cspell:enable */
@@ -0,0 +1,71 @@
1
+ /** The MCP client configuration file `--mcp` writes, next to `zuke.ts`. */
2
+ export declare const MCP_CONFIG_FILE = ".mcp.json";
3
+ /** The server name registered in the file. */
4
+ export declare const MCP_SERVER_NAME = "zuke";
5
+ /** One server entry in `mcpServers`: the command and its arguments. */
6
+ export interface McpServerEntry {
7
+ /**
8
+ * The executable: `deno`, which is the same on every platform, or the
9
+ * compiled `zuke` for a hosted build it registered.
10
+ */
11
+ command: string;
12
+ /**
13
+ * The arguments: `run -A zuke.ts mcp`, with the engine release in place of
14
+ * `zuke.ts` for a hosted build, or just `mcp` for the compiled `zuke`; plus
15
+ * `--allow-run` when asked for.
16
+ */
17
+ args: string[];
18
+ }
19
+ /**
20
+ * The entry that launches the MCP server of a TypeScript build whose file is
21
+ * `buildFile`: `deno run -A zuke.ts mcp`.
22
+ * Read-only by default: the agent can inspect the build but not execute
23
+ * targets until `allowRun` opts in, mirroring `zuke mcp --allow-run`.
24
+ */
25
+ export declare function mcpServerEntry(allowRun: boolean, buildFile: string): McpServerEntry;
26
+ /**
27
+ * The entry a hosted build is registered with: `zuke mcp`, which the
28
+ * standalone binary runs on the engine it carries, with no Deno.
29
+ */
30
+ export declare function binaryMcpEntry(allowRun: boolean): McpServerEntry;
31
+ /**
32
+ * The entry a Node project is registered with: `node zuke.ts mcp`, the Node
33
+ * counterpart of {@link mcpServerEntry}. `.mcp.json` is committed and shared,
34
+ * so it names the runtime rather than a launcher script, which a Windows MCP
35
+ * client could not start. It needs Node 26 or newer on `PATH` and the
36
+ * project's dependencies installed, which a first `./zuke` run does.
37
+ */
38
+ export declare function nodeMcpEntry(allowRun: boolean, buildFile: string): McpServerEntry;
39
+ /**
40
+ * A parsed `.mcp.json`, ready to merge. `present` means a well-formed
41
+ * {@link McpServerEntry} is registered as `zuke` (whatever its arguments — a
42
+ * deliberate `--allow-run` or transport choice survives a re-run without
43
+ * `--force`); `absent` covers a missing key and a malformed one alike, so a
44
+ * broken registration is repaired rather than kept. `document` is the file's
45
+ * top-level object — empty when the text was not one — for the merge to
46
+ * extend. An `unparseable` text carries no document: it is never rewritten,
47
+ * because there is no telling what it held.
48
+ */
49
+ export type McpConfig = {
50
+ /** The `zuke` entry is registered, or not. */
51
+ state: "present" | "absent";
52
+ /** The top-level object every other key and server is preserved from. */
53
+ document: Record<string, unknown>;
54
+ } | {
55
+ /** The text is not JSON. */
56
+ state: "unparseable";
57
+ };
58
+ /**
59
+ * Parse an `.mcp.json` text and classify its `zuke` entry. This is the only
60
+ * place the text is parsed: {@link mergeMcpConfig} takes the document it
61
+ * yields, so an unparseable file is rejected here, once, and can never reach
62
+ * the merge.
63
+ */
64
+ export declare function parseMcpConfig(text: string): McpConfig;
65
+ /**
66
+ * Merge `entry` as the `zuke` server into a parsed `.mcp.json` document,
67
+ * preserving every other server and top-level key. `document` is the object
68
+ * {@link parseMcpConfig} yielded, or `{}` to start fresh; an existing `zuke`
69
+ * entry is replaced. Pure: it parses nothing and cannot throw.
70
+ */
71
+ export declare function mergeMcpConfig(document: Record<string, unknown>, entry: McpServerEntry): string;
@@ -0,0 +1,96 @@
1
+ // Copyright (c) 2026 the Zuke contributors
2
+ // SPDX-License-Identifier: MIT
3
+ /**
4
+ * The MCP client configuration `zuke setup --mcp` writes: a project-scoped
5
+ * `.mcp.json` registering the build's own MCP server, so an agent can list
6
+ * the targets, read the graph and run one through typed calls from the first
7
+ * commit — instead of someone hand-writing the registration later.
8
+ *
9
+ * The file is Claude Code's project format (`mcpServers.<name>`), which Codex
10
+ * and most stdio MCP clients read too. The command is `deno run -A zuke.ts
11
+ * mcp` rather than the launcher because it is the same on every platform. A
12
+ * build another SDK hosts runs `jsr:@zuke/engine@<version>` in its place, or,
13
+ * when the compiled `zuke` binary is the one registering it, `zuke mcp`: the
14
+ * binary carries the engine, so that needs no Deno and cannot drift from the
15
+ * pin, and it is a real executable an MCP client can start without a shell.
16
+ *
17
+ * @module
18
+ */
19
+ import { isRecord } from "./records.js";
20
+ /** The MCP client configuration file `--mcp` writes, next to `zuke.ts`. */
21
+ export const MCP_CONFIG_FILE = ".mcp.json";
22
+ /** The server name registered in the file. */
23
+ export const MCP_SERVER_NAME = "zuke";
24
+ /** The `mcp` command's arguments: read-only unless `allowRun` opts in. */
25
+ function mcpArgs(allowRun) {
26
+ return ["mcp", ...(allowRun ? ["--allow-run"] : [])];
27
+ }
28
+ /**
29
+ * The entry that launches the MCP server of a TypeScript build whose file is
30
+ * `buildFile`: `deno run -A zuke.ts mcp`.
31
+ * Read-only by default: the agent can inspect the build but not execute
32
+ * targets until `allowRun` opts in, mirroring `zuke mcp --allow-run`.
33
+ */
34
+ export function mcpServerEntry(allowRun, buildFile) {
35
+ return {
36
+ command: "deno",
37
+ args: ["run", "-A", buildFile, ...mcpArgs(allowRun)],
38
+ };
39
+ }
40
+ /**
41
+ * The entry a hosted build is registered with: `zuke mcp`, which the
42
+ * standalone binary runs on the engine it carries, with no Deno.
43
+ */
44
+ export function binaryMcpEntry(allowRun) {
45
+ return { command: "zuke", args: mcpArgs(allowRun) };
46
+ }
47
+ /**
48
+ * The entry a Node project is registered with: `node zuke.ts mcp`, the Node
49
+ * counterpart of {@link mcpServerEntry}. `.mcp.json` is committed and shared,
50
+ * so it names the runtime rather than a launcher script, which a Windows MCP
51
+ * client could not start. It needs Node 26 or newer on `PATH` and the
52
+ * project's dependencies installed, which a first `./zuke` run does.
53
+ */
54
+ export function nodeMcpEntry(allowRun, buildFile) {
55
+ return { command: "node", args: [buildFile, ...mcpArgs(allowRun)] };
56
+ }
57
+ /** Whether `value` is a well-formed server entry: a command and its arguments. */
58
+ function isServerEntry(value) {
59
+ return isRecord(value) && typeof value.command === "string" &&
60
+ Array.isArray(value.args) &&
61
+ value.args.every((arg) => typeof arg === "string");
62
+ }
63
+ /**
64
+ * Parse an `.mcp.json` text and classify its `zuke` entry. This is the only
65
+ * place the text is parsed: {@link mergeMcpConfig} takes the document it
66
+ * yields, so an unparseable file is rejected here, once, and can never reach
67
+ * the merge.
68
+ */
69
+ export function parseMcpConfig(text) {
70
+ let parsed;
71
+ try {
72
+ parsed = JSON.parse(text);
73
+ }
74
+ catch {
75
+ return { state: "unparseable" };
76
+ }
77
+ const document = isRecord(parsed) ? parsed : {};
78
+ const state = isRecord(document.mcpServers) &&
79
+ isServerEntry(document.mcpServers[MCP_SERVER_NAME])
80
+ ? "present"
81
+ : "absent";
82
+ return { state, document };
83
+ }
84
+ /**
85
+ * Merge `entry` as the `zuke` server into a parsed `.mcp.json` document,
86
+ * preserving every other server and top-level key. `document` is the object
87
+ * {@link parseMcpConfig} yielded, or `{}` to start fresh; an existing `zuke`
88
+ * entry is replaced. Pure: it parses nothing and cannot throw.
89
+ */
90
+ export function mergeMcpConfig(document, entry) {
91
+ const servers = isRecord(document.mcpServers)
92
+ ? { ...document.mcpServers }
93
+ : {};
94
+ servers[MCP_SERVER_NAME] = entry;
95
+ return `${JSON.stringify({ ...document, mcpServers: servers }, null, 2)}\n`;
96
+ }
@@ -0,0 +1,19 @@
1
+ import { type NodePin } from "./node_pin.ts";
2
+ /** What a Node launcher is rendered for. */
3
+ export interface NodeLauncherOptions {
4
+ /** The build file the launcher runs. Omitted: `zuke.ts`. */
5
+ buildFile?: string;
6
+ }
7
+ /**
8
+ * The bash launcher (`./zuke`) of a Node project.
9
+ *
10
+ * @throws {Error} when the build file name is not a plain file name.
11
+ */
12
+ export declare function nodeLauncherBash(options?: NodeLauncherOptions, pin?: NodePin): string;
13
+ /**
14
+ * The PowerShell launcher (`.\zuke.ps1`) of a Node project, mirroring
15
+ * {@link nodeLauncherBash}.
16
+ *
17
+ * @throws {Error} when the build file name is not a plain file name.
18
+ */
19
+ export declare function nodeLauncherPowerShell(options?: NodeLauncherOptions, pin?: NodePin): string;