codewhale 0.10.0 → 0.10.2

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
@@ -15,7 +15,7 @@ Both names run the same compiled runtime. The application state and credentials
15
15
  still live in Codewhale's normal config files, not inside `node_modules`.
16
16
 
17
17
  > Previously published as `deepseek-tui`. See
18
- > [docs/REBRAND.md](https://github.com/Hmbown/CodeWhale/blob/main/docs/REBRAND.md)
18
+ > [docs/REBRAND.md](https://github.com/codewhale-hq/CodeWhale/blob/main/docs/REBRAND.md)
19
19
  > for the migration notes; the legacy `deepseek-tui` npm package is deprecated
20
20
  > and receives no further releases.
21
21
 
@@ -27,6 +27,12 @@ npm install -g codewhale
27
27
  pnpm add -g codewhale
28
28
  ```
29
29
 
30
+ On Windows, the Node launcher stays alive while the native program runs.
31
+ Killing Node by process name can also interrupt other Codewhale npm sessions
32
+ and prevent normal terminal cleanup. Stop dev servers by their owned PID or
33
+ port, or use Codewhale's task cancellation. The Windows native archive or
34
+ installer avoids this launcher dependency. See the [Windows npm note](https://github.com/codewhale-hq/CodeWhale/blob/main/docs/INSTALL.md#4-npm).
35
+
30
36
  For project-local usage:
31
37
 
32
38
  ```bash
@@ -53,7 +59,7 @@ codewhale
53
59
  Every provider is the same one-line shape — `--provider openrouter`,
54
60
  `--provider huggingface`, `--provider ollama`, or `--provider anthropic` for a
55
61
  Claude key; the full registry lives in
56
- [docs/PROVIDERS.md](https://github.com/Hmbown/CodeWhale/blob/main/docs/PROVIDERS.md).
62
+ [docs/PROVIDERS.md](https://github.com/codewhale-hq/CodeWhale/blob/main/docs/PROVIDERS.md).
57
63
 
58
64
  The single runtime reads `~/.codewhale/config.toml` for auth and default model
59
65
  settings. Legacy `~/.deepseek/config.toml` installs are still read as a
@@ -72,20 +78,28 @@ Prebuilt binaries for the GitHub release are downloaded automatically:
72
78
  - Android arm64 / Termux (preview; requires matching Android assets in the
73
79
  selected GitHub Release)
74
80
 
75
- The source-candidate wrapper recognizes Android arm64 and resolves the
81
+ The wrapper recognizes Android arm64 and resolves the
76
82
  Termux-native `codewhale` and `codew` assets. That path works only for package
77
83
  versions whose matching GitHub Release publishes both assets, and remains
78
84
  preview support pending real-device QA. See the support table in
79
- [docs/INSTALL.md](https://github.com/Hmbown/CodeWhale/blob/main/docs/INSTALL.md).
80
-
81
- HarmonyOS PC (`openharmony`) is treated as `linux`, so it gets the Linux
82
- binaries matching your CPU architecture (x64 or arm64). Linux riscv64 prebuilts
83
- are temporarily paused while the locked `rquickjs-sys` dependency lacks
84
- `riscv64gc-unknown-linux-gnu` bindings. Other platform/architecture combinations
85
- (FreeBSD, Linux riscv64, …) aren't shipped as prebuilts. Unsupported platforms,
86
- checksum failures, and glibc compatibility problems still fail with a clear
87
- error pointing you at the full
88
- [docs/INSTALL.md](https://github.com/Hmbown/CodeWhale/blob/main/docs/INSTALL.md)
85
+ [docs/INSTALL.md](https://github.com/codewhale-hq/CodeWhale/blob/main/docs/INSTALL.md).
86
+
87
+ On a HarmonyOS PC, install inside the Linux subsystem (融合开发引擎, openEuler),
88
+ where the wrapper sees `linux` and installs the Linux arm64 binaries. In a native
89
+ HarmonyOS or OpenHarmony terminal (`openharmony`), the wrapper still installs the
90
+ static Linux build matching your CPU architecture (x64 or arm64) as a best
91
+ effort. That build is untested on native HarmonyOS. If the binary cannot start,
92
+ `codewhale` prints directions to use the Linux subsystem or build
93
+ `aarch64-unknown-linux-ohos` from source. The install script also prints a
94
+ warning, which npm 7 and later show only with `--foreground-scripts`. See
95
+ [docs/HarmonyOS.md](https://github.com/codewhale-hq/CodeWhale/blob/main/docs/HarmonyOS.md).
96
+
97
+ Linux riscv64 prebuilts are temporarily paused while the locked `rquickjs-sys`
98
+ dependency lacks `riscv64gc-unknown-linux-gnu` bindings. Other
99
+ platform/architecture combinations (FreeBSD, Linux riscv64, …) aren't shipped
100
+ as prebuilts. Unsupported platforms, checksum failures, and glibc compatibility
101
+ problems still fail with a clear error pointing you at the full
102
+ [docs/INSTALL.md](https://github.com/codewhale-hq/CodeWhale/blob/main/docs/INSTALL.md)
89
103
  guide.
90
104
 
91
105
  ## Wrapper configuration
@@ -96,7 +110,7 @@ guide.
96
110
  | `CODEWHALE_RELEASE_BASE_URL` | Canonical override: use an internal or mirrored release-asset directory and skip the Linux x64 GitHub/CNB race. The directory must contain `codewhale-artifacts-sha256.txt` and the platform binaries. `DEEPSEEK_TUI_RELEASE_BASE_URL` and `DEEPSEEK_RELEASE_BASE_URL` are the implemented legacy fallbacks. |
97
111
  | `CODEWHALE_USE_CNB_MIRROR=1` | Force the CNB (China-friendly) first-party mirror on Linux x64 and OpenHarmony x64, skipping the automatic race. Other targets fail with a clear unsupported-mirror error; use GitHub or a complete `CODEWHALE_RELEASE_BASE_URL` mirror there. Without this variable, Linux x64 still probes CNB and GitHub together and uses the first valid checksum manifest. |
98
112
  | `CODEWHALE_VERSION` | Override the release version to download. |
99
- | `CODEWHALE_GITHUB_REPO` | Override the source repo. Defaults to `Hmbown/CodeWhale`. |
113
+ | `CODEWHALE_GITHUB_REPO` | Override the source repo. Defaults to `codewhale-hq/CodeWhale`. |
100
114
  | `CODEWHALE_FORCE_DOWNLOAD=1` | Force download even when the cached binary is already present. |
101
115
  | `CODEWHALE_DISABLE_INSTALL=1` | Skip install-time download. |
102
116
  | `CODEWHALE_OPTIONAL_INSTALL=1` | Make install-time retryable download failures warn and exit `0` instead of failing `npm install`. |
@@ -129,7 +143,7 @@ offline installs, set `CODEWHALE_DISABLE_INSTALL=1` or point
129
143
 
130
144
  ## Links
131
145
 
132
- - Repository: <https://github.com/Hmbown/CodeWhale>
146
+ - Repository: <https://github.com/codewhale-hq/CodeWhale>
133
147
  - Website: <https://codewhale.net/>
134
- - Provider registry: [docs/PROVIDERS.md](https://github.com/Hmbown/CodeWhale/blob/main/docs/PROVIDERS.md)
135
- - Changelog: [CHANGELOG.md](https://github.com/Hmbown/CodeWhale/blob/main/CHANGELOG.md)
148
+ - Provider registry: [docs/PROVIDERS.md](https://github.com/codewhale-hq/CodeWhale/blob/main/docs/PROVIDERS.md)
149
+ - Changelog: [CHANGELOG.md](https://github.com/codewhale-hq/CodeWhale/blob/main/CHANGELOG.md)
package/bin/codew.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { run } = require("../scripts/run");
3
+ const { run, reportStartFailure } = require("../scripts/run");
4
4
 
5
5
  run("codew").catch((error) => {
6
- console.error("Failed to start codew:", error.message);
6
+ reportStartFailure("codew", error);
7
7
  process.exit(1);
8
8
  });
package/bin/codewhale.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { runCodeWhale } = require("../scripts/run");
3
+ const { runCodeWhale, reportStartFailure } = require("../scripts/run");
4
4
 
5
5
  runCodeWhale().catch((error) => {
6
- console.error("Failed to start codewhale:", error.message);
6
+ reportStartFailure("codewhale", error);
7
7
  process.exit(1);
8
8
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "codewhale",
3
- "version": "0.10.0",
4
- "codewhaleBinaryVersion": "0.10.0",
3
+ "version": "0.10.2",
4
+ "codewhaleBinaryVersion": "0.10.2",
5
5
  "description": "Terminal coding agent for supported hosted and local models. One runtime on your machine. Rust, MIT.",
6
6
  "author": "Hmbown",
7
7
  "license": "MIT",
@@ -15,13 +15,13 @@
15
15
  "url": "https://www.buymeacoffee.com/hmbown"
16
16
  }
17
17
  ],
18
- "homepage": "https://github.com/Hmbown/CodeWhale",
18
+ "homepage": "https://github.com/codewhale-hq/Codewhale",
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "git+https://github.com/Hmbown/CodeWhale.git"
21
+ "url": "git+https://github.com/codewhale-hq/Codewhale.git"
22
22
  },
23
23
  "bugs": {
24
- "url": "https://github.com/Hmbown/CodeWhale/issues"
24
+ "url": "https://github.com/codewhale-hq/Codewhale/issues"
25
25
  },
26
26
  "keywords": [
27
27
  "codewhale",
@@ -1,5 +1,6 @@
1
1
  const path = require("path");
2
2
  const os = require("os");
3
+ const compiledHosts = require("./compiled-hosts");
3
4
 
4
5
  const CHECKSUM_MANIFEST = "codewhale-artifacts-sha256.txt";
5
6
  const BUNDLE_CHECKSUM_MANIFEST = "codewhale-bundles-sha256.txt";
@@ -60,8 +61,8 @@ const ASSET_MATRIX = {
60
61
  },
61
62
  };
62
63
 
63
- // HarmonyPC (openharmony) is an x86_64 Linux-compatible environment; map it to
64
- // the linux binary family so npm install succeeds without a separate build target.
64
+ // Native HarmonyOS/OpenHarmony (openharmony) gets the static musl Linux build as
65
+ // a best effort; that build is untested on native HarmonyOS.
65
66
  const PLATFORM_ALIASES = {
66
67
  openharmony: "linux",
67
68
  };
@@ -101,20 +102,31 @@ function unsupportedBuildHint() {
101
102
  "No prebuilt binary is available for this platform/architecture combo.",
102
103
  "You can still run codewhale by building from source with Cargo (single binary):",
103
104
  "",
104
- " # Requires Rust 1.88+ (https://rustup.rs)",
105
+ " # Requires Rust 1.89+ (https://rustup.rs)",
105
106
  " cargo install codewhale-cli --locked # provides `codewhale`",
106
107
  "",
107
108
  "Or build from a checkout:",
108
109
  "",
109
- " git clone https://github.com/Hmbown/CodeWhale.git",
110
+ " git clone https://github.com/codewhale-hq/CodeWhale.git",
110
111
  " cd CodeWhale",
111
112
  " cargo install --path crates/cli --locked # single binary",
112
113
  "",
113
- "See https://github.com/Hmbown/CodeWhale/blob/main/docs/INSTALL.md",
114
+ "See https://github.com/codewhale-hq/CodeWhale/blob/main/docs/INSTALL.md",
114
115
  "for cross-compilation, mirror, Linux ARM64, FreeBSD, and winget specifics.",
115
116
  ].join("\n");
116
117
  }
117
118
 
119
+ function openHarmonyDirections() {
120
+ return [
121
+ "On a HarmonyOS PC, install Codewhale inside the Linux subsystem (融合开发引擎, openEuler):",
122
+ "",
123
+ " curl -fsSL https://codewhale.net/install.sh | sh",
124
+ "",
125
+ "Or build the native aarch64-unknown-linux-ohos binary from source by following",
126
+ "\"Cross-Compiling To OpenHarmony\" in docs/HarmonyOS.md of codewhale-hq/CodeWhale.",
127
+ ].join("\n");
128
+ }
129
+
118
130
  function unsupportedRiscvHint() {
119
131
  return [
120
132
  "Linux riscv64 prebuilt binaries are temporarily unavailable.",
@@ -134,7 +146,7 @@ function ensureTrailingSlash(baseUrl) {
134
146
  return trimmed.endsWith("/") ? trimmed : `${trimmed}/`;
135
147
  }
136
148
 
137
- function githubReleaseBaseUrl(version, repo = "Hmbown/CodeWhale") {
149
+ function githubReleaseBaseUrl(version, repo = "codewhale-hq/CodeWhale") {
138
150
  return `https://github.com/${repo}/releases/download/v${version}/`;
139
151
  }
140
152
 
@@ -173,7 +185,7 @@ function isCnbSupportedTarget(
173
185
  return platform === "linux" && arch === "x64";
174
186
  }
175
187
 
176
- function releaseBaseUrl(version, repo = "Hmbown/CodeWhale") {
188
+ function releaseBaseUrl(version, repo = "codewhale-hq/CodeWhale") {
177
189
  // CODEWHALE_RELEASE_BASE_URL is the canonical override.
178
190
  // DEEPSEEK_TUI_RELEASE_BASE_URL / DEEPSEEK_RELEASE_BASE_URL are legacy aliases.
179
191
  const override = explicitReleaseBase();
@@ -205,7 +217,7 @@ function shouldRaceFirstPartyMirrors(
205
217
  );
206
218
  }
207
219
 
208
- function firstPartyReleaseSources(version, repo = "Hmbown/CodeWhale") {
220
+ function firstPartyReleaseSources(version, repo = "codewhale-hq/CodeWhale") {
209
221
  return [
210
222
  {
211
223
  id: "github",
@@ -235,11 +247,11 @@ function assertCnbMirrorSupportedPlatform(
235
247
  );
236
248
  }
237
249
 
238
- function releaseAssetUrl(baseName, version, repo = "Hmbown/CodeWhale") {
250
+ function releaseAssetUrl(baseName, version, repo = "codewhale-hq/CodeWhale") {
239
251
  return releaseAssetUrlFromBase(baseName, releaseBaseUrl(version, repo));
240
252
  }
241
253
 
242
- function checksumManifestUrl(version, repo = "Hmbown/CodeWhale") {
254
+ function checksumManifestUrl(version, repo = "codewhale-hq/CodeWhale") {
243
255
  return releaseAssetUrl(CHECKSUM_MANIFEST, version, repo);
244
256
  }
245
257
 
@@ -257,7 +269,7 @@ function allAssetNames() {
257
269
  return Array.from(new Set(names));
258
270
  }
259
271
 
260
- function allReleaseAssetNames() {
272
+ function allReleaseAssetNames(catalog) {
261
273
  return [
262
274
  ...allAssetNames(),
263
275
  ...LEGACY_TUI_BRIDGE_ASSET_NAMES,
@@ -265,11 +277,12 @@ function allReleaseAssetNames() {
265
277
  WINDOWS_INSTALLER_ASSET,
266
278
  BUNDLE_CHECKSUM_MANIFEST,
267
279
  CHECKSUM_MANIFEST,
280
+ ...compiledHosts.assets(catalog),
268
281
  ];
269
282
  }
270
283
 
271
- function checksummedReleaseAssetNames() {
272
- return allReleaseAssetNames().filter((name) => name !== CHECKSUM_MANIFEST);
284
+ function checksummedReleaseAssetNames(catalog) {
285
+ return allReleaseAssetNames(catalog).filter((name) => name !== CHECKSUM_MANIFEST);
273
286
  }
274
287
 
275
288
  module.exports = {
@@ -292,6 +305,7 @@ module.exports = {
292
305
  hasExplicitReleaseBase,
293
306
  isCnbSupportedTarget,
294
307
  LEGACY_TUI_BRIDGE_ASSET_NAMES,
308
+ openHarmonyDirections,
295
309
  releaseAssetUrl,
296
310
  releaseAssetUrlFromBase,
297
311
  releaseBaseUrl,
@@ -0,0 +1,91 @@
1
+ // Optional release payloads. The Core remains the runtime/authority validator;
2
+ // this contract only prevents installers from mixing release bytes or silently
3
+ // substituting an unqualified runtime. No host is selected by default.
4
+ const crypto = require("node:crypto");
5
+ const fs = require("node:fs");
6
+ const path = require("node:path");
7
+
8
+ const HOST_CATALOG = "codewhale-extension-hosts.json";
9
+ const HOST_NAME = "codewhale-extension-host";
10
+ const TARGETS = Object.freeze({
11
+ "linux-x64": ["linux", "x64"],
12
+ "linux-arm64": ["linux", "arm64"],
13
+ "macos-x64": ["darwin", "x64"],
14
+ "macos-arm64": ["darwin", "arm64"],
15
+ "windows-x64": ["win32", "x64"],
16
+ "windows-arm64": ["win32", "arm64"],
17
+ });
18
+ const SHA = /^[a-f0-9]{64}$/;
19
+ const SOURCE = /^[a-f0-9]{40}$/;
20
+ const VERSION = /^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/;
21
+ const fail = (message) => { throw new Error(`compiled host: ${message}`); };
22
+ const sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex");
23
+
24
+ function names(target) {
25
+ if (!TARGETS[target]) fail(`unsupported target ${target}; Android is not a qualified Codewhale delivery target`);
26
+ const stem = `${HOST_NAME}-${target}`;
27
+ return {
28
+ binary: `${stem}${target.startsWith("windows-") ? ".exe" : ""}`,
29
+ notices: `${stem}-LICENSES.txt`,
30
+ source: `${stem}-relink-source.tar.gz`,
31
+ };
32
+ }
33
+
34
+ // Direct protocol cases and actual Rust kernel authority are separate proofs.
35
+ function compiledMinimum(target) { return target.startsWith("macos-") ? 6 : 5; }
36
+ function nativeMinimum(target) { return target.startsWith("windows-") ? 9 : 2; }
37
+
38
+ function parseCatalog(input, expectedVersion) {
39
+ if (Buffer.isBuffer(input)) input = input.toString("utf8");
40
+ if (Buffer.byteLength(typeof input === "string" ? input : JSON.stringify(input)) > 64 * 1024) fail("catalog exceeds 64 KiB");
41
+ const catalog = typeof input === "string" ? JSON.parse(input) : input;
42
+ if (!catalog || catalog.schema !== 1 || !VERSION.test(catalog.version) || !SOURCE.test(catalog.source_sha) || !SHA.test(catalog.bundle_sha256) || !Array.isArray(catalog.hosts) || catalog.hosts.length > 6) fail("malformed catalog identity");
43
+ if (expectedVersion && catalog.version !== expectedVersion) fail(`catalog version ${catalog.version} differs from requested ${expectedVersion}`);
44
+ const seen = new Set();
45
+ for (const host of catalog.hosts) {
46
+ if (!host || !TARGETS[host.target] || seen.has(host.target)) fail("duplicate or unsupported target");
47
+ seen.add(host.target);
48
+ const expected = names(host.target);
49
+ if (host.asset !== expected.binary || host.notices_asset !== expected.notices || host.source_asset !== expected.source) fail("noncanonical asset name");
50
+ for (const field of ["sha256", "notices_sha256", "source_sha256", "test_log_sha256", "runtime_sha256", "native_log_sha256"]) if (!SHA.test(host[field])) fail(`invalid ${field}`);
51
+ if (!VERSION.test(host.runtime_version) || !SOURCE.test(host.runtime_revision)) fail("invalid runtime identity");
52
+ if (!SOURCE.test(host.webkit_revision) || host.bundle_sha256 !== catalog.bundle_sha256 || host.source_commit !== catalog.source_sha) fail("host/source identity disagreement");
53
+ if (!Number.isSafeInteger(host.passed) || host.passed !== compiledMinimum(host.target) || host.failed !== 0 || host.skipped !== 0 || host.native_platform !== TARGETS[host.target][0] || host.native_arch !== TARGETS[host.target][1]) fail("no successful matching-native compiled-image qualification");
54
+ if (!Number.isSafeInteger(host.native_passed) || host.native_passed < nativeMinimum(host.target) || host.native_failed !== 0 || host.native_skipped !== 0) fail("no actual Native compiled-image containment and memory qualification");
55
+ if (host.target.startsWith("linux-") ? !["glibc", "musl"].includes(host.libc) : host.libc !== "none") fail("unknown runtime libc");
56
+ if (host.license_closure !== "complete" || host.relink_source !== "complete") fail("runtime notices and relinkable corresponding source are required");
57
+ }
58
+ return catalog;
59
+ }
60
+
61
+ function assets(catalog) {
62
+ return catalog ? [HOST_CATALOG, ...parseCatalog(catalog).hosts.flatMap((host) => [host.asset, host.notices_asset, host.source_asset])] : [];
63
+ }
64
+
65
+ function selectedHost(catalog, platform = process.platform, arch = process.arch) {
66
+ if (platform === "android") fail("Android is not a qualified Codewhale compiled-host delivery target; Node remains available");
67
+ const entry = parseCatalog(catalog).hosts.find((host) => TARGETS[host.target][0] === platform && TARGETS[host.target][1] === arch);
68
+ if (!entry) fail(`no qualified image for ${platform}/${arch}; use Node or explicitly qualify a matching local Bun`);
69
+ return entry;
70
+ }
71
+
72
+ function requested(env = process.env) {
73
+ return env.CODEWHALE_INSTALL_COMPILED_HOST === "1";
74
+ }
75
+
76
+ function verifyBytes(bytes, expected, name) {
77
+ if (!SHA.test(expected) || sha256(bytes) !== expected) fail(`SHA256 mismatch for ${name}`);
78
+ }
79
+
80
+ function verifyDirectory(directory, catalog) {
81
+ for (const host of parseCatalog(catalog).hosts) {
82
+ for (const [name, digest] of [[host.asset, host.sha256], [host.notices_asset, host.notices_sha256], [host.source_asset, host.source_sha256]]) {
83
+ const file = path.join(directory, name);
84
+ const stat = fs.lstatSync(file);
85
+ if (!stat.isFile() || stat.isSymbolicLink()) fail(`not a regular payload: ${name}`);
86
+ verifyBytes(fs.readFileSync(file), digest, name);
87
+ }
88
+ }
89
+ }
90
+
91
+ module.exports = { HOST_CATALOG, HOST_NAME, TARGETS, assets, names, compiledMinimum, nativeMinimum, parseCatalog, requested, selectedHost, sha256, verifyBytes, verifyDirectory };
@@ -34,13 +34,15 @@ const {
34
34
  explicitReleaseBase,
35
35
  firstPartyReleaseSources,
36
36
  githubReleaseBaseUrl,
37
+ openHarmonyDirections,
37
38
  releaseAssetUrl,
38
39
  releaseAssetUrlFromBase,
39
40
  releaseBinaryDirectory,
40
41
  shouldRaceFirstPartyMirrors,
41
42
  usesCnbMirror,
42
43
  } = require("./artifacts");
43
- const { preflightGlibc } = require("./preflight-glibc");
44
+ const { preflightGlibc, detectHostGlibc, detectBinaryRequiredGlibc, _internal: glibc } = require("./preflight-glibc");
45
+ const compiledHosts = require("./compiled-hosts");
44
46
  const pkg = require("../package.json");
45
47
 
46
48
  const DEFAULT_TIMEOUT_MS = 300_000; // 5 minutes per attempt
@@ -123,7 +125,7 @@ function resolveRepo(env = process.env) {
123
125
  env.CODEWHALE_GITHUB_REPO ||
124
126
  env.DEEPSEEK_TUI_GITHUB_REPO ||
125
127
  env.DEEPSEEK_GITHUB_REPO ||
126
- "Hmbown/CodeWhale"
128
+ "codewhale-hq/CodeWhale"
127
129
  );
128
130
  }
129
131
 
@@ -267,7 +269,7 @@ function installFailureHint(error) {
267
269
  " CODEWHALE_RELEASE_BASE_URL=https://<mirror>/<release-asset-directory>/",
268
270
  " or CODEWHALE_USE_CNB_MIRROR=1 on Linux x64.",
269
271
  " The directory must contain codewhale-artifacts-sha256.txt and the platform binaries.",
270
- " See docs/INSTALL.md#npm-binary-download-times-out.",
272
+ " See https://github.com/codewhale-hq/CodeWhale/blob/main/docs/INSTALL.md#npm-binary-download-times-out",
271
273
  ].join("\n");
272
274
  }
273
275
 
@@ -566,6 +568,7 @@ function httpRequest(rawUrl, opts = {}) {
566
568
  let totalTimer = null;
567
569
  let stallTimer = null;
568
570
  let settled = false;
571
+ let handedOff = false;
569
572
  let req = null;
570
573
  let res = null;
571
574
  const signal = opts.signal;
@@ -587,7 +590,20 @@ function httpRequest(rawUrl, opts = {}) {
587
590
  };
588
591
 
589
592
  const fail = (err) => {
590
- if (settled) return;
593
+ if (settled) {
594
+ // The stall, total, and abort budgets outlive the handoff: once the
595
+ // caller owns the body, end it with the error so the caller's own
596
+ // `error` handler rejects instead of waiting on a silent socket.
597
+ if (handedOff) {
598
+ cleanup();
599
+ try {
600
+ if (res && !res.destroyed) res.destroy(err);
601
+ } catch {
602
+ // ignore
603
+ }
604
+ }
605
+ return;
606
+ }
591
607
  settled = true;
592
608
  cleanup();
593
609
  try {
@@ -603,6 +619,15 @@ function httpRequest(rawUrl, opts = {}) {
603
619
  reject(err);
604
620
  };
605
621
 
622
+ // Hand the live response stream to the caller. The timers stay armed
623
+ // until the body ends or closes (see `fail`).
624
+ const handOff = (response) => {
625
+ settled = true;
626
+ handedOff = true;
627
+ response.on("close", () => cleanup());
628
+ resolve({ redirect: null, response });
629
+ };
630
+
606
631
  if (signal) {
607
632
  if (signal.aborted) {
608
633
  reject(abortError());
@@ -627,6 +652,12 @@ function httpRequest(rawUrl, opts = {}) {
627
652
  if (stallMs <= 0) return;
628
653
  if (stallTimer) clearTimeout(stallTimer);
629
654
  stallTimer = setTimeout(() => {
655
+ // A body the caller has paused (a slow disk pushing back through
656
+ // `pipe`) is not a stalled network. The total budget still bounds it.
657
+ if (handedOff && res && res.readableFlowing === false) {
658
+ armStallTimer();
659
+ return;
660
+ }
630
661
  fail(new DownloadTimeoutError(
631
662
  `download stalled — no bytes received for ${stallMs} ms ` +
632
663
  `(set CODEWHALE_DOWNLOAD_STALL_MS to raise it; total budget is ${totalTimeoutMs} ms)`,
@@ -692,9 +723,7 @@ function httpRequest(rawUrl, opts = {}) {
692
723
  return;
693
724
  }
694
725
  if (settled) return;
695
- settled = true;
696
- // Hand the live response stream to the caller.
697
- resolve({ redirect: null, response });
726
+ handOff(response);
698
727
  });
699
728
  req.once("error", (err) => fail(err));
700
729
  req.once("socket", (s) => {
@@ -757,8 +786,7 @@ function httpRequest(rawUrl, opts = {}) {
757
786
  return;
758
787
  }
759
788
  if (settled) return;
760
- settled = true;
761
- resolve({ redirect: null, response });
789
+ handOff(response);
762
790
  },
763
791
  );
764
792
  req.once("error", (err) => fail(err));
@@ -821,8 +849,7 @@ function httpRequest(rawUrl, opts = {}) {
821
849
  return;
822
850
  }
823
851
  if (settled) return;
824
- settled = true;
825
- resolve({ redirect: null, response });
852
+ handOff(response);
826
853
  });
827
854
  req.once("error", (err) => fail(err));
828
855
  req.end();
@@ -1356,7 +1383,7 @@ async function raceFirstPartyManifests(sources, options) {
1356
1383
 
1357
1384
  async function selectReleaseSource(options) {
1358
1385
  const version = options.version;
1359
- const repo = options.repo || "Hmbown/CodeWhale";
1386
+ const repo = options.repo || "codewhale-hq/CodeWhale";
1360
1387
  const env = options.env || process.env;
1361
1388
  const platform =
1362
1389
  options.platform === undefined || options.platform === null
@@ -1550,6 +1577,116 @@ function shouldIgnoreInstallFailure(
1550
1577
  return isInstallContext(context) && isOptionalInstall(argv, env) && isRetryable(error);
1551
1578
  }
1552
1579
 
1580
+ function preflightCompiledHost(file, host) {
1581
+ if (!host.target.startsWith("linux-")) return;
1582
+ const required = detectBinaryRequiredGlibc(file);
1583
+ const available = detectHostGlibc();
1584
+ if (host.libc === "glibc" && (!available || (required && glibc.compareVersion(available, required) < 0))) {
1585
+ throw new NonRetryableError("compiled Bun image requires a matching GNU libc; the Codewhale CLI remains static musl. Use Node on a musl-only installation.");
1586
+ }
1587
+ if (host.libc === "musl" && required) throw new NonRetryableError("qualified musl host unexpectedly contains GNU libc dependencies");
1588
+ }
1589
+
1590
+ async function prepareCompiledHost({ version, releaseDir, source, context, options }) {
1591
+ const catalogUrl = releaseAssetUrlFromBase(compiledHosts.HOST_CATALOG, source.baseUrl);
1592
+ const fetchText = options.fetchText || downloadText;
1593
+ const text = await fetchText(catalogUrl, { context });
1594
+ compiledHosts.verifyBytes(Buffer.from(text), source.checksums.get(compiledHosts.HOST_CATALOG), compiledHosts.HOST_CATALOG);
1595
+ const catalog = compiledHosts.parseCatalog(text, version);
1596
+ const host = compiledHosts.selectedHost(catalog, options.platform, options.arch);
1597
+ const suffix = host.target.startsWith("windows-") ? ".exe" : "";
1598
+ const payloads = [
1599
+ { asset: host.asset, name: compiledHosts.HOST_NAME + suffix, hash: host.sha256, executable: true },
1600
+ { asset: host.notices_asset, name: compiledHosts.HOST_NAME + ".LICENSES.txt", hash: host.notices_sha256 },
1601
+ { asset: host.source_asset, name: compiledHosts.HOST_NAME + ".relink-source.tar.gz", hash: host.source_sha256 },
1602
+ ];
1603
+ const stageDir = await fs.promises.mkdtemp(path.join(releaseDir, ".compiled-host-"));
1604
+ const snapshots = [];
1605
+ const published = [];
1606
+ let retainBackups = false;
1607
+ const existingHash = async (file) => {
1608
+ try {
1609
+ const metadata = await fs.promises.lstat(file);
1610
+ if (!metadata.isFile() || metadata.isSymbolicLink()) throw new NonRetryableError(`refusing nonregular compiled host destination ${file}`);
1611
+ return compiledHosts.sha256(await readFile(file));
1612
+ } catch (error) { if (error.code === "ENOENT") return undefined; throw error; }
1613
+ };
1614
+ const cleanup = async () => { if (!retainBackups) await fs.promises.rm(stageDir, { recursive: true, force: true }); };
1615
+ const rollback = async (original) => {
1616
+ const failures = [];
1617
+ for (const snapshot of published.slice().reverse()) {
1618
+ try {
1619
+ if (await existingHash(snapshot.target) !== snapshot.newHash) throw new Error(`destination changed after publication: ${snapshot.target}`);
1620
+ if (snapshot.hash) await rename(path.join(stageDir, snapshot.name + ".previous"), snapshot.target);
1621
+ else await unlink(snapshot.target);
1622
+ } catch (error) { failures.push(error.message); }
1623
+ }
1624
+ if (failures.length) {
1625
+ retainBackups = true;
1626
+ throw new NonRetryableError(`${original.message}; rollback incomplete: ${failures.join("; ")}. Recovery files retained at ${stageDir}`);
1627
+ }
1628
+ throw original;
1629
+ };
1630
+ try {
1631
+ for (const payload of payloads) {
1632
+ if (source.checksums.get(payload.asset) !== payload.hash) throw new NonRetryableError(`catalog and checksum manifest disagree for ${payload.asset}`);
1633
+ const stage = path.join(stageDir, payload.name);
1634
+ await (options.download || download)(releaseAssetUrlFromBase(payload.asset, source.baseUrl), stage, { context, assetName: payload.asset });
1635
+ compiledHosts.verifyBytes(await readFile(stage), payload.hash, payload.asset);
1636
+ if (payload.executable) preflightCompiledHost(stage, host);
1637
+ if (process.platform !== "win32") await chmod(stage, payload.executable ? 0o755 : 0o644);
1638
+ }
1639
+ const receiptName = compiledHosts.HOST_NAME + ".release.json";
1640
+ await writeFile(path.join(stageDir, receiptName), text, { mode: 0o644 });
1641
+ const oldReceipt = path.join(releaseDir, receiptName);
1642
+ const oldReceiptHash = await existingHash(oldReceipt);
1643
+ let oldPayloadHashes;
1644
+ if (oldReceiptHash) {
1645
+ const previous = compiledHosts.selectedHost(compiledHosts.parseCatalog(await readFile(oldReceipt)), options.platform, options.arch);
1646
+ oldPayloadHashes = [previous.sha256, previous.notices_sha256, previous.source_sha256];
1647
+ }
1648
+ const names = [...payloads.map((payload) => payload.name), receiptName];
1649
+ for (const [index, name] of names.entries()) {
1650
+ const target = path.join(releaseDir, name);
1651
+ const hash = await existingHash(target);
1652
+ if (index < payloads.length && hash && (!oldPayloadHashes || hash !== oldPayloadHashes[index])) throw new NonRetryableError(`refusing unclaimed or modified compiled host destination ${target}`);
1653
+ if (hash) {
1654
+ const backup = path.join(stageDir, name + ".previous");
1655
+ await fs.promises.copyFile(target, backup);
1656
+ if (compiledHosts.sha256(await readFile(backup)) !== hash) throw new NonRetryableError(`compiled host changed while backing up ${target}`);
1657
+ }
1658
+ snapshots.push({ name, target, hash, newHash: compiledHosts.sha256(await readFile(path.join(stageDir, name))) });
1659
+ }
1660
+ } catch (error) { await cleanup(); throw error; }
1661
+ return {
1662
+ cleanup,
1663
+ async publish() {
1664
+ try {
1665
+ // Validate every destination before publication, then each immediately
1666
+ // before replacement. Only bytes proven by the prior receipt are owned.
1667
+ for (const snapshot of snapshots) if (await existingHash(snapshot.target) !== snapshot.hash) throw new NonRetryableError(`compiled host destination changed during installation: ${snapshot.target}`);
1668
+ for (const snapshot of snapshots) {
1669
+ if (await existingHash(snapshot.target) !== snapshot.hash) throw new NonRetryableError(`compiled host destination changed during installation: ${snapshot.target}`);
1670
+ const staged = path.join(stageDir, snapshot.name);
1671
+ if (snapshot.hash === undefined) {
1672
+ await fs.promises.link(staged, snapshot.target); // fresh install never clobbers a raced-in file
1673
+ published.push(snapshot);
1674
+ await unlink(staged);
1675
+ } else {
1676
+ await rename(staged, snapshot.target);
1677
+ published.push(snapshot);
1678
+ }
1679
+ }
1680
+ } catch (error) { await rollback(error); }
1681
+ },
1682
+ };
1683
+ }
1684
+
1685
+ async function installCompiledHost(options) {
1686
+ const prepared = await prepareCompiledHost(options);
1687
+ try { await prepared.publish(); } finally { await prepared.cleanup(); }
1688
+ }
1689
+
1553
1690
  async function run(options = {}) {
1554
1691
  const context =
1555
1692
  options.context === undefined || options.context === null ? "runtime" : options.context;
@@ -1566,6 +1703,16 @@ async function run(options = {}) {
1566
1703
  const version = resolvePackageVersion(pkg, env);
1567
1704
  const repo = resolveRepo(env);
1568
1705
  const paths = options.paths || binaryPaths();
1706
+ if (
1707
+ isInstallContext(context) &&
1708
+ (options.platform || os.platform()) === "openharmony" &&
1709
+ !isQuietInstall(env)
1710
+ ) {
1711
+ process.stderr.write(
1712
+ `codewhale: warning: installing ${paths.codewhale.asset}, the Linux build, which is untested on native HarmonyOS/OpenHarmony.\n` +
1713
+ `${openHarmonyDirections()}\n`,
1714
+ );
1715
+ }
1569
1716
  const releaseDir = options.releaseDir || releaseBinaryDirectory();
1570
1717
  await mkdir(releaseDir, { recursive: true });
1571
1718
 
@@ -1575,7 +1722,7 @@ async function run(options = {}) {
1575
1722
  sourcePromise = selectReleaseSource({
1576
1723
  version,
1577
1724
  repo,
1578
- requiredAssets: [paths.codewhale.asset, paths.codew.asset],
1725
+ requiredAssets: [paths.codewhale.asset, paths.codew.asset, ...(compiledHosts.requested(env) ? [compiledHosts.HOST_CATALOG] : [])],
1579
1726
  context,
1580
1727
  env,
1581
1728
  platform: options.platform,
@@ -1588,7 +1735,13 @@ async function run(options = {}) {
1588
1735
  };
1589
1736
  const getChecksums = () => getSource().then((source) => source.checksums);
1590
1737
 
1591
- await Promise.all([
1738
+ // Fully validate and stage an explicitly requested companion before any CLI
1739
+ // replacement. Missing qualification cannot leave an updated CLI behind.
1740
+ const preparedHost = compiledHosts.requested(env)
1741
+ ? await prepareCompiledHost({ version, releaseDir, source: await getSource(), context, options })
1742
+ : undefined;
1743
+ try {
1744
+ await Promise.all([
1592
1745
  ensureBinary(paths.codewhale.target, paths.codewhale.asset, version, repo, getChecksums, {
1593
1746
  context,
1594
1747
  getSource,
@@ -1602,6 +1755,8 @@ async function run(options = {}) {
1602
1755
  env,
1603
1756
  }),
1604
1757
  ]); // single binary
1758
+ if (preparedHost) await preparedHost.publish();
1759
+ } finally { if (preparedHost) await preparedHost.cleanup(); }
1605
1760
  }
1606
1761
 
1607
1762
  async function getBinaryPath(name) {
@@ -1640,6 +1795,9 @@ module.exports = {
1640
1795
  downloadTimeoutMs,
1641
1796
  downloadStallMs,
1642
1797
  binaryPaths,
1798
+ installCompiledHost,
1799
+ prepareCompiledHost,
1800
+ preflightCompiledHost,
1643
1801
  ensureBinary,
1644
1802
  maxAttempts,
1645
1803
  withRetry,