Commit 744c68cd1 for llama.cpp

commit 744c68cd14a8867c6048ac7af946864c74406069
Author: Aleksander Grygier <aleksander.grygier@gmail.com>
Date:   Tue Nov 17 23:19:05 2026 +0100

    ui: publish @ggml-org/llama-ui from CI, and release 0.4.0 (#32480)

    * ui: publish @ggml-org/llama-ui from CI when its version moves

    ui/lib/ui reaches npm only when someone remembers to publish it by hand, which let 0.3.0
    sit a day behind master. The version in its package.json becomes the release: a commit
    landing on master with a version npm does not have gets built, linted and published with a
    provenance attestation, through OIDC rather than a stored token, as release-publish.yml
    already does for GitHub releases. A library change carrying no bump publishes nothing and
    says so, on the PR and on the run.

    Assisted-by: Llama Chat (unsloth/Qwen-3.8-Flash-Next:IQ4_XS)

    * ui: bump @ggml-org/llama-ui to 0.4.0

    The library on npm, published before the design system PR merged, holds no entry points for
    the Model UI, the app components or the shared constants and enums, and no dependency on
    @ggml-org/llama-brand, whose colours the primitives now build on. Consumers import the new
    subpaths and get ERR_PACKAGE_PATH_NOT_EXPORTED.

    Assisted-by: Llama Chat (unsloth/Qwen-3.8-Flash-Next:IQ4_XS)

    * ui: name no environment for the Llama UI publish job

    Creating a repository environment needs admin rights the UI maintainers do not hold, so a job
    that names one cannot be set up by them. The job works without it: npm's trusted publisher
    matches on the repository and the workflow file, and its environment field stays blank to
    match. Nothing else in the job depends on an environment.

    Assisted-by: Llama Chat (unsloth/Qwen-3.8-Flash-Next:IQ4_XS)

    * ui: address review on the Llama UI publish job

    - the advisory version check leaves ui.yml for the publish workflow, on a pull_request trigger
      whose path filter keeps it off PRs that touch only Llama Chat: a chat-only PR was told to
      bump a library it did not change
    - publish and verify run on master only. The trusted publisher matches on the repository and
      the workflow file, not the branch, so a dispatch from a PR branch - anything with write
      access can start one - could publish code no one reviewed. With no environment, this was the
      only branch protection in place.
    - the registry read after a publish retries six times rather than sleeping once, so a release
      the registry is slow to serve is not reported as a failure
    - a build metadata suffix (1.2.3+build) is not a prerelease, and versions order by semver's
      prerelease rules, so 0.4.0-beta.1 behind a released 0.4.0 is refused instead of shipped to next
    - the summary step passes its values through env like the others, actions: read is gone, and the
      concurrency comment claims only what the setting does
    - npm older than 11.5.1 is refused up front, as it cannot publish with an OIDC token

    Assisted-by: Llama Chat (unsloth/Qwen-3.8-Flash-Next:IQ4_XS)

    * ui: note the two trusted-publishing traps in the Llama UI README

    A publisher names a workflow file that must already be in .github/workflows, so it is added
    after this workflow lands rather than before, and one created now publishes only through
    staged publishing until npm publish is permitted for it. Provenance comes free with either,
    and only on a GitHub-hosted runner.

    Assisted-by: Llama Chat (unsloth/Qwen-3.8-Flash-Next:IQ4_XS)

    * Update .github/workflows/ui-lib-publish.yml

    Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>

    ---------

    Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>

diff --git a/.github/workflows/ui-lib-publish.yml b/.github/workflows/ui-lib-publish.yml
new file mode 100644
index 000000000..0faf11c4d
--- /dev/null
+++ b/.github/workflows/ui-lib-publish.yml
@@ -0,0 +1,201 @@
+name: UI Lib Publish
+
+# Publishes @ggml-org/llama-ui, the library in ui/lib/ui, to npm.
+#
+# The version in ui/lib/ui/package.json is the release. A commit that reaches master with a
+# version npm does not have builds the library and publishes it; a commit that changes the
+# library without bumping it publishes nothing and says so on the run, which is the drift that
+# let 0.3.0 sit a day behind master. Bump the version in the PR whose change should ship, and
+# this workflow does the rest.
+#
+# Auth: no npm token is stored here. The job exchanges its OIDC identity for one (npm trusted
+# publishing) and signs the tarball with a provenance attestation. release-publish.yml has done
+# the same exchange on every push to master since it landed, its actions/attest step being the
+# proof that this repository can be issued a token.
+#
+# One-time setup, before this can publish: on the package, Publishing settings, Trusted
+# Publisher, GitHub Actions, with organization ggml-org, repository llama.cpp, workflow file
+# ui-lib-publish.yml, and Environment left blank - this job names no environment, since creating
+# one needs repository admin. Merging this workflow before that exists leaves the publish step
+# red on master: the release is late rather than wrong, and re-running the job publishes it.
+
+on:
+  workflow_dispatch:
+    inputs:
+      dry_run:
+        description: 'Build and pack, but do not publish'
+        required: false
+        type: boolean
+        default: false
+  push:
+    branches:
+      - master
+    paths: [
+      '.github/workflows/ui-lib-publish.yml',
+      'ui/lib/ui/**.*'
+    ]
+  # the advisory half, so a library change without a bump is annotated on the PR rather than
+  # discovered after the merge: the path filter keeps it off PRs that touch only Llama Chat
+  pull_request:
+    types: [opened, synchronize, reopened]
+    paths: [
+      '.github/workflows/ui-lib-publish.yml',
+      'ui/lib/ui/**.*'
+    ]
+
+cache-mode: none
+permissions:
+  contents: read
+  id-token: write
+
+concurrency:
+  # never cancel a run mid-publish: a version half-published cannot be taken back. GitHub holds
+  # one pending run per group, so a newer push replaces an older queued one - no release is lost,
+  # as each run reads the version from its own commit.
+  group: ${{ github.workflow }}
+  cancel-in-progress: false
+
+env:
+  LIB_DIR: ui/lib/ui
+
+jobs:
+  publish:
+    name: Publish @ggml-org/llama-ui
+    if: github.repository == 'ggml-org/llama.cpp'
+    runs-on: ubuntu-26.04-arm
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v6
+
+      - name: Setup Node.js
+        uses: actions/setup-node@v6
+        with:
+          node-version: "24"
+          registry-url: 'https://registry.npmjs.org'
+          package-manager-cache: false
+
+      - name: Check npm can publish with an OIDC token
+        run: |
+          npm -v
+          node -e '
+            const v = process.argv[1];
+            const [major, minor] = v.split(".").map(Number);
+            if (major < 11 || (major === 11 && minor < 5)) {
+              console.error(`npm ${v} cannot publish with trusted publishing: 11.5.1 or newer is needed`);
+              process.exit(1);
+            }
+          ' "$(npm -v)"
+
+      - name: Install dependencies
+        run: npm ci
+        working-directory: ${{ env.LIB_DIR }}
+
+      - name: Run type checking
+        run: npm run check
+        working-directory: ${{ env.LIB_DIR }}
+
+      - name: Build the package and lint it
+        run: npm run prepack
+        working-directory: ${{ env.LIB_DIR }}
+
+      - name: Compare the version with npm
+        id: version
+        # on a PR this is advisory and must not fail the job: a registry outage is not the
+        # contributor's mistake. On master the publish decision rests on the answer, so it fails.
+        continue-on-error: ${{ github.event_name == 'pull_request' }}
+        run: node scripts/npm-version-check.mjs
+        working-directory: ${{ env.LIB_DIR }}
+
+      - name: Note a library change that ships no new version
+        if: github.event_name == 'pull_request' && always() && steps.version.outcome == 'success' && steps.version.outputs.should_publish != 'true'
+        env:
+          NOTE: ${{ steps.version.outputs.note }}
+        run: echo "::warning::$NOTE"
+
+      - name: Publish
+        # master only. npm's trusted publisher matches on the repository and the workflow file,
+        # not the branch, so this condition is the only thing stopping a manual run from a PR
+        # branch - one that anyone with write access can start - from publishing code that no
+        # one reviewed. A dispatch on master remains the way to re-run a release.
+        if: github.ref == 'refs/heads/master' && steps.version.outputs.should_publish == 'true' && inputs.dry_run != true
+        # --ignore-scripts publishes the tarball prepack built and publint passed rather than
+        # rebuilding it here; --provenance is implied by trusted publishing and named to be
+        # explicit. A package published with nothing in it cannot be taken back, so refuse first.
+        env:
+          TAG: ${{ steps.version.outputs.tag }}
+        run: |
+          test -d dist || { echo "dist/ is missing: nothing was built, so nothing is published"; exit 1; }
+          npm publish --access public --provenance --ignore-scripts --tag "$TAG"
+        working-directory: ${{ env.LIB_DIR }}
+
+      - name: Verify it landed
+        if: github.ref == 'refs/heads/master' && steps.version.outputs.should_publish == 'true' && inputs.dry_run != true
+        env:
+          NAME: ${{ steps.version.outputs.name }}
+          VERSION: ${{ steps.version.outputs.version }}
+        run: |
+          # the registry can serve a new version some time after publish returns, so retry rather
+          # than call a release that worked a failure
+          for try in 1 2 3 4 5 6; do
+            seen=$(npm view "$NAME@$VERSION" version 2>/dev/null || true)
+            if [ "$seen" = "$VERSION" ]; then
+              echo "$NAME@$VERSION is on npm"
+              npm view "$NAME@$VERSION" dist-tags version dist.integrity
+              exit 0
+            fi
+            echo "not visible yet (attempt $try of 6)"
+            sleep 10
+          done
+          echo "::error::$NAME@$VERSION published without error but is not visible on the registry after 6 attempts. The publish did not fail: check the package on npm before publishing again."
+          exit 1
+
+      - name: Report
+        if: always()
+        # every value reaches the shell through env, not through the script, so a package name
+        # from a PR's package.json cannot inject into this step
+        env:
+          NAME: ${{ steps.version.outputs.name || '@ggml-org/llama-ui' }}
+          VERSION: ${{ steps.version.outputs.version || 'unknown' }}
+          LATEST: ${{ steps.version.outputs.latest }}
+          VERDICT: ${{ steps.version.outputs.verdict || 'not reached' }}
+          NOTE: ${{ steps.version.outputs.note }}
+          SHOULD: ${{ steps.version.outputs.should_publish }}
+          DRY: ${{ inputs.dry_run }}
+        run: |
+          if [ "$DRY" = "true" ]; then published="no (dry run)"
+          elif [ "$SHOULD" = "true" ]; then published=yes
+          else published=no
+          fi
+          {
+            echo "### $NAME $VERSION"
+            echo
+            echo "| | |"
+            echo "| --- | --- |"
+            echo "| npm latest was | ${LATEST:-nothing published yet} |"
+            echo "| verdict | \`$VERDICT\` |"
+            echo "| published | $published |"
+            echo
+            echo "> $NOTE"
+          } >> "$GITHUB_STEP_SUMMARY"
+
+      - name: Mind the verdict
+        if: always() && github.event_name != 'pull_request' && steps.version.outcome == 'success'
+        # a version going backwards is a mistake; a version not bumped is usually one too, but it
+        # is also what a stories-only commit looks like, so that only fails the run when the
+        # repository variable UI_LIB_PUBLISH_FAIL_ON_UNBUMPED is set to true
+        env:
+          NOTE: ${{ steps.version.outputs.note }}
+          VERDICT: ${{ steps.version.outputs.verdict }}
+          FAIL_ON_UNBUMPED: ${{ vars.UI_LIB_PUBLISH_FAIL_ON_UNBUMPED }}
+        run: |
+          case "$VERDICT" in
+            stale)
+              echo "::error::$NOTE"
+              exit 1 ;;
+            published)
+              if [ "$FAIL_ON_UNBUMPED" = "true" ]; then
+                echo "::error::$NOTE"
+                exit 1
+              fi
+              echo "::warning::$NOTE" ;;
+          esac
diff --git a/ui/lib/ui/README.md b/ui/lib/ui/README.md
index 6efb96756..7aee651c7 100644
--- a/ui/lib/ui/README.md
+++ b/ui/lib/ui/README.md
@@ -70,3 +70,22 @@ shows in the app at once and the app keeps no copy of a component or a token. Fo
 - `npm run dev`: a small SvelteKit check page (`src/routes`)
 - `npm run check`: svelte-check
 - `npm run prepack`: build the library into `dist/` and run publint
