Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

refine(ops): make the build-info dirty flag accurate

nirholas38e438678cac
diff --git a/package.json b/package.json
index f4ff446f0..0d9cfe780 100644
--- a/package.json
+++ b/package.json
@@ -217,7 +217,8 @@
"check:dist": "node scripts/check-dist.mjs",
"deploy": "npm run build:all && npm run check:dist && vercel --local-config vercel.json --prod",
"build:info": "node scripts/write-build-info.mjs",
- "build:gcp": "npm run build && npm run build:lib:full && npm run publish:lib && npm run build:info && npm run check:dist",
+ "build:info:snapshot": "node scripts/write-build-info.mjs --snapshot",
+ "build:gcp": "npm run build:info:snapshot && npm run build && npm run build:lib:full && npm run publish:lib && npm run build:info && npm run check:dist",
"deploy:gcp": "npm run check:dist && npm run db:check && gcloud builds submit --config server/cloudbuild.yaml --region us-central1 --project aerial-vehicle-466722-p5 && npm run deploy:gcp:purge-cdn",
"deploy:gcp:full": "npm run build:gcp && npm run deploy:gcp",
"deploy:gcp:purge-cdn": "gcloud compute url-maps invalidate-cdn-cache three-ws-lb --path '/*' --project aerial-vehicle-466722-p5 --async",
diff --git a/scripts/write-build-info.mjs b/scripts/write-build-info.mjs
index da197e954..4237bbe23 100644
--- a/scripts/write-build-info.mjs
+++ b/scripts/write-build-info.mjs
@@ -11,22 +11,37 @@
* in the image (the Dockerfile `COPY . .` includes dist) and is both served as a
* static file (`/build-info.json`) and read by the `/api/version` handler.
*
- * Run automatically as the last step of `npm run build:gcp`. Safe to run alone.
- * Fail-soft: if git is unavailable (e.g. building from a tarball with no .git),
- * it falls back to CI-provided commit env vars, then to `unknown` — never throws,
- * never fails the build.
+ * Two modes:
+ * --snapshot : record ONLY whether the working tree is dirty, into a sidecar
+ * in the git dir. Run this FIRST in build:gcp, before the site
+ * build mutates tracked files (inject-seo-meta/theme-boot rewrite
+ * pages/*.html in place; build-page-index regenerates public/*).
+ * Without it, the stamp would always read `dirty: true` because
+ * the build itself dirties the tree — making the flag useless.
+ * (default) : write the full stamp. If a snapshot sidecar exists, trust its
+ * dirty value (the pre-build truth) and consume it; otherwise fall
+ * back to a live `git status` (correct for a standalone run).
+ *
+ * Fail-soft everywhere: if git is unavailable (e.g. building from a tarball with
+ * no .git), commit fields fall back to CI-provided env vars, then to `unknown`.
+ * Never throws, never fails the build.
*/
import { execSync } from 'node:child_process';
-import { mkdirSync, writeFileSync, readFileSync } from 'node:fs';
-import { resolve, dirname } from 'node:path';
+import { mkdirSync, writeFileSync, readFileSync, existsSync, rmSync } from 'node:fs';
+import { resolve, dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
+const SNAPSHOT_ONLY = process.argv.includes('--snapshot');
/** Run a git command from the repo root; return trimmed stdout or '' on any error. */
function git(args) {
try {
- return execSync(`git ${args}`, { cwd: ROOT, stdio: ['ignore', 'pipe', 'ignore'] })
+ return execSync(`git ${args}`, {
+ cwd: ROOT,
+ stdio: ['ignore', 'pipe', 'ignore'],
+ maxBuffer: 64 * 1024 * 1024,
+ })
.toString()
.trim();
} catch {
@@ -34,6 +49,34 @@ function git(args) {
}
}
+/** Absolute path to the dirty-state sidecar, inside this worktree's git dir. */
+function sidecarPath() {
+ const gitDir = git('rev-parse --absolute-git-dir');
+ if (!gitDir) return null;
+ return join(gitDir, 'three-ws-build-dirty');
+}
+
+/** True if the working tree has uncommitted changes right now. */
+function treeIsDirty() {
+ return git('rev-parse HEAD') !== '' && git('status --porcelain') !== '';
+}
+
+// --- snapshot mode: stamp the pre-build dirty state and exit ---
+if (SNAPSHOT_ONLY) {
+ const p = sidecarPath();
+ if (p) {
+ try {
+ writeFileSync(p, treeIsDirty() ? '1' : '0');
+ } catch {
+ /* best-effort — a missing snapshot just means the stamp computes dirty live */
+ }
+ }
+ console.log(
+ `[build-info] snapshot: working tree ${treeIsDirty() ? 'dirty' : 'clean'} pre-build`,
+ );
+ process.exit(0);
+}
+
function packageVersion() {
try {
return JSON.parse(readFileSync(resolve(ROOT, 'package.json'), 'utf8')).version || 'unknown';
@@ -57,7 +100,24 @@ const branch =
process.env.BRANCH_NAME ||
'unknown';
const subject = git('show -s --format=%s HEAD') || null;
-const dirty = fullSha !== 'unknown' && git('status --porcelain') !== '';
+
+// Dirty: prefer the pre-build snapshot (the build mutates tracked files, so a
+// live read here would almost always be `true` and meaningless). Consume the
+// sidecar so it never leaks into a later build.
+let dirty = false;
+if (fullSha !== 'unknown') {
+ const p = sidecarPath();
+ if (p && existsSync(p)) {
+ try {
+ dirty = readFileSync(p, 'utf8').trim() === '1';
+ rmSync(p, { force: true });
+ } catch {
+ dirty = treeIsDirty();
+ }
+ } else {
+ dirty = treeIsDirty();
+ }
+}
const info = {
version: packageVersion(),
diff --git a/tests/version-endpoint.test.js b/tests/version-endpoint.test.js
index 383526f85..5224fb57a 100644
--- a/tests/version-endpoint.test.js
+++ b/tests/version-endpoint.test.js
@@ -10,7 +10,7 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { execSync } from 'node:child_process';
-import { readFileSync, existsSync } from 'node:fs';
+import { readFileSync, existsSync, writeFileSync, rmSync } from 'node:fs';
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import handler, { _resetBuildInfoCache } from '../api/version.js';
@@ -117,4 +117,23 @@ describe('write-build-info.mjs generator', () => {
expect(new Date(info.builtAt).toISOString()).toBe(info.builtAt);
expect(typeof info.dirty).toBe('boolean');
});
+
+ it('trusts a pre-build snapshot for the dirty flag, then consumes it', () => {
+ // The build mutates tracked files, so a live dirty read at stamp time is
+ // meaningless. build:gcp records the pre-build truth via --snapshot; the
+ // final stamp must honor that snapshot even though the tree is now dirty.
+ const gitDir = execSync('git rev-parse --absolute-git-dir', { cwd: ROOT })
+ .toString()
+ .trim();
+ const sidecar = resolve(gitDir, 'three-ws-build-dirty');
+ writeFileSync(sidecar, '0'); // pretend the tree was clean pre-build
+ try {
+ execSync('node scripts/write-build-info.mjs', { cwd: ROOT, stdio: 'ignore' });
+ const info = JSON.parse(readFileSync(resolve(ROOT, 'dist/build-info.json'), 'utf8'));
+ expect(info.dirty).toBe(false); // honored the snapshot, not the live (dirty) tree
+ expect(existsSync(sidecar)).toBe(false); // consumed so it can't leak into a later build
+ } finally {
+ if (existsSync(sidecar)) rmSync(sidecar, { force: true });
+ }
+ });
});