Merge branch 'main' into fix/ci-singleton-bucket-oom-chunking

This commit is contained in:
Muhammad Mustaqeem
2026-08-13 23:57:21 +05:00
committed by GitHub
1045 changed files with 52750 additions and 18940 deletions
+18 -16
View File
@@ -25,13 +25,16 @@
* (packages/natives/scripts/build-bindings.ts) against the installed VS Build
* Tools; every other target on a win32 host fails fast with guidance.
*
* Set `OMP_NATIVE_BUILD_BACKEND=cargo` to route the host target through the
* same local N-API build on systems where Bazel's prebuilt host tools cannot run.
*
* Note: musl addons intentionally reuse the plain linux-<arch> filenames, so a
* `linux-all` copy overwrites the gnu addon with the musl one (and vice versa);
* CI jobs that ship files always request an explicit disjoint target set.
*/
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { detectHostAvx2Support } from "./host-detect";
import { detectHostAvx2Support, resolveLocalHostAddon } from "./host-detect";
const repoRoot = path.join(import.meta.dir, "..");
@@ -221,14 +224,10 @@ async function installAddon(sourcePath: string, destPath: string): Promise<void>
}
}
/**
* win32-host path for the `host` pseudo-target: the bazel msvc cross toolchain
* cannot run here, but real MSVC can — build the addon via the napi local
* build and install it into destDir like the bazel path would.
*/
async function buildWindowsHostAddon(host: HostInfo, destDir: string): Promise<void> {
/** Build and install the host addon through the local Cargo/N-API path. */
async function buildLocalHostAddon(host: HostInfo, destDir: string): Promise<void> {
const script = path.join(repoRoot, "packages/natives/scripts/build-bindings.ts");
console.log(`win32 host: bazel msvc toolchain is linux/mac-only; building via ${path.relative(repoRoot, script)}`);
console.log(`local host build: using ${path.relative(repoRoot, script)}`);
const proc = Bun.spawn([process.execPath, script], {
cwd: repoRoot,
stdout: "inherit",
@@ -237,7 +236,7 @@ async function buildWindowsHostAddon(host: HostInfo, destDir: string): Promise<v
const exitCode = await proc.exited;
if (exitCode !== 0) process.exit(exitCode || 1);
const filename = `pi_natives.win32-x64-${host.avx2 ? "modern" : "baseline"}.node`;
const filename = resolveLocalHostAddon(host).filename;
const builtPath = path.join(repoRoot, "packages/natives/native", filename);
if (path.dirname(builtPath) !== destDir) {
await fs.mkdir(destDir, { recursive: true });
@@ -251,15 +250,18 @@ async function main(): Promise<void> {
const host: HostInfo = { platform: process.platform, arch: process.arch, avx2: detectHostAvx2Support() };
const destDir = options.dest ? path.resolve(options.dest) : path.join(repoRoot, "packages/natives/native");
if (host.platform === "win32" && !options.source) {
if ((host.platform === "win32" || Bun.env.OMP_NATIVE_BUILD_BACKEND === "cargo") && !options.source) {
if (options.targets.length !== 1 || options.targets[0] !== "host") {
throw new Error(
`Cannot bazel-build [${options.targets.join(", ")}] on a Windows host: the msvc cross ` +
"toolchain (bazel/toolchains/msvc) only runs on linux/mac exec hosts. Use `host` here " +
"(local napi build via VS Build Tools), or run this script from WSL/linux for cross targets.",
);
if (host.platform === "win32") {
throw new Error(
`Cannot bazel-build [${options.targets.join(", ")}] on a Windows host: the msvc cross ` +
"toolchain (bazel/toolchains/msvc) only runs on linux/mac exec hosts. Use `host` here " +
"(local napi build via VS Build Tools), or run this script from WSL/linux for cross targets.",
);
}
throw new Error("OMP_NATIVE_BUILD_BACKEND=cargo supports only the host target");
}
await buildWindowsHostAddon(host, destDir);
await buildLocalHostAddon(host, destDir);
return;
}
let outputs: string[];
+2 -1
View File
@@ -14,6 +14,7 @@
*/
import * as path from "node:path";
import { USER_AGENT } from "@oh-my-pi/pi-utils";
const PROVIDER_FILE = path.join(import.meta.dir, "../packages/catalog/src/wire/gemini-headers.ts");
@@ -36,7 +37,7 @@ async function fetchLatestGitHubRelease(
try {
// /releases/latest only returns non-prerelease, non-draft releases
const res = await fetch(`https://api.github.com/repos/${repo}/releases/latest`, {
headers: { Accept: "application/vnd.github+json", "User-Agent": "oh-my-pi/version-check" },
headers: { Accept: "application/vnd.github+json", "User-Agent": USER_AGENT },
});
if (!res.ok) return null;
const data = (await res.json()) as { tag_name?: string };
+26
View File
@@ -0,0 +1,26 @@
import { describe, expect, test } from "bun:test";
import { BUN2NIX_NPM_SPEC, resolveNixBunDepsGenerator } from "./gen-nix-bun";
describe("resolveNixBunDepsGenerator", () => {
test("prefers bun2nix from the active development shell", () => {
const generator = resolveNixBunDepsGenerator(command => {
if (command === "bun2nix") return "/nix/store/bun2nix";
return "/nix/store/nix";
});
expect(generator).toEqual({ kind: "bun2nix", executable: "/nix/store/bun2nix" });
});
test("falls back to entering the Nix development shell", () => {
const generator = resolveNixBunDepsGenerator(command => (command === "nix" ? "/usr/bin/nix" : null));
expect(generator).toEqual({ kind: "nix", executable: "/usr/bin/nix" });
});
test("falls back to the pinned portable bunx package", () => {
expect(resolveNixBunDepsGenerator(() => null)).toEqual({
kind: "bunx",
package: BUN2NIX_NPM_SPEC,
});
});
});
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env bun
import * as path from "node:path";
import { $ } from "bun";
import { $which } from "../packages/utils/src/which";
const repoRoot = path.join(import.meta.dir, "..");
/** Pinned npm package matching flake.lock's bun2nix revision (`0f2a1f…`). */
export const BUN2NIX_NPM_SPEC = "bun2nix@2.1.2";
type FindExecutable = (command: string) => string | null;
/** The executable path and invocation mode for the pinned Bun dependency generator. */
export type NixBunDepsGenerator =
| { kind: "bun2nix"; executable: string }
| { kind: "nix"; executable: string }
| { kind: "bunx"; package: typeof BUN2NIX_NPM_SPEC };
/** Resolve the generator needed by releases before they mutate repository state. */
export function resolveNixBunDepsGenerator(findExecutable: FindExecutable = $which): NixBunDepsGenerator {
const bun2nix = findExecutable("bun2nix");
if (bun2nix) return { kind: "bun2nix", executable: bun2nix };
const nix = findExecutable("nix");
if (nix) return { kind: "nix", executable: nix };
return { kind: "bunx", package: BUN2NIX_NPM_SPEC };
}
/** Regenerate the checked-in Bun dependency expression with the pinned bun2nix input. */
export async function generateNixBunDeps(generator: NixBunDepsGenerator = resolveNixBunDepsGenerator()): Promise<void> {
if (generator.kind === "bun2nix") {
await $`${generator.executable} -l bun.lock -c ../ -o nix/bun.nix`.cwd(repoRoot);
return;
}
if (generator.kind === "nix") {
await $`${generator.executable} --extra-experimental-features ${"nix-command flakes"} --accept-flake-config develop --command bun2nix -l bun.lock -c ../ -o nix/bun.nix`.cwd(
repoRoot,
);
return;
}
await $`bunx ${generator.package} -l bun.lock -c ../ -o nix/bun.nix`.cwd(repoRoot);
}
if (import.meta.main) await generateNixBunDeps();
+20
View File
@@ -10,7 +10,27 @@ function runCommand(command: string, args: string[]): string | null {
return null;
}
}
/** Local N-API addon identity derived from a host platform and ISA. */
export interface LocalHostAddon {
readonly filename: string;
readonly x64Variant: "modern" | "baseline" | null;
}
/** Resolve the exact filename and x86-64 ISA emitted by the local N-API build. */
export function resolveLocalHostAddon(host: {
readonly platform: string;
readonly arch: string;
readonly avx2: boolean;
}): LocalHostAddon {
const x64Variant = host.arch === "x64" ? (host.avx2 ? "modern" : "baseline") : null;
const variantSuffix = x64Variant ? `-${x64Variant}` : "";
return {
filename: `pi_natives.${host.platform}-${host.arch}${variantSuffix}.node`,
x64Variant,
};
}
/** Detect whether this x86-64 host can run the modern AVX2 addon. */
export function detectHostAvx2Support(): boolean {
if (process.arch !== "x64") return false;
+5
View File
@@ -11,6 +11,7 @@
import { $, Glob } from "bun";
import { compareVersions } from "../packages/utils/src/version.ts";
import { runChangelogFixer } from "./fix-changelogs";
import { generateNixBunDeps, resolveNixBunDepsGenerator } from "./gen-nix-bun";
const changelogGlob = new Glob("packages/*/CHANGELOG.md");
const packageJsonGlob = new Glob("packages/*/package.json");
@@ -241,6 +242,9 @@ async function cmdRelease(versionOrBump: string): Promise<void> {
}
console.log(" Working directory clean");
const nixBunDepsGenerator = resolveNixBunDepsGenerator();
console.log(` Nix dependency generator: ${nixBunDepsGenerator.kind}`);
const latestTag = (await git(["describe", "--tags", "--abbrev=0", "--match", "v*"]).text()).trim();
let version = versionOrBump;
if (version === "major" || version === "minor" || version === "patch") {
@@ -341,6 +345,7 @@ async function cmdRelease(versionOrBump: string): Promise<void> {
await $`rm -f bun.lock`;
await $`bun install`;
await $`cargo generate-lockfile`;
await generateNixBunDeps(nixBunDepsGenerator);
console.log();
// 5. Update changelogs
+1 -1
View File
@@ -417,7 +417,7 @@ export function makeOpenRouterRewriter(opts: OpenRouterOptions): RewriteChunk {
Authorization: `Bearer ${opts.apiKey}`,
"Content-Type": "application/json",
"HTTP-Referer": "https://omp.sh/",
"X-Title": "Oh-My-Pi",
"X-Title": "omp",
},
body,
});