codewhale 0.10.1 → 0.10.3
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 +16 -8
- package/codewhale-notices/LICENSE +21 -0
- package/codewhale-notices/THIRD_PARTY_NOTICES.md +1011 -0
- package/codewhale-notices/docs/THIRD_PARTY_NOTICES.md +66 -0
- package/package.json +4 -3
- package/scripts/artifacts.js +140 -17
- package/scripts/install.js +47 -10
- package/scripts/run.js +22 -1
- package/scripts/verify-release-assets.js +102 -126
- package/test/artifacts.test.js +74 -10
- package/test/install.test.js +58 -0
- package/test/release-assets.test.js +65 -0
- package/test/source-selection.test.js +14 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
Codewhale is MIT licensed (see [`LICENSE`](../LICENSE)). Portions of it are
|
|
4
|
+
adapted from other open-source projects. Their copyright and permission
|
|
5
|
+
notices are reproduced here, and each adapted file carries an attribution
|
|
6
|
+
header pointing back to its origin.
|
|
7
|
+
|
|
8
|
+
Rust crate dependencies are covered by `cargo deny` (see [`deny.toml`](../deny.toml))
|
|
9
|
+
and are not duplicated here; this file records source-level adaptations, where
|
|
10
|
+
the licence obligation travels with the code rather than with a package.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## pi-mono — credential resolution design
|
|
15
|
+
|
|
16
|
+
- **Project:** pi-mono (<https://github.com/earendil-works/pi-mono>)
|
|
17
|
+
- **Author:** Mario Zechner
|
|
18
|
+
- **Licence:** MIT
|
|
19
|
+
- **Used in:** `crates/runtime/src/credentials/` and
|
|
20
|
+
`crates/runtime/src/config/credential_resolve.rs`
|
|
21
|
+
- **What was taken:** the design of `packages/ai/src/auth/` — one type-tagged
|
|
22
|
+
credential per provider, `modify` as the only serialized write path, a single
|
|
23
|
+
stated precedence rule enforced in one place, an injectable auth context, and
|
|
24
|
+
a resolution result that names its source. This is a design port into
|
|
25
|
+
idiomatic synchronous Rust over Codewhale's existing stores, not a
|
|
26
|
+
line-for-line copy; several doc comments are adapted closely.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
MIT License
|
|
30
|
+
|
|
31
|
+
Copyright (c) 2025 Mario Zechner
|
|
32
|
+
|
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
34
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
35
|
+
in the Software without restriction, including without limitation the rights
|
|
36
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
37
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
38
|
+
furnished to do so, subject to the following conditions:
|
|
39
|
+
|
|
40
|
+
The above copyright notice and this permission notice shall be included in all
|
|
41
|
+
copies or substantial portions of the Software.
|
|
42
|
+
|
|
43
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
44
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
45
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
46
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
47
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
48
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
49
|
+
SOFTWARE.
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Other source-level adaptations
|
|
55
|
+
|
|
56
|
+
These predate this file. Each already names its origin in a header comment on
|
|
57
|
+
the adapting file; they are listed here so the set is discoverable from one
|
|
58
|
+
place. Their licence text has not been reproduced below — that is a gap, not a
|
|
59
|
+
claim that none is required.
|
|
60
|
+
|
|
61
|
+
| Codewhale file | Adapted from |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| `crates/tui/src/tui/frame_rate_limiter.rs` | `codex-rs/tui/src/tui/frame_rate_limiter.rs`, [openai/codex](https://github.com/openai/codex) |
|
|
64
|
+
| `crates/tui/src/tui/display_refresh.rs` | Grok CLI's host display-refresh probe |
|
|
65
|
+
| `patches/unicode-width-0.2.2/` | vendored patch; upstream `LICENSE-MIT` retained in-tree |
|
|
66
|
+
| `patches/crossterm-0.29.0/` | vendored patch (surrogate key-up handling in `src/event/sys/windows/parse.rs`, the change proposed upstream as crossterm-rs/crossterm#1073); upstream MIT `LICENSE` retained in-tree |
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codewhale",
|
|
3
|
-
"version": "0.10.
|
|
4
|
-
"codewhaleBinaryVersion": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
4
|
+
"codewhaleBinaryVersion": "0.10.3",
|
|
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",
|
|
@@ -45,13 +45,14 @@
|
|
|
45
45
|
"test": "node --test test/*.test.js"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
48
|
+
"node": ">=22"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
53
|
"preferGlobal": true,
|
|
54
54
|
"files": [
|
|
55
|
+
"codewhale-notices",
|
|
55
56
|
"bin/*.js",
|
|
56
57
|
"scripts/*.js",
|
|
57
58
|
"test/*.js",
|
package/scripts/artifacts.js
CHANGED
|
@@ -3,8 +3,21 @@ const os = require("os");
|
|
|
3
3
|
const compiledHosts = require("./compiled-hosts");
|
|
4
4
|
|
|
5
5
|
const CHECKSUM_MANIFEST = "codewhale-artifacts-sha256.txt";
|
|
6
|
+
const CHECKSUM_SIGNATURE = `${CHECKSUM_MANIFEST}.sig`;
|
|
6
7
|
const BUNDLE_CHECKSUM_MANIFEST = "codewhale-bundles-sha256.txt";
|
|
7
8
|
const WINDOWS_INSTALLER_ASSET = "CodeWhaleSetup.exe";
|
|
9
|
+
const RELEASE_GITHUB_HOSTS = new Set([
|
|
10
|
+
"github.com",
|
|
11
|
+
"api.github.com",
|
|
12
|
+
"objects.githubusercontent.com",
|
|
13
|
+
"release-assets.githubusercontent.com",
|
|
14
|
+
"github-releases.githubusercontent.com",
|
|
15
|
+
]);
|
|
16
|
+
const RELEASE_CNB_HOST = "cnb.cool";
|
|
17
|
+
const UPDATE_ALLOWED_HOSTS_ENV = "CODEWHALE_UPDATE_ALLOWED_HOSTS";
|
|
18
|
+
const transportOptions = {
|
|
19
|
+
allowLoopbackHttp: false,
|
|
20
|
+
};
|
|
8
21
|
|
|
9
22
|
// Compatibility bridge introduced in v0.9.5: already-shipped v0.9.4 clients
|
|
10
23
|
// require these names before
|
|
@@ -15,6 +28,10 @@ const LEGACY_TUI_BRIDGE_ASSET_NAMES = [
|
|
|
15
28
|
"codewhale-tui-linux-x64",
|
|
16
29
|
"codewhale-tui-linux-arm64",
|
|
17
30
|
"codewhale-tui-android-arm64",
|
|
31
|
+
// Published for symmetry with every other platform: the name exists so
|
|
32
|
+
// release completeness stays one rule, not a case analysis. No shipped client
|
|
33
|
+
// requests it; nothing else references it.
|
|
34
|
+
"codewhale-tui-ohos-arm64",
|
|
18
35
|
"codewhale-tui-macos-x64",
|
|
19
36
|
"codewhale-tui-macos-arm64",
|
|
20
37
|
"codewhale-tui-windows-x64.exe",
|
|
@@ -35,6 +52,7 @@ const BUNDLE_ASSET_NAMES = [
|
|
|
35
52
|
"codewhale-linux-x64.tar.gz",
|
|
36
53
|
"codewhale-linux-arm64.tar.gz",
|
|
37
54
|
"codewhale-android-arm64.tar.gz",
|
|
55
|
+
"codewhale-ohos-arm64.tar.gz",
|
|
38
56
|
"codewhale-macos-x64.tar.gz",
|
|
39
57
|
"codewhale-macos-arm64.tar.gz",
|
|
40
58
|
"codewhale-windows-x64.zip",
|
|
@@ -51,6 +69,12 @@ const ASSET_MATRIX = {
|
|
|
51
69
|
android: {
|
|
52
70
|
arm64: ["codewhale-android-arm64", "codew-android-arm64"],
|
|
53
71
|
},
|
|
72
|
+
// Native HarmonyOS/OpenHarmony (aarch64-unknown-linux-ohos). These binaries
|
|
73
|
+
// only run on a device when they are code-signed, so the release build
|
|
74
|
+
// self-signs them; see docs/HarmonyOS.md.
|
|
75
|
+
openharmony: {
|
|
76
|
+
arm64: ["codewhale-ohos-arm64", "codew-ohos-arm64"],
|
|
77
|
+
},
|
|
54
78
|
darwin: {
|
|
55
79
|
x64: ["codewhale-macos-x64", "codew-macos-x64"],
|
|
56
80
|
arm64: ["codewhale-macos-arm64", "codew-macos-arm64"],
|
|
@@ -61,21 +85,14 @@ const ASSET_MATRIX = {
|
|
|
61
85
|
},
|
|
62
86
|
};
|
|
63
87
|
|
|
64
|
-
// HarmonyPC (openharmony) is an x86_64 Linux-compatible environment; map it to
|
|
65
|
-
// the linux binary family so npm install succeeds without a separate build target.
|
|
66
|
-
const PLATFORM_ALIASES = {
|
|
67
|
-
openharmony: "linux",
|
|
68
|
-
};
|
|
69
|
-
|
|
70
88
|
function detectBinaryNames() {
|
|
71
|
-
const
|
|
72
|
-
const platform = PLATFORM_ALIASES[rawPlatform] || rawPlatform;
|
|
89
|
+
const platform = os.platform();
|
|
73
90
|
const arch = os.arch();
|
|
74
91
|
const defaults = ASSET_MATRIX[platform];
|
|
75
92
|
if (!defaults) {
|
|
76
93
|
const supported = Object.keys(ASSET_MATRIX).map(p => `'${p}'`).join(', ');
|
|
77
94
|
throw new Error(
|
|
78
|
-
`Unsupported platform: ${
|
|
95
|
+
`Unsupported platform: ${platform}. Supported platforms: ${supported}.\n\n` +
|
|
79
96
|
unsupportedBuildHint(),
|
|
80
97
|
);
|
|
81
98
|
}
|
|
@@ -116,6 +133,17 @@ function unsupportedBuildHint() {
|
|
|
116
133
|
].join("\n");
|
|
117
134
|
}
|
|
118
135
|
|
|
136
|
+
function openHarmonyDirections() {
|
|
137
|
+
return [
|
|
138
|
+
"On a HarmonyOS PC, install Codewhale inside the Linux subsystem (融合开发引擎, openEuler):",
|
|
139
|
+
"",
|
|
140
|
+
" curl -fsSL https://codewhale.net/install.sh | sh",
|
|
141
|
+
"",
|
|
142
|
+
"Or build the native aarch64-unknown-linux-ohos binary from source by following",
|
|
143
|
+
"\"Cross-Compiling To OpenHarmony\" in docs/HarmonyOS.md of codewhale-hq/CodeWhale.",
|
|
144
|
+
].join("\n");
|
|
145
|
+
}
|
|
146
|
+
|
|
119
147
|
function unsupportedRiscvHint() {
|
|
120
148
|
return [
|
|
121
149
|
"Linux riscv64 prebuilt binaries are temporarily unavailable.",
|
|
@@ -167,10 +195,9 @@ function hasExplicitReleaseBase(env = process.env) {
|
|
|
167
195
|
}
|
|
168
196
|
|
|
169
197
|
function isCnbSupportedTarget(
|
|
170
|
-
|
|
198
|
+
platform = os.platform(),
|
|
171
199
|
arch = os.arch(),
|
|
172
200
|
) {
|
|
173
|
-
const platform = PLATFORM_ALIASES[rawPlatform] || rawPlatform;
|
|
174
201
|
return platform === "linux" && arch === "x64";
|
|
175
202
|
}
|
|
176
203
|
|
|
@@ -196,11 +223,11 @@ function usesCnbMirror(env = process.env) {
|
|
|
196
223
|
|
|
197
224
|
function shouldRaceFirstPartyMirrors(
|
|
198
225
|
env = process.env,
|
|
199
|
-
|
|
226
|
+
platform = os.platform(),
|
|
200
227
|
arch = os.arch(),
|
|
201
228
|
) {
|
|
202
229
|
return (
|
|
203
|
-
isCnbSupportedTarget(
|
|
230
|
+
isCnbSupportedTarget(platform, arch) &&
|
|
204
231
|
!hasExplicitReleaseBase(env) &&
|
|
205
232
|
env.CODEWHALE_USE_CNB_MIRROR !== "1"
|
|
206
233
|
);
|
|
@@ -222,15 +249,16 @@ function firstPartyReleaseSources(version, repo = "codewhale-hq/CodeWhale") {
|
|
|
222
249
|
}
|
|
223
250
|
|
|
224
251
|
function assertCnbMirrorSupportedPlatform(
|
|
225
|
-
|
|
252
|
+
platform = os.platform(),
|
|
226
253
|
arch = os.arch(),
|
|
227
254
|
) {
|
|
228
|
-
if (isCnbSupportedTarget(
|
|
255
|
+
if (isCnbSupportedTarget(platform, arch)) {
|
|
229
256
|
return;
|
|
230
257
|
}
|
|
231
258
|
throw new Error(
|
|
232
|
-
"CODEWHALE_USE_CNB_MIRROR=1 currently supports only Linux x64 " +
|
|
233
|
-
`
|
|
259
|
+
"CODEWHALE_USE_CNB_MIRROR=1 currently supports only Linux x64; " +
|
|
260
|
+
`detected ${platform} ${arch}. Native HarmonyOS has its own asset and ` +
|
|
261
|
+
"no CNB mirror. " +
|
|
234
262
|
"Use the GitHub Release or set CODEWHALE_RELEASE_BASE_URL to a " +
|
|
235
263
|
"complete mirror for this platform.",
|
|
236
264
|
);
|
|
@@ -244,6 +272,94 @@ function checksumManifestUrl(version, repo = "codewhale-hq/CodeWhale") {
|
|
|
244
272
|
return releaseAssetUrl(CHECKSUM_MANIFEST, version, repo);
|
|
245
273
|
}
|
|
246
274
|
|
|
275
|
+
function redactUrl(rawUrl) {
|
|
276
|
+
const input = String(rawUrl || "");
|
|
277
|
+
try {
|
|
278
|
+
const parsed = new URL(input);
|
|
279
|
+
if (parsed.username || parsed.password) {
|
|
280
|
+
parsed.username = "";
|
|
281
|
+
parsed.password = "";
|
|
282
|
+
return parsed.toString();
|
|
283
|
+
}
|
|
284
|
+
return input;
|
|
285
|
+
} catch {
|
|
286
|
+
return input.replace(/^([a-z][a-z0-9+\-.]*:\/\/)[^/@\s]+@/i, "$1");
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function extraAllowedReleaseHosts(env = process.env) {
|
|
291
|
+
const extra = new Set();
|
|
292
|
+
const override = explicitReleaseBase(env);
|
|
293
|
+
if (override) {
|
|
294
|
+
try {
|
|
295
|
+
const parsed = new URL(override);
|
|
296
|
+
if (parsed.hostname) {
|
|
297
|
+
extra.add(parsed.hostname.toLowerCase());
|
|
298
|
+
}
|
|
299
|
+
} catch {
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const configured = env && env[UPDATE_ALLOWED_HOSTS_ENV];
|
|
303
|
+
if (configured) {
|
|
304
|
+
for (const part of String(configured).split(",")) {
|
|
305
|
+
const host = part.trim().toLowerCase();
|
|
306
|
+
if (host) {
|
|
307
|
+
extra.add(host);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return extra;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function isAllowedReleaseHost(hostname, env = process.env) {
|
|
315
|
+
const host = String(hostname || "").toLowerCase();
|
|
316
|
+
if (!host) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
if (
|
|
320
|
+
RELEASE_GITHUB_HOSTS.has(host) ||
|
|
321
|
+
host === RELEASE_CNB_HOST ||
|
|
322
|
+
host.endsWith(`.${RELEASE_CNB_HOST}`)
|
|
323
|
+
) {
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
return extraAllowedReleaseHosts(env).has(host);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function isLoopbackHost(hostname) {
|
|
330
|
+
const host = String(hostname || "").toLowerCase();
|
|
331
|
+
return host === "127.0.0.1" || host === "localhost" || host === "::1" || host === "[::1]";
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function validateReleaseUrl(rawUrl, options = {}) {
|
|
335
|
+
const env = options.env || process.env;
|
|
336
|
+
const allowLoopbackHttp =
|
|
337
|
+
options.allowLoopbackHttp === undefined
|
|
338
|
+
? transportOptions.allowLoopbackHttp
|
|
339
|
+
: Boolean(options.allowLoopbackHttp);
|
|
340
|
+
const safeUrl = redactUrl(rawUrl);
|
|
341
|
+
let parsed;
|
|
342
|
+
try {
|
|
343
|
+
parsed = new URL(rawUrl);
|
|
344
|
+
} catch (err) {
|
|
345
|
+
throw new Error(`Invalid release URL: ${safeUrl} (${err.message})`);
|
|
346
|
+
}
|
|
347
|
+
if (allowLoopbackHttp && parsed.protocol === "http:" && isLoopbackHost(parsed.hostname)) {
|
|
348
|
+
return parsed;
|
|
349
|
+
}
|
|
350
|
+
if (parsed.protocol !== "https:") {
|
|
351
|
+
throw new Error(`Release download requires HTTPS, not ${parsed.protocol}: ${safeUrl}`);
|
|
352
|
+
}
|
|
353
|
+
if (!isAllowedReleaseHost(parsed.hostname, env)) {
|
|
354
|
+
throw new Error(
|
|
355
|
+
`Release host "${parsed.hostname}" is not an allowed release host. ` +
|
|
356
|
+
"A private mirror's host is allowed when it is the CODEWHALE_RELEASE_BASE_URL HTTPS base URL; " +
|
|
357
|
+
`any other host can be added with ${UPDATE_ALLOWED_HOSTS_ENV}=host1,host2`,
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
return parsed;
|
|
361
|
+
}
|
|
362
|
+
|
|
247
363
|
function releaseBinaryDirectory() {
|
|
248
364
|
return path.join(__dirname, "..", "bin", "downloads");
|
|
249
365
|
}
|
|
@@ -281,6 +397,7 @@ module.exports = {
|
|
|
281
397
|
BUNDLE_ASSET_NAMES,
|
|
282
398
|
BUNDLE_CHECKSUM_MANIFEST,
|
|
283
399
|
CHECKSUM_MANIFEST,
|
|
400
|
+
CHECKSUM_SIGNATURE,
|
|
284
401
|
checksummedReleaseAssetNames,
|
|
285
402
|
CNB_BINARY_ASSET_NAMES,
|
|
286
403
|
CNB_RELEASE_ASSET_NAMES,
|
|
@@ -292,13 +409,19 @@ module.exports = {
|
|
|
292
409
|
firstPartyReleaseSources,
|
|
293
410
|
githubReleaseBaseUrl,
|
|
294
411
|
hasExplicitReleaseBase,
|
|
412
|
+
isAllowedReleaseHost,
|
|
295
413
|
isCnbSupportedTarget,
|
|
296
414
|
LEGACY_TUI_BRIDGE_ASSET_NAMES,
|
|
415
|
+
openHarmonyDirections,
|
|
416
|
+
redactUrl,
|
|
297
417
|
releaseAssetUrl,
|
|
298
418
|
releaseAssetUrlFromBase,
|
|
299
419
|
releaseBaseUrl,
|
|
300
420
|
releaseBinaryDirectory,
|
|
301
421
|
shouldRaceFirstPartyMirrors,
|
|
422
|
+
transportOptions,
|
|
423
|
+
UPDATE_ALLOWED_HOSTS_ENV,
|
|
302
424
|
usesCnbMirror,
|
|
425
|
+
validateReleaseUrl,
|
|
303
426
|
WINDOWS_INSTALLER_ASSET,
|
|
304
427
|
};
|
package/scripts/install.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
function assertSupportedNode() {
|
|
2
2
|
const version = process.versions && process.versions.node ? process.versions.node : "unknown";
|
|
3
3
|
const major = Number.parseInt(String(version).split(".")[0], 10);
|
|
4
|
-
if (Number.isNaN(major) || major <
|
|
4
|
+
if (Number.isNaN(major) || major < 22) {
|
|
5
5
|
process.stderr.write(
|
|
6
|
-
"codewhale: Node.js
|
|
6
|
+
"codewhale: Node.js 22 or newer is required for npm installation. " +
|
|
7
7
|
`Current Node.js version is ${version}. ` +
|
|
8
8
|
"Please upgrade Node.js and rerun `npm install -g codewhale`.\n",
|
|
9
9
|
);
|
|
@@ -34,11 +34,14 @@ const {
|
|
|
34
34
|
explicitReleaseBase,
|
|
35
35
|
firstPartyReleaseSources,
|
|
36
36
|
githubReleaseBaseUrl,
|
|
37
|
+
openHarmonyDirections,
|
|
38
|
+
redactUrl,
|
|
37
39
|
releaseAssetUrl,
|
|
38
40
|
releaseAssetUrlFromBase,
|
|
39
41
|
releaseBinaryDirectory,
|
|
40
42
|
shouldRaceFirstPartyMirrors,
|
|
41
43
|
usesCnbMirror,
|
|
44
|
+
validateReleaseUrl,
|
|
42
45
|
} = require("./artifacts");
|
|
43
46
|
const { preflightGlibc, detectHostGlibc, detectBinaryRequiredGlibc, _internal: glibc } = require("./preflight-glibc");
|
|
44
47
|
const compiledHosts = require("./compiled-hosts");
|
|
@@ -77,7 +80,7 @@ class NonRetryableError extends Error {
|
|
|
77
80
|
|
|
78
81
|
class HttpStatusError extends Error {
|
|
79
82
|
constructor(status, url) {
|
|
80
|
-
super(`Request failed with status ${status}: ${url}`);
|
|
83
|
+
super(`Request failed with status ${status}: ${redactUrl(url)}`);
|
|
81
84
|
this.name = "HttpStatusError";
|
|
82
85
|
this.status = status;
|
|
83
86
|
}
|
|
@@ -253,7 +256,7 @@ function installFailureHint(error) {
|
|
|
253
256
|
if (releaseBase) {
|
|
254
257
|
return [
|
|
255
258
|
"codewhale install hint:",
|
|
256
|
-
` CODEWHALE_RELEASE_BASE_URL resolves to ${releaseBase}`,
|
|
259
|
+
` CODEWHALE_RELEASE_BASE_URL resolves to ${redactUrl(releaseBase)}`,
|
|
257
260
|
" Verify that this directory contains codewhale-artifacts-sha256.txt",
|
|
258
261
|
" plus the codewhale/codew binary assets for your platform (single binary).",
|
|
259
262
|
].join("\n");
|
|
@@ -548,7 +551,7 @@ function httpRequest(rawUrl, opts = {}) {
|
|
|
548
551
|
try {
|
|
549
552
|
url = new URL(rawUrl);
|
|
550
553
|
} catch (err) {
|
|
551
|
-
reject(new NonRetryableError(`Invalid URL: ${rawUrl} (${err.message})`));
|
|
554
|
+
reject(new NonRetryableError(`Invalid URL: ${redactUrl(rawUrl)} (${err.message})`));
|
|
552
555
|
return;
|
|
553
556
|
}
|
|
554
557
|
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
@@ -997,18 +1000,28 @@ async function followRedirects(url, opts = {}) {
|
|
|
997
1000
|
const maxRedirects = 10;
|
|
998
1001
|
let current = url;
|
|
999
1002
|
for (let hop = 0; hop < maxRedirects; hop++) {
|
|
1003
|
+
try {
|
|
1004
|
+
validateReleaseUrl(current, {
|
|
1005
|
+
env: opts.env,
|
|
1006
|
+
allowLoopbackHttp: opts.allowLoopbackHttp,
|
|
1007
|
+
});
|
|
1008
|
+
} catch (err) {
|
|
1009
|
+
throw new NonRetryableError(err.message);
|
|
1010
|
+
}
|
|
1000
1011
|
const result = await httpRequest(current, opts);
|
|
1001
1012
|
if (result.redirect) {
|
|
1002
1013
|
try {
|
|
1003
1014
|
current = new URL(result.redirect, current).toString();
|
|
1004
|
-
} catch {
|
|
1005
|
-
|
|
1015
|
+
} catch (err) {
|
|
1016
|
+
throw new NonRetryableError(
|
|
1017
|
+
`Invalid redirect URL from ${redactUrl(current)}: ${err.message}`,
|
|
1018
|
+
);
|
|
1006
1019
|
}
|
|
1007
1020
|
continue;
|
|
1008
1021
|
}
|
|
1009
1022
|
return result;
|
|
1010
1023
|
}
|
|
1011
|
-
throw new NonRetryableError(`too many redirects starting at ${url}`);
|
|
1024
|
+
throw new NonRetryableError(`too many redirects starting at ${redactUrl(url)}`);
|
|
1012
1025
|
}
|
|
1013
1026
|
|
|
1014
1027
|
function streamToFile(response, destination, progress, signal) {
|
|
@@ -1062,6 +1075,8 @@ async function download(url, destination, options = {}) {
|
|
|
1062
1075
|
await withRetry(`download ${assetName}`, async (attempt) => {
|
|
1063
1076
|
const result = await followRedirects(url, {
|
|
1064
1077
|
context,
|
|
1078
|
+
env: options.env,
|
|
1079
|
+
allowLoopbackHttp: options.allowLoopbackHttp,
|
|
1065
1080
|
totalTimeoutMs: downloadTimeoutMs(context),
|
|
1066
1081
|
stallMs: downloadStallMs(context),
|
|
1067
1082
|
signal: options.signal,
|
|
@@ -1099,9 +1114,11 @@ async function downloadText(url, options = {}) {
|
|
|
1099
1114
|
options.stallMs === undefined || options.stallMs === null
|
|
1100
1115
|
? downloadStallMs(context)
|
|
1101
1116
|
: options.stallMs;
|
|
1102
|
-
return withRetry(`fetch ${url}`, async () => {
|
|
1117
|
+
return withRetry(`fetch ${redactUrl(url)}`, async () => {
|
|
1103
1118
|
const result = await followRedirects(url, {
|
|
1104
1119
|
context,
|
|
1120
|
+
env: options.env,
|
|
1121
|
+
allowLoopbackHttp: options.allowLoopbackHttp,
|
|
1105
1122
|
totalTimeoutMs,
|
|
1106
1123
|
stallMs,
|
|
1107
1124
|
signal: options.signal,
|
|
@@ -1257,6 +1274,7 @@ async function fetchChecksumManifest(url, options) {
|
|
|
1257
1274
|
const fetchText = options.fetchText || downloadText;
|
|
1258
1275
|
const text = await fetchText(url, {
|
|
1259
1276
|
context: options.context,
|
|
1277
|
+
env: options.env,
|
|
1260
1278
|
signal: options.signal,
|
|
1261
1279
|
totalTimeoutMs:
|
|
1262
1280
|
options.totalTimeoutMs === undefined || options.totalTimeoutMs === null
|
|
@@ -1369,6 +1387,7 @@ async function raceFirstPartyManifests(sources, options) {
|
|
|
1369
1387
|
const source = sources[i];
|
|
1370
1388
|
loadSourceManifest(source, {
|
|
1371
1389
|
context: options.context,
|
|
1390
|
+
env: options.env,
|
|
1372
1391
|
fetchText: options.fetchText,
|
|
1373
1392
|
requiredAssets: options.requiredAssets,
|
|
1374
1393
|
signal: controllers[i].signal,
|
|
@@ -1407,6 +1426,7 @@ async function selectReleaseSource(options) {
|
|
|
1407
1426
|
},
|
|
1408
1427
|
{
|
|
1409
1428
|
context,
|
|
1429
|
+
env,
|
|
1410
1430
|
fetchText,
|
|
1411
1431
|
requiredAssets,
|
|
1412
1432
|
},
|
|
@@ -1423,6 +1443,7 @@ async function selectReleaseSource(options) {
|
|
|
1423
1443
|
},
|
|
1424
1444
|
{
|
|
1425
1445
|
context,
|
|
1446
|
+
env,
|
|
1426
1447
|
fetchText,
|
|
1427
1448
|
requiredAssets,
|
|
1428
1449
|
},
|
|
@@ -1433,6 +1454,7 @@ async function selectReleaseSource(options) {
|
|
|
1433
1454
|
return raceFirstPartyManifests(sources, {
|
|
1434
1455
|
version,
|
|
1435
1456
|
context,
|
|
1457
|
+
env,
|
|
1436
1458
|
fetchText,
|
|
1437
1459
|
requiredAssets,
|
|
1438
1460
|
});
|
|
@@ -1446,6 +1468,7 @@ async function selectReleaseSource(options) {
|
|
|
1446
1468
|
},
|
|
1447
1469
|
{
|
|
1448
1470
|
context,
|
|
1471
|
+
env,
|
|
1449
1472
|
fetchText,
|
|
1450
1473
|
requiredAssets,
|
|
1451
1474
|
},
|
|
@@ -1541,7 +1564,7 @@ async function ensureBinary(targetPath, assetName, version, repo, getChecksums,
|
|
|
1541
1564
|
const progressName = locked.sourceLabel
|
|
1542
1565
|
? `${assetName} from ${locked.sourceLabel}`
|
|
1543
1566
|
: assetName;
|
|
1544
|
-
await downloadFn(url, destination, { assetName: progressName, context: options.context });
|
|
1567
|
+
await downloadFn(url, destination, { assetName: progressName, context: options.context, env });
|
|
1545
1568
|
try {
|
|
1546
1569
|
await verifyChecksum(destination, assetName, checksums, locked.sourceLabel);
|
|
1547
1570
|
preflightGlibc(destination);
|
|
@@ -1702,6 +1725,19 @@ async function run(options = {}) {
|
|
|
1702
1725
|
const version = resolvePackageVersion(pkg, env);
|
|
1703
1726
|
const repo = resolveRepo(env);
|
|
1704
1727
|
const paths = options.paths || binaryPaths();
|
|
1728
|
+
if (
|
|
1729
|
+
isInstallContext(context) &&
|
|
1730
|
+
(options.platform || os.platform()) === "openharmony" &&
|
|
1731
|
+
!isQuietInstall(env)
|
|
1732
|
+
) {
|
|
1733
|
+
process.stderr.write(
|
|
1734
|
+
`codewhale: note: installing ${paths.codewhale.asset}, the native HarmonyOS/OpenHarmony build.\n` +
|
|
1735
|
+
`It is code-signed, but a native HarmonyOS terminal (HiShell) is not a Linux shell:\n` +
|
|
1736
|
+
`there is no git and no package manager, and the debugging shell (hdc shell) cannot\n` +
|
|
1737
|
+
`execute it at all. details: docs/HarmonyOS.md\n` +
|
|
1738
|
+
`${openHarmonyDirections()}\n`,
|
|
1739
|
+
);
|
|
1740
|
+
}
|
|
1705
1741
|
const releaseDir = options.releaseDir || releaseBinaryDirectory();
|
|
1706
1742
|
await mkdir(releaseDir, { recursive: true });
|
|
1707
1743
|
|
|
@@ -1778,6 +1814,7 @@ module.exports = {
|
|
|
1778
1814
|
adoptExistingBinaryIfValid,
|
|
1779
1815
|
shouldIgnoreInstallFailure,
|
|
1780
1816
|
shouldSkipOptionalPostinstall,
|
|
1817
|
+
followRedirects,
|
|
1781
1818
|
httpRequest,
|
|
1782
1819
|
defaultTimeoutMs,
|
|
1783
1820
|
defaultStallMs,
|
package/scripts/run.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { spawn: spawnChild } = require("child_process");
|
|
2
2
|
const os = require("os");
|
|
3
3
|
const { getBinaryPath, installFailureHint } = require("./install");
|
|
4
|
+
const { openHarmonyDirections } = require("./artifacts");
|
|
4
5
|
|
|
5
6
|
const pkg = require("../package.json");
|
|
6
7
|
|
|
@@ -8,9 +9,18 @@ function isVersionFlag(args = process.argv.slice(2)) {
|
|
|
8
9
|
return args.includes("--version") || args.includes("-V");
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
const OPEN_HARMONY_EXEC_ERRORS = ["ENOEXEC", "EACCES", "EPERM"];
|
|
13
|
+
const OPEN_HARMONY_STARTUP_SIGNALS = ["SIGKILL", "SIGSYS", "SIGSEGV", "SIGBUS", "SIGILL", "SIGABRT"];
|
|
14
|
+
const OPEN_HARMONY_STARTUP_MS = 5_000;
|
|
15
|
+
|
|
11
16
|
// Print the install hint (mirror / release-base guidance) for a failure that
|
|
12
|
-
// looks like a download problem
|
|
17
|
+
// looks like a download problem, or the HarmonyOS directions when the Linux
|
|
18
|
+
// build cannot be executed on native HarmonyOS. Prints nothing otherwise.
|
|
13
19
|
function printInstallFailureHint(error, log = console.error) {
|
|
20
|
+
if (os.platform() === "openharmony" && OPEN_HARMONY_EXEC_ERRORS.includes(error && error.code)) {
|
|
21
|
+
log(`The Linux build could not start on native HarmonyOS/OpenHarmony.\n${openHarmonyDirections()}`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
14
24
|
const hint = installFailureHint(error);
|
|
15
25
|
if (hint) {
|
|
16
26
|
log(hint);
|
|
@@ -134,6 +144,7 @@ async function run(binaryName, options = {}) {
|
|
|
134
144
|
throw error;
|
|
135
145
|
}
|
|
136
146
|
|
|
147
|
+
const startedAt = Date.now();
|
|
137
148
|
const result = await runChild(spawn, binaryPath, args, proc);
|
|
138
149
|
if (result.error) {
|
|
139
150
|
if (versionFlag) {
|
|
@@ -142,6 +153,16 @@ async function run(binaryName, options = {}) {
|
|
|
142
153
|
}
|
|
143
154
|
throw result.error;
|
|
144
155
|
}
|
|
156
|
+
if (
|
|
157
|
+
os.platform() === "openharmony" &&
|
|
158
|
+
OPEN_HARMONY_STARTUP_SIGNALS.includes(result.signal) &&
|
|
159
|
+
Date.now() - startedAt < OPEN_HARMONY_STARTUP_MS
|
|
160
|
+
) {
|
|
161
|
+
console.error(
|
|
162
|
+
`${binaryName} stopped with ${result.signal} at startup; the Linux build may not run on native HarmonyOS/OpenHarmony.\n` +
|
|
163
|
+
openHarmonyDirections(),
|
|
164
|
+
);
|
|
165
|
+
}
|
|
145
166
|
return exitLikeChild(result, exit, proc);
|
|
146
167
|
}
|
|
147
168
|
|