codewhale 0.10.0 → 0.10.1
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 +15 -9
- package/bin/codew.js +2 -2
- package/bin/codewhale.js +2 -2
- package/package.json +5 -5
- package/scripts/artifacts.js +13 -11
- package/scripts/compiled-hosts.js +91 -0
- package/scripts/install.js +161 -14
- package/scripts/preflight-glibc.js +8 -8
- package/scripts/run.js +117 -14
- package/scripts/verify-release-assets.js +107 -38
- package/test/compiled-hosts.test.js +156 -0
- package/test/install.test.js +112 -6
- package/test/native-host-receipt.test.js +110 -0
- package/test/release-assets.test.js +108 -0
- package/test/run.test.js +218 -8
- package/test/source-selection.test.js +1 -1
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/
|
|
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/
|
|
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,11 +78,11 @@ 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
|
|
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/
|
|
85
|
+
[docs/INSTALL.md](https://github.com/codewhale-hq/CodeWhale/blob/main/docs/INSTALL.md).
|
|
80
86
|
|
|
81
87
|
HarmonyOS PC (`openharmony`) is treated as `linux`, so it gets the Linux
|
|
82
88
|
binaries matching your CPU architecture (x64 or arm64). Linux riscv64 prebuilts
|
|
@@ -85,7 +91,7 @@ are temporarily paused while the locked `rquickjs-sys` dependency lacks
|
|
|
85
91
|
(FreeBSD, Linux riscv64, …) aren't shipped as prebuilts. Unsupported platforms,
|
|
86
92
|
checksum failures, and glibc compatibility problems still fail with a clear
|
|
87
93
|
error pointing you at the full
|
|
88
|
-
[docs/INSTALL.md](https://github.com/
|
|
94
|
+
[docs/INSTALL.md](https://github.com/codewhale-hq/CodeWhale/blob/main/docs/INSTALL.md)
|
|
89
95
|
guide.
|
|
90
96
|
|
|
91
97
|
## Wrapper configuration
|
|
@@ -96,7 +102,7 @@ guide.
|
|
|
96
102
|
| `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
103
|
| `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
104
|
| `CODEWHALE_VERSION` | Override the release version to download. |
|
|
99
|
-
| `CODEWHALE_GITHUB_REPO` | Override the source repo. Defaults to `
|
|
105
|
+
| `CODEWHALE_GITHUB_REPO` | Override the source repo. Defaults to `codewhale-hq/CodeWhale`. |
|
|
100
106
|
| `CODEWHALE_FORCE_DOWNLOAD=1` | Force download even when the cached binary is already present. |
|
|
101
107
|
| `CODEWHALE_DISABLE_INSTALL=1` | Skip install-time download. |
|
|
102
108
|
| `CODEWHALE_OPTIONAL_INSTALL=1` | Make install-time retryable download failures warn and exit `0` instead of failing `npm install`. |
|
|
@@ -129,7 +135,7 @@ offline installs, set `CODEWHALE_DISABLE_INSTALL=1` or point
|
|
|
129
135
|
|
|
130
136
|
## Links
|
|
131
137
|
|
|
132
|
-
- Repository: <https://github.com/
|
|
138
|
+
- Repository: <https://github.com/codewhale-hq/CodeWhale>
|
|
133
139
|
- Website: <https://codewhale.net/>
|
|
134
|
-
- Provider registry: [docs/PROVIDERS.md](https://github.com/
|
|
135
|
-
- Changelog: [CHANGELOG.md](https://github.com/
|
|
140
|
+
- Provider registry: [docs/PROVIDERS.md](https://github.com/codewhale-hq/CodeWhale/blob/main/docs/PROVIDERS.md)
|
|
141
|
+
- 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
|
-
|
|
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
|
-
|
|
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.
|
|
4
|
-
"codewhaleBinaryVersion": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
|
+
"codewhaleBinaryVersion": "0.10.1",
|
|
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/
|
|
18
|
+
"homepage": "https://github.com/codewhale-hq/Codewhale",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/
|
|
21
|
+
"url": "git+https://github.com/codewhale-hq/Codewhale.git"
|
|
22
22
|
},
|
|
23
23
|
"bugs": {
|
|
24
|
-
"url": "https://github.com/
|
|
24
|
+
"url": "https://github.com/codewhale-hq/Codewhale/issues"
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
27
27
|
"codewhale",
|
package/scripts/artifacts.js
CHANGED
|
@@ -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";
|
|
@@ -101,16 +102,16 @@ 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.
|
|
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/
|
|
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/
|
|
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
|
}
|
|
@@ -134,7 +135,7 @@ function ensureTrailingSlash(baseUrl) {
|
|
|
134
135
|
return trimmed.endsWith("/") ? trimmed : `${trimmed}/`;
|
|
135
136
|
}
|
|
136
137
|
|
|
137
|
-
function githubReleaseBaseUrl(version, repo = "
|
|
138
|
+
function githubReleaseBaseUrl(version, repo = "codewhale-hq/CodeWhale") {
|
|
138
139
|
return `https://github.com/${repo}/releases/download/v${version}/`;
|
|
139
140
|
}
|
|
140
141
|
|
|
@@ -173,7 +174,7 @@ function isCnbSupportedTarget(
|
|
|
173
174
|
return platform === "linux" && arch === "x64";
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
function releaseBaseUrl(version, repo = "
|
|
177
|
+
function releaseBaseUrl(version, repo = "codewhale-hq/CodeWhale") {
|
|
177
178
|
// CODEWHALE_RELEASE_BASE_URL is the canonical override.
|
|
178
179
|
// DEEPSEEK_TUI_RELEASE_BASE_URL / DEEPSEEK_RELEASE_BASE_URL are legacy aliases.
|
|
179
180
|
const override = explicitReleaseBase();
|
|
@@ -205,7 +206,7 @@ function shouldRaceFirstPartyMirrors(
|
|
|
205
206
|
);
|
|
206
207
|
}
|
|
207
208
|
|
|
208
|
-
function firstPartyReleaseSources(version, repo = "
|
|
209
|
+
function firstPartyReleaseSources(version, repo = "codewhale-hq/CodeWhale") {
|
|
209
210
|
return [
|
|
210
211
|
{
|
|
211
212
|
id: "github",
|
|
@@ -235,11 +236,11 @@ function assertCnbMirrorSupportedPlatform(
|
|
|
235
236
|
);
|
|
236
237
|
}
|
|
237
238
|
|
|
238
|
-
function releaseAssetUrl(baseName, version, repo = "
|
|
239
|
+
function releaseAssetUrl(baseName, version, repo = "codewhale-hq/CodeWhale") {
|
|
239
240
|
return releaseAssetUrlFromBase(baseName, releaseBaseUrl(version, repo));
|
|
240
241
|
}
|
|
241
242
|
|
|
242
|
-
function checksumManifestUrl(version, repo = "
|
|
243
|
+
function checksumManifestUrl(version, repo = "codewhale-hq/CodeWhale") {
|
|
243
244
|
return releaseAssetUrl(CHECKSUM_MANIFEST, version, repo);
|
|
244
245
|
}
|
|
245
246
|
|
|
@@ -257,7 +258,7 @@ function allAssetNames() {
|
|
|
257
258
|
return Array.from(new Set(names));
|
|
258
259
|
}
|
|
259
260
|
|
|
260
|
-
function allReleaseAssetNames() {
|
|
261
|
+
function allReleaseAssetNames(catalog) {
|
|
261
262
|
return [
|
|
262
263
|
...allAssetNames(),
|
|
263
264
|
...LEGACY_TUI_BRIDGE_ASSET_NAMES,
|
|
@@ -265,11 +266,12 @@ function allReleaseAssetNames() {
|
|
|
265
266
|
WINDOWS_INSTALLER_ASSET,
|
|
266
267
|
BUNDLE_CHECKSUM_MANIFEST,
|
|
267
268
|
CHECKSUM_MANIFEST,
|
|
269
|
+
...compiledHosts.assets(catalog),
|
|
268
270
|
];
|
|
269
271
|
}
|
|
270
272
|
|
|
271
|
-
function checksummedReleaseAssetNames() {
|
|
272
|
-
return allReleaseAssetNames().filter((name) => name !== CHECKSUM_MANIFEST);
|
|
273
|
+
function checksummedReleaseAssetNames(catalog) {
|
|
274
|
+
return allReleaseAssetNames(catalog).filter((name) => name !== CHECKSUM_MANIFEST);
|
|
273
275
|
}
|
|
274
276
|
|
|
275
277
|
module.exports = {
|
|
@@ -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 };
|
package/scripts/install.js
CHANGED
|
@@ -40,7 +40,8 @@ const {
|
|
|
40
40
|
shouldRaceFirstPartyMirrors,
|
|
41
41
|
usesCnbMirror,
|
|
42
42
|
} = require("./artifacts");
|
|
43
|
-
const { preflightGlibc } = require("./preflight-glibc");
|
|
43
|
+
const { preflightGlibc, detectHostGlibc, detectBinaryRequiredGlibc, _internal: glibc } = require("./preflight-glibc");
|
|
44
|
+
const compiledHosts = require("./compiled-hosts");
|
|
44
45
|
const pkg = require("../package.json");
|
|
45
46
|
|
|
46
47
|
const DEFAULT_TIMEOUT_MS = 300_000; // 5 minutes per attempt
|
|
@@ -123,7 +124,7 @@ function resolveRepo(env = process.env) {
|
|
|
123
124
|
env.CODEWHALE_GITHUB_REPO ||
|
|
124
125
|
env.DEEPSEEK_TUI_GITHUB_REPO ||
|
|
125
126
|
env.DEEPSEEK_GITHUB_REPO ||
|
|
126
|
-
"
|
|
127
|
+
"codewhale-hq/CodeWhale"
|
|
127
128
|
);
|
|
128
129
|
}
|
|
129
130
|
|
|
@@ -267,7 +268,7 @@ function installFailureHint(error) {
|
|
|
267
268
|
" CODEWHALE_RELEASE_BASE_URL=https://<mirror>/<release-asset-directory>/",
|
|
268
269
|
" or CODEWHALE_USE_CNB_MIRROR=1 on Linux x64.",
|
|
269
270
|
" The directory must contain codewhale-artifacts-sha256.txt and the platform binaries.",
|
|
270
|
-
" See docs/INSTALL.md#npm-binary-download-times-out
|
|
271
|
+
" See https://github.com/codewhale-hq/CodeWhale/blob/main/docs/INSTALL.md#npm-binary-download-times-out",
|
|
271
272
|
].join("\n");
|
|
272
273
|
}
|
|
273
274
|
|
|
@@ -566,6 +567,7 @@ function httpRequest(rawUrl, opts = {}) {
|
|
|
566
567
|
let totalTimer = null;
|
|
567
568
|
let stallTimer = null;
|
|
568
569
|
let settled = false;
|
|
570
|
+
let handedOff = false;
|
|
569
571
|
let req = null;
|
|
570
572
|
let res = null;
|
|
571
573
|
const signal = opts.signal;
|
|
@@ -587,7 +589,20 @@ function httpRequest(rawUrl, opts = {}) {
|
|
|
587
589
|
};
|
|
588
590
|
|
|
589
591
|
const fail = (err) => {
|
|
590
|
-
if (settled)
|
|
592
|
+
if (settled) {
|
|
593
|
+
// The stall, total, and abort budgets outlive the handoff: once the
|
|
594
|
+
// caller owns the body, end it with the error so the caller's own
|
|
595
|
+
// `error` handler rejects instead of waiting on a silent socket.
|
|
596
|
+
if (handedOff) {
|
|
597
|
+
cleanup();
|
|
598
|
+
try {
|
|
599
|
+
if (res && !res.destroyed) res.destroy(err);
|
|
600
|
+
} catch {
|
|
601
|
+
// ignore
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
591
606
|
settled = true;
|
|
592
607
|
cleanup();
|
|
593
608
|
try {
|
|
@@ -603,6 +618,15 @@ function httpRequest(rawUrl, opts = {}) {
|
|
|
603
618
|
reject(err);
|
|
604
619
|
};
|
|
605
620
|
|
|
621
|
+
// Hand the live response stream to the caller. The timers stay armed
|
|
622
|
+
// until the body ends or closes (see `fail`).
|
|
623
|
+
const handOff = (response) => {
|
|
624
|
+
settled = true;
|
|
625
|
+
handedOff = true;
|
|
626
|
+
response.on("close", () => cleanup());
|
|
627
|
+
resolve({ redirect: null, response });
|
|
628
|
+
};
|
|
629
|
+
|
|
606
630
|
if (signal) {
|
|
607
631
|
if (signal.aborted) {
|
|
608
632
|
reject(abortError());
|
|
@@ -627,6 +651,12 @@ function httpRequest(rawUrl, opts = {}) {
|
|
|
627
651
|
if (stallMs <= 0) return;
|
|
628
652
|
if (stallTimer) clearTimeout(stallTimer);
|
|
629
653
|
stallTimer = setTimeout(() => {
|
|
654
|
+
// A body the caller has paused (a slow disk pushing back through
|
|
655
|
+
// `pipe`) is not a stalled network. The total budget still bounds it.
|
|
656
|
+
if (handedOff && res && res.readableFlowing === false) {
|
|
657
|
+
armStallTimer();
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
630
660
|
fail(new DownloadTimeoutError(
|
|
631
661
|
`download stalled — no bytes received for ${stallMs} ms ` +
|
|
632
662
|
`(set CODEWHALE_DOWNLOAD_STALL_MS to raise it; total budget is ${totalTimeoutMs} ms)`,
|
|
@@ -692,9 +722,7 @@ function httpRequest(rawUrl, opts = {}) {
|
|
|
692
722
|
return;
|
|
693
723
|
}
|
|
694
724
|
if (settled) return;
|
|
695
|
-
|
|
696
|
-
// Hand the live response stream to the caller.
|
|
697
|
-
resolve({ redirect: null, response });
|
|
725
|
+
handOff(response);
|
|
698
726
|
});
|
|
699
727
|
req.once("error", (err) => fail(err));
|
|
700
728
|
req.once("socket", (s) => {
|
|
@@ -757,8 +785,7 @@ function httpRequest(rawUrl, opts = {}) {
|
|
|
757
785
|
return;
|
|
758
786
|
}
|
|
759
787
|
if (settled) return;
|
|
760
|
-
|
|
761
|
-
resolve({ redirect: null, response });
|
|
788
|
+
handOff(response);
|
|
762
789
|
},
|
|
763
790
|
);
|
|
764
791
|
req.once("error", (err) => fail(err));
|
|
@@ -821,8 +848,7 @@ function httpRequest(rawUrl, opts = {}) {
|
|
|
821
848
|
return;
|
|
822
849
|
}
|
|
823
850
|
if (settled) return;
|
|
824
|
-
|
|
825
|
-
resolve({ redirect: null, response });
|
|
851
|
+
handOff(response);
|
|
826
852
|
});
|
|
827
853
|
req.once("error", (err) => fail(err));
|
|
828
854
|
req.end();
|
|
@@ -1356,7 +1382,7 @@ async function raceFirstPartyManifests(sources, options) {
|
|
|
1356
1382
|
|
|
1357
1383
|
async function selectReleaseSource(options) {
|
|
1358
1384
|
const version = options.version;
|
|
1359
|
-
const repo = options.repo || "
|
|
1385
|
+
const repo = options.repo || "codewhale-hq/CodeWhale";
|
|
1360
1386
|
const env = options.env || process.env;
|
|
1361
1387
|
const platform =
|
|
1362
1388
|
options.platform === undefined || options.platform === null
|
|
@@ -1550,6 +1576,116 @@ function shouldIgnoreInstallFailure(
|
|
|
1550
1576
|
return isInstallContext(context) && isOptionalInstall(argv, env) && isRetryable(error);
|
|
1551
1577
|
}
|
|
1552
1578
|
|
|
1579
|
+
function preflightCompiledHost(file, host) {
|
|
1580
|
+
if (!host.target.startsWith("linux-")) return;
|
|
1581
|
+
const required = detectBinaryRequiredGlibc(file);
|
|
1582
|
+
const available = detectHostGlibc();
|
|
1583
|
+
if (host.libc === "glibc" && (!available || (required && glibc.compareVersion(available, required) < 0))) {
|
|
1584
|
+
throw new NonRetryableError("compiled Bun image requires a matching GNU libc; the Codewhale CLI remains static musl. Use Node on a musl-only installation.");
|
|
1585
|
+
}
|
|
1586
|
+
if (host.libc === "musl" && required) throw new NonRetryableError("qualified musl host unexpectedly contains GNU libc dependencies");
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
async function prepareCompiledHost({ version, releaseDir, source, context, options }) {
|
|
1590
|
+
const catalogUrl = releaseAssetUrlFromBase(compiledHosts.HOST_CATALOG, source.baseUrl);
|
|
1591
|
+
const fetchText = options.fetchText || downloadText;
|
|
1592
|
+
const text = await fetchText(catalogUrl, { context });
|
|
1593
|
+
compiledHosts.verifyBytes(Buffer.from(text), source.checksums.get(compiledHosts.HOST_CATALOG), compiledHosts.HOST_CATALOG);
|
|
1594
|
+
const catalog = compiledHosts.parseCatalog(text, version);
|
|
1595
|
+
const host = compiledHosts.selectedHost(catalog, options.platform, options.arch);
|
|
1596
|
+
const suffix = host.target.startsWith("windows-") ? ".exe" : "";
|
|
1597
|
+
const payloads = [
|
|
1598
|
+
{ asset: host.asset, name: compiledHosts.HOST_NAME + suffix, hash: host.sha256, executable: true },
|
|
1599
|
+
{ asset: host.notices_asset, name: compiledHosts.HOST_NAME + ".LICENSES.txt", hash: host.notices_sha256 },
|
|
1600
|
+
{ asset: host.source_asset, name: compiledHosts.HOST_NAME + ".relink-source.tar.gz", hash: host.source_sha256 },
|
|
1601
|
+
];
|
|
1602
|
+
const stageDir = await fs.promises.mkdtemp(path.join(releaseDir, ".compiled-host-"));
|
|
1603
|
+
const snapshots = [];
|
|
1604
|
+
const published = [];
|
|
1605
|
+
let retainBackups = false;
|
|
1606
|
+
const existingHash = async (file) => {
|
|
1607
|
+
try {
|
|
1608
|
+
const metadata = await fs.promises.lstat(file);
|
|
1609
|
+
if (!metadata.isFile() || metadata.isSymbolicLink()) throw new NonRetryableError(`refusing nonregular compiled host destination ${file}`);
|
|
1610
|
+
return compiledHosts.sha256(await readFile(file));
|
|
1611
|
+
} catch (error) { if (error.code === "ENOENT") return undefined; throw error; }
|
|
1612
|
+
};
|
|
1613
|
+
const cleanup = async () => { if (!retainBackups) await fs.promises.rm(stageDir, { recursive: true, force: true }); };
|
|
1614
|
+
const rollback = async (original) => {
|
|
1615
|
+
const failures = [];
|
|
1616
|
+
for (const snapshot of published.slice().reverse()) {
|
|
1617
|
+
try {
|
|
1618
|
+
if (await existingHash(snapshot.target) !== snapshot.newHash) throw new Error(`destination changed after publication: ${snapshot.target}`);
|
|
1619
|
+
if (snapshot.hash) await rename(path.join(stageDir, snapshot.name + ".previous"), snapshot.target);
|
|
1620
|
+
else await unlink(snapshot.target);
|
|
1621
|
+
} catch (error) { failures.push(error.message); }
|
|
1622
|
+
}
|
|
1623
|
+
if (failures.length) {
|
|
1624
|
+
retainBackups = true;
|
|
1625
|
+
throw new NonRetryableError(`${original.message}; rollback incomplete: ${failures.join("; ")}. Recovery files retained at ${stageDir}`);
|
|
1626
|
+
}
|
|
1627
|
+
throw original;
|
|
1628
|
+
};
|
|
1629
|
+
try {
|
|
1630
|
+
for (const payload of payloads) {
|
|
1631
|
+
if (source.checksums.get(payload.asset) !== payload.hash) throw new NonRetryableError(`catalog and checksum manifest disagree for ${payload.asset}`);
|
|
1632
|
+
const stage = path.join(stageDir, payload.name);
|
|
1633
|
+
await (options.download || download)(releaseAssetUrlFromBase(payload.asset, source.baseUrl), stage, { context, assetName: payload.asset });
|
|
1634
|
+
compiledHosts.verifyBytes(await readFile(stage), payload.hash, payload.asset);
|
|
1635
|
+
if (payload.executable) preflightCompiledHost(stage, host);
|
|
1636
|
+
if (process.platform !== "win32") await chmod(stage, payload.executable ? 0o755 : 0o644);
|
|
1637
|
+
}
|
|
1638
|
+
const receiptName = compiledHosts.HOST_NAME + ".release.json";
|
|
1639
|
+
await writeFile(path.join(stageDir, receiptName), text, { mode: 0o644 });
|
|
1640
|
+
const oldReceipt = path.join(releaseDir, receiptName);
|
|
1641
|
+
const oldReceiptHash = await existingHash(oldReceipt);
|
|
1642
|
+
let oldPayloadHashes;
|
|
1643
|
+
if (oldReceiptHash) {
|
|
1644
|
+
const previous = compiledHosts.selectedHost(compiledHosts.parseCatalog(await readFile(oldReceipt)), options.platform, options.arch);
|
|
1645
|
+
oldPayloadHashes = [previous.sha256, previous.notices_sha256, previous.source_sha256];
|
|
1646
|
+
}
|
|
1647
|
+
const names = [...payloads.map((payload) => payload.name), receiptName];
|
|
1648
|
+
for (const [index, name] of names.entries()) {
|
|
1649
|
+
const target = path.join(releaseDir, name);
|
|
1650
|
+
const hash = await existingHash(target);
|
|
1651
|
+
if (index < payloads.length && hash && (!oldPayloadHashes || hash !== oldPayloadHashes[index])) throw new NonRetryableError(`refusing unclaimed or modified compiled host destination ${target}`);
|
|
1652
|
+
if (hash) {
|
|
1653
|
+
const backup = path.join(stageDir, name + ".previous");
|
|
1654
|
+
await fs.promises.copyFile(target, backup);
|
|
1655
|
+
if (compiledHosts.sha256(await readFile(backup)) !== hash) throw new NonRetryableError(`compiled host changed while backing up ${target}`);
|
|
1656
|
+
}
|
|
1657
|
+
snapshots.push({ name, target, hash, newHash: compiledHosts.sha256(await readFile(path.join(stageDir, name))) });
|
|
1658
|
+
}
|
|
1659
|
+
} catch (error) { await cleanup(); throw error; }
|
|
1660
|
+
return {
|
|
1661
|
+
cleanup,
|
|
1662
|
+
async publish() {
|
|
1663
|
+
try {
|
|
1664
|
+
// Validate every destination before publication, then each immediately
|
|
1665
|
+
// before replacement. Only bytes proven by the prior receipt are owned.
|
|
1666
|
+
for (const snapshot of snapshots) if (await existingHash(snapshot.target) !== snapshot.hash) throw new NonRetryableError(`compiled host destination changed during installation: ${snapshot.target}`);
|
|
1667
|
+
for (const snapshot of snapshots) {
|
|
1668
|
+
if (await existingHash(snapshot.target) !== snapshot.hash) throw new NonRetryableError(`compiled host destination changed during installation: ${snapshot.target}`);
|
|
1669
|
+
const staged = path.join(stageDir, snapshot.name);
|
|
1670
|
+
if (snapshot.hash === undefined) {
|
|
1671
|
+
await fs.promises.link(staged, snapshot.target); // fresh install never clobbers a raced-in file
|
|
1672
|
+
published.push(snapshot);
|
|
1673
|
+
await unlink(staged);
|
|
1674
|
+
} else {
|
|
1675
|
+
await rename(staged, snapshot.target);
|
|
1676
|
+
published.push(snapshot);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
} catch (error) { await rollback(error); }
|
|
1680
|
+
},
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
async function installCompiledHost(options) {
|
|
1685
|
+
const prepared = await prepareCompiledHost(options);
|
|
1686
|
+
try { await prepared.publish(); } finally { await prepared.cleanup(); }
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1553
1689
|
async function run(options = {}) {
|
|
1554
1690
|
const context =
|
|
1555
1691
|
options.context === undefined || options.context === null ? "runtime" : options.context;
|
|
@@ -1575,7 +1711,7 @@ async function run(options = {}) {
|
|
|
1575
1711
|
sourcePromise = selectReleaseSource({
|
|
1576
1712
|
version,
|
|
1577
1713
|
repo,
|
|
1578
|
-
requiredAssets: [paths.codewhale.asset, paths.codew.asset],
|
|
1714
|
+
requiredAssets: [paths.codewhale.asset, paths.codew.asset, ...(compiledHosts.requested(env) ? [compiledHosts.HOST_CATALOG] : [])],
|
|
1579
1715
|
context,
|
|
1580
1716
|
env,
|
|
1581
1717
|
platform: options.platform,
|
|
@@ -1588,7 +1724,13 @@ async function run(options = {}) {
|
|
|
1588
1724
|
};
|
|
1589
1725
|
const getChecksums = () => getSource().then((source) => source.checksums);
|
|
1590
1726
|
|
|
1591
|
-
|
|
1727
|
+
// Fully validate and stage an explicitly requested companion before any CLI
|
|
1728
|
+
// replacement. Missing qualification cannot leave an updated CLI behind.
|
|
1729
|
+
const preparedHost = compiledHosts.requested(env)
|
|
1730
|
+
? await prepareCompiledHost({ version, releaseDir, source: await getSource(), context, options })
|
|
1731
|
+
: undefined;
|
|
1732
|
+
try {
|
|
1733
|
+
await Promise.all([
|
|
1592
1734
|
ensureBinary(paths.codewhale.target, paths.codewhale.asset, version, repo, getChecksums, {
|
|
1593
1735
|
context,
|
|
1594
1736
|
getSource,
|
|
@@ -1602,6 +1744,8 @@ async function run(options = {}) {
|
|
|
1602
1744
|
env,
|
|
1603
1745
|
}),
|
|
1604
1746
|
]); // single binary
|
|
1747
|
+
if (preparedHost) await preparedHost.publish();
|
|
1748
|
+
} finally { if (preparedHost) await preparedHost.cleanup(); }
|
|
1605
1749
|
}
|
|
1606
1750
|
|
|
1607
1751
|
async function getBinaryPath(name) {
|
|
@@ -1640,6 +1784,9 @@ module.exports = {
|
|
|
1640
1784
|
downloadTimeoutMs,
|
|
1641
1785
|
downloadStallMs,
|
|
1642
1786
|
binaryPaths,
|
|
1787
|
+
installCompiledHost,
|
|
1788
|
+
prepareCompiledHost,
|
|
1789
|
+
preflightCompiledHost,
|
|
1643
1790
|
ensureBinary,
|
|
1644
1791
|
maxAttempts,
|
|
1645
1792
|
withRetry,
|
|
@@ -68,20 +68,20 @@ function buildFromSourceHint() {
|
|
|
68
68
|
return [
|
|
69
69
|
"You can still run codewhale by building from source with Cargo:",
|
|
70
70
|
"",
|
|
71
|
-
" # Requires Rust 1.
|
|
71
|
+
" # Requires Rust 1.89+ (https://rustup.rs)",
|
|
72
72
|
" cargo install codewhale-cli --locked # provides `codewhale`",
|
|
73
73
|
" bin=$(dirname \"$(command -v codewhale)\")",
|
|
74
74
|
" ln -sf \"$bin/codewhale\" \"$bin/codew\" # optional short alias",
|
|
75
75
|
"",
|
|
76
76
|
"Or build from a checkout:",
|
|
77
77
|
"",
|
|
78
|
-
" git clone https://github.com/
|
|
78
|
+
" git clone https://github.com/codewhale-hq/CodeWhale.git",
|
|
79
79
|
" cd CodeWhale",
|
|
80
80
|
" cargo install --path crates/cli --locked",
|
|
81
81
|
" bin=$(dirname \"$(command -v codewhale)\")",
|
|
82
82
|
" ln -sf \"$bin/codewhale\" \"$bin/codew\"",
|
|
83
83
|
"",
|
|
84
|
-
"See https://github.com/
|
|
84
|
+
"See https://github.com/codewhale-hq/CodeWhale/blob/main/docs/INSTALL.md",
|
|
85
85
|
].join("\n");
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -96,13 +96,13 @@ function skipGlibcCheck() {
|
|
|
96
96
|
function glibcCompatibilityMessage(required, host) {
|
|
97
97
|
const hostLine = host
|
|
98
98
|
? `this system has glibc ${formatVersion(host)}, which is too old for that asset.`
|
|
99
|
-
: "this system does not appear to provide
|
|
99
|
+
: "this system does not appear to provide glibc.";
|
|
100
100
|
return [
|
|
101
|
-
`
|
|
101
|
+
`This Codewhale binary requires GLIBC_${formatVersion(required)}, but ${hostLine}`,
|
|
102
102
|
"",
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"
|
|
103
|
+
"Official Codewhale Linux release assets (x64 and arm64) are static musl builds",
|
|
104
|
+
"with no glibc dependency, so this binary is not an official release asset.",
|
|
105
|
+
"Check where it came from, or build from source on this host.",
|
|
106
106
|
"",
|
|
107
107
|
buildFromSourceHint(),
|
|
108
108
|
"",
|