+- `node scripts/npm-version-check.mjs`: what the release workflow would make of this folder, against the real registry
+
+## Releases
+
+The package is published from here by
+[`ui-lib-publish.yml`](../../../.github/workflows/ui-lib-publish.yml), which runs when a commit reaches `master` with
+`ui/lib/ui` in it. The version in `package.json` is the release: land a bump together with the change that should ship
+and the workflow type-checks, builds, lints and publishes that version to npm, with a provenance attestation. A library
+change that carries no bump publishes nothing and leaves a warning on the run.
+
+- `npm version <patch|minor> --no-git-tag-version` and commit: it moves `package.json` and both version fields of the
+  lockfile together.
+- Below `1.0`: a breaking change bumps the minor, a feature bumps the patch.
+- A version with a prerelease suffix (`0.5.0-beta.1`) publishes under the `next` tag, so `latest` stays a stable build.
+- Publishing needs no token in the repo: the job trades its OIDC identity for one, so the only place to look when a
+  publish is refused is the package's trusted-publisher settings on npm. A publisher names a workflow that must already
+  exist under `.github/workflows`, so it is added after this workflow lands, and it allows staged publishing until
+  `npm publish` is permitted for it. Provenance is generated without asking, and only on a GitHub-hosted runner: a
+  self-hosted one cannot publish this way.
diff --git a/ui/lib/ui/package-lock.json b/ui/lib/ui/package-lock.json
index 543d49f6f..1a88b0fa6 100644
--- a/ui/lib/ui/package-lock.json
+++ b/ui/lib/ui/package-lock.json
@@ -1,12 +1,12 @@
 {
 	"name": "@ggml-org/llama-ui",
-	"version": "0.3.0",
+	"version": "0.4.0",
 	"lockfileVersion": 3,
 	"requires": true,
 	"packages": {
 		"": {
 			"name": "@ggml-org/llama-ui",
-			"version": "0.3.0",
+			"version": "0.4.0",
 			"license": "MIT",
 			"dependencies": {
 				"@ggml-org/llama-brand": "https://codeload.github.com/ggml-org/llama-brand/tar.gz/f05540643c1ca2a18d732ed6491c839686da9a3a",
diff --git a/ui/lib/ui/package.json b/ui/lib/ui/package.json
index f29f6d109..5a93894fb 100644
--- a/ui/lib/ui/package.json
+++ b/ui/lib/ui/package.json
@@ -1,6 +1,6 @@
 {
 	"name": "@ggml-org/llama-ui",
-	"version": "0.3.0",
+	"version": "0.4.0",
 	"description": "Shared UI library for llama.cpp frontend apps.",
 	"license": "MIT",
 	"repository": {
diff --git a/ui/lib/ui/scripts/npm-version-check.mjs b/ui/lib/ui/scripts/npm-version-check.mjs
new file mode 100644
index 000000000..e992c2e96
--- /dev/null
+++ b/ui/lib/ui/scripts/npm-version-check.mjs
@@ -0,0 +1,128 @@
+#!/usr/bin/env node
+// Decides whether this library is a version npm does not have yet, for
+// .github/workflows/ui-lib-publish.yml. It reads package.json next to its own folder, so it
+// runs from anywhere.
+//
+// The version in package.json is the release: this takes it, asks the registry what it holds,
+// and says whether to publish, under which dist-tag, and why not when not. The version already
+// being on npm is the case that let a release drift once (the library moved, the version did
+// not), so it is reported as a verdict rather than passed over in silence.
+//
+// It writes its findings to $GITHUB_OUTPUT when that is set, and always exits 0 unless the
+// registry could not be read: the workflow decides between warning and failing.
+
+import { readFileSync, appendFileSync } from 'node:fs';
+
+const REGISTRY = process.env.NPM_REGISTRY_URL ?? 'https://registry.npmjs.org';
+
+const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
+const { name, version } = pkg;
+
+if (!name || !version) {
+	console.error(`package.json holds no name or version (got ${name}@${version})`);
+	process.exit(1);
+}
+
+// @scoped/name goes in the registry path with only the slash escaped
+const url = `${REGISTRY}/${name.replace('/', '%2F')}`;
+let doc;
+try {
+	const res = await fetch(url);
+	if (res.status === 404) {
+		doc = null; // never published
+	} else if (!res.ok) {
+		console.error(`${url} answered ${res.status}`);
+		process.exit(1);
+	} else {
+		doc = await res.json();
+	}
+} catch (err) {
+	console.error(`${url} could not be read: ${err.message}`);
+	process.exit(1);
+}
+
+const latest = doc?.['dist-tags']?.latest ?? null;
+const publishedHere = Boolean(doc?.versions?.[version]);
+// a hyphen marks a prerelease; a plus is build metadata, which is not one
+const prerelease = version.split('+')[0].includes('-');
+
+let verdict = 'new';
+let shouldPublish = true;
+let note = `${name}@${version} is not on npm${latest ? `, which holds ${latest}` : ''}`;
+
+if (publishedHere) {
+	verdict = 'published';
+	shouldPublish = false;
+	note = `${name}@${version} is already on npm. Bump the version in ui/lib/ui/package.json to release these changes.`;
+} else if (latest && compare(version, latest) < 0) {
+	// covers the prerelease of an already-released core: 0.4.0-beta.1 behind 0.4.0
+	verdict = 'stale';
+	shouldPublish = false;
+	note = `${name}@${version} is older than the ${latest} on npm.`;
+}
+
+const tag = prerelease ? 'next' : 'latest';
+
+console.log(`package.json : ${name}@${version}`);
+console.log(`npm latest   : ${latest ?? 'nothing published yet'}`);
+console.log(`that version : ${publishedHere ? 'already on npm' : 'not on npm'}`);
+console.log(`verdict      : ${verdict} (publish: ${shouldPublish}, dist-tag: ${tag})`);
+console.log(`               ${note}`);
+
+if (process.env.GITHUB_OUTPUT) {
+	appendFileSync(
+		process.env.GITHUB_OUTPUT,
+		[
+			`name=${name}`,
+			`version=${version}`,
+			`latest=${latest ?? ''}`,
+			`verdict=${verdict}`,
+			`should_publish=${shouldPublish}`,
+			`tag=${tag}`,
+			`note=${note}`,
+			'',
+		].join('\n'),
+	);
+}
+
+/**
+ * Order two semver versions: negative when a < b, positive when a > b, 0 when they are equal.
+ * Written out rather than pulled in as a dependency for a CI check: prerelease identifiers
+ * order before the release they lead up to (0.4.0-beta.1 < 0.4.0), fewer identifiers sort
+ * first when one is a prefix of the other, numeric identifiers order before alphanumeric ones,
+ * and build metadata is ignored (semver 11.4.x of the specification).
+ */
+function compare(a, b) {
+	const [coreA, preA] = split(a);
+	const [coreB, preB] = split(b);
+	for (let i = 0; i < 3; i++) {
+		if (coreA[i] !== coreB[i]) return coreA[i] < coreB[i] ? -1 : 1;
+	}
+	if (preA.length === 0 && preB.length === 0) return 0;
+	if (preA.length === 0) return 1;
+	if (preB.length === 0) return -1;
+	for (let i = 0; ; i++) {
+		const x = preA[i];
+		const y = preB[i];
+		if (x === undefined && y === undefined) return 0;
+		if (x === undefined) return -1;
+		if (y === undefined) return 1;
+		if (x === y) continue;
+		const numX = /^\d+$/.test(x);
+		const numY = /^\d+$/.test(y);
+		if (numX && numY) return Number(x) < Number(y) ? -1 : 1;
+		if (numX) return -1;
+		if (numY) return 1;
+		return x < y ? -1 : 1;
+	}
+}
+
+/** Split a version into its numeric core and its prerelease identifiers, dropping build metadata. */
+function split(version) {
+	const withoutBuild = version.split('+')[0];
+	const dash = withoutBuild.indexOf('-');
+	const core = (dash === -1 ? withoutBuild : withoutBuild.slice(0, dash)).split('.').map((n) => Number(n) || 0);
+	while (core.length < 3) core.push(0);
+	const pre = dash === -1 ? [] : withoutBuild.slice(dash + 1).split('.');
+	return [core, pre];
+}