Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(desktop): sync package version with CLI via git tag at build time (#1050)

LinYushen6bbe05905540
diff --git a/.gitignore b/.gitignore
index 9fba95f14f..ffb24ceeb4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,10 +12,17 @@ build
bin
dist-electron
*.tsbuildinfo
+# ...except electron-builder's source resources dir, which holds tracked
+# config files (entitlements, icons) — not build output.
+!apps/desktop/build/
+!apps/desktop/build/**
# env
.env*
!.env.example
+# Desktop production config is public (backend URL, etc.) — track it so
+# `pnpm package` produces a release-ready build without extra setup.
+!apps/desktop/.env.production
# test coverage
coverage
diff --git a/apps/desktop/.env.production b/apps/desktop/.env.production
new file mode 100644
index 0000000000..e6e6affb4a
--- /dev/null
+++ b/apps/desktop/.env.production
@@ -0,0 +1,12 @@
+# Production environment for `pnpm package` / `pnpm build`.
+# electron-vite (Vite under the hood) reads this automatically in
+# production mode and inlines the values into the renderer bundle via
+# import.meta.env.VITE_*. These are public URLs, not secrets.
+
+# Backend API + websocket the desktop app talks to.
+VITE_API_URL=https://api.multica.ai
+VITE_WS_URL=wss://api.multica.ai/ws
+
+# Public web app URL — used to build shareable links like "Copy link to
+# issue" that users paste into Slack / messages. See platform/navigation.tsx.
+VITE_APP_URL=https://multica.ai
diff --git a/apps/desktop/build/entitlements.mac.plist b/apps/desktop/build/entitlements.mac.plist
new file mode 100644
index 0000000000..f453dfe1a1
--- /dev/null
+++ b/apps/desktop/build/entitlements.mac.plist
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <!-- Electron / V8 need JIT and unsigned executable memory under the
+ hardened runtime. -->
+ <key>com.apple.security.cs.allow-jit</key>
+ <true/>
+ <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
+ <true/>
+ <!-- Required so the app can spawn the bundled `multica` Go binary and
+ any other child processes (e.g. agent CLIs) without Gatekeeper
+ blocking exec. -->
+ <key>com.apple.security.cs.disable-library-validation</key>
+ <true/>
+ <key>com.apple.security.cs.allow-dyld-environment-variables</key>
+ <true/>
+ <!-- Network client — the daemon talks to the backend + GitHub releases. -->
+ <key>com.apple.security.network.client</key>
+ <true/>
+ <key>com.apple.security.network.server</key>
+ <true/>
+</dict>
+</plist>
diff --git a/apps/desktop/electron-builder.yml b/apps/desktop/electron-builder.yml
index f1315c112b..b0f40681e5 100644
--- a/apps/desktop/electron-builder.yml
+++ b/apps/desktop/electron-builder.yml
@@ -19,10 +19,16 @@ mac:
target:
- dmg
- zip
- artifactName: ${name}-${version}-${arch}.${ext}
- notarize: false
+ # Hardcoded name avoids the `@multica/desktop-*` subdirectory that
+ # `${name}` produces for scoped package names.
+ artifactName: multica-desktop-${version}-${arch}.${ext}
+ # Notarize via notarytool. Requires APPLE_ID + APPLE_APP_SPECIFIC_PASSWORD
+ # + APPLE_TEAM_ID env vars at package time. Non-mac contributors are
+ # unaffected because `pnpm package` already requires the Developer ID
+ # signing cert — notarization is a strict superset.
+ notarize: true
dmg:
- artifactName: ${name}-${version}.${ext}
+ artifactName: multica-desktop-${version}-${arch}.${ext}
linux:
target:
- AppImage
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 366d77f0df..2062ddb4b4 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -11,7 +11,7 @@
"typecheck:web": "tsc --noEmit -p tsconfig.web.json --composite false",
"typecheck": "pnpm run typecheck:node && pnpm run typecheck:web",
"preview": "electron-vite preview",
- "package": "pnpm run bundle-cli && electron-builder",
+ "package": "node scripts/package.mjs",
"lint": "eslint .",
"test": "vitest run",
"postinstall": "electron-builder install-app-deps"
diff --git a/apps/desktop/scripts/package.mjs b/apps/desktop/scripts/package.mjs
new file mode 100644
index 0000000000..d06845988f
--- /dev/null
+++ b/apps/desktop/scripts/package.mjs
@@ -0,0 +1,122 @@
+#!/usr/bin/env node
+// Wrapper around `electron-builder` that keeps the Desktop version in
+// lockstep with the CLI. Both are derived from `git describe --tags
+// --always --dirty` — the same source GoReleaser reads for the CLI
+// binary via the `main.version` ldflag — so a single `vX.Y.Z` tag push
+// produces matching CLI and Desktop versions.
+//
+// Runs the existing bundle-cli.mjs first (so the Go binary is compiled
+// and copied into resources/bin/), then invokes electron-builder with
+// `-c.extraMetadata.version=<derived>` so the override applies at build
+// time without mutating the tracked package.json.
+//
+// Extra CLI args after `pnpm package --` are forwarded to electron-builder
+// unchanged (e.g. `--mac --arm64`).
+//
+// The `normalizeGitVersion` helper is exported so tests can cover the
+// version-derivation logic without shelling out.
+
+import { execFileSync, spawnSync, execSync } from "node:child_process";
+import { dirname, resolve } from "node:path";
+import { fileURLToPath, pathToFileURL } from "node:url";
+
+const here = dirname(fileURLToPath(import.meta.url));
+const desktopRoot = resolve(here, "..");
+
+function sh(cmd) {
+ try {
+ return execSync(cmd, { encoding: "utf-8" }).trim();
+ } catch {
+ return "";
+ }
+}
+
+/**
+ * Pure transformation from the `git describe --tags --always --dirty`
+ * output to the value we feed into electron-builder's extraMetadata.version.
+ *
+ * - empty input → null (caller should fall back)
+ * - "v0.1.36" → "0.1.36"
+ * - "v0.1.35-14-gf1415e96" → "0.1.35-14-gf1415e96" (semver prerelease)
+ * - "v0.1.35-…-dirty" → same, dirty suffix preserved
+ * - "f1415e96" (no tag) → "0.0.0-f1415e96" (fallback)
+ *
+ * Leading `v` is stripped so the result is valid semver for package.json.
+ */
+export function normalizeGitVersion(raw) {
+ if (!raw) return null;
+ const stripped = raw.replace(/^v/, "");
+ if (!/^\d/.test(stripped)) {
+ // No reachable tag — `git describe` fell back to just the commit hash.
+ return `0.0.0-${stripped}`;
+ }
+ return stripped;
+}
+
+function deriveVersion() {
+ return normalizeGitVersion(sh("git describe --tags --always --dirty"));
+}
+
+function main() {
+ // Step 1: build + bundle the Go CLI via the existing script.
+ execFileSync("node", [resolve(here, "bundle-cli.mjs")], {
+ stdio: "inherit",
+ cwd: desktopRoot,
+ });
+
+ // Step 2: derive the version that should be written into the app.
+ const version = deriveVersion();
+ if (version) {
+ console.log(`[package] Desktop version → ${version} (from git describe)`);
+ } else {
+ console.warn(
+ "[package] could not derive version from git; falling back to package.json",
+ );
+ }
+
+ // Step 3: assemble electron-builder args.
+ const passthrough = process.argv.slice(2);
+ const builderArgs = [];
+ if (version) builderArgs.push(`-c.extraMetadata.version=${version}`);
+
+ // Step 4: gracefully degrade for local dev builds. electron-builder.yml
+ // sets `notarize: true` so real releases notarize in-build (keeping the
+ // stapled .app consistent with latest-mac.yml's SHA512). But a mac dev
+ // who just wants to smoke-test a local package doesn't have Apple
+ // credentials, and would otherwise hit a hard failure at the notarize
+ // step. Detect the missing env and flip notarize off for this run only.
+ if (!process.env.APPLE_TEAM_ID) {
+ console.warn(
+ "[package] APPLE_TEAM_ID not set — skipping notarization (local dev build). " +
+ "Set APPLE_ID + APPLE_APP_SPECIFIC_PASSWORD + APPLE_TEAM_ID for a release build.",
+ );
+ builderArgs.push("-c.mac.notarize=false");
+ }
+
+ builderArgs.push(...passthrough);
+
+ // Step 5: invoke electron-builder. pnpm puts node_modules/.bin on PATH
+ // for the script run, so spawnSync finds the binary without needing a
+ // shell wrapper (avoids any risk of argv interpolation).
+ const result = spawnSync("electron-builder", builderArgs, {
+ stdio: "inherit",
+ cwd: desktopRoot,
+ });
+
+ if (result.error) {
+ console.error(
+ "[package] failed to spawn electron-builder:",
+ result.error.message,
+ );
+ process.exit(1);
+ }
+ process.exit(result.status ?? 1);
+}
+
+// Only run when invoked as a CLI, not when imported by a test file.
+if (
+ process.argv[1] &&
+ import.meta.url === pathToFileURL(process.argv[1]).href
+) {
+ main();
+}
diff --git a/apps/desktop/scripts/package.test.mjs b/apps/desktop/scripts/package.test.mjs
new file mode 100644
index 0000000000..9fc5e391f7
--- /dev/null
+++ b/apps/desktop/scripts/package.test.mjs
@@ -0,0 +1,39 @@
+import { describe, it, expect } from "vitest";
+import { normalizeGitVersion } from "./package.mjs";
+
+describe("normalizeGitVersion", () => {
+ it("returns null for empty / nullish input", () => {
+ expect(normalizeGitVersion("")).toBe(null);
+ expect(normalizeGitVersion(null)).toBe(null);
+ expect(normalizeGitVersion(undefined)).toBe(null);
+ });
+
+ it("strips the leading v on a clean tag", () => {
+ expect(normalizeGitVersion("v0.1.36")).toBe("0.1.36");
+ expect(normalizeGitVersion("v1.0.0")).toBe("1.0.0");
+ });
+
+ it("preserves the prerelease suffix between tags", () => {
+ expect(normalizeGitVersion("v0.1.35-14-gf1415e96")).toBe(
+ "0.1.35-14-gf1415e96",
+ );
+ });
+
+ it("preserves the dirty suffix on a modified worktree", () => {
+ expect(normalizeGitVersion("v0.1.35-14-gf1415e96-dirty")).toBe(
+ "0.1.35-14-gf1415e96-dirty",
+ );
+ });
+
+ it("handles v-prefixed prerelease tags", () => {
+ expect(normalizeGitVersion("v1.0.0-alpha")).toBe("1.0.0-alpha");
+ expect(normalizeGitVersion("v1.0.0-rc.2")).toBe("1.0.0-rc.2");
+ });
+
+ it("falls back to 0.0.0-<hash> when no tags are reachable", () => {
+ // `git describe --tags --always` returns just the short commit hash
+ // when there are no tags in the history at all.
+ expect(normalizeGitVersion("f1415e96")).toBe("0.0.0-f1415e96");
+ expect(normalizeGitVersion("abc1234")).toBe("0.0.0-abc1234");
+ });
+});
diff --git a/apps/desktop/src/renderer/src/platform/navigation.tsx b/apps/desktop/src/renderer/src/platform/navigation.tsx
index 7ebeb862f4..09eebb215e 100644
--- a/apps/desktop/src/renderer/src/platform/navigation.tsx
+++ b/apps/desktop/src/renderer/src/platform/navigation.tsx
@@ -7,6 +7,11 @@ import {
import { useAuthStore } from "@multica/core/auth";
import { useTabStore, resolveRouteIcon } from "@/stores/tab-store";
+// Public web app URL — injected at build time via .env.production. Falls
+// back to the production host for dev builds so "Copy link" yields a URL
+// that actually points somewhere a teammate can open.
+const APP_URL = import.meta.env.VITE_APP_URL || "https://multica.ai";
+
/**
* Root-level navigation provider for components outside the per-tab RouterProviders
* (sidebar, search dialog, modals, etc.).
@@ -64,7 +69,7 @@ export function DesktopNavigationProvider({
const tabId = store.openTab(path, title ?? path, icon);
store.setActiveTab(tabId);
},
- getShareableUrl: (path: string) => `https://www.multica.ai${path}`,
+ getShareableUrl: (path: string) => `${APP_URL}${path}`,
}),
[pathname],
);
@@ -107,7 +112,7 @@ export function TabNavigationProvider({
const newTabId = store.openTab(path, title ?? path, icon);
store.setActiveTab(newTabId);
},
- getShareableUrl: (path: string) => `https://www.multica.ai${path}`,
+ getShareableUrl: (path: string) => `${APP_URL}${path}`,
}),
[router, location],
);
diff --git a/apps/desktop/vitest.config.ts b/apps/desktop/vitest.config.ts
index bd8c8f627e..cb39b650c8 100644
--- a/apps/desktop/vitest.config.ts
+++ b/apps/desktop/vitest.config.ts
@@ -3,7 +3,7 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
globals: true,
- include: ["src/**/*.test.ts"],
+ include: ["src/**/*.test.ts", "scripts/**/*.test.mjs"],
environment: "node",
passWithNoTests: true,
},