From 33358bca6ce87c84630992493d8408fec00108c8 Mon Sep 17 00:00:00 2001 From: Egutierrez Date: Tue, 16 Jun 2026 20:27:45 +0200 Subject: [PATCH] chore: build.sh con version desde app.md + pre-commit anti-stale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit build.sh inyecta la version de app.md por -ldflags (-X main.version), haciendo de app.md la unica fuente de verdad — el binario ya no puede quedar por detras (drift 0.7.0 vs 0.8.0 del 16/06/2026). main.go pasa la version de const a var para permitir el override por ldflags. scripts/pre-commit recompila en cada commit para que el binario que sirve el .mcp.json nunca quede stale respecto a los .go commiteados (la causa raiz del mismo bug). scripts/install-hooks.sh lo instala via symlink. --- build.sh | 17 +++++++++++++++++ main.go | 6 +++++- scripts/install-hooks.sh | 6 ++++++ scripts/pre-commit | 12 ++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 build.sh create mode 100755 scripts/install-hooks.sh create mode 100755 scripts/pre-commit diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..7ab160e --- /dev/null +++ b/build.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Compila browser_mcp inyectando la versión declarada en app.md como única fuente +# de verdad. Evita el drift entre la constante del binario y app.md (bug 16/06/2026: +# serverInfo reportaba 0.7.0 mientras app.md ya iba por 0.8.0). +# +# Uso: ./build.sh +set -euo pipefail +cd "$(dirname "$0")" + +version="$(grep -m1 '^version:' app.md | awk '{print $2}')" +if [ -z "${version}" ]; then + echo "build.sh: no pude leer 'version:' de app.md" >&2 + exit 1 +fi + +CGO_ENABLED=0 go build -ldflags "-X main.version=${version}" -o browser_mcp . +echo "built browser_mcp version=${version}" diff --git a/main.go b/main.go index 5262d02..ee5229f 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,11 @@ import ( "fn-registry/functions/browser" ) -const version = "0.8.0" +// version is the server version reported in serverInfo. The literal here is a +// fallback for `go build` with no flags; build.sh overrides it via +// -ldflags "-X main.version=" so app.md stays the single source +// of truth and the binary can never drift behind it (see build.sh). +var version = "0.8.0" type config struct { httpAddr string diff --git a/scripts/install-hooks.sh b/scripts/install-hooks.sh new file mode 100755 index 0000000..f2e1265 --- /dev/null +++ b/scripts/install-hooks.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +# Instala los git hooks versionados de este repo en .git/hooks. +set -euo pipefail +cd "$(dirname "$0")/.." +ln -sf ../../scripts/pre-commit .git/hooks/pre-commit +echo "instalado .git/hooks/pre-commit -> scripts/pre-commit" diff --git a/scripts/pre-commit b/scripts/pre-commit new file mode 100755 index 0000000..74998c2 --- /dev/null +++ b/scripts/pre-commit @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# Anti-stale binary guard. El .mcp.json ejecuta el binario ./browser_mcp; si se +# commitea un cambio en los .go sin recompilar, la sesión sirve código viejo +# (bug 16/06/2026). Este hook recompila en cada commit. Instálalo con +# scripts/install-hooks.sh. +set -euo pipefail +cd "$(git rev-parse --show-toplevel)" +if ! ./build.sh >/tmp/browser_mcp_build.log 2>&1; then + echo "pre-commit: build.sh falló — commit abortado. Log:" >&2 + cat /tmp/browser_mcp_build.log >&2 + exit 1 +fi