From 7f308c957b0d53aafa7f9b73ba1dd69f1fefd24e Mon Sep 17 00:00:00 2001 From: Rohit Ghumare Date: Thu, 1 Oct 2026 17:31:57 +0530 Subject: [PATCH 1/6] feat(cli): verify the iii engine download against pinned SHA-256 hashes The automatic engine installer now downloads the release archive, checks its SHA-256 against a hash pinned in the CLI for each platform of iii v0.22.1, and only then extracts it. A mismatch deletes the download and prints the manual install command, which also verifies the hash before extracting. A version or platform without a pinned hash is not auto-installed. The hashes match the .sha256 assets of the iii-hq/iii v0.22.1 release and the archives themselves. --- README.md | 4 +- eval/scripts/sandbox.sh | 4 +- src/cli.ts | 41 ++++++++--- src/cli/engine-install.ts | 116 ++++++++++++++++++++++++++--- test/engine-install.test.ts | 143 +++++++++++++++++++++++++++++------- 5 files changed, 260 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 4fa80f5eeb..811f8620aa 100644 --- a/README.md +++ b/README.md @@ -795,12 +795,14 @@ This starts agentmemory with a local `iii-engine` if the pinned binary is alread Install `iii-engine` manually. **agentmemory currently pins `iii-engine` to `v0.22.1`**, the same release as its `iii-sdk` dependency; the worker speaks that engine's wire protocol, and 0.20.0 reorganized the SDK surface, so the two move together in agentmemory releases. Override with `AGENTMEMORY_III_VERSION=` if you run your own engine and know it matches. -- **macOS arm64:** `mkdir -p ~/.local/bin && curl -fsSL https://github.com/iii-hq/iii/releases/download/iii/v0.22.1/iii-aarch64-apple-darwin.tar.gz | tar -xz -C ~/.local/bin && chmod +x ~/.local/bin/iii` +- **macOS arm64:** `mkdir -p ~/.local/bin && curl -fsSLo iii.tar.gz https://github.com/iii-hq/iii/releases/download/iii/v0.22.1/iii-aarch64-apple-darwin.tar.gz && echo "2b309019b909a896cae874dc947e2cdf877b4f3c51dd026b79850af858517fa4 iii.tar.gz" | shasum -a 256 -c - && tar -xzf iii.tar.gz -C ~/.local/bin && chmod +x ~/.local/bin/iii` - **macOS x64:** swap `aarch64-apple-darwin` for `x86_64-apple-darwin` - **Linux x64:** swap for `x86_64-unknown-linux-gnu` - **Linux arm64:** swap for `aarch64-unknown-linux-gnu` - **Windows:** download `iii-x86_64-pc-windows-msvc.zip` from [iii-hq/iii releases v0.22.1](https://github.com/iii-hq/iii/releases/tag/iii%2Fv0.22.1) and extract `iii.exe` to `%USERPROFILE%\.agentmemory\bin\iii.exe` +Every archive has a matching `.sha256` file on the release page; when you swap the platform, use that file's hash in the check above (on Windows: `Get-FileHash`). The automatic installer in `npx @agentmemory/agentmemory` pins these hashes and refuses an archive that does not match. + Or use Docker (the bundled `docker-compose.yml` pulls `iiidev/iii:0.22.1`). Full docs: [iii.dev/docs](https://iii.dev/docs). ### Windows diff --git a/eval/scripts/sandbox.sh b/eval/scripts/sandbox.sh index 7d030c2d01..2cf6edeea6 100755 --- a/eval/scripts/sandbox.sh +++ b/eval/scripts/sandbox.sh @@ -14,7 +14,9 @@ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" if ! command -v iii >/dev/null 2>&1; then echo "iii binary not on PATH. Install pinned version:" - echo " curl -fsSL https://github.com/iii-hq/iii/releases/download/iii/v0.22.1/iii-aarch64-apple-darwin.tar.gz | tar -xz -C ~/.local/bin" + echo ' curl -fsSLo iii.tar.gz https://github.com/iii-hq/iii/releases/download/iii/v0.22.1/iii-aarch64-apple-darwin.tar.gz' + echo ' echo "2b309019b909a896cae874dc947e2cdf877b4f3c51dd026b79850af858517fa4 iii.tar.gz" | shasum -a 256 -c - && tar -xzf iii.tar.gz -C ~/.local/bin' + echo ' (other platforms: check the matching .sha256 file on the release page before extracting)' exit 1 fi diff --git a/src/cli.ts b/src/cli.ts index 9ff18051ee..5557b696d9 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -56,7 +56,7 @@ import { type RemoveOptions, } from "./cli/remove-plan.js"; import { portFlagSuffix } from "./cli/ready-hint.js"; -import { describeInstallFailure, iiiInstallShellCommand, iiiManualInstallCommand, III_INSTALL_SPAWN_TIMEOUT_MS } from "./cli/engine-install.js"; +import { expectedIiiSha256, iiiManualInstallCommand, installIiiArchive } from "./cli/engine-install.js"; import { dockerComposeArgs, dockerProjectName, @@ -1311,6 +1311,7 @@ async function runIiiInstaller(): Promise<{ ok: boolean; binPath: string | null p.log.info( `Auto-install unavailable on ${platform()} — ${asset} isn't tar-compatible. Install manually:\n` + ` 1. Download ${releaseUrl}\n` + + ` Its SHA-256 must be ${expectedIiiSha256(IIPINNED_VERSION, asset ?? "") ?? `the value in ${releaseUrl.replace(/\.zip$/, ".sha256")}`}\n` + ` 2. Extract iii.exe and place it on PATH (e.g. %USERPROFILE%\\.local\\bin)\n` + `Or use Docker: docker pull iiidev/iii:${IIPINNED_VERSION}`, ); @@ -1333,17 +1334,31 @@ async function runIiiInstaller(): Promise<{ ok: boolean; binPath: string | null const label = `Installing iii-engine v${IIPINNED_VERSION} (pinned)`; const spinner = p.spinner(); spinner.start(label); - const result = spawnSync( - shBin, - ["-c", iiiInstallShellCommand(releaseUrl, binDir, binPath)], - { stdio: "pipe", encoding: "utf-8", timeout: III_INSTALL_SPAWN_TIMEOUT_MS }, - ); - if (result.status !== 0) { + const outcome = installIiiArchive({ + sh: shBin, + releaseUrl, + version: IIPINNED_VERSION, + asset: asset ?? "", + binDir, + binPath, + }); + if (!outcome.ok) { spinner.stop(`${label} ${pc.red("✗")}`); + const sha256 = expectedIiiSha256(IIPINNED_VERSION, asset ?? ""); + const heading = + outcome.reason === "checksum" + ? "iii-engine download failed verification" + : outcome.reason === "no-checksum" + ? "iii-engine auto-install skipped" + : "iii-engine download failed"; + const checksumHint = sha256 + ? "" + : `Compare the archive against ${releaseUrl.replace(/\.(tar\.gz|zip)$/, ".sha256")} before extracting.\n`; p.log.warn( - `iii-engine download failed: ${describeInstallFailure(result).slice(0, 300)}\n` + + `${heading}: ${outcome.detail.slice(0, 300)}\n` + `Install it manually, then re-run agentmemory:\n` + - ` ${iiiManualInstallCommand(releaseUrl, binDir, binPath)}\n` + + ` ${iiiManualInstallCommand(releaseUrl, binDir, binPath, sha256)}\n` + + checksumHint + `Or use Docker: docker pull iiidev/iii:${IIPINNED_VERSION}`, ); return { ok: false, binPath: null }; @@ -1837,12 +1852,18 @@ async function reconcilePersistedDockerEngine(): Promise { function installInstructions(): string[] { const releaseUrl = iiiReleaseUrl(); if (IS_WINDOWS) { + const asset = iiiReleaseAsset() ?? ""; + const sha256 = expectedIiiSha256(IIPINNED_VERSION, asset); + const verify = sha256 + ? ` Verify before extracting: (Get-FileHash .\\${asset}).Hash must be ${sha256.toUpperCase()}` + : ` Verify before extracting against the matching .sha256 file on the release page`; return [ `agentmemory needs iii-engine v${IIPINNED_VERSION}. Pick one:`, "", " A) Download the prebuilt Windows binary:", ` 1. Open https://github.com/iii-hq/iii/releases/tag/iii%2Fv${IIPINNED_VERSION}`, ` 2. Download iii-x86_64-pc-windows-msvc.zip (or iii-aarch64-pc-windows-msvc.zip on ARM)`, + verify, " 3. Extract iii.exe to %USERPROFILE%\\.local\\bin\\iii.exe (or add to PATH)", " 4. Re-run: npx @agentmemory/agentmemory", "", @@ -1855,7 +1876,7 @@ function installInstructions(): string[] { ]; } const linuxInstall = releaseUrl - ? ` A) mkdir -p ~/.agentmemory/bin && curl -fsSL "${releaseUrl}" | tar -xz -C ~/.agentmemory/bin && chmod +x ~/.agentmemory/bin/iii` + ? ` A) ${iiiManualInstallCommand(releaseUrl, agentmemoryBinDir(), privateIiiPath(), expectedIiiSha256(IIPINNED_VERSION, iiiReleaseAsset() ?? ""))}` : ` A) Manual download: https://github.com/iii-hq/iii/releases/tag/iii%2Fv${IIPINNED_VERSION}`; return [ `agentmemory needs iii-engine v${IIPINNED_VERSION}. Pick one:`, diff --git a/src/cli/engine-install.ts b/src/cli/engine-install.ts index db1b38b49f..e7af439589 100644 --- a/src/cli/engine-install.ts +++ b/src/cli/engine-install.ts @@ -1,32 +1,71 @@ +import { spawnSync } from "node:child_process"; +import { createHash } from "node:crypto"; +import { readFileSync, rmSync } from "node:fs"; +import { join } from "node:path"; + export const III_INSTALL_CONNECT_TIMEOUT_S = 15; export const III_INSTALL_MAX_TIME_S = 300; export const III_INSTALL_SPAWN_TIMEOUT_MS = (III_INSTALL_CONNECT_TIMEOUT_S + III_INSTALL_MAX_TIME_S + 30) * 1000; +type ChecksumTable = Readonly>>>; + +export const III_RELEASE_SHA256: ChecksumTable = { + "0.22.1": { + "iii-aarch64-apple-darwin.tar.gz": "2b309019b909a896cae874dc947e2cdf877b4f3c51dd026b79850af858517fa4", + "iii-x86_64-apple-darwin.tar.gz": "6d33940db2d3ad6a9aef9837aa5b89bf5c5e4acd0679e8178fec258af229d7e1", + "iii-x86_64-unknown-linux-gnu.tar.gz": "34d4bd2ec1873e6114bb836be7db9cb3f410d0d63353d240917f0bc9c30df13b", + "iii-aarch64-unknown-linux-gnu.tar.gz": "87efc60210c1580ef2e11b13c679a4dad91917a9d80f737c5ba7e3475b3ca413", + "iii-armv7-unknown-linux-gnueabihf.tar.gz": "af5dfc45149678c647e5adaca55c055428eebfa73d65884b052c30c98abcfd19", + "iii-x86_64-pc-windows-msvc.zip": "d862bf7cf1e864f3290c8a6fc17c308c6ecac097cb2666e4a739efc0040aae96", + "iii-aarch64-pc-windows-msvc.zip": "4777a48cee3fc1a742daee929e3d943df09e4ddd3357d27a33d31c9dc9e520ac", + }, +}; + +export function expectedIiiSha256( + version: string, + asset: string, + checksums: ChecksumTable = III_RELEASE_SHA256, +): string | null { + return checksums[version]?.[asset] ?? null; +} + +export function sha256File(path: string): string { + return createHash("sha256").update(readFileSync(path)).digest("hex"); +} + function curlTimeoutFlags(): string { return `--connect-timeout ${III_INSTALL_CONNECT_TIMEOUT_S} --max-time ${III_INSTALL_MAX_TIME_S}`; } -export function iiiInstallShellCommand( - releaseUrl: string, - binDir: string, - binPath: string, -): string { - const archive = `${binDir}/.iii-download.tar.gz`; +export function iiiArchivePath(binDir: string): string { + return join(binDir, ".iii-download.tar.gz"); +} + +export function iiiDownloadShellCommand(releaseUrl: string, binDir: string): string { + const archive = iiiArchivePath(binDir); return [ `mkdir -p "${binDir}"`, `rm -f "${archive}"`, - `if curl -fsSL ${curlTimeoutFlags()} -o "${archive}" "${releaseUrl}" && tar -xzf "${archive}" -C "${binDir}"; then rm -f "${archive}"; else code=$?; rm -f "${archive}"; exit $code; fi`, - `chmod +x "${binPath}"`, + `if curl -fsSL ${curlTimeoutFlags()} -o "${archive}" "${releaseUrl}"; then :; else code=$?; rm -f "${archive}"; exit $code; fi`, ].join(" && "); } +export function iiiExtractShellCommand(binDir: string, binPath: string): string { + const archive = iiiArchivePath(binDir); + return `if tar -xzf "${archive}" -C "${binDir}"; then rm -f "${archive}"; else code=$?; rm -f "${archive}"; exit $code; fi && chmod +x "${binPath}"`; +} + export function iiiManualInstallCommand( releaseUrl: string, binDir: string, binPath: string, + sha256: string | null, ): string { - return `mkdir -p "${binDir}" && archive="$(mktemp "${binDir}/.iii-download.XXXXXX")" && { curl -fL --connect-timeout ${III_INSTALL_CONNECT_TIMEOUT_S} -o "$archive" "${releaseUrl}" && tar -xzf "$archive" -C "${binDir}"; code=$?; rm -f "$archive"; (exit $code); } && chmod +x "${binPath}"`; + const verify = sha256 + ? ` && printf '%s %s\\n' "${sha256}" "$archive" | { sha256sum -c - 2>/dev/null || shasum -a 256 -c -; }` + : ""; + return `mkdir -p "${binDir}" && archive="$(mktemp "${binDir}/.iii-download.XXXXXX")" && { curl -fL --connect-timeout ${III_INSTALL_CONNECT_TIMEOUT_S} -o "$archive" "${releaseUrl}"${verify} && tar -xzf "$archive" -C "${binDir}"; code=$?; rm -f "$archive"; (exit $code); } && chmod +x "${binPath}"`; } export function describeInstallFailure(result: { @@ -48,3 +87,62 @@ export function describeInstallFailure(result: { if (result.error) return result.error.message; return `installer exited with status ${result.status ?? "unknown"}`; } + +export type IiiInstallOutcome = + | { ok: true } + | { ok: false; reason: "no-checksum" | "download" | "checksum" | "extract"; detail: string }; + +export function installIiiArchive(opts: { + sh: string; + releaseUrl: string; + version: string; + asset: string; + binDir: string; + binPath: string; + env?: NodeJS.ProcessEnv; + checksums?: ChecksumTable; +}): IiiInstallOutcome { + const expected = expectedIiiSha256(opts.version, opts.asset, opts.checksums); + if (!expected) { + return { + ok: false, + reason: "no-checksum", + detail: `no pinned SHA-256 for ${opts.asset} in iii v${opts.version}, so the download cannot be verified`, + }; + } + const run = (command: string) => + spawnSync(opts.sh, ["-c", command], { + stdio: "pipe", + encoding: "utf-8", + timeout: III_INSTALL_SPAWN_TIMEOUT_MS, + env: opts.env ?? process.env, + }); + + const download = run(iiiDownloadShellCommand(opts.releaseUrl, opts.binDir)); + if (download.status !== 0) { + return { ok: false, reason: "download", detail: describeInstallFailure(download) }; + } + + const archive = iiiArchivePath(opts.binDir); + let actual: string; + try { + actual = sha256File(archive); + } catch (err) { + rmSync(archive, { force: true }); + return { ok: false, reason: "download", detail: err instanceof Error ? err.message : String(err) }; + } + if (actual !== expected) { + rmSync(archive, { force: true }); + return { + ok: false, + reason: "checksum", + detail: `SHA-256 mismatch for ${opts.asset}: expected ${expected}, got ${actual}. The download was deleted and nothing was installed`, + }; + } + + const extract = run(iiiExtractShellCommand(opts.binDir, opts.binPath)); + if (extract.status !== 0) { + return { ok: false, reason: "extract", detail: describeInstallFailure(extract) }; + } + return { ok: true }; +} diff --git a/test/engine-install.test.ts b/test/engine-install.test.ts index 04fb46056c..45c9e36da4 100644 --- a/test/engine-install.test.ts +++ b/test/engine-install.test.ts @@ -6,11 +6,17 @@ import { afterEach, describe, expect, it } from "vitest"; import { III_INSTALL_CONNECT_TIMEOUT_S, III_INSTALL_MAX_TIME_S, + III_RELEASE_SHA256, describeInstallFailure, - iiiInstallShellCommand, + expectedIiiSha256, + iiiDownloadShellCommand, iiiManualInstallCommand, + installIiiArchive, + sha256File, } from "../src/cli/engine-install.js"; +import { III_PINNED_VERSION } from "../src/version.js"; +const ASSET = "iii-x86_64-unknown-linux-gnu.tar.gz"; const sandboxes: string[] = []; function sandbox(): string { @@ -32,66 +38,149 @@ function fakeCurl(dir: string, script: string): string { return bin; } -function runInstall(dir: string, bin: string) { +function buildTarball(dir: string): string { + const staging = join(dir, "staging"); + mkdirSync(staging); + writeFileSync(join(staging, "iii"), "#!/bin/sh\necho iii\n"); + const tarball = join(dir, "iii.tar.gz"); + spawnSync("tar", ["-czf", tarball, "-C", staging, "iii"]); + return tarball; +} + +function curlServing(dir: string, tarball: string): string { + return fakeCurl( + dir, + `out=""; while [ $# -gt 0 ]; do if [ "$1" = "-o" ]; then out="$2"; fi; shift; done; cp "${tarball}" "$out"`, + ); +} + +function runInstall(dir: string, bin: string, sha256: string | null, asset = ASSET) { const binDir = join(dir, "bin"); const binPath = join(binDir, "iii"); - const result = spawnSync( - "sh", - ["-c", iiiInstallShellCommand("https://example.invalid/iii.tar.gz", binDir, binPath)], - { encoding: "utf-8", env: { ...process.env, PATH: `${bin}:${process.env.PATH}` } }, - ); - return { result, binDir, binPath }; + const checksums = sha256 ? { "9.9.9": { [ASSET]: sha256 } } : {}; + const outcome = installIiiArchive({ + sh: "sh", + releaseUrl: "https://example.invalid/iii.tar.gz", + version: "9.9.9", + asset, + binDir, + binPath, + env: { ...process.env, PATH: `${bin}:${process.env.PATH}` }, + checksums, + }); + return { outcome, binDir, binPath }; } describe("iii engine auto-installer", () => { it("passes connect and overall timeouts to curl", () => { - const cmd = iiiInstallShellCommand("https://x/iii.tar.gz", "/b", "/b/iii"); + const cmd = iiiDownloadShellCommand("https://x/iii.tar.gz", "/b"); expect(cmd).toContain(`--connect-timeout ${III_INSTALL_CONNECT_TIMEOUT_S}`); expect(cmd).toContain(`--max-time ${III_INSTALL_MAX_TIME_S}`); }); + it("pins a SHA-256 for every auto-installable asset of the pinned engine release", () => { + const pinned = III_RELEASE_SHA256[III_PINNED_VERSION]; + expect(pinned).toBeDefined(); + for (const asset of [ + "iii-aarch64-apple-darwin.tar.gz", + "iii-x86_64-apple-darwin.tar.gz", + "iii-x86_64-unknown-linux-gnu.tar.gz", + "iii-aarch64-unknown-linux-gnu.tar.gz", + "iii-armv7-unknown-linux-gnueabihf.tar.gz", + "iii-x86_64-pc-windows-msvc.zip", + "iii-aarch64-pc-windows-msvc.zip", + ]) { + expect(expectedIiiSha256(III_PINNED_VERSION, asset)).toMatch(/^[0-9a-f]{64}$/); + } + }); + it("leaves no partial binary or archive behind when the download times out", () => { const dir = sandbox(); const bin = fakeCurl( dir, 'out=""; while [ $# -gt 0 ]; do if [ "$1" = "-o" ]; then out="$2"; fi; shift; done; printf partial > "$out"; echo "curl: (28) Operation timed out" >&2; exit 28', ); - const { result, binDir, binPath } = runInstall(dir, bin); + const { outcome, binDir, binPath } = runInstall(dir, bin, "0".repeat(64)); - expect(result.status).toBe(28); + expect(outcome.ok).toBe(false); + if (!outcome.ok) { + expect(outcome.reason).toBe("download"); + expect(outcome.detail).toContain("timed out"); + } expect(existsSync(binPath)).toBe(false); expect(readdirSync(binDir)).toEqual([]); - expect(describeInstallFailure(result)).toContain("timed out"); }); - it("installs the binary when the download completes", () => { + it("installs the binary when the download matches the pinned SHA-256", () => { const dir = sandbox(); - const staging = join(dir, "staging"); - mkdirSync(staging); - writeFileSync(join(staging, "iii"), "#!/bin/sh\necho iii\n"); - const tarball = join(dir, "iii.tar.gz"); - spawnSync("tar", ["-czf", tarball, "-C", staging, "iii"]); - const bin = fakeCurl( - dir, - `out=""; while [ $# -gt 0 ]; do if [ "$1" = "-o" ]; then out="$2"; fi; shift; done; cp "${tarball}" "$out"`, - ); - const { result, binDir, binPath } = runInstall(dir, bin); + const tarball = buildTarball(dir); + const { outcome, binDir, binPath } = runInstall(dir, curlServing(dir, tarball), sha256File(tarball)); - expect(result.status).toBe(0); + expect(outcome).toEqual({ ok: true }); expect(existsSync(binPath)).toBe(true); expect(readdirSync(binDir)).toEqual(["iii"]); }); - it("explains a timeout without stderr and prints a copyable manual command", () => { + it("refuses to extract a download whose SHA-256 does not match", () => { + const dir = sandbox(); + const tarball = buildTarball(dir); + const wrong = "f".repeat(64); + const { outcome, binDir, binPath } = runInstall(dir, curlServing(dir, tarball), wrong); + + expect(outcome.ok).toBe(false); + if (!outcome.ok) { + expect(outcome.reason).toBe("checksum"); + expect(outcome.detail).toContain(`expected ${wrong}`); + expect(outcome.detail).toContain(`got ${sha256File(tarball)}`); + } + expect(existsSync(binPath)).toBe(false); + expect(readdirSync(binDir)).toEqual([]); + }); + + it("does not download anything for a platform or version without a pinned SHA-256", () => { + const dir = sandbox(); + const bin = fakeCurl(dir, `touch "${join(dir, "curl-called")}"; exit 1`); + const { outcome, binDir } = runInstall(dir, bin, null, "iii-riscv64-unknown-linux-gnu.tar.gz"); + + expect(outcome.ok).toBe(false); + if (!outcome.ok) expect(outcome.reason).toBe("no-checksum"); + expect(existsSync(join(dir, "curl-called"))).toBe(false); + expect(existsSync(binDir)).toBe(false); + expect(expectedIiiSha256(III_PINNED_VERSION, "iii-riscv64-unknown-linux-gnu.tar.gz")).toBeNull(); + }); + + it("explains a timeout without stderr and prints a copyable manual command that verifies the archive", () => { expect(describeInstallFailure({ status: 28, stderr: "" })).toContain("download timed out"); expect( describeInstallFailure({ status: null, error: Object.assign(new Error("x"), { code: "ETIMEDOUT" }) }), ).toContain("timed out after"); - const manual = iiiManualInstallCommand("https://x/iii.tar.gz", "/b", "/b/iii"); - expect(manual).toContain('curl -fL --connect-timeout'); + const sha = "a".repeat(64); + const manual = iiiManualInstallCommand("https://x/iii.tar.gz", "/b", "/b/iii", sha); + expect(manual).toContain("curl -fL --connect-timeout"); expect(manual).toContain('chmod +x "/b/iii"'); expect(manual).toContain('mktemp "/b/.iii-download.XXXXXX"'); expect(manual).not.toContain("/tmp/"); expect(manual).toContain('rm -f "$archive"; (exit $code)'); + expect(manual).toContain(sha); + expect(manual.indexOf(sha)).toBeLessThan(manual.indexOf("tar -xzf")); + expect(iiiManualInstallCommand("https://x/iii.tar.gz", "/b", "/b/iii", null)).not.toContain("sha256sum"); + }); + + it("the manual command stops before extraction when the checksum does not match", () => { + const dir = sandbox(); + const tarball = buildTarball(dir); + const bin = curlServing(dir, tarball); + const binDir = join(dir, "manual"); + const binPath = join(binDir, "iii"); + const run = (sha: string) => + spawnSync("sh", ["-c", iiiManualInstallCommand("https://example.invalid/iii.tar.gz", binDir, binPath, sha)], { + encoding: "utf-8", + env: { ...process.env, PATH: `${bin}:${process.env.PATH}` }, + }); + + expect(run("e".repeat(64)).status).not.toBe(0); + expect(existsSync(binPath)).toBe(false); + expect(run(sha256File(tarball)).status).toBe(0); + expect(existsSync(binPath)).toBe(true); }); }); From 9f6bd54fe934e4acbc2ed98a7a68a2535ae2c951 Mon Sep 17 00:00:00 2001 From: Rohit Ghumare Date: Thu, 1 Oct 2026 17:34:46 +0530 Subject: [PATCH 2/6] ci: pin actions to commit SHAs and set read-only permissions actions/checkout and actions/setup-node now reference the commit behind the v6 tag they already used, with the version kept next to the pin so Dependabot can update it. The CI workflow declares contents: read. --- .github/workflows/ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cbedfaa6df..3eab56a8d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} +permissions: + contents: read + jobs: test: runs-on: ${{ matrix.os }} @@ -54,10 +57,10 @@ jobs: os: [ubuntu-latest, macos-latest] node-version: [20, 22, 24, 26] steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 with: persist-credentials: false - - uses: actions/setup-node@v6 + - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 with: node-version: ${{ matrix.node-version }} # Lockfiles are gitignored, so `npm ci` (which strictly re-validates a From 94c43ec644c8d8020777304f59aa24b9db51e50a Mon Sep 17 00:00:00 2001 From: Rohit Ghumare Date: Thu, 1 Oct 2026 17:34:46 +0530 Subject: [PATCH 3/6] chore(deploy): pin base images by digest The deploy Dockerfiles pin node:22-slim and the iiidev/iii image by digest. The iii image digest is a build argument next to III_VERSION, and the build stops with a clear message when the binary in the pinned image is not III_VERSION, so the two are overridden together. The busybox init container in docker-compose.yml is pinned the same way. --- deploy/coolify/Dockerfile | 7 +++++-- deploy/fly/Dockerfile | 7 +++++-- deploy/railway/Dockerfile | 7 +++++-- deploy/render/Dockerfile | 7 +++++-- docker-compose.yml | 2 +- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/deploy/coolify/Dockerfile b/deploy/coolify/Dockerfile index c6ac809d8b..a141f3e04b 100644 --- a/deploy/coolify/Dockerfile +++ b/deploy/coolify/Dockerfile @@ -1,8 +1,9 @@ ARG III_VERSION=0.11.2 -FROM iiidev/iii:${III_VERSION} AS iii-image +ARG III_IMAGE_DIGEST=sha256:15f8d4ed16c0bec350b98f4e18ed04498b1fc5ccc50585e087b736717300cf26 +FROM iiidev/iii:${III_VERSION}@${III_IMAGE_DIGEST} AS iii-image -FROM node:22-slim +FROM node:22-slim@sha256:43ac6c60b8f89723f746e8a92ce91abd5017e627ce1ddfe4238355d3a30b772c ARG AGENTMEMORY_VERSION=0.9.29 ARG III_VERSION=0.11.2 @@ -13,6 +14,8 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* COPY --from=iii-image /app/iii /usr/local/bin/iii +RUN iii --version 2>&1 | grep -qF "${III_VERSION}" \ + || { echo "the iiidev/iii image pinned by III_IMAGE_DIGEST is not III_VERSION=${III_VERSION}: override III_IMAGE_DIGEST together with III_VERSION (docker buildx imagetools inspect iiidev/iii:${III_VERSION})" >&2; exit 1; } WORKDIR /opt/agentmemory RUN [ "${III_VERSION}" = "${III_SDK_VERSION}" ] \ diff --git a/deploy/fly/Dockerfile b/deploy/fly/Dockerfile index 4fa61c4874..8c322696b3 100644 --- a/deploy/fly/Dockerfile +++ b/deploy/fly/Dockerfile @@ -1,8 +1,9 @@ ARG III_VERSION=0.11.2 -FROM iiidev/iii:${III_VERSION} AS iii-image +ARG III_IMAGE_DIGEST=sha256:15f8d4ed16c0bec350b98f4e18ed04498b1fc5ccc50585e087b736717300cf26 +FROM iiidev/iii:${III_VERSION}@${III_IMAGE_DIGEST} AS iii-image -FROM node:22-slim +FROM node:22-slim@sha256:43ac6c60b8f89723f746e8a92ce91abd5017e627ce1ddfe4238355d3a30b772c ARG AGENTMEMORY_VERSION=0.9.29 ARG III_VERSION=0.11.2 @@ -13,6 +14,8 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* COPY --from=iii-image /app/iii /usr/local/bin/iii +RUN iii --version 2>&1 | grep -qF "${III_VERSION}" \ + || { echo "the iiidev/iii image pinned by III_IMAGE_DIGEST is not III_VERSION=${III_VERSION}: override III_IMAGE_DIGEST together with III_VERSION (docker buildx imagetools inspect iiidev/iii:${III_VERSION})" >&2; exit 1; } # Install agentmemory into a dedicated prefix so the local package.json's # `overrides` field pins iii-sdk to the exact engine release in this image diff --git a/deploy/railway/Dockerfile b/deploy/railway/Dockerfile index 4fa61c4874..8c322696b3 100644 --- a/deploy/railway/Dockerfile +++ b/deploy/railway/Dockerfile @@ -1,8 +1,9 @@ ARG III_VERSION=0.11.2 -FROM iiidev/iii:${III_VERSION} AS iii-image +ARG III_IMAGE_DIGEST=sha256:15f8d4ed16c0bec350b98f4e18ed04498b1fc5ccc50585e087b736717300cf26 +FROM iiidev/iii:${III_VERSION}@${III_IMAGE_DIGEST} AS iii-image -FROM node:22-slim +FROM node:22-slim@sha256:43ac6c60b8f89723f746e8a92ce91abd5017e627ce1ddfe4238355d3a30b772c ARG AGENTMEMORY_VERSION=0.9.29 ARG III_VERSION=0.11.2 @@ -13,6 +14,8 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* COPY --from=iii-image /app/iii /usr/local/bin/iii +RUN iii --version 2>&1 | grep -qF "${III_VERSION}" \ + || { echo "the iiidev/iii image pinned by III_IMAGE_DIGEST is not III_VERSION=${III_VERSION}: override III_IMAGE_DIGEST together with III_VERSION (docker buildx imagetools inspect iiidev/iii:${III_VERSION})" >&2; exit 1; } # Install agentmemory into a dedicated prefix so the local package.json's # `overrides` field pins iii-sdk to the exact engine release in this image diff --git a/deploy/render/Dockerfile b/deploy/render/Dockerfile index 4fa61c4874..8c322696b3 100644 --- a/deploy/render/Dockerfile +++ b/deploy/render/Dockerfile @@ -1,8 +1,9 @@ ARG III_VERSION=0.11.2 -FROM iiidev/iii:${III_VERSION} AS iii-image +ARG III_IMAGE_DIGEST=sha256:15f8d4ed16c0bec350b98f4e18ed04498b1fc5ccc50585e087b736717300cf26 +FROM iiidev/iii:${III_VERSION}@${III_IMAGE_DIGEST} AS iii-image -FROM node:22-slim +FROM node:22-slim@sha256:43ac6c60b8f89723f746e8a92ce91abd5017e627ce1ddfe4238355d3a30b772c ARG AGENTMEMORY_VERSION=0.9.29 ARG III_VERSION=0.11.2 @@ -13,6 +14,8 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* COPY --from=iii-image /app/iii /usr/local/bin/iii +RUN iii --version 2>&1 | grep -qF "${III_VERSION}" \ + || { echo "the iiidev/iii image pinned by III_IMAGE_DIGEST is not III_VERSION=${III_VERSION}: override III_IMAGE_DIGEST together with III_VERSION (docker buildx imagetools inspect iiidev/iii:${III_VERSION})" >&2; exit 1; } # Install agentmemory into a dedicated prefix so the local package.json's # `overrides` field pins iii-sdk to the exact engine release in this image diff --git a/docker-compose.yml b/docker-compose.yml index f0be2cc5b6..d289b92f53 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: # restart — the exact symptom v0.9.7's working-directory fix set out # to solve. Runs once at compose-up and exits. iii-init: - image: busybox:1.36 + image: busybox:1.36@sha256:73aaf090f3d85aa34ee199857f03fa3a95c8ede2ffd4cc2cdb5b94e566b11662 user: "0:0" environment: AGENTMEMORY_DOCKER_UID: "${AGENTMEMORY_DOCKER_UID:-65532}" From 05063b1251a8ba67f341b028dc1559281bdd2c41 Mon Sep 17 00:00:00 2001 From: Rohit Ghumare Date: Thu, 1 Oct 2026 17:36:17 +0530 Subject: [PATCH 4/6] fix(cli): pass engine installer paths to the shell as arguments The download and extract scripts are now fixed strings, and the release URL, install directory, archive and binary paths reach them as positional arguments, so a home directory containing shell syntax is never evaluated. --- src/cli/engine-install.ts | 24 +++++++++--------------- test/engine-install.test.ts | 24 +++++++++++++++++++++++- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/cli/engine-install.ts b/src/cli/engine-install.ts index e7af439589..843c1d1507 100644 --- a/src/cli/engine-install.ts +++ b/src/cli/engine-install.ts @@ -42,18 +42,12 @@ export function iiiArchivePath(binDir: string): string { return join(binDir, ".iii-download.tar.gz"); } -export function iiiDownloadShellCommand(releaseUrl: string, binDir: string): string { - const archive = iiiArchivePath(binDir); - return [ - `mkdir -p "${binDir}"`, - `rm -f "${archive}"`, - `if curl -fsSL ${curlTimeoutFlags()} -o "${archive}" "${releaseUrl}"; then :; else code=$?; rm -f "${archive}"; exit $code; fi`, - ].join(" && "); +export function iiiDownloadShellCommand(): string { + return `mkdir -p "$2" && rm -f "$3" && if curl -fsSL ${curlTimeoutFlags()} -o "$3" "$1"; then :; else code=$?; rm -f "$3"; exit $code; fi`; } -export function iiiExtractShellCommand(binDir: string, binPath: string): string { - const archive = iiiArchivePath(binDir); - return `if tar -xzf "${archive}" -C "${binDir}"; then rm -f "${archive}"; else code=$?; rm -f "${archive}"; exit $code; fi && chmod +x "${binPath}"`; +export function iiiExtractShellCommand(): string { + return 'if tar -xzf "$1" -C "$2"; then rm -f "$1"; else code=$?; rm -f "$1"; exit $code; fi && chmod +x "$3"'; } export function iiiManualInstallCommand( @@ -110,20 +104,20 @@ export function installIiiArchive(opts: { detail: `no pinned SHA-256 for ${opts.asset} in iii v${opts.version}, so the download cannot be verified`, }; } - const run = (command: string) => - spawnSync(opts.sh, ["-c", command], { + const run = (script: string, args: string[]) => + spawnSync(opts.sh, ["-c", script, "sh", ...args], { stdio: "pipe", encoding: "utf-8", timeout: III_INSTALL_SPAWN_TIMEOUT_MS, env: opts.env ?? process.env, }); - const download = run(iiiDownloadShellCommand(opts.releaseUrl, opts.binDir)); + const archive = iiiArchivePath(opts.binDir); + const download = run(iiiDownloadShellCommand(), [opts.releaseUrl, opts.binDir, archive]); if (download.status !== 0) { return { ok: false, reason: "download", detail: describeInstallFailure(download) }; } - const archive = iiiArchivePath(opts.binDir); let actual: string; try { actual = sha256File(archive); @@ -140,7 +134,7 @@ export function installIiiArchive(opts: { }; } - const extract = run(iiiExtractShellCommand(opts.binDir, opts.binPath)); + const extract = run(iiiExtractShellCommand(), [archive, opts.binDir, opts.binPath]); if (extract.status !== 0) { return { ok: false, reason: "extract", detail: describeInstallFailure(extract) }; } diff --git a/test/engine-install.test.ts b/test/engine-install.test.ts index 45c9e36da4..c02e4158a4 100644 --- a/test/engine-install.test.ts +++ b/test/engine-install.test.ts @@ -73,7 +73,7 @@ function runInstall(dir: string, bin: string, sha256: string | null, asset = ASS describe("iii engine auto-installer", () => { it("passes connect and overall timeouts to curl", () => { - const cmd = iiiDownloadShellCommand("https://x/iii.tar.gz", "/b"); + const cmd = iiiDownloadShellCommand(); expect(cmd).toContain(`--connect-timeout ${III_INSTALL_CONNECT_TIMEOUT_S}`); expect(cmd).toContain(`--max-time ${III_INSTALL_MAX_TIME_S}`); }); @@ -137,6 +137,28 @@ describe("iii engine auto-installer", () => { expect(readdirSync(binDir)).toEqual([]); }); + it("passes paths to the shell as arguments, never as script text", () => { + const dir = sandbox(); + const tarball = buildTarball(dir); + const tricky = join(dir, 'odd $(touch pwned) "dir"'); + const binPath = join(tricky, "iii"); + const outcome = installIiiArchive({ + sh: "sh", + releaseUrl: "https://example.invalid/iii.tar.gz", + version: "9.9.9", + asset: ASSET, + binDir: tricky, + binPath, + env: { ...process.env, PATH: `${curlServing(dir, tarball)}:${process.env.PATH}` }, + checksums: { "9.9.9": { [ASSET]: sha256File(tarball) } }, + }); + + expect(outcome).toEqual({ ok: true }); + expect(existsSync(binPath)).toBe(true); + expect(existsSync(join(process.cwd(), "pwned"))).toBe(false); + expect(iiiDownloadShellCommand()).not.toContain(dir); + }); + it("does not download anything for a platform or version without a pinned SHA-256", () => { const dir = sandbox(); const bin = fakeCurl(dir, `touch "${join(dir, "curl-called")}"; exit 1`); From d318a068b9b242ad8418a0c1fa567335cf97b4c2 Mon Sep 17 00:00:00 2001 From: Rohit Ghumare Date: Thu, 1 Oct 2026 18:02:20 +0530 Subject: [PATCH 5/6] chore(ci,deploy): use version tags for actions and base images Digest-pinned base images stop picking up the security patches published under node:22-slim and busybox:1.36 until someone bumps the digest, and the CI workflow runs with read-only permissions and no secrets, so SHA pins on its actions add upkeep without protecting anything that matters. Actions and images go back to version tags. The CI workflow keeps contents: read, and the deploy Dockerfiles keep the check that the iii binary copied from iiidev/iii matches III_VERSION. --- .github/workflows/ci.yml | 4 ++-- deploy/coolify/Dockerfile | 7 +++---- deploy/fly/Dockerfile | 7 +++---- deploy/railway/Dockerfile | 7 +++---- deploy/render/Dockerfile | 7 +++---- docker-compose.yml | 2 +- 6 files changed, 15 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3eab56a8d9..219caac397 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,10 +57,10 @@ jobs: os: [ubuntu-latest, macos-latest] node-version: [20, 22, 24, 26] steps: - - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + - uses: actions/checkout@v6 with: persist-credentials: false - - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 + - uses: actions/setup-node@v6 with: node-version: ${{ matrix.node-version }} # Lockfiles are gitignored, so `npm ci` (which strictly re-validates a diff --git a/deploy/coolify/Dockerfile b/deploy/coolify/Dockerfile index a141f3e04b..8a100474f8 100644 --- a/deploy/coolify/Dockerfile +++ b/deploy/coolify/Dockerfile @@ -1,9 +1,8 @@ ARG III_VERSION=0.11.2 -ARG III_IMAGE_DIGEST=sha256:15f8d4ed16c0bec350b98f4e18ed04498b1fc5ccc50585e087b736717300cf26 -FROM iiidev/iii:${III_VERSION}@${III_IMAGE_DIGEST} AS iii-image +FROM iiidev/iii:${III_VERSION} AS iii-image -FROM node:22-slim@sha256:43ac6c60b8f89723f746e8a92ce91abd5017e627ce1ddfe4238355d3a30b772c +FROM node:22-slim ARG AGENTMEMORY_VERSION=0.9.29 ARG III_VERSION=0.11.2 @@ -15,7 +14,7 @@ RUN apt-get update \ COPY --from=iii-image /app/iii /usr/local/bin/iii RUN iii --version 2>&1 | grep -qF "${III_VERSION}" \ - || { echo "the iiidev/iii image pinned by III_IMAGE_DIGEST is not III_VERSION=${III_VERSION}: override III_IMAGE_DIGEST together with III_VERSION (docker buildx imagetools inspect iiidev/iii:${III_VERSION})" >&2; exit 1; } + || { echo "the iiidev/iii:${III_VERSION} image does not contain iii ${III_VERSION}" >&2; exit 1; } WORKDIR /opt/agentmemory RUN [ "${III_VERSION}" = "${III_SDK_VERSION}" ] \ diff --git a/deploy/fly/Dockerfile b/deploy/fly/Dockerfile index 8c322696b3..1a0198792b 100644 --- a/deploy/fly/Dockerfile +++ b/deploy/fly/Dockerfile @@ -1,9 +1,8 @@ ARG III_VERSION=0.11.2 -ARG III_IMAGE_DIGEST=sha256:15f8d4ed16c0bec350b98f4e18ed04498b1fc5ccc50585e087b736717300cf26 -FROM iiidev/iii:${III_VERSION}@${III_IMAGE_DIGEST} AS iii-image +FROM iiidev/iii:${III_VERSION} AS iii-image -FROM node:22-slim@sha256:43ac6c60b8f89723f746e8a92ce91abd5017e627ce1ddfe4238355d3a30b772c +FROM node:22-slim ARG AGENTMEMORY_VERSION=0.9.29 ARG III_VERSION=0.11.2 @@ -15,7 +14,7 @@ RUN apt-get update \ COPY --from=iii-image /app/iii /usr/local/bin/iii RUN iii --version 2>&1 | grep -qF "${III_VERSION}" \ - || { echo "the iiidev/iii image pinned by III_IMAGE_DIGEST is not III_VERSION=${III_VERSION}: override III_IMAGE_DIGEST together with III_VERSION (docker buildx imagetools inspect iiidev/iii:${III_VERSION})" >&2; exit 1; } + || { echo "the iiidev/iii:${III_VERSION} image does not contain iii ${III_VERSION}" >&2; exit 1; } # Install agentmemory into a dedicated prefix so the local package.json's # `overrides` field pins iii-sdk to the exact engine release in this image diff --git a/deploy/railway/Dockerfile b/deploy/railway/Dockerfile index 8c322696b3..1a0198792b 100644 --- a/deploy/railway/Dockerfile +++ b/deploy/railway/Dockerfile @@ -1,9 +1,8 @@ ARG III_VERSION=0.11.2 -ARG III_IMAGE_DIGEST=sha256:15f8d4ed16c0bec350b98f4e18ed04498b1fc5ccc50585e087b736717300cf26 -FROM iiidev/iii:${III_VERSION}@${III_IMAGE_DIGEST} AS iii-image +FROM iiidev/iii:${III_VERSION} AS iii-image -FROM node:22-slim@sha256:43ac6c60b8f89723f746e8a92ce91abd5017e627ce1ddfe4238355d3a30b772c +FROM node:22-slim ARG AGENTMEMORY_VERSION=0.9.29 ARG III_VERSION=0.11.2 @@ -15,7 +14,7 @@ RUN apt-get update \ COPY --from=iii-image /app/iii /usr/local/bin/iii RUN iii --version 2>&1 | grep -qF "${III_VERSION}" \ - || { echo "the iiidev/iii image pinned by III_IMAGE_DIGEST is not III_VERSION=${III_VERSION}: override III_IMAGE_DIGEST together with III_VERSION (docker buildx imagetools inspect iiidev/iii:${III_VERSION})" >&2; exit 1; } + || { echo "the iiidev/iii:${III_VERSION} image does not contain iii ${III_VERSION}" >&2; exit 1; } # Install agentmemory into a dedicated prefix so the local package.json's # `overrides` field pins iii-sdk to the exact engine release in this image diff --git a/deploy/render/Dockerfile b/deploy/render/Dockerfile index 8c322696b3..1a0198792b 100644 --- a/deploy/render/Dockerfile +++ b/deploy/render/Dockerfile @@ -1,9 +1,8 @@ ARG III_VERSION=0.11.2 -ARG III_IMAGE_DIGEST=sha256:15f8d4ed16c0bec350b98f4e18ed04498b1fc5ccc50585e087b736717300cf26 -FROM iiidev/iii:${III_VERSION}@${III_IMAGE_DIGEST} AS iii-image +FROM iiidev/iii:${III_VERSION} AS iii-image -FROM node:22-slim@sha256:43ac6c60b8f89723f746e8a92ce91abd5017e627ce1ddfe4238355d3a30b772c +FROM node:22-slim ARG AGENTMEMORY_VERSION=0.9.29 ARG III_VERSION=0.11.2 @@ -15,7 +14,7 @@ RUN apt-get update \ COPY --from=iii-image /app/iii /usr/local/bin/iii RUN iii --version 2>&1 | grep -qF "${III_VERSION}" \ - || { echo "the iiidev/iii image pinned by III_IMAGE_DIGEST is not III_VERSION=${III_VERSION}: override III_IMAGE_DIGEST together with III_VERSION (docker buildx imagetools inspect iiidev/iii:${III_VERSION})" >&2; exit 1; } + || { echo "the iiidev/iii:${III_VERSION} image does not contain iii ${III_VERSION}" >&2; exit 1; } # Install agentmemory into a dedicated prefix so the local package.json's # `overrides` field pins iii-sdk to the exact engine release in this image diff --git a/docker-compose.yml b/docker-compose.yml index d289b92f53..f0be2cc5b6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: # restart — the exact symptom v0.9.7's working-directory fix set out # to solve. Runs once at compose-up and exits. iii-init: - image: busybox:1.36@sha256:73aaf090f3d85aa34ee199857f03fa3a95c8ede2ffd4cc2cdb5b94e566b11662 + image: busybox:1.36 user: "0:0" environment: AGENTMEMORY_DOCKER_UID: "${AGENTMEMORY_DOCKER_UID:-65532}" From aa44961d7810ea09603289dfd111f7ea2312553f Mon Sep 17 00:00:00 2001 From: Rohit Ghumare Date: Thu, 1 Oct 2026 18:02:20 +0530 Subject: [PATCH 6/6] chore(scripts): add engine:hashes to refresh the pinned engine checksums npm run engine:hashes [version] downloads every iii release archive the CLI installs, checks each against the .sha256 file published with the release, and rewrites the III_RELEASE_SHA256 table in src/cli/engine-install.ts. Without an argument it uses III_PINNED_VERSION. An engine bump becomes: change III_PINNED_VERSION, run the script, commit. --- package.json | 1 + scripts/engine-hashes.mjs | 52 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 scripts/engine-hashes.mjs diff --git a/package.json b/package.json index 385cbd4842..148342d05e 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "test:integration": "vitest run test/integration.test.ts", "test:all": "vitest run", "skills:gen": "tsx scripts/skills/generate.ts", + "engine:hashes": "node scripts/engine-hashes.mjs", "skills:check": "tsx scripts/skills/generate.ts --check && tsx scripts/skills/check.ts", "bench:load": "node --import tsx benchmark/load-100k.ts", "eval:longmemeval": "tsx eval/runner/longmemeval.ts", diff --git a/scripts/engine-hashes.mjs b/scripts/engine-hashes.mjs new file mode 100644 index 0000000000..a18ce81137 --- /dev/null +++ b/scripts/engine-hashes.mjs @@ -0,0 +1,52 @@ +import { createHash } from "node:crypto"; +import { readFileSync, writeFileSync } from "node:fs"; + +const versionFile = new URL("../src/version.ts", import.meta.url); +const installFile = new URL("../src/cli/engine-install.ts", import.meta.url); + +const pinned = readFileSync(versionFile, "utf8").match(/III_PINNED_VERSION = "([^"]+)"/)?.[1]; +const version = process.argv[2] ?? pinned; +if (!version) { + console.error("usage: npm run engine:hashes [version]"); + process.exit(1); +} + +const assets = [ + "iii-aarch64-apple-darwin.tar.gz", + "iii-x86_64-apple-darwin.tar.gz", + "iii-x86_64-unknown-linux-gnu.tar.gz", + "iii-aarch64-unknown-linux-gnu.tar.gz", + "iii-armv7-unknown-linux-gnueabihf.tar.gz", + "iii-x86_64-pc-windows-msvc.zip", + "iii-aarch64-pc-windows-msvc.zip", +]; + +async function fetchOk(url) { + const res = await fetch(url); + if (!res.ok) throw new Error(`${url}: HTTP ${res.status}`); + return res; +} + +const base = `https://github.com/iii-hq/iii/releases/download/iii/v${version}`; +const lines = []; +for (const asset of assets) { + const archive = Buffer.from(await (await fetchOk(`${base}/${asset}`)).arrayBuffer()); + const actual = createHash("sha256").update(archive).digest("hex"); + const published = (await (await fetchOk(`${base}/${asset.replace(/\.(tar\.gz|zip)$/, "")}.sha256`)).text()).trim().split(/\s+/)[0]; + if (published !== actual) { + console.error(`${asset}: archive hashes to ${actual} but the release lists ${published}`); + process.exit(1); + } + console.log(`${asset} ${actual}`); + lines.push(` "${asset}": "${actual}",`); +} + +const source = readFileSync(installFile, "utf8"); +const table = /export const III_RELEASE_SHA256: ChecksumTable = \{\n[\s\S]*?\n\};\n/; +if (!table.test(source)) { + console.error("III_RELEASE_SHA256 table not found in src/cli/engine-install.ts"); + process.exit(1); +} +const block = `export const III_RELEASE_SHA256: ChecksumTable = {\n "${version}": {\n${lines.join("\n")}\n },\n};\n`; +writeFileSync(installFile, source.replace(table, block)); +console.log(`wrote hashes for iii v${version} to src/cli/engine-install.ts`);