codewhale 0.8.64 → 0.8.66

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
@@ -103,6 +103,10 @@ offline installs, set `DEEPSEEK_TUI_DISABLE_INSTALL=1` or point
103
103
 
104
104
  - `npm publish` runs a release-asset check to ensure all required binary assets
105
105
  exist for the target GitHub release before publishing.
106
+ - For the default GitHub Release source, `npm run release:check` also verifies
107
+ that the npm-facing assets were updated by a successful `release.yml` run for
108
+ the tag commit. When `CODEWHALE_RELEASE_BASE_URL` or a legacy mirror override
109
+ is set, it checks the mirror asset URLs and checksum manifest instead.
106
110
  - Install-time downloads are verified against the release checksum manifest before
107
111
  the wrapper marks them executable.
108
112
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "codewhale",
3
- "version": "0.8.64",
4
- "codewhaleBinaryVersion": "0.8.64",
3
+ "version": "0.8.66",
4
+ "codewhaleBinaryVersion": "0.8.66",
5
5
  "description": "Install and run CodeWhale, the agentic terminal for open-source and open-weight coding models, from GitHub release artifacts.",
6
6
  "author": "Hmbown",
7
7
  "license": "MIT",
@@ -5,16 +5,16 @@ const CHECKSUM_MANIFEST = "codewhale-artifacts-sha256.txt";
5
5
 
6
6
  const ASSET_MATRIX = {
7
7
  linux: {
8
- x64: ["codewhale-linux-x64", "codewhale-tui-linux-x64"],
9
- arm64: ["codewhale-linux-arm64", "codewhale-tui-linux-arm64"],
10
- riscv64: ["codewhale-linux-riscv64", "codewhale-tui-linux-riscv64"],
8
+ x64: ["codewhale-linux-x64", "codewhale-tui-linux-x64", "codew-linux-x64"],
9
+ arm64: ["codewhale-linux-arm64", "codewhale-tui-linux-arm64", "codew-linux-arm64"],
10
+ riscv64: ["codewhale-linux-riscv64", "codewhale-tui-linux-riscv64", "codew-linux-riscv64"],
11
11
  },
12
12
  darwin: {
13
- x64: ["codewhale-macos-x64", "codewhale-tui-macos-x64"],
14
- arm64: ["codewhale-macos-arm64", "codewhale-tui-macos-arm64"],
13
+ x64: ["codewhale-macos-x64", "codewhale-tui-macos-x64", "codew-macos-x64"],
14
+ arm64: ["codewhale-macos-arm64", "codewhale-tui-macos-arm64", "codew-macos-arm64"],
15
15
  },
16
16
  win32: {
17
- x64: ["codewhale-windows-x64.exe", "codewhale-tui-windows-x64.exe", "codewhale.bat"],
17
+ x64: ["codewhale-windows-x64.exe", "codewhale-tui-windows-x64.exe", "codew-windows-x64.exe", "codewhale.bat"],
18
18
  },
19
19
  };
20
20
 
@@ -50,6 +50,7 @@ function detectBinaryNames() {
50
50
  arch,
51
51
  codewhale: pair[0],
52
52
  tui: pair[1],
53
+ codew: pair[2],
53
54
  };
54
55
  }
55
56
 
@@ -59,7 +60,7 @@ function unsupportedBuildHint() {
59
60
  "You can still run codewhale by building from source with Cargo:",
60
61
  "",
61
62
  " # Requires Rust 1.88+ (https://rustup.rs)",
62
- " cargo install codewhale-cli --locked # provides `codewhale`",
63
+ " cargo install codewhale-cli --locked # provides `codewhale` and `codew`",
63
64
  " cargo install codewhale-tui --locked # provides `codewhale-tui`",
64
65
  "",
65
66
  "Or build from a checkout:",
@@ -78,12 +78,18 @@ class DownloadTimeoutError extends Error {
78
78
  }
79
79
  }
80
80
 
