v0.18.9:collector 併進同一支執行檔——磁碟上不再攤出第二支 exe

leo 08-06 裁決:「不要兩支,寫成一支檔案」。

## 為什麼
v0.18.7-8 的「單一 exe」其實是**一支包著另一支**:collector.exe 被 go:embed
進 Arcrun.exe,執行時攤到 ~/.arcrun-rag/bin/ 再跑。
那正是防毒軟體眼中的 dropper 特徵 —— 封測者實撞
`Trojan:Win32/Sabsik.FL.A!ml`,檔案當場被隔離、自動刪除。

⚠️ 誠實界定:`!ml` 結尾=**機器學習判定**,Sabsik 是最常見的通用誤判家族,
   主因是「未簽章+下載次數少」,**不是**特別指向 dropper 行為。
   所以本次改動**不保證**解除誤判——真正的解是上架 MS Store(微軟簽章)。
   但「執行時把第二支 PE 寫到磁碟再執行」本來就該拿掉,這是對的方向且順手變小。

## 怎麼做
- `collector/` 39 個檔 `package main` → `package collector`,`main()` → 匯出的 `Run(args) int`
- 新增 `collector/cmd/collector/`(薄殼 CLI,讓單獨跑 collector 這條路仍可用)
- App 直接 import 該套件;`main()` 第一件事就判 `--collector`,是的話走 `collector.Run` 不碰 GUI
- `supervisor` 加 `ArgPrefix`,App 把 `BinPath` 指向 `os.Executable()` 自己
- 刪掉 `bundled_collector_{windows,other}.go`(embed + 攤檔那套)
- 三支打包腳本不再編/複製第二支;版本注入同時打到兩個 package
- build-win.sh 的機械閘改成**直接問它**:`--collector --version` 回得出版本才放行
  (舊閘是比大小,只能證明「有 embed」,證明不了「分派是對的」)

## 驗(真機實跑)
· `.app/Contents/MacOS/` 只有 **一個** 執行檔(原本兩個)
· 跑起來兩個行程是**同一個 exe**:
    …/MacOS/arcrun-app
    …/MacOS/arcrun-app --collector direct --config …
· `~/.arcrun-rag/bin` **不存在**(沒有任何東西被攤出來)
· 端到端:丟檔進看守資料夾 → collector.log `"status":"ingested","http_status":200`
· `lsappinfo` 仍是 `type="UIElement"`、`Version="0.18.9"`
· collector 39 檔測試全過;app 測試過;go vet 全綠;mac + windows 交叉編譯皆過
· 單檔 26MB → 22MB(不再夾帶第二份完整程式)
This commit is contained in:
2026-08-06 16:00:47 +08:00
parent f4eb3c9fa1
commit 4d3a6a09a6
50 changed files with 196 additions and 193 deletions
+5 -12
View File
@@ -19,19 +19,14 @@ VERSION="${VERSION:-$(./daemon-version.py --stamp)}"
./changelog-section.sh "$VERSION" --check
BUILD_TIME="$(date '+%Y%m%d-%H%M')"
LDFLAGS_VER="-X main.version=${VERSION} -X main.buildTime=${BUILD_TIME}"
LDFLAGS_VER="-X main.version=${VERSION} -X main.buildTime=${BUILD_TIME} -X arcrun-rag/collector.version=${VERSION} -X arcrun-rag/collector.buildTime=${BUILD_TIME}"
export PATH="$PATH:$(go env GOPATH)/bin"
echo "🏷 版本:${VERSION}build ${BUILD_TIME}"
echo "① 編 collector(同綑執行檔,純 stdlib、CGO_ENABLED=0"
# 🔴 2026-08-06 補回版本注入(**Wails 換代時掉的**):
# 退役的 fyne 版 `arcrun-tray/build-mac.sh:24` 本來就有這個(t150t72
# leo 07-29「我的和下載下來的會是同一個嗎?」),t194 重寫成 Wails 版時沒帶過來
# ⇒ 同綑的 collector 一路自稱 `dev`App 門面卻顯示 v0.18.x。
# **幹活的是 collector**:它不報版本,就沒人能判斷某個修復有沒有真的到使用者手上——
# 正是「版本號是 leo 唯一驗收介面」要擋的那個病。
# 實撞:v0.18.6 打包後 `arcrun-collector --version` 回 `dev`。
( cd ../.. && CGO_ENABLED=0 go build -ldflags "-s -w ${LDFLAGS_VER}" -o "cmd/arcrun-app/arcrun-collector" . )
# 🔴 2026-08-06 起**不再單獨編 collector**(leo:「不要兩支,寫成一支檔案」)。
# collector 已改成可被引用的套件,直接編進同一個執行檔,靠 `--collector` 換身分。
# Mac 這邊原本是 .app 裡放兩個執行檔(沒有 dropper 問題),但兩邊做法統一才不會再漂移
# ——「Mac 有、Windows 漏了」這種病本 repo 已經犯過兩次(2b83c47、v0.18.6 版本注入)。
# 🔴 2026-08-05leo 開 DMG 檢查時抓到):Info.plist 的 CFBundleShortVersionString
# 是 **1.0.0**(Wails 預設),不是我們的版本號——因為 wails.json 沒有 info.productVersion
@@ -58,12 +53,10 @@ APP="build/bin/Arcrun.app"
[ -d "build/bin/arcrun-app.app" ] && { rm -rf "$APP"; mv "build/bin/arcrun-app.app" "$APP"; }
echo "③ 同綑 collector 進 .appApp 用 os.Executable() 找同層)"
cp arcrun-collector "$APP/Contents/MacOS/arcrun-collector"
echo "④ ad-hoc 重簽(改過 bundle 內容必重簽,否則 launchd 拒開)"
codesign --force --deep --sign - "$APP" 2>/dev/null || true
rm -f arcrun-collector
echo "✅ 完成:$APP"
echo " 驗法:open '$APP' → 選單列出現 icon、Dock **不出現** icon"
echo " 點 icon → 立刻展開視窗;右鍵 → 只有「結束 Arcrun」"