harnessed 5.0.11 → 5.0.12

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/CHANGELOG.md CHANGED
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [5.0.12] - 2026-11-03
11
+
12
+ ### Fixed
13
+
14
+ - The compiled-binary self-update now survives a slow link and says what actually failed. The release-metadata hop gets a 30 s budget instead of 10 s and reports the stage it failed in — a timeout, a network error, an HTTP status, or an unparsable response — instead of one generic "could not reach GitHub releases" line, and the "the release may still be publishing" hint is now shown only for the case it describes. The binary asset is streamed to disk instead of being buffered in memory (it is ≈99 MB), the transfer aborts if no data arrives for 120 s, a progress line reports the downloaded size and rate while it runs, and a failed download states how many bytes arrived, how long it took and the average rate.
15
+ - `harnessed doctor` no longer reports a second install channel that is not installed. Channel presence is decided by what exists on disk, so running from a source checkout no longer counts as an npm-global install, and the single-channel line names the channel that is actually installed.
16
+
10
17
  ## [5.0.11] - 2026-11-03
11
18
 
12
19
  ### Fixed
@@ -65,7 +65,7 @@ var init_package = __esm({
65
65
  'package.json'() {
66
66
  package_default = {
67
67
  name: 'harnessed',
68
- version: '5.0.11',
68
+ version: '5.0.12',
69
69
  description: 'AI coding harness package manager + composition orchestrator',
70
70
  type: 'module',
71
71
  license: 'Apache-2.0',
@@ -14,7 +14,7 @@ var init_package = __esm({
14
14
  'package.json'() {
15
15
  package_default = {
16
16
  name: 'harnessed',
17
- version: '5.0.11',
17
+ version: '5.0.12',
18
18
  description: 'AI coding harness package manager + composition orchestrator',
19
19
  type: 'module',
20
20
  license: 'Apache-2.0',
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { readFileSync, existsSync, mkdirSync, readdirSync, writeFileSync, appendFileSync, accessSync, constants, statSync, unlinkSync, realpathSync, renameSync, openSync, closeSync, fsyncSync, rmSync, mkdtempSync, lstatSync, readSync, utimesSync, createReadStream } from 'fs';
2
+ import { readFileSync, existsSync, mkdirSync, readdirSync, writeFileSync, appendFileSync, accessSync, constants, statSync, unlinkSync, realpathSync, renameSync, openSync, closeSync, fsyncSync, rmSync, mkdtempSync, lstatSync, readSync, utimesSync, createReadStream, createWriteStream } from 'fs';
3
3
  import { homedir, tmpdir } from 'os';
4
4
  import { join, dirname, resolve, basename, isAbsolute, relative, sep, win32, posix } from 'path';
5
5
  import { Type } from '@sinclair/typebox';
@@ -19,6 +19,8 @@ import * as p from '@clack/prompts';
19
19
  import { createPatch } from 'diff';
20
20
  import pc from 'picocolors';
21
21
  import { setTimeout as setTimeout$1 } from 'timers/promises';
22
+ import { Transform, Readable } from 'stream';
23
+ import { pipeline } from 'stream/promises';
22
24
  import { stdout, stdin } from 'process';
23
25
  import * as readline from 'readline/promises';
24
26
  import { parse as parse$1 } from 'smol-toml';
@@ -40,7 +42,7 @@ var init_package = __esm({
40
42
  "package.json"() {
41
43
  package_default = {
42
44
  name: "harnessed",
43
- version: "5.0.11",
45
+ version: "5.0.12",
44
46
  description: "AI coding harness package manager + composition orchestrator",
45
47
  type: "module",
46
48
  license: "Apache-2.0",
@@ -8709,8 +8711,8 @@ function detectInstallChannels(deps) {
8709
8711
  const binaryPath = running === "binary" ? execPath : binaryPresent ? binCand : null;
8710
8712
  const prefix = npmPrefix();
8711
8713
  const npmCand = prefix ? npmCandidate(platform, prefix) : null;
8712
- const npmPresent = running === "npm" || npmCand != null && exists(npmCand);
8713
8714
  const npmPath2 = npmCand != null && exists(npmCand) ? npmCand : null;
8715
+ const npmPresent = npmPath2 != null;
8714
8716
  return { binaryPath, npmPath: npmPath2, running, both: binaryPresent && npmPresent };
8715
8717
  }
8716
8718
  function bunPackageAdvisory(binaryPath) {
@@ -8751,10 +8753,11 @@ function checkInstallChannels(deps) {
8751
8753
  }
8752
8754
  const r = detectInstallChannels(deps);
8753
8755
  if (!r.both) {
8756
+ const installed2 = r.npmPath ? "npm" : r.binaryPath ? "binary" : null;
8754
8757
  return {
8755
8758
  name: "install channel",
8756
8759
  status: "pass",
8757
- message: `single channel (${r.running})`
8760
+ message: installed2 ? `single channel (${installed2})` : "no install channel on disk (running from a source checkout?)"
8758
8761
  };
8759
8762
  }
8760
8763
  return {
@@ -21094,7 +21097,7 @@ function normalized(p8) {
21094
21097
  function downloadFailureMessage(error, version, url) {
21095
21098
  const detail = error instanceof Error ? error.message : String(error);
21096
21099
  const target = version ? ` for release v${version}` : "";
21097
- return `download failed${target}${url ? ` (tried ${url})` : ""}: ${detail} \u2014 if the network blocks GitHub, use the npm channel (\`npm i -g harnessed@latest\`) or a local build via \`HARNESSED_UPDATE_SOURCE_DIR=<dir> harnessed update\``;
21100
+ return `download failed${target}${url ? ` (tried ${url})` : ""}: ${detail} \u2014 the original binary was left untouched; if the network blocks GitHub, use the npm channel (\`npm i -g harnessed@latest\`) or a local build via \`HARNESSED_UPDATE_SOURCE_DIR=<dir> harnessed update\``;
21098
21101
  }
21099
21102
  async function sha256File(p8) {
21100
21103
  const buf = await readFile(p8);
@@ -21153,14 +21156,13 @@ async function runBinarySelfUpdate(deps, opts) {
21153
21156
  if (rel === null) {
21154
21157
  return {
21155
21158
  status: "error",
21156
- message: "could not reach GitHub releases to resolve the latest binary \u2014 check the network or use the npm channel (`npm i -g harnessed@latest`), or point `HARNESSED_UPDATE_SOURCE_DIR=<dir>` at a local build and re-run `harnessed update`"
21159
+ message: "could not resolve the latest release from GitHub (no release information returned) \u2014 use the npm channel (`npm i -g harnessed@latest`), or point `HARNESSED_UPDATE_SOURCE_DIR=<dir>` at a local build and re-run `harnessed update`"
21157
21160
  };
21158
21161
  }
21159
21162
  if ("error" in rel) {
21160
- return {
21161
- status: "error",
21162
- message: `${rel.error} \u2014 the release may still be publishing (retry in a few minutes) or use the npm channel (\`npm i -g harnessed@latest\`)`
21163
- };
21163
+ const publishing = rel.kind === void 0 || rel.kind === "publishing";
21164
+ const remedy = publishing ? "the release may still be publishing (retry in a few minutes) or use the npm channel (`npm i -g harnessed@latest`)" : "the original binary was left untouched; use the npm channel (`npm i -g harnessed@latest`) or point `HARNESSED_UPDATE_SOURCE_DIR=<dir>` at a local build and re-run `harnessed update`";
21165
+ return { status: "error", message: `${rel.error} \u2014 ${remedy}` };
21164
21166
  }
21165
21167
  targetVersion = rel.version;
21166
21168
  assetUrl = rel.assetUrl;
@@ -21423,11 +21425,13 @@ async function runBinaryRollback(deps, opts) {
21423
21425
  });
21424
21426
  return { status: "rolled-back", from: deps.currentVersion, to: target, backupUsed: backupBin };
21425
21427
  }
21426
- async function fetchWithTimeout(url, timeoutMs, net = {}, headers = {}) {
21428
+ async function fetchWithTimeout(url, timeoutMs, net = {}, headers = {}, controller) {
21427
21429
  await ensureProxyDispatcher();
21428
21430
  const doFetch = net.fetchImpl ?? fetch;
21429
- const ac = new AbortController();
21430
- const timer = setTimeout(() => ac.abort(), timeoutMs);
21431
+ const ac = controller ?? new AbortController();
21432
+ const timer = setTimeout(() => {
21433
+ ac.abort(new RequestTimeoutError(`the request to ${url} timed out after ${timeoutMs} ms`));
21434
+ }, timeoutMs);
21431
21435
  try {
21432
21436
  return await doFetch(url, {
21433
21437
  signal: ac.signal,
@@ -21451,20 +21455,31 @@ function isTransientNetworkError(error) {
21451
21455
  message
21452
21456
  );
21453
21457
  }
21454
- async function fetchAsset(url, fallbackUrl, timeoutMs, net, label) {
21458
+ async function fetchAsset(url, fallbackUrl, timeoutMs, net, label, consume) {
21455
21459
  const sleep2 = net.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
21456
21460
  const attempts = [];
21457
21461
  let lastError;
21458
21462
  for (const candidate of [url, fallbackUrl].filter((u) => !!u)) {
21459
21463
  for (let attempt = 1; attempt <= DOWNLOAD_ATTEMPTS; attempt++) {
21464
+ const ac = new AbortController();
21460
21465
  try {
21461
- const res = await fetchWithTimeout(candidate, timeoutMs, net, {
21462
- accept: "application/octet-stream"
21463
- });
21464
- if (res.ok) return res;
21465
- lastError = new Error(`HTTP ${res.status} downloading ${candidate}`);
21466
- if (res.status < 500) break;
21466
+ const res = await fetchWithTimeout(
21467
+ candidate,
21468
+ timeoutMs,
21469
+ net,
21470
+ {
21471
+ accept: "application/octet-stream"
21472
+ },
21473
+ ac
21474
+ );
21475
+ if (!res.ok) {
21476
+ lastError = new Error(`HTTP ${res.status} downloading ${candidate}`);
21477
+ if (res.status < 500) break;
21478
+ } else {
21479
+ return await consume(res, ac);
21480
+ }
21467
21481
  } catch (error) {
21482
+ if (error instanceof TransferStalledError) throw error;
21468
21483
  lastError = error;
21469
21484
  if (!isTransientNetworkError(error)) break;
21470
21485
  }
@@ -21476,46 +21491,134 @@ async function fetchAsset(url, fallbackUrl, timeoutMs, net, label) {
21476
21491
  `${label} download failed (${attempts.length} attempt(s) over ${[url, fallbackUrl].filter(Boolean).join(", ")}): ${lastError instanceof Error ? lastError.message : String(lastError)}`
21477
21492
  );
21478
21493
  }
21494
+ function formatBytes(n) {
21495
+ if (n >= 1024 * 1024) return `${(n / 1024 / 1024).toFixed(1)} MB`;
21496
+ if (n >= 1024) return `${(n / 1024).toFixed(1)} KB`;
21497
+ return `${n} B`;
21498
+ }
21499
+ function formatRate(received, elapsedMs) {
21500
+ if (received <= 0 || elapsedMs <= 0) return "0 KB/s";
21501
+ return `${(received / 1024 / (elapsedMs / 1e3)).toFixed(1)} KB/s`;
21502
+ }
21503
+ function transferStats(received, elapsedMs) {
21504
+ const seconds = (elapsedMs / 1e3).toFixed(1);
21505
+ const rate = received > 0 ? `, ${formatRate(received, elapsedMs)} average` : "";
21506
+ return `${received} bytes received in ${seconds} s${rate}`;
21507
+ }
21508
+ async function streamAssetToFile(res, dest, ac, stallTimeoutMs, progressIntervalMs, log) {
21509
+ if (!res.body) throw new Error("the release asset response carried no body");
21510
+ const started = Date.now();
21511
+ let received = 0;
21512
+ let lastProgressAt = started;
21513
+ let stalled = false;
21514
+ let stallTimer;
21515
+ const resetStall = () => {
21516
+ if (stallTimer) clearTimeout(stallTimer);
21517
+ stallTimer = setTimeout(() => {
21518
+ stalled = true;
21519
+ ac.abort(
21520
+ new TransferStalledError(`no data received for ${Math.round(stallTimeoutMs / 1e3)} s`)
21521
+ );
21522
+ }, stallTimeoutMs);
21523
+ };
21524
+ const meter = new Transform({
21525
+ transform(chunk, _encoding, callback) {
21526
+ received += chunk.length;
21527
+ const now = Date.now();
21528
+ if (now - lastProgressAt >= progressIntervalMs) {
21529
+ lastProgressAt = now;
21530
+ log(`downloading ${formatBytes(received)} (${formatRate(received, now - started)})`);
21531
+ }
21532
+ resetStall();
21533
+ callback(null, chunk);
21534
+ }
21535
+ });
21536
+ resetStall();
21537
+ try {
21538
+ await pipeline(
21539
+ // undici types the body as a DOM-ish ReadableStream; node:stream/web's
21540
+ // class is the one Readable.fromWeb accepts.
21541
+ Readable.fromWeb(res.body),
21542
+ meter,
21543
+ // flags 'w' truncates: a retried attempt must not append to the bytes
21544
+ // a previous attempt already wrote.
21545
+ createWriteStream(dest),
21546
+ { signal: ac.signal }
21547
+ );
21548
+ } catch (e) {
21549
+ if (stalled) {
21550
+ throw new TransferStalledError(
21551
+ `the download stalled \u2014 no data for ${Math.round(stallTimeoutMs / 1e3)} s (${transferStats(received, Date.now() - started)})`
21552
+ );
21553
+ }
21554
+ throw e;
21555
+ } finally {
21556
+ if (stallTimer) clearTimeout(stallTimer);
21557
+ }
21558
+ }
21479
21559
  async function resolveLatestRelease(platform = process.platform, arch = process.arch, net = {}) {
21560
+ let res;
21480
21561
  try {
21481
- const res = await fetchWithTimeout(RELEASES_LATEST_URL, 1e4, net);
21482
- if (!res.ok) return null;
21483
- const body = await res.json();
21484
- const version = (body.tag_name ?? "").replace(/^v/, "");
21485
- if (!/^\d+\.\d+\.\d+/.test(version)) return null;
21486
- const asset = assetNameFor(platform, arch);
21487
- const pick = (name) => body.assets?.find((a) => a.name === name);
21488
- const found = pick(asset);
21489
- const sha = pick(`${asset}.sha256`);
21490
- const sig = pick(`${asset}.sha256.sig`);
21491
- if (!found?.browser_download_url && !found?.url) {
21492
- return { error: `asset ${asset} not found on release v${version}` };
21493
- }
21494
- if (!sha?.browser_download_url && !sha?.url) {
21495
- return { error: `asset ${asset}.sha256 not found on release v${version}` };
21496
- }
21497
- const pair = (a) => {
21498
- const api = a?.url;
21499
- const browser = a?.browser_download_url;
21500
- return api && browser ? { primary: api, fallback: browser } : { primary: api ?? browser ?? "", fallback: void 0 };
21562
+ res = await fetchWithTimeout(RELEASES_LATEST_URL, RELEASE_METADATA_TIMEOUT_MS, net);
21563
+ } catch (e) {
21564
+ const budget = `${RELEASE_METADATA_TIMEOUT_MS / 1e3} s timeout budget`;
21565
+ return {
21566
+ error: e instanceof RequestTimeoutError ? `the request to the GitHub releases API timed out (${budget})` : `the request to the GitHub releases API failed or timed out (${budget}): ${e instanceof Error ? e.message : String(e)}`,
21567
+ kind: e instanceof RequestTimeoutError ? "timeout" : "network"
21501
21568
  };
21502
- const assetPair = pair(found);
21503
- const shaPair = pair(sha);
21504
- const sigPair = pair(sig);
21569
+ }
21570
+ if (!res.ok) {
21571
+ return { error: `the GitHub releases API returned HTTP ${res.status}`, kind: "http" };
21572
+ }
21573
+ let body;
21574
+ try {
21575
+ body = await res.json();
21576
+ } catch (e) {
21505
21577
  return {
21506
- version,
21507
- assetUrl: assetPair.primary,
21508
- shaUrl: shaPair.primary,
21509
- sigUrl: sigPair.primary || void 0,
21510
- assetFallbackUrl: assetPair.fallback,
21511
- shaFallbackUrl: shaPair.fallback,
21512
- sigFallbackUrl: sigPair.fallback
21578
+ error: `the GitHub releases API response could not be parsed: ${e instanceof Error ? e.message : String(e)}`,
21579
+ kind: "parse"
21513
21580
  };
21514
- } catch {
21515
- return null;
21516
21581
  }
21582
+ const version = (body.tag_name ?? "").replace(/^v/, "");
21583
+ if (!/^\d+\.\d+\.\d+/.test(version)) {
21584
+ return {
21585
+ error: `the GitHub releases API response could not be parsed: unexpected tag_name "${body.tag_name ?? ""}"`,
21586
+ kind: "parse"
21587
+ };
21588
+ }
21589
+ const asset = assetNameFor(platform, arch);
21590
+ const pick = (name) => body.assets?.find((a) => a.name === name);
21591
+ const found = pick(asset);
21592
+ const sha = pick(`${asset}.sha256`);
21593
+ const sig = pick(`${asset}.sha256.sig`);
21594
+ if (!found?.browser_download_url && !found?.url) {
21595
+ return { error: `asset ${asset} not found on release v${version}`, kind: "publishing" };
21596
+ }
21597
+ if (!sha?.browser_download_url && !sha?.url) {
21598
+ return { error: `asset ${asset}.sha256 not found on release v${version}`, kind: "publishing" };
21599
+ }
21600
+ const pair = (a) => {
21601
+ const api = a?.url;
21602
+ const browser = a?.browser_download_url;
21603
+ return api && browser ? { primary: api, fallback: browser } : { primary: api ?? browser ?? "", fallback: void 0 };
21604
+ };
21605
+ const assetPair = pair(found);
21606
+ const shaPair = pair(sha);
21607
+ const sigPair = pair(sig);
21608
+ return {
21609
+ version,
21610
+ assetUrl: assetPair.primary,
21611
+ shaUrl: shaPair.primary,
21612
+ sigUrl: sigPair.primary || void 0,
21613
+ assetFallbackUrl: assetPair.fallback,
21614
+ shaFallbackUrl: shaPair.fallback,
21615
+ sigFallbackUrl: sigPair.fallback
21616
+ };
21517
21617
  }
21518
21618
  function realSelfUpdateDeps(context, net = {}) {
21619
+ const log = (line) => console.warn(line);
21620
+ const stallTimeoutMs = net.stallTimeoutMs ?? ASSET_STALL_TIMEOUT_MS;
21621
+ const progressIntervalMs = net.progressIntervalMs ?? ASSET_PROGRESS_INTERVAL_MS;
21519
21622
  return {
21520
21623
  execPath: process.execPath,
21521
21624
  platform: process.platform,
@@ -21524,13 +21627,17 @@ function realSelfUpdateDeps(context, net = {}) {
21524
21627
  sourceDir: process.env.HARNESSED_UPDATE_SOURCE_DIR?.trim() || null,
21525
21628
  resolveRelease: () => resolveLatestRelease(process.platform, process.arch, net),
21526
21629
  downloadTo: async (url, dest, fallbackUrl) => {
21527
- const res = await fetchAsset(url, fallbackUrl, 12e4, net, "binary");
21528
- const buf = Buffer.from(await res.arrayBuffer());
21529
- await writeFile(dest, buf);
21630
+ await fetchAsset(
21631
+ url,
21632
+ fallbackUrl,
21633
+ ASSET_HEADERS_TIMEOUT_MS,
21634
+ net,
21635
+ "binary",
21636
+ (res, attempt) => streamAssetToFile(res, dest, attempt, stallTimeoutMs, progressIntervalMs, log)
21637
+ );
21530
21638
  },
21531
21639
  fetchShaText: async (url, fallbackUrl) => {
21532
- const res = await fetchAsset(url, fallbackUrl, 3e4, net, "checksum");
21533
- return res.text();
21640
+ return fetchAsset(url, fallbackUrl, CHECKSUM_TIMEOUT_MS, net, "checksum", (res) => res.text());
21534
21641
  },
21535
21642
  smoke: async (bin) => {
21536
21643
  const { execFile: execFile5 } = await import('child_process');
@@ -21544,7 +21651,7 @@ function realSelfUpdateDeps(context, net = {}) {
21544
21651
  return stdout2;
21545
21652
  },
21546
21653
  stateRoot: () => context.platform.stateRoot,
21547
- log: (l) => console.warn(l),
21654
+ log,
21548
21655
  pid: process.pid
21549
21656
  };
21550
21657
  }
@@ -21560,7 +21667,7 @@ async function execDirWritable(execPath) {
21560
21667
  return false;
21561
21668
  }
21562
21669
  }
21563
- var OWNER_REPO, RELEASES_LATEST_URL, DOWNLOAD_ATTEMPTS;
21670
+ var OWNER_REPO, RELEASES_LATEST_URL, RELEASE_METADATA_TIMEOUT_MS, ASSET_HEADERS_TIMEOUT_MS, CHECKSUM_TIMEOUT_MS, ASSET_STALL_TIMEOUT_MS, ASSET_PROGRESS_INTERVAL_MS, RequestTimeoutError, TransferStalledError, DOWNLOAD_ATTEMPTS;
21564
21671
  var init_selfUpdateBinary = __esm({
21565
21672
  "src/cli/lib/selfUpdateBinary.ts"() {
21566
21673
  init_package();
@@ -21570,6 +21677,15 @@ var init_selfUpdateBinary = __esm({
21570
21677
  init_version_check();
21571
21678
  OWNER_REPO = "easyinplay/harnessed";
21572
21679
  RELEASES_LATEST_URL = `https://api.github.com/repos/${OWNER_REPO}/releases/latest`;
21680
+ RELEASE_METADATA_TIMEOUT_MS = 3e4;
21681
+ ASSET_HEADERS_TIMEOUT_MS = 12e4;
21682
+ CHECKSUM_TIMEOUT_MS = 3e4;
21683
+ ASSET_STALL_TIMEOUT_MS = 12e4;
21684
+ ASSET_PROGRESS_INTERVAL_MS = 6e4;
21685
+ RequestTimeoutError = class extends Error {
21686
+ };
21687
+ TransferStalledError = class extends Error {
21688
+ };
21573
21689
  DOWNLOAD_ATTEMPTS = 3;
21574
21690
  }
21575
21691
  });