81
- function resolvePackageVersion() {
81
+ // Binary-version precedence must match run.js and verify-release-assets.js so
82
+ // install-time asset resolution agrees with runtime and release verification.
83
+ // `codewhaleBinaryVersion` lets a packaging-only npm release target a specific
84
+ // CodeWhale binary; legacy env vars and `deepseekBinaryVersion` stay supported
85
+ // for backward compatibility (#3769). `pkgObj`/`env` are injectable for tests.
86
+ function resolvePackageVersion(pkgObj = pkg, env = process.env) {
82
87
  const configuredVersion =
83
- process.env.DEEPSEEK_TUI_VERSION ||
84
- process.env.DEEPSEEK_VERSION ||
85
- pkg.deepseekBinaryVersion ||
86
- pkg.version;
88
+ env.DEEPSEEK_TUI_VERSION ||
89
+ env.DEEPSEEK_VERSION ||
90
+ pkgObj.codewhaleBinaryVersion ||
91
+ pkgObj.deepseekBinaryVersion ||
92
+ pkgObj.version;
87
93
  return String(configuredVersion).trim();
88
94
  }
89
95
 
@@ -1148,6 +1154,7 @@ module.exports = {
1148
1154
  installFailureHint,
1149
1155
  run,
1150
1156
  _internal: {
1157
+ resolvePackageVersion,
1151
1158
  isOptionalInstall,
1152
1159
  adoptExistingBinaryIfValid,
1153
1160
  shouldIgnoreInstallFailure,
@@ -69,7 +69,7 @@ function buildFromSourceHint() {
69
69
  "You can still run codewhale by building from source with Cargo:",
70
70
  "",
71
71
  " # Requires Rust 1.88+ (https://rustup.rs)",
72
- " cargo install codewhale-cli --locked # provides `codewhale`",
72
+ " cargo install codewhale-cli --locked # provides `codewhale` and `codew`",
73
73
  " cargo install codewhale-tui --locked # provides `codewhale-tui`",
74
74
  "",
75
75
  "Or build from a checkout:",
@@ -22,6 +22,35 @@ function resolveRepo() {
22
22
  return process.env.DEEPSEEK_TUI_GITHUB_REPO || process.env.DEEPSEEK_GITHUB_REPO || "Hmbown/CodeWhale";
23
23
  }
24
24
 
25
+ function hasReleaseBaseOverride() {
26
+ return Boolean(
27
+ process.env.CODEWHALE_RELEASE_BASE_URL ||
28
+ process.env.DEEPSEEK_TUI_RELEASE_BASE_URL ||
29
+ process.env.DEEPSEEK_RELEASE_BASE_URL ||
30
+ process.env.CODEWHALE_USE_CNB_MIRROR,
31
+ );
32
+ }
33
+
34
+ function packageVersionMatchesBinaryVersion(version) {
35
+ return String(pkg.version).trim() === version;
36
+ }
37
+
38
+ function assertPackageVersionMatchesBinaryVersion(version) {
39
+ if (packageVersionMatchesBinaryVersion(version)) {
40
+ return;
41
+ }
42
+ if (process.env.CODEWHALE_ALLOW_NPM_BINARY_MISMATCH === "1") {
43
+ console.log(
44
+ `npm package version ${pkg.version} points at binary release ${version} (allowed packaging-only mismatch).`,
45
+ );
46
+ return;
47
+ }
48
+ throw new Error(
49
+ `npm package version ${pkg.version} does not match codewhaleBinaryVersion ${version}. ` +
50
+ "Set CODEWHALE_ALLOW_NPM_BINARY_MISMATCH=1 only for an intentional packaging-only npm release.",
51
+ );
52
+ }
53
+
25
54
  function requestStatus(url, method = "HEAD", redirects = 0) {
26
55
  if (redirects > 10) {
27
56
  throw new Error(`Too many redirects while checking ${url}`);
@@ -63,7 +92,10 @@ async function verifyAsset(url, label) {
63
92
  }
64
93
  }
65
94
 
66
- async function downloadText(url) {
95
+ async function downloadText(url, redirects = 0) {
96
+ if (redirects > 10) {
97
+ throw new Error(`Too many redirects while downloading ${url}`);
98
+ }
67
99
  const client = url.startsWith("https:") ? https : http;
68
100
  return new Promise((resolve, reject) => {
69
101
  client
@@ -78,7 +110,8 @@ async function downloadText(url) {
78
110
  const status = res.statusCode || 0;
79
111
  if (status >= 300 && status < 400 && res.headers.location) {
80
112
  const next = new URL(res.headers.location, url).toString();
81
- resolve(downloadText(next));
113
+ res.resume();
114
+ resolve(downloadText(next, redirects + 1));
82
115
  return;
83
116
  }
84
117
  if (status !== 200) {
@@ -96,6 +129,145 @@ async function downloadText(url) {
96
129
  });
97
130
  }
98
131
 
132
+ async function downloadJson(url, redirects = 0) {
133
+ if (redirects > 10) {
134
+ throw new Error(`Too many redirects while downloading ${url}`);
135
+ }
136
+ const client = url.startsWith("https:") ? https : http;
137
+ return new Promise((resolve, reject) => {
138
+ const headers = {
139
+ Accept: "application/vnd.github+json",
140
+ "User-Agent": "codewhale-npm-release-check",
141
+ "X-GitHub-Api-Version": "2022-11-28",
142
+ };
143
+ const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
144
+ if (token) {
145
+ headers.Authorization = `Bearer ${token}`;
146
+ }
147
+ client
148
+ .get(url, { headers }, (res) => {
149
+ const status = res.statusCode || 0;
150
+ if (status >= 300 && status < 400 && res.headers.location) {
151
+ const next = new URL(res.headers.location, url).toString();
152
+ res.resume();
153
+ resolve(downloadJson(next, redirects + 1));
154
+ return;
155
+ }
156
+ const chunks = [];
157
+ res.setEncoding("utf8");
158
+ res.on("data", (chunk) => chunks.push(chunk));
159
+ res.on("end", () => {
160
+ const body = chunks.join("");
161
+ let parsed;
162
+ try {
163
+ parsed = body ? JSON.parse(body) : {};
164
+ } catch (error) {
165
+ reject(new Error(`Invalid JSON from ${url}: ${error.message}`));
166
+ return;
167
+ }
168
+ if (status < 200 || status >= 300) {
169
+ const message = parsed.message ? `: ${parsed.message}` : "";
170
+ reject(new Error(`GitHub API request failed with status ${status}${message} (${url})`));
171
+ return;
172
+ }
173
+ resolve(parsed);
174
+ });
175
+ })
176
+ .on("error", reject);
177
+ });
178
+ }
179
+
180
+ function githubApiUrl(repo, path) {
181
+ return `https://api.github.com/repos/${repo}${path}`;
182
+ }
183
+
184
+ async function githubApi(repo, path) {
185
+ return downloadJson(githubApiUrl(repo, path));
186
+ }
187
+
188
+ async function resolveTagCommitSha(repo, tag) {
189
+ const ref = await githubApi(repo, `/git/ref/tags/${encodeURIComponent(tag)}`);
190
+ if (!ref.object || !ref.object.sha || !ref.object.type) {
191
+ throw new Error(`GitHub tag ref ${tag} did not include an object SHA`);
192
+ }
193
+ if (ref.object.type === "commit") {
194
+ return ref.object.sha;
195
+ }
196
+ if (ref.object.type !== "tag") {
197
+ throw new Error(`GitHub tag ref ${tag} points at ${ref.object.type}, not a commit or annotated tag`);
198
+ }
199
+ const tagObject = await githubApi(repo, `/git/tags/${ref.object.sha}`);
200
+ if (!tagObject.object || tagObject.object.type !== "commit" || !tagObject.object.sha) {
201
+ throw new Error(`Annotated tag ${tag} did not peel to a commit SHA`);
202
+ }
203
+ return tagObject.object.sha;
204
+ }
205
+
206
+ async function findReleaseWorkflowRun(repo, tag, tagSha) {
207
+ const runs = await githubApi(repo, "/actions/workflows/release.yml/runs?per_page=100");
208
+ const matches = (runs.workflow_runs || [])
209
+ .filter((run) => run.head_sha === tagSha)
210
+ .filter((run) => run.conclusion === "success")
211
+ .filter((run) => run.event === "push" || run.event === "workflow_dispatch")
212
+ .sort((a, b) => String(b.updated_at).localeCompare(String(a.updated_at)));
213
+ const tagBranchMatch = matches.find((run) => run.head_branch === tag);
214
+ const match = tagBranchMatch || matches[0];
215
+ if (!match) {
216
+ throw new Error(
217
+ `No successful release.yml workflow run found for ${tag} at ${tagSha}. ` +
218
+ "Rerun the Release workflow before publishing npm, or increase the verifier's last-100-runs search window.",
219
+ );
220
+ }
221
+ return match;
222
+ }
223
+
224
+ function parseGitHubTime(value, label) {
225
+ const timestamp = Date.parse(value);
226
+ if (!Number.isFinite(timestamp)) {
227
+ throw new Error(`GitHub ${label} timestamp is invalid: ${value}`);
228
+ }
229
+ return timestamp;
230
+ }
231
+
232
+ function assertReleaseAssetsFresh(release, expectedAssets, run) {
233
+ const assetsByName = new Map((release.assets || []).map((asset) => [asset.name, asset]));
234
+ const missing = expectedAssets.filter((asset) => !assetsByName.has(asset));
235
+ if (missing.length > 0) {
236
+ throw new Error(`GitHub Release is missing required npm-facing asset(s): ${missing.join(", ")}`);
237
+ }
238
+
239
+ const runStartedAt = parseGitHubTime(run.run_started_at || run.created_at, "workflow run start");
240
+ const stale = [];
241
+ for (const expected of expectedAssets) {
242
+ const asset = assetsByName.get(expected);
243
+ if (asset.state && asset.state !== "uploaded") {
244
+ stale.push(`${expected} has state ${asset.state}`);
245
+ continue;
246
+ }
247
+ const updatedAt = parseGitHubTime(asset.updated_at || asset.created_at, `${expected} update`);
248
+ if (updatedAt < runStartedAt) {
249
+ stale.push(`${expected} updated at ${asset.updated_at || asset.created_at}`);
250
+ }
251
+ }
252
+
253
+ if (stale.length > 0) {
254
+ throw new Error(
255
+ `GitHub Release asset set is stale for workflow run ${run.database_id || run.id}: ${stale.join("; ")}`,
256
+ );
257
+ }
258
+ }
259
+
260
+ async function verifyGitHubReleaseFreshness(repo, version, expectedAssets) {
261
+ const tag = `v${version}`;
262
+ const tagSha = await resolveTagCommitSha(repo, tag);
263
+ const release = await githubApi(repo, `/releases/tags/${encodeURIComponent(tag)}`);
264
+ const run = await findReleaseWorkflowRun(repo, tag, tagSha);
265
+ assertReleaseAssetsFresh(release, expectedAssets, run);
266
+ console.log(
267
+ `GitHub release asset freshness OK: ${expectedAssets.length} npm-facing assets for ${tag} were produced by run ${run.database_id || run.id} at ${tagSha.slice(0, 12)}.`,
268
+ );
269
+ }
270
+
99
271
  function parseChecksumManifest(text) {
100
272
  const checksums = new Map();
101
273
  for (const line of text.split(/\r?\n/)) {
@@ -117,7 +289,14 @@ async function run() {
117
289
  const repo = resolveRepo();
118
290
  const assets = allReleaseAssetNames();
119
291
 
292
+ assertPackageVersionMatchesBinaryVersion(version);
293
+
120
294
  console.log(`Verifying ${assets.length} release assets for ${repo}@v${version}...`);
295
+ if (hasReleaseBaseOverride()) {
296
+ console.log("Skipping GitHub workflow freshness check because a release asset mirror/base URL override is set.");
297
+ } else {
298
+ await verifyGitHubReleaseFreshness(repo, version, assets);
299
+ }
121
300
  for (const asset of assets) {
122
301
  const url = releaseAssetUrl(asset, version, repo);
123
302
  await verifyAsset(url, asset);
@@ -134,7 +313,16 @@ async function run() {
134
313
  console.log("Release assets verified.");
135
314
  }
136
315
 
137
- run().catch((error) => {
138
- console.error("Release asset verification failed:", error.message);
139
- process.exit(1);
140
- });
316
+ if (require.main === module) {
317
+ run().catch((error) => {
318
+ console.error("Release asset verification failed:", error.message);
319
+ process.exit(1);
320
+ });
321
+ }
322
+
323
+ module.exports = {
324
+ assertPackageVersionMatchesBinaryVersion,
325
+ assertReleaseAssetsFresh,
326
+ hasReleaseBaseOverride,
327
+ parseChecksumManifest,
328
+ };
@@ -26,6 +26,7 @@ test("openharmony x64 resolves to linux x64 binaries", () => {
26
26
  const result = detectBinaryNames();
27
27
  assert.equal(result.codewhale, "codewhale-linux-x64");
28
28
  assert.equal(result.tui, "codewhale-tui-linux-x64");
29
+ assert.equal(result.codew, "codew-linux-x64");
29
30
  });
30
31
  });
31
32
 
@@ -35,6 +36,7 @@ test("openharmony arm64 resolves to linux arm64 binaries", () => {
35
36
  const result = detectBinaryNames();
36
37
  assert.equal(result.codewhale, "codewhale-linux-arm64");
37
38
  assert.equal(result.tui, "codewhale-tui-linux-arm64");
39
+ assert.equal(result.codew, "codew-linux-arm64");
38
40
  });
39
41
  });
40
42
 
@@ -71,6 +73,8 @@ test("allAssetNames includes every matrix entry", () => {
71
73
  const assetNames = allAssetNames();
72
74
  assert.ok(assetNames.includes("codewhale-windows-x64.exe"));
73
75
  assert.ok(assetNames.includes("codewhale-tui-windows-x64.exe"));
76
+ assert.ok(assetNames.includes("codew-windows-x64.exe"));
74
77
  assert.ok(assetNames.includes("codewhale.bat"));
78
+ assert.ok(allReleaseAssetNames().includes("codew-windows-x64.exe"));
75
79
  assert.ok(allReleaseAssetNames().includes("codewhale.bat"));
76
80
  });
@@ -223,3 +223,43 @@ test("manual binaries with mismatched checksums are not adopted", async (t) => {
223
223
  assert.equal(adopted, false);
224
224
  assert.equal(await exists(`${target}.version`), false);
225
225
  });
226
+
227
+ test("resolvePackageVersion honors codewhaleBinaryVersion precedence (#3769)", () => {
228
+ const { resolvePackageVersion } = _internal;
229
+
230
+ // codewhaleBinaryVersion wins over deepseekBinaryVersion and pkg.version.
231
+ assert.equal(
232
+ resolvePackageVersion(
233
+ {
234
+ codewhaleBinaryVersion: "1.2.3",
235
+ deepseekBinaryVersion: "0.0.1",
236
+ version: "9.9.9",
237
+ },
238
+ {},
239
+ ),
240
+ "1.2.3",
241
+ );
242
+
243
+ // Falls back to deepseekBinaryVersion, then pkg.version.
244
+ assert.equal(
245
+ resolvePackageVersion({ deepseekBinaryVersion: "0.0.1", version: "9.9.9" }, {}),
246
+ "0.0.1",
247
+ );
248
+ assert.equal(resolvePackageVersion({ version: "9.9.9" }, {}), "9.9.9");
249
+
250
+ // Legacy env vars still take precedence over package fields, unchanged.
251
+ assert.equal(
252
+ resolvePackageVersion(
253
+ { codewhaleBinaryVersion: "1.2.3", version: "9.9.9" },
254
+ { DEEPSEEK_TUI_VERSION: "7.7.7" },
255
+ ),
256
+ "7.7.7",
257
+ );
258
+ assert.equal(
259
+ resolvePackageVersion(
260
+ { codewhaleBinaryVersion: "1.2.3" },
261
+ { DEEPSEEK_VERSION: "8.8.8" },
262
+ ),
263
+ "8.8.8",
264
+ );
265
+ });
@@ -0,0 +1,94 @@
1
+ const assert = require("node:assert/strict");
2
+ const test = require("node:test");
3
+
4
+ const pkg = require("../package.json");
5
+ const {
6
+ assertPackageVersionMatchesBinaryVersion,
7
+ assertReleaseAssetsFresh,
8
+ parseChecksumManifest,
9
+ } = require("../scripts/verify-release-assets");
10
+
11
+ test("parseChecksumManifest accepts GNU and BSD filename forms", () => {
12
+ const manifest = parseChecksumManifest(
13
+ [
14
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa codewhale-linux-x64",
15
+ "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb *codewhale-windows-x64.exe",
16
+ ].join("\n"),
17
+ );
18
+
19
+ assert.equal(manifest.get("codewhale-linux-x64"), "a".repeat(64));
20
+ assert.equal(manifest.get("codewhale-windows-x64.exe"), "b".repeat(64));
21
+ });
22
+
23
+ test("parseChecksumManifest rejects malformed checksum rows", () => {
24
+ assert.throws(
25
+ () => parseChecksumManifest("not-a-sha codewhale-linux-x64"),
26
+ /Invalid checksum manifest line/,
27
+ );
28
+ });
29
+
30
+ test("assertReleaseAssetsFresh rejects missing npm-facing assets", () => {
31
+ assert.throws(
32
+ () =>
33
+ assertReleaseAssetsFresh(
34
+ { assets: [{ name: "codewhale-linux-x64", state: "uploaded", updated_at: "2026-06-26T00:10:00Z" }] },
35
+ ["codewhale-linux-x64", "codewhale-artifacts-sha256.txt"],
36
+ { database_id: 123, created_at: "2026-06-26T00:00:00Z" },
37
+ ),
38
+ /missing required npm-facing asset/,
39
+ );
40
+ });
41
+
42
+ test("assertReleaseAssetsFresh rejects assets older than the release workflow run", () => {
43
+ assert.throws(
44
+ () =>
45
+ assertReleaseAssetsFresh(
46
+ { assets: [{ name: "codewhale-linux-x64", state: "uploaded", updated_at: "2026-06-25T23:59:59Z" }] },
47
+ ["codewhale-linux-x64"],
48
+ { database_id: 123, created_at: "2026-06-26T00:00:00Z" },
49
+ ),
50
+ /asset set is stale/,
51
+ );
52
+ });
53
+
54
+ test("assertReleaseAssetsFresh rejects non-uploaded assets", () => {
55
+ assert.throws(
56
+ () =>
57
+ assertReleaseAssetsFresh(
58
+ { assets: [{ name: "codewhale-linux-x64", state: "new", updated_at: "2026-06-26T00:10:00Z" }] },
59
+ ["codewhale-linux-x64"],
60
+ { database_id: 123, created_at: "2026-06-26T00:00:00Z" },
61
+ ),
62
+ /asset set is stale/,
63
+ );
64
+ });
65
+
66
+ test("assertReleaseAssetsFresh accepts assets updated by the release workflow run", () => {
67
+ assert.doesNotThrow(() =>
68
+ assertReleaseAssetsFresh(
69
+ { assets: [{ name: "codewhale-linux-x64", state: "uploaded", updated_at: "2026-06-26T00:10:00Z" }] },
70
+ ["codewhale-linux-x64"],
71
+ { database_id: 123, created_at: "2026-06-26T00:00:00Z" },
72
+ ),
73
+ );
74
+ });
75
+
76
+ test("assertPackageVersionMatchesBinaryVersion allows packaging-only releases only with an explicit override", () => {
77
+ assert.doesNotThrow(() => assertPackageVersionMatchesBinaryVersion(pkg.version));
78
+ assert.throws(
79
+ () => assertPackageVersionMatchesBinaryVersion("0.0.0-packaging-test"),
80
+ /does not match codewhaleBinaryVersion/,
81
+ );
82
+
83
+ const previous = process.env.CODEWHALE_ALLOW_NPM_BINARY_MISMATCH;
84
+ process.env.CODEWHALE_ALLOW_NPM_BINARY_MISMATCH = "1";
85
+ try {
86
+ assert.doesNotThrow(() => assertPackageVersionMatchesBinaryVersion("0.0.0-packaging-test"));
87
+ } finally {
88
+ if (previous === undefined) {
89
+ delete process.env.CODEWHALE_ALLOW_NPM_BINARY_MISMATCH;
90
+ } else {
91
+ process.env.CODEWHALE_ALLOW_NPM_BINARY_MISMATCH = previous;
92
+ }
93
+ }
94
+ });