Non-invasive MCP accelerator plugin for Google Antigravity (CLI/Desktop/IDE): cuts LLM turns (-34%), token quota (-31%), and upload traffic (-40%) without affecting native UI or diffs.
TypeScript ai-agentai-codingantigravityantigravity-cliantigravity-ideantigravity-pluginscoding-agentcontext-optimizationdeveloper-productivitydeveloper-toolsgeminigoogle-antigravitylatency-optimizationmcpmcp-pluginmcp-servermodel-context-protocolperformanceplugintoken-optimization
fix(updater,docs): force LF clone for checksums, tolerate legacy annotated tag SHAs, and sync FAQ copy
inkwhiteb0b2b479c166
diff --git a/.gitattributes b/.gitattributesnew file mode 100644index 0000000..861713a--- /dev/null+++ b/.gitattributes@@ -0,0 +1,3 @@+# Preserve LF line endings across platforms so SHA256SUMS.txt digests+# generated on Linux match fresh clones on Windows (even with core.autocrlf=true).+* text=auto eol=lfdiff --git a/README.ja.md b/README.ja.mdindex 53028b3..6d31227 100644--- a/README.ja.md+++ b/README.ja.md@@ -393,13 +393,13 @@ Override Rule 3: Always allow direct image reads in the main session for UI/desi`agy-fast` は **Antigravity CLI(`agy`)**、**Antigravity Desktop 2.0**、**Antigravity IDE** に対応し、**macOS、Linux、Windows** で動作します。**Node.js >= 20** が必要で、ランタイム依存関係はゼロです(任意の `ripgrep`/`rg` には自動的に純粋な Node.js フォールバックがあります)。### `agy-fast` はコードやトランスクリプトのデータを外部サーバーに送信しますか?-いいえ。すべての MCP ツール、`SessionStart` スナップショットフック、トランスクリプト用ベンチマーク CLI は100%ローカルで動作します。任意のネットワークリクエストは、4時間に1回、公開されている GitHub リリースタグを確認するバックグラウンド更新チェッカーだけであり、`config --auto-update off` または `AGY_FAST_AUTO_UPDATE=off` で `notify` に切り替えたり、完全に無効化したりできます。+いいえ。すべての MCP ツール、`SessionStart` スナップショットフック、トランスクリプト用ベンチマーク CLI は100%ローカルで動作します。任意のネットワークリクエストは、4時間に1回、公開されている GitHub リリースタグを確認する通知専用(`notify` デフォルト)のバックグラウンド更新チェッカーだけであり(手動で `update` を実行するか `config --auto-update auto` を有効にしない限りローカルファイルは書き換えません)、`config --auto-update off` または `AGY_FAST_AUTO_UPDATE=off` で完全に無効化できます。### 速度向上を検証したり、`agy-fast` をクリーンにアンインストールしたりするには?`node dist/benchmark.mjs analyze --local --split-usage` を実行すると、自分のローカルトランスクリプトを完全にオフラインでベンチマークできます。`agy-fast` をいつでも削除するには、`node ~/.gemini/config/plugins/agy-fast/scripts/install.mjs uninstall` を実行してください。### 長いターン(`>60s–120s`)がプロキシの背後で `unexpected EOF` / `broken pipe` / `stream interrupted` になるのはなぜ?-長い思考や複数ファイルのコーディングターンでは、単一の SSE ストリームが1–5分間開いたままになります。自動切り替えのプロキシグループ(`url-test` / `fallback`)、UDP/QUIC のアイドルドロップ、短いプロキシ読み取りタイムアウトは、それらのストリームを途中でき頻繁に切断します(`benchmark.mjs` はこれらを `Network/SSE disconnect errors` として表面化させます)。`agy-fast` はサードパーティのプロキシ設定を読んだり変更したりすることは決してありません。その代わりに、Antigravity の API ドメインを**静的で低損失の TCP ノード**(`url-test` ではない)に固定し、プロキシクライアントで TCP KeepAlive を有効にしてください:+長い思考や複数ファイルのコーディングターンでは、単一の SSE ストリームが1–5分間開いたままになります。自動切り替えのプロキシグループ(`url-test` / `fallback`)、UDP/QUIC のアイドルドロップ、短いプロキシ読み取りタイムアウトは、それらのストリームを途中で頻繁に切断します(`benchmark.mjs` はこれらを `Network/SSE disconnect errors` として表面化させます)。`agy-fast` はサードパーティのプロキシ設定を読んだり変更したりすることは決してありません。その代わりに、Antigravity の API ドメインを**静的で低損失の TCP ノード**(`url-test` ではない)に固定し、プロキシクライアントで TCP KeepAlive を有効にしてください:<details><summary>コピー可能なプロキシルーティングテンプレート(Clash / Mihomo Merge Override、Surge、sing-box)</summary>diff --git a/README.md b/README.mdindex f193176..3e75b67 100644--- a/README.md+++ b/README.md@@ -393,7 +393,7 @@ Override Rule 3: Always allow direct image reads in the main session for UI/desi`agy-fast` supports **Antigravity CLI (`agy`)**, **Antigravity Desktop 2.0**, and **Antigravity IDE** across **macOS, Linux, and Windows**. It requires **Node.js >= 20** with zero runtime dependencies (optional `ripgrep`/`rg` with automatic pure-Node.js fallback).### Does `agy-fast` send any code or transcript data to external servers?-No. All MCP tools, the `SessionStart` snapshot hook, and the transcript benchmark CLI operate 100% locally. The only optional network request is the background update checker checking public GitHub release tags once every 4 hours, which can be switched to `notify` or disabled completely via `config --auto-update off` or `AGY_FAST_AUTO_UPDATE=off`.+No. All MCP tools, the `SessionStart` snapshot hook, and the transcript benchmark CLI operate 100% locally. The only optional network request is the notify-only background update checker checking public GitHub release tags once every 4 hours (never modifying local files unless you run `update` or opt in via `config --auto-update auto`), which can be disabled completely via `config --auto-update off` or `AGY_FAST_AUTO_UPDATE=off`.### How do I verify the speedup or uninstall `agy-fast` cleanly?Run `node dist/benchmark.mjs analyze --local --split-usage` to benchmark your own local transcripts completely offline. To remove `agy-fast` at any time, run `node ~/.gemini/config/plugins/agy-fast/scripts/install.mjs uninstall`.diff --git a/README.zh-CN.md b/README.zh-CN.mdindex ad1b876..e1e7f9d 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -391,7 +391,7 @@ Override Rule 3: Always allow direct image reads in the main session for UI/desi同时支持 **Antigravity CLI(`agy`)**、**Antigravity Desktop 2.0** 与 **Antigravity IDE**,兼容 **macOS、Linux 与 Windows**。仅需 **Node.js >= 20** 且零运行期依赖(可选安装 `ripgrep`/`rg`,缺失时自动回退纯 Node.js)。### `agy-fast` 会向外部上传代码或会话日志吗?-不会。全部 5 个 MCP 工具、`SessionStart` 快照以及离线基准测试均 100% 在本机运行。唯一的可选外网动作是每 4 小时检查一次 GitHub 公开 Release 标签以支持自动更新,可随时通过 `config --auto-update off` 或 `AGY_FAST_AUTO_UPDATE=off` 完全关闭。+不会。全部 5 个 MCP 工具、`SessionStart` 快照以及离线基准测试均 100% 在本机运行。唯一的可选外网动作是默认仅提醒(`notify`)的后台更新检查,每 4 小时检查一次 GitHub 公开 Release 标签(除非手动运行 `update` 或显式开启 `config --auto-update auto`,绝不改动本地文件),也可随时通过 `config --auto-update off` 或 `AGY_FAST_AUTO_UPDATE=off` 完全关闭。### 如何验证本机加速效果或彻底卸载?运行 `node dist/benchmark.mjs analyze --local --split-usage` 即可纯离线统计本机日志的前后对比。随时可执行 `node ~/.gemini/config/plugins/agy-fast/scripts/install.mjs uninstall` 一键干净卸载。diff --git a/README.zh-TW.md b/README.zh-TW.mdindex 59d63d7..fa7107d 100644--- a/README.zh-TW.md+++ b/README.zh-TW.md@@ -391,7 +391,7 @@ Override Rule 3: Always allow direct image reads in the main session for UI/desi同時支援 **Antigravity CLI(`agy`)**、**Antigravity Desktop 2.0** 與 **Antigravity IDE**,相容 **macOS、Linux 與 Windows**。僅需 **Node.js >= 20** 且零執行階段依賴(可選安裝 `ripgrep`/`rg`,缺失時自動回退純 Node.js)。### `agy-fast` 會向外部上傳程式碼或工作階段日誌嗎?-不會。全部 5 個 MCP 工具、`SessionStart` 快照以及離線基準測試均 100% 在本機執行。唯一的可選外網動作是每 4 小時檢查一次 GitHub 公開 Release 標籤以支援自動更新,可隨時透過 `config --auto-update off` 或 `AGY_FAST_AUTO_UPDATE=off` 完全關閉。+不會。全部 5 個 MCP 工具、`SessionStart` 快照以及離線基準測試均 100% 在本機執行。唯一的可選外網動作是預設僅提醒(`notify`)的背景更新檢查,每 4 小時檢查一次 GitHub 公開 Release 標籤(除非手動執行 `update` 或顯式開啟 `config --auto-update auto`,絕不更動本機檔案),也可隨時透過 `config --auto-update off` 或 `AGY_FAST_AUTO_UPDATE=off` 完全關閉。### 如何驗證本機加速效果或徹底解除安裝?執行 `node dist/benchmark.mjs analyze --local --split-usage` 即可純離線統計本機日誌的前後比較。隨時可執行 `node ~/.gemini/config/plugins/agy-fast/scripts/install.mjs uninstall` 一鍵乾淨解除安裝。diff --git a/SECURITY.md b/SECURITY.mdindex cec0131..39bafc7 100644--- a/SECURITY.md+++ b/SECURITY.md@@ -27,7 +27,7 @@ Any developer can independently verify `agy-fast` locally without trusting pre-b1. **Confirm zero runtime dependencies**: Inspect `package.json` — only 3 build-time `devDependencies` (`esbuild`, `typescript`, `@types/node`), zero `dependencies`.2. **Verify reproducible bundles (`dist/` == `src/`)**:```bash- git clone --branch v0.3.3 --depth 1 https://github.com/INK-Q/agy-fast.git+ git clone --branch v0.3.4 --depth 1 https://github.com/INK-Q/agy-fast.gitcd agy-fast && npm ci && npm run build && git diff --exit-code -- dist/```Exit code `0` proves every line of `dist/*.mjs` matches the readable TypeScript source byte-for-byte.@@ -38,14 +38,17 @@ Any developer can independently verify `agy-fast` locally without trusting pre-bConfirm the only outbound network calls are optional GitHub Release checks inside `src/utils/updater-core.ts`.4. **Verify Release checksums & SLSA provenance attestation** *(releases `>= v0.3.4`)*:```bash- sha256sum -c SHA256SUMS.txt+ # Linux (filter the 3 leading '#' metadata comment lines for --strict cleanliness)+ grep -v '^#' SHA256SUMS.txt | sha256sum -c -+ # macOS+ grep -v '^#' SHA256SUMS.txt | shasum -a 256 -c -gh attestation verify dist/mcp-server.mjs --repo INK-Q/agy-fast```5. **Lock down runtime surface (optional)**:- **Air-gapped / 0 network**: `node ~/.gemini/config/plugins/agy-fast/scripts/install.mjs config --auto-update off`- **Strict checksum enforcement on updates**: `AGY_FAST_REQUIRE_CHECKSUMS=1`- **Read-only MCP**: `--tools batch_search,quick_outline,read_slices` (or `AGY_FAST_TOOLS`)- - **Pinned install**: clone a specific tag (`git checkout v0.3.3 && ./install.sh`) or run `npx [email protected]` instead of tracking `main`.+ - **Pinned install**: clone a specific tag (`git checkout v0.3.4 && ./install.sh`) or run `npx [email protected]` instead of tracking `main`.## Reporting a Vulnerabilitydiff --git a/dist/updater.mjs b/dist/updater.mjsindex 4b7fb5e..1fceff8 100755--- a/dist/updater.mjs+++ b/dist/updater.mjs@@ -465,7 +465,8 @@ function pickLatestSemverTag(lsRemoteOutput) {const commitSha = cand.peeledSha ?? cand.directSha;if (!commitSha) continue;if (!best || compareSemver(cand.version, best.version) > 0) {- best = { tag: cand.tag, version: cand.version, commitSha };+ const tagObjectSha = cand.peeledSha && cand.directSha && cand.directSha !== cand.peeledSha ? cand.directSha : void 0;+ best = tagObjectSha ? { tag: cand.tag, version: cand.version, commitSha, tagObjectSha } : { tag: cand.tag, version: cand.version, commitSha };}}return best;@@ -485,7 +486,7 @@ function normalizeCommitSha(raw) {const trimmed = raw.trim().toLowerCase();return FULL_COMMIT_SHA_RE.test(trimmed) ? trimmed : void 0;}-function detectTagHijack(prevState, tag, observedCommitSha) {+function detectTagHijack(prevState, tag, observedCommitSha, observedTagObjectSha) {const normObserved = normalizeCommitSha(observedCommitSha);if (!normObserved) return null;const parsed = parseSemver(tag);@@ -493,13 +494,23 @@ function detectTagHijack(prevState, tag, observedCommitSha) {const trimmedTag = tag.trim();const normalizedVer = `${parsed[0]}.${parsed[1]}.${parsed[2]}`;const recordedFromMap = normalizeCommitSha(prevState.knownTagCommits?.[trimmedTag]);+ if (recordedFromMap) {+ if (recordedFromMap !== normObserved) {+ return `Security check failed: release tag '${trimmedTag}' moved from previously observed commit ${recordedFromMap.slice(0, 12)} to ${normObserved.slice(0, 12)} (possible tag hijack or force re-tag). Refusing update; inspect the repository before taking action.`;+ }+ return null;+ }const recordedFromApplied = prevState.latestRef === trimmedTag && prevState.lastAppliedVersion === normalizedVer ? normalizeCommitSha(prevState.lastAppliedCommit) : void 0;const recordedFromAvailable = prevState.availableRef === trimmedTag ? normalizeCommitSha(prevState.availableCommit) : void 0;- const previousSha = recordedFromMap ?? recordedFromApplied ?? recordedFromAvailable;- if (previousSha && previousSha !== normObserved) {- return `Security check failed: release tag '${trimmedTag}' moved from previously observed commit ${previousSha.slice(0, 12)} to ${normObserved.slice(0, 12)} (possible tag hijack or force re-tag). Refusing update; inspect the repository before taking action.`;+ const legacySha = recordedFromApplied ?? recordedFromAvailable;+ if (!legacySha || legacySha === normObserved) {+ return null;}- return null;+ const normTagObj = normalizeCommitSha(observedTagObjectSha);+ if (normTagObj && legacySha === normTagObj) {+ return null;+ }+ return `Security check failed: release tag '${trimmedTag}' moved from previously observed commit ${legacySha.slice(0, 12)} to ${normObserved.slice(0, 12)} (possible tag hijack or force re-tag). Refusing update; inspect the repository before taking action.`;}function mergeKnownTagCommits(existing, tag, commitSha) {const normSha = normalizeCommitSha(commitSha);@@ -980,6 +991,7 @@ async function fetchLatestRemoteVersion(opts) {ref: latest.tag,version: latest.version,commitSha: latest.commitSha,+ ...latest.tagObjectSha ? { tagObjectSha: latest.tagObjectSha } : {},releaseUrl: buildGithubReleaseUrl(safeRepoUrl, latest.tag, latest.commitSha),source: "git-tags"};@@ -1346,7 +1358,12 @@ async function runPluginUpdate(opts) {fetchFn: opts.fetchFn});const prevState = await readUpdateState(env, pluginDir);- const remoteHijackError = detectTagHijack(prevState, remote.ref, remote.commitSha);+ const remoteHijackError = detectTagHijack(+ prevState,+ remote.ref,+ remote.commitSha,+ remote.tagObjectSha+ );if (remoteHijackError) {throw new Error(remoteHijackError);}@@ -1441,7 +1458,31 @@ async function runPluginUpdate(opts) {await fs.mkdir(paths.cacheDir, { recursive: true });const gitEnv = withNonInteractiveGitEnv(env);const safeRepoUrl = validateRepoUrl(repoUrl);- const cloneArgs = remote.ref === "HEAD" ? ["clone", "--depth", "1", "--", safeRepoUrl, stagingDir] : ["clone", "--depth", "1", "--branch", remote.ref, "--", safeRepoUrl, stagingDir];+ const cloneArgs = remote.ref === "HEAD" ? [+ "-c",+ "core.autocrlf=false",+ "-c",+ "core.eol=lf",+ "clone",+ "--depth",+ "1",+ "--",+ safeRepoUrl,+ stagingDir+ ] : [+ "-c",+ "core.autocrlf=false",+ "-c",+ "core.eol=lf",+ "clone",+ "--depth",+ "1",+ "--branch",+ remote.ref,+ "--",+ safeRepoUrl,+ stagingDir+ ];const cloneRes = await execBinaryAsync("git", cloneArgs, {cwd: paths.cacheDir,timeoutMs: Math.max(timeoutMs, 3e4),@@ -1459,12 +1500,17 @@ async function runPluginUpdate(opts) {});const stagedCommitSha = !headRevRes.error && !headRevRes.timedOut && headRevRes.exitCode === 0 ? normalizeCommitSha(headRevRes.stdout) : void 0;const expectedCommitSha = normalizeCommitSha(remote.commitSha);- if (expectedCommitSha && stagedCommitSha && stagedCommitSha !== expectedCommitSha) {+ if (expectedCommitSha && stagedCommitSha !== expectedCommitSha) {throw new Error(- `Security check failed: cloned '${remote.ref}' resolved to commit ${stagedCommitSha.slice(0, 12)}, expected ${expectedCommitSha.slice(0, 12)} (possible tag hijack during fetch).`+ stagedCommitSha ? `Security check failed: cloned '${remote.ref}' resolved to commit ${stagedCommitSha.slice(0, 12)}, expected ${expectedCommitSha.slice(0, 12)} (possible tag hijack during fetch).` : `Security check failed: unable to verify cloned HEAD commit for '${remote.ref}' (expected ${expectedCommitSha.slice(0, 12)}).`);}- const stagedHijackError = detectTagHijack(prevState, remote.ref, stagedCommitSha);+ const stagedHijackError = detectTagHijack(+ prevState,+ remote.ref,+ stagedCommitSha,+ remote.tagObjectSha+ );if (stagedHijackError) {throw new Error(stagedHijackError);}diff --git a/src/utils/updater-core.ts b/src/utils/updater-core.tsindex 77cc2e5..fbbd052 100644--- a/src/utils/updater-core.ts+++ b/src/utils/updater-core.ts@@ -108,6 +108,8 @@ export interface RemoteVersionInfo {ref: string;version: string | null;commitSha?: string;+ /** Unpeeled annotated/signed tag object SHA (used only for pre-v0.3.4 state migration). */+ tagObjectSha?: string;releaseUrl?: string;publishedAt?: string;source: "git-tags" | "git-main" | "github-api";@@ -262,7 +264,7 @@ export function compareSemver(a: string, b: string): number {export function pickLatestSemverTag(lsRemoteOutput: string,-): { tag: string; version: string; commitSha: string } | null {+): { tag: string; version: string; commitSha: string; tagObjectSha?: string } | null {const candidates = new Map<string,{ tag: string; version: string; directSha?: string; peeledSha?: string }@@ -290,12 +292,18 @@ export function pickLatestSemverTag(}candidates.set(tag, existing);}- let best: { tag: string; version: string; commitSha: string } | null = null;+ let best: { tag: string; version: string; commitSha: string; tagObjectSha?: string } | null = null;for (const cand of candidates.values()) {const commitSha = cand.peeledSha ?? cand.directSha;if (!commitSha) continue;if (!best || compareSemver(cand.version, best.version) > 0) {- best = { tag: cand.tag, version: cand.version, commitSha };+ const tagObjectSha =+ cand.peeledSha && cand.directSha && cand.directSha !== cand.peeledSha+ ? cand.directSha+ : undefined;+ best = tagObjectSha+ ? { tag: cand.tag, version: cand.version, commitSha, tagObjectSha }+ : { tag: cand.tag, version: cand.version, commitSha };}}return best;@@ -322,6 +330,7 @@ export function detectTagHijack(prevState: UpdateState,tag: string,observedCommitSha?: string,+ observedTagObjectSha?: string,): string | null {const normObserved = normalizeCommitSha(observedCommitSha);if (!normObserved) return null;@@ -331,6 +340,17 @@ export function detectTagHijack(const normalizedVer = `${parsed[0]}.${parsed[1]}.${parsed[2]}`;const recordedFromMap = normalizeCommitSha(prevState.knownTagCommits?.[trimmedTag]);+ if (recordedFromMap) {+ if (recordedFromMap !== normObserved) {+ return (+ `Security check failed: release tag '${trimmedTag}' moved from previously observed commit ` ++ `${recordedFromMap.slice(0, 12)} to ${normObserved.slice(0, 12)} (possible tag hijack or force re-tag). ` ++ `Refusing update; inspect the repository before taking action.`+ );+ }+ return null;+ }+const recordedFromApplied =prevState.latestRef === trimmedTag && prevState.lastAppliedVersion === normalizedVer? normalizeCommitSha(prevState.lastAppliedCommit)@@ -340,15 +360,23 @@ export function detectTagHijack(? normalizeCommitSha(prevState.availableCommit): undefined;- const previousSha = recordedFromMap ?? recordedFromApplied ?? recordedFromAvailable;- if (previousSha && previousSha !== normObserved) {- return (- `Security check failed: release tag '${trimmedTag}' moved from previously observed commit ` +- `${previousSha.slice(0, 12)} to ${normObserved.slice(0, 12)} (possible tag hijack or force re-tag). ` +- `Refusing update; inspect the repository before taking action.`- );+ const legacySha = recordedFromApplied ?? recordedFromAvailable;+ if (!legacySha || legacySha === normObserved) {+ return null;}- return null;+ // Pre-v0.3.4 updaters persisted unpeeled annotated tag object SHAs into legacy+ // lastAppliedCommit/availableCommit fields before knownTagCommits existed.+ // Because a Git tag object cryptographically binds to its target commit SHA,+ // matching observedTagObjectSha safely migrates legacy state without weakening defense.+ const normTagObj = normalizeCommitSha(observedTagObjectSha);+ if (normTagObj && legacySha === normTagObj) {+ return null;+ }+ return (+ `Security check failed: release tag '${trimmedTag}' moved from previously observed commit ` ++ `${legacySha.slice(0, 12)} to ${normObserved.slice(0, 12)} (possible tag hijack or force re-tag). ` ++ `Refusing update; inspect the repository before taking action.`+ );}function mergeKnownTagCommits(@@ -1063,6 +1091,7 @@ export async function fetchLatestRemoteVersion(opts: {ref: latest.tag,version: latest.version,commitSha: latest.commitSha,+ ...(latest.tagObjectSha ? { tagObjectSha: latest.tagObjectSha } : {}),releaseUrl: buildGithubReleaseUrl(safeRepoUrl, latest.tag, latest.commitSha),source: "git-tags",};@@ -1512,7 +1541,12 @@ export async function runPluginUpdate(fetchFn: opts.fetchFn,});const prevState = await readUpdateState(env, pluginDir);- const remoteHijackError = detectTagHijack(prevState, remote.ref, remote.commitSha);+ const remoteHijackError = detectTagHijack(+ prevState,+ remote.ref,+ remote.commitSha,+ remote.tagObjectSha,+ );if (remoteHijackError) {throw new Error(remoteHijackError);}@@ -1650,10 +1684,36 @@ export async function runPluginUpdate(const gitEnv = withNonInteractiveGitEnv(env);const safeRepoUrl = validateRepoUrl(repoUrl);+ // Force LF checkout regardless of host core.autocrlf (e.g. Git for Windows defaults+ // to core.autocrlf=true), so SHA256SUMS.txt digests generated on Linux match staged bytes.const cloneArgs =remote.ref === "HEAD"- ? ["clone", "--depth", "1", "--", safeRepoUrl, stagingDir]- : ["clone", "--depth", "1", "--branch", remote.ref, "--", safeRepoUrl, stagingDir];+ ? [+ "-c",+ "core.autocrlf=false",+ "-c",+ "core.eol=lf",+ "clone",+ "--depth",+ "1",+ "--",+ safeRepoUrl,+ stagingDir,+ ]+ : [+ "-c",+ "core.autocrlf=false",+ "-c",+ "core.eol=lf",+ "clone",+ "--depth",+ "1",+ "--branch",+ remote.ref,+ "--",+ safeRepoUrl,+ stagingDir,+ ];const cloneRes = await execBinaryAsync("git", cloneArgs, {cwd: paths.cacheDir,timeoutMs: Math.max(timeoutMs, 30_000),@@ -1677,12 +1737,19 @@ export async function runPluginUpdate(? normalizeCommitSha(headRevRes.stdout): undefined;const expectedCommitSha = normalizeCommitSha(remote.commitSha);- if (expectedCommitSha && stagedCommitSha && stagedCommitSha !== expectedCommitSha) {+ if (expectedCommitSha && stagedCommitSha !== expectedCommitSha) {throw new Error(- `Security check failed: cloned '${remote.ref}' resolved to commit ${stagedCommitSha.slice(0, 12)}, expected ${expectedCommitSha.slice(0, 12)} (possible tag hijack during fetch).`,+ stagedCommitSha+ ? `Security check failed: cloned '${remote.ref}' resolved to commit ${stagedCommitSha.slice(0, 12)}, expected ${expectedCommitSha.slice(0, 12)} (possible tag hijack during fetch).`+ : `Security check failed: unable to verify cloned HEAD commit for '${remote.ref}' (expected ${expectedCommitSha.slice(0, 12)}).`,);}- const stagedHijackError = detectTagHijack(prevState, remote.ref, stagedCommitSha);+ const stagedHijackError = detectTagHijack(+ prevState,+ remote.ref,+ stagedCommitSha,+ remote.tagObjectSha,+ );if (stagedHijackError) {throw new Error(stagedHijackError);}diff --git a/test/updater.test.ts b/test/updater.test.tsindex adc2a76..dda884e 100644--- a/test/updater.test.ts+++ b/test/updater.test.ts@@ -57,11 +57,12 @@ function makeNoGitEnv(extra: NodeJS.ProcessEnv = {}): NodeJS.ProcessEnv {return { ...cleaned, PATH: "", ...extra };}-function git(cwd: string, args: string[]): string {+function git(cwd: string, args: string[], env?: NodeJS.ProcessEnv): string {return execFileSync("git", args, {cwd,encoding: "utf8",stdio: ["ignore", "pipe", "pipe"],+ ...(env ? { env } : {}),});}@@ -1304,7 +1305,7 @@ rl.on("line", (line) => {});it("defends against release tag hijacking, peels annotated tag commit SHAs, and verifies SHA256SUMS.txt", async () => {- // 1. pickLatestSemverTag peels annotated ^{} tags to their true commit SHA+ // 1. pickLatestSemverTag peels annotated ^{} tags to their true commit SHA and keeps tagObjectShaconst peeled = pickLatestSemverTag(["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa refs/tags/v0.2.0",@@ -1315,6 +1316,15 @@ rl.on("line", (line) => {tag: "v0.2.0",version: "0.2.0",commitSha: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",+ tagObjectSha: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",+ });+ const lightweight = pickLatestSemverTag(+ "cccccccccccccccccccccccccccccccccccccccc refs/tags/v0.2.1\n",+ );+ assert.deepEqual(lightweight, {+ tag: "v0.2.1",+ version: "0.2.1",+ commitSha: "cccccccccccccccccccccccccccccccccccccccc",});// 2. buildGithubCompareUrl formats compare diff links cleanly@@ -1327,12 +1337,43 @@ rl.on("line", (line) => {undefined,);- // 3. detectTagHijack unit checks+ // 3. detectTagHijack unit checks (including pre-v0.3.4 unpeeled annotated tag migration)const shaA = "1111111111111111111111111111111111111111";const shaB = "2222222222222222222222222222222222222222";+ const tagObjA = "3333333333333333333333333333333333333333";+ const tagObjB = "4444444444444444444444444444444444444444";assert.equal(detectTagHijack({ knownTagCommits: { "v0.5.0": shaA } }, "v0.5.0", shaA), null);assert.match(- detectTagHijack({ knownTagCommits: { "v0.5.0": shaA } }, "v0.5.0", shaB) ?? "",+ detectTagHijack({ knownTagCommits: { "v0.5.0": shaA } }, "v0.5.0", shaB, tagObjA) ?? "",+ /possible tag hijack or force re-tag/i,+ );+ // Legacy v0.3.3 state (no knownTagCommits) containing unpeeled tag object SHA passes for the same tag+ assert.equal(+ detectTagHijack(+ { latestRef: "v0.5.0", lastAppliedVersion: "0.5.0", lastAppliedCommit: tagObjA },+ "v0.5.0",+ shaA,+ tagObjA,+ ),+ null,+ );+ assert.equal(+ detectTagHijack(+ { availableRef: "v0.5.0", availableCommit: tagObjA },+ "v0.5.0",+ shaA,+ tagObjA,+ ),+ null,+ );+ // Legacy v0.3.3 state still rejects a force re-tag pointing to a different tag object + commit+ assert.match(+ detectTagHijack(+ { latestRef: "v0.5.0", lastAppliedVersion: "0.5.0", lastAppliedCommit: tagObjA },+ "v0.5.0",+ shaB,+ tagObjB,+ ) ?? "",/possible tag hijack or force re-tag/i,);@@ -1450,23 +1491,77 @@ rl.on("line", (line) => {assert.match(requireMissing.message, /AGY_FAST_REQUIRE_CHECKSUMS=1/);assert.equal(await readInstalledVersion(targetPlugin), "0.2.0");- // Valid checksums pass end-to-end on a separate copy and set checksumVerified: true- const validTargetPlugin = path.join(rootTmp, "hijack-valid-home", ".gemini", "config", "plugins", "agy-fast");+ // Valid checksums pass end-to-end even when host git config sets core.autocrlf=true (Windows default)+ const crlfHome = path.join(rootTmp, "hijack-valid-home");+ const validTargetPlugin = path.join(crlfHome, ".gemini", "config", "plugins", "agy-fast");+ const crlfGitConfig = path.join(crlfHome, ".gitconfig");await copyRuntimeFixture(validTargetPlugin, "0.2.0", "installed-0.2.0");+ await fs.writeFile(crlfGitConfig, "[safe]\n\tdirectory = *\n[core]\n\tautocrlf = true\n", "utf8");+ const crlfEnv: NodeJS.ProcessEnv = {+ ...hijackEnv,+ HOME: crlfHome,+ USERPROFILE: crlfHome,+ GIT_CONFIG_GLOBAL: crlfGitConfig,+ AGY_FAST_CACHE_DIR: path.join(crlfHome, ".gemini", "cache", "agy-fast"),+ };+ // Confirm a plain git clone under crlfEnv really converts LF -> CRLF, proving our -c override is exercised+ const controlClone = path.join(rootTmp, "crlf-control-clone");+ git(rootTmp, ["clone", "--depth", "1", "--branch", "v0.5.0", "--", hijackRepoUrl, controlClone], crlfEnv);+ const controlLicense = await fs.readFile(path.join(controlClone, "LICENSE"), "utf8");+ assert.ok(controlLicense.includes("\r\n"), "control clone with core.autocrlf=true should check out CRLF");++ // Also seed legacy pre-v0.3.4 availableCommit with unpeeled annotated tag object SHA to verify smooth migration+ const legitTagObjSha = git(hijackWork, ["rev-parse", "refs/tags/v0.5.0"]).trim();+ assert.notEqual(legitTagObjSha, legitCommit, "v0.5.0 fixture should be an annotated tag");+ await writeUpdateState(+ {+ availableRef: "v0.5.0",+ availableVersion: "0.5.0",+ availableCommit: legitTagObjSha,+ },+ crlfEnv,+ validTargetPlugin,+ );+const validUpd = await runPluginUpdate({pluginDir: validTargetPlugin,- env: {- ...hijackEnv,- HOME: path.join(rootTmp, "hijack-valid-home"),- USERPROFILE: path.join(rootTmp, "hijack-valid-home"),- AGY_FAST_CACHE_DIR: path.join(rootTmp, "hijack-valid-home", ".gemini", "cache", "agy-fast"),- },+ env: crlfEnv,checksumsText: validSums,});assert.equal(validUpd.status, "updated");assert.equal(validUpd.checksumVerified, true);assert.match(validUpd.message, /SHA-256 verified/);assert.equal(await readInstalledVersion(validTargetPlugin), "0.5.0");+ const migratedState = await readUpdateState(crlfEnv, validTargetPlugin);+ assert.equal(migratedState.knownTagCommits?.["v0.5.0"], legitCommit);++ // Also verify legacy v0.3.3 already-applied state (unpeeled tag object SHA in lastAppliedCommit) migrates cleanly+ const legacyAppliedHome = path.join(rootTmp, "hijack-legacy-applied-home");+ const legacyAppliedPlugin = path.join(legacyAppliedHome, ".gemini", "config", "plugins", "agy-fast");+ await copyRuntimeFixture(legacyAppliedPlugin, "0.5.0", "installed-0.5.0");+ const legacyAppliedEnv: NodeJS.ProcessEnv = {+ ...hijackEnv,+ HOME: legacyAppliedHome,+ USERPROFILE: legacyAppliedHome,+ AGY_FAST_CACHE_DIR: path.join(legacyAppliedHome, ".gemini", "cache", "agy-fast"),+ };+ await writeUpdateState(+ {+ latestRef: "v0.5.0",+ lastAppliedVersion: "0.5.0",+ lastAppliedCommit: legitTagObjSha,+ },+ legacyAppliedEnv,+ legacyAppliedPlugin,+ );+ const legacyCheck = await runPluginUpdate({+ pluginDir: legacyAppliedPlugin,+ checkOnly: true,+ env: legacyAppliedEnv,+ });+ assert.equal(legacyCheck.status, "up-to-date");+ const legacyMigratedState = await readUpdateState(legacyAppliedEnv, legacyAppliedPlugin);+ assert.equal(legacyMigratedState.knownTagCommits?.["v0.5.0"], legitCommit);// Now force-move v0.5.0 to a new malicious commit -> updater refuses BOTH normal & force updatesawait fs.writeFile(path.join(hijackWork, "rules", "AGENTS.md"), "# hijacked rules\n", "utf8");