From 96a06fa32822c1110a5fa9e20cb2d56f55db7a76 Mon Sep 17 00:00:00 2001 From: "Christian M. Todie" Date: Thu, 22 Oct 2026 11:25:17 -0400 Subject: [PATCH] feat(cortex): add the cortex formula and a private-release download strategy cortex's release assets are in a private repository. The tap gains lib/github_private_release_download_strategy.rb, which downloads them through GitHub's release-asset API with HOMEBREW_GITHUB_API_TOKEN: - the token reaches curl only through a 0600 header file (--header @file) that is deleted after use: never on argv, never in a URL; - the release is looked up by tag and the asset by exact name, then fetched with Accept: application/octet-stream; curl does not resend the header after the cross-host redirect to the signed asset URL; - no unauthenticated HEAD probe of the private URL; - it fails before any network call without a token, and refuses to run with HOMEBREW_CURL_VERBOSE or HOMEBREW_CURLRC, which can print request headers. Formula/cortex.rb installs cortex v1.0.0-rc.46 (darwin and musl, both architectures); each sha256 equals GitHub's asset digest. The licence is proprietary, so license :cannot_represent. The README gains cortex's brew and mise lines and the private-tool setup. Refs OPS-1744 --- Formula/cortex.rb | 41 ++++++++++ README.md | 16 ++++ ...ithub_private_release_download_strategy.rb | 82 +++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 Formula/cortex.rb create mode 100644 lib/github_private_release_download_strategy.rb diff --git a/Formula/cortex.rb b/Formula/cortex.rb new file mode 100644 index 0000000..fdd124b --- /dev/null +++ b/Formula/cortex.rb @@ -0,0 +1,41 @@ +require_relative "../lib/github_private_release_download_strategy" + +class Cortex < Formula + desc "Cerebral agent mesh CLI" + homepage "https://github.com/cerebral-work/cortex" + license :cannot_represent + + on_macos do + on_intel do + url "https://github.com/cerebral-work/cortex/releases/download/v1.0.0-rc.46/cortex-v1.0.0-rc.46-x86_64-apple-darwin.tar.gz", + using: GitHubPrivateReleaseDownloadStrategy + sha256 "e5f0e606acd742ac1ef1e892f26f10888eb4460bf9a76003deb4bf56f1ff5062" + end + on_arm do + url "https://github.com/cerebral-work/cortex/releases/download/v1.0.0-rc.46/cortex-v1.0.0-rc.46-aarch64-apple-darwin.tar.gz", + using: GitHubPrivateReleaseDownloadStrategy + sha256 "899a5f24acb571184042fe985e1e0873c412d084a6a3f7c661b2bcefe0e93a36" + end + end + + on_linux do + on_intel do + url "https://github.com/cerebral-work/cortex/releases/download/v1.0.0-rc.46/cortex-v1.0.0-rc.46-x86_64-unknown-linux-musl.tar.gz", + using: GitHubPrivateReleaseDownloadStrategy + sha256 "541ebf9e36a14d72b87a944afaa60b70a2cf2545be26759518b23fca0d1abed8" + end + on_arm do + url "https://github.com/cerebral-work/cortex/releases/download/v1.0.0-rc.46/cortex-v1.0.0-rc.46-aarch64-unknown-linux-musl.tar.gz", + using: GitHubPrivateReleaseDownloadStrategy + sha256 "53d4d0260124f0b65f7077e6051f5093786341afc1963c5a9c35294d388967d0" + end + end + + def install + bin.install "cortex" + end + + test do + assert_match "cortex #{version}", shell_output("#{bin}/cortex --version") + end +end diff --git a/README.md b/README.md index ee7c861..468ba38 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,26 @@ brew install unsigned-gg/unsigned/ # CLIs | Tool | Homebrew | mise | |---|---|---| | herdr | `brew install unsigned-gg/unsigned/herdr` (Linux) | `mise use github:unsigned-gg/herdr@ug-v0.9.5.1` | +| cortex (private) | `brew install unsigned-gg/unsigned/cortex` | `mise use github:cerebral-work/cortex@v1.0.0-rc.46` | mise's `ubi:` backend (`mise use ubi:unsigned-gg/herdr@ug-v0.9.5.1`) installs the same binary, but mise has deprecated it and removes it in 2027.1.0. +### Private tools + +Their release assets live in private repositories, so installing one needs a +read-only GitHub token in the **environment**: `HOMEBREW_GITHUB_API_TOKEN` for +Homebrew, `GITHUB_TOKEN` for mise. Export it from your secret store; never pass +it as a command-line argument or put it in a URL. + +Homebrew fetches these assets with `lib/github_private_release_download_strategy.rb`, +which hands the token to curl through a 0600 header file, never on curl's +command line. It refuses to run with `HOMEBREW_CURL_VERBOSE` or +`HOMEBREW_CURLRC` set, since either can print request headers. + +Pin private tools to a tag: mise's "latest" skips prereleases such as +`v1.0.0-rc.46`. + ## Layout - `Casks/` — GUI app casks (`.dmg`/`.zip`/`.pkg` artifacts) diff --git a/lib/github_private_release_download_strategy.rb b/lib/github_private_release_download_strategy.rb new file mode 100644 index 0000000..327b889 --- /dev/null +++ b/lib/github_private_release_download_strategy.rb @@ -0,0 +1,82 @@ +# typed: false +# frozen_string_literal: true + +require "download_strategy" +require "json" +require "tempfile" + +# Downloads a release asset of a private GitHub repository through the +# release-asset API, authenticated by HOMEBREW_GITHUB_API_TOKEN. +# +# The token reaches curl only through a header file (`--header @file`, mode +# 0600, deleted after use). It is never on curl's argv, so it never shows in a +# process list or in the command line Homebrew prints when curl fails, and it is +# never part of a URL. curl does not resend the header after the cross-host +# redirect to the signed asset URL. +# +# A formula names the asset by its browser URL and selects this strategy: +# url "https://github.com///releases/download//", +# using: GitHubPrivateReleaseDownloadStrategy +class GitHubPrivateReleaseDownloadStrategy < CurlDownloadStrategy + URL_PATTERN = %r{\Ahttps://github\.com/([^/]+)/([^/]+)/releases/download/([^/]+)/([^/]+)\z} + + def initialize(url, name, version, **meta) + super + @owner, @repo, @tag, @asset = URL_PATTERN.match(url)&.captures + raise CurlDownloadStrategyError, "not a GitHub release-asset URL: #{url}" unless @asset + end + + # The browser URL of a private asset is not readable without auth, so nothing + # is probed before the download: no unauthenticated HEAD request. + def resolve_url_basename_time_file_size(url, timeout: nil) + [url, @asset, nil, nil, nil, false] + end + + private + + def _fetch(url:, resolved_url:, timeout:) + with_auth_header do + curl_download "https://api.github.com/repos/#{@owner}/#{@repo}/releases/assets/#{asset_id}", + "--header", "Accept: application/octet-stream", + to: temporary_path, timeout: + end + end + + def asset_id + release = JSON.parse(curl_output("--header", "Accept: application/vnd.github+json", + "https://api.github.com/repos/#{@owner}/#{@repo}/releases/tags/#{@tag}").stdout) + asset = release["assets"]&.find { |a| a["name"] == @asset } + return asset["id"] if asset + + reason = release["message"] || "no asset named #{@asset}" + raise CurlDownloadStrategyError, "#{@owner}/#{@repo} release #{@tag}: #{reason}" + end + + def with_auth_header + token = Homebrew::EnvConfig.github_api_token + if token.blank? + raise CurlDownloadStrategyError, + "#{@owner}/#{@repo} is private: set HOMEBREW_GITHUB_API_TOKEN to a read-only token" + end + # curl's --verbose, and options a user curlrc can add, print request headers. + if Homebrew::EnvConfig.curl_verbose? || Homebrew::EnvConfig.curlrc + raise CurlDownloadStrategyError, + "#{@owner}/#{@repo}: unset HOMEBREW_CURL_VERBOSE and HOMEBREW_CURLRC; they would print the token" + end + + Tempfile.create("brew-github-auth") do |file| + file.write("Authorization: Bearer #{token}\n") + file.flush + @auth_header_file = file.path + yield + ensure + @auth_header_file = nil + end + end + + def _curl_args + args = super + args += ["--header", "@#{@auth_header_file}"] if @auth_header_file + args + end +end