diff --git a/docs/adr/0047_assemble_the_t3_desktop_app_bundle_in_dotfiles.md b/docs/adr/0047_assemble_the_t3_desktop_app_bundle_in_dotfiles.md new file mode 100644 index 0000000..7c3e6a5 --- /dev/null +++ b/docs/adr/0047_assemble_the_t3_desktop_app_bundle_in_dotfiles.md @@ -0,0 +1,41 @@ +--- +status: proposed +date: 2026-11-22 +related: [ADR-0041] +--- + +# Assemble the T3 desktop app bundle in dotfiles + +## Context and Problem Statement + +The T3 Code desktop app from `llm-agents` shows up as "Electron", with Electron's icon, in the Dock, +Cmd+Tab and the menu bar. Its `.app` is only a launcher that execs the binary inside nixpkgs' +`Electron.app`, and macOS names a process after the bundle that holds its executable. Issue #494 +tracks the work; T3's code, version and provider PATH (including the signed Codex of ADR-0041) +should keep coming from `llm-agents`. + +## Considered Options + +- A dotfiles package (`nix/packages/t3code_desktop.nix`) that copies the `Electron.app` of the + Electron `llm-agents` builds T3 against, renames it to T3, adds a launcher with the `llm-agents` + wrappers' arguments and PATH, and re-signs the bundle ad-hoc. +- Keep the `llm-agents` `t3code-desktop` package and wait for an upstream fix. + +## Decision Outcome + +Chosen option: "A dotfiles package that copies `Electron.app` and renames it to T3", because the +running Electron then lives in a bundle whose name, identifier and icon are T3's, while only the +bundle assembly leaves `llm-agents`. Electron comes from the `llm-agents` nixpkgs input, not the +dotfiles one, so T3 runs on the Electron it was built for. Waiting for upstream leaves the wrong +name and icon in place with no date. + +### Consequences + +- Good, because the Dock, Cmd+Tab and the menu bar show T3 Code (Beta) and T3's icon. +- Good, because T3's code and version still update with `llm-agents`, and the launchd server's + `t3codePackage` is unchanged. +- Bad, because dotfiles duplicates the `llm-agents` wrappers' arguments and PATH; the + `t3-desktop-app-bundle` check fails when they, the app directory, or the Electron version drift. +- Bad, because the store holds a second, ad-hoc signed copy of `Electron.app`, and macOS asks for + notification permission again after the identifier and signature change. +- Revert to the `llm-agents` package once upstream assembles a T3-named bundle itself. diff --git a/nix/checks.nix b/nix/checks.nix index 9c31a8e..c56c599 100644 --- a/nix/checks.nix +++ b/nix/checks.nix @@ -36,6 +36,11 @@ let t3Package = builtins.head ( builtins.filter (package: (package.pname or "") == "t3code") mbpHome.home.packages ); + t3DesktopPackage = builtins.head ( + builtins.filter ( + package: (package.pname or package.name or "") == "t3code-desktop" + ) mbpHome.home.packages + ); t3ServicePath = lib.splitString ":" t3Service.EnvironmentVariables.PATH; t3ServiceState = "${mbpHome.home.homeDirectory}/.t3"; claudePackage = inputs.llm-agents.packages.${pkgs.stdenv.hostPlatform.system}.claude-code; @@ -533,6 +538,46 @@ in touch "$out" ''; + # macOS names the Dock and Cmd+Tab entry after the bundle of the running binary, so the + # launcher must exec the Electron inside the T3 bundle with the llm-agents wrapper's environment. + t3-desktop-app-bundle = + pkgs.runCommand "t3-desktop-app-bundle" + { + nativeBuildInputs = [ pkgs.cctools ]; + app = "${t3DesktopPackage}/Applications/T3 Code (Beta).app"; + upstreamApp = "${t3Package.desktop}/Applications/T3 Code (Beta).app"; + upstreamLauncher = "${t3Package.desktop}/bin/t3code-desktop"; + unwrappedLauncher = "${t3Package.unwrapped.desktop}/bin/t3code-desktop"; + appDirectory = "${t3Package.unwrapped.desktop}/libexec/t3code/apps/desktop"; + signedCodex = lib.makeBinPath [ codexPackage ]; + } + '' + info() { /usr/bin/plutil -extract "$2" raw -o - "$1/Contents/Info.plist"; } + wrapperPath() { strings "$1" | sed -n "s/^ *--prefix 'PATH' ':' '\(.*\)' .*$/\1/p"; } + test "$(info "$app" CFBundleName)" = 'T3 Code (Beta)' + test "$(info "$app" CFBundleDisplayName)" = 'T3 Code (Beta)' + # Apple allows only letters, digits, "-" and "." in a bundle identifier. + info "$app" CFBundleIdentifier | grep -qxE '[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+' + info "$app" CFBundleIdentifier | grep -qF t3code + cmp "$app/Contents/Resources/$(info "$app" CFBundleIconFile)" "$upstreamApp/Contents/Resources/t3code.icns" + + launcher="$app/Contents/MacOS/$(info "$app" CFBundleExecutable)" + test -f "$launcher" && test -x "$launcher" && test ! -L "$launcher" + strings "$launcher" | grep -qF "$app/Contents/MacOS/Electron" + strings "$launcher" | grep -qF "$appDirectory" + test -n "$(wrapperPath "$upstreamLauncher")" + test "$(wrapperPath "$launcher")" = "$(wrapperPath "$upstreamLauncher")" + wrapperPath "$launcher" | tr ':' '\n' | grep -qxF "$signedCodex" + + # Electron looks its helpers up as "Electron Helper*.app". + test -x "$app/Contents/Frameworks/Electron Helper.app/Contents/MacOS/Electron Helper" + upstreamElectron=$(strings "$unwrappedLauncher" | grep -m1 -oE '/nix/store/[^ ]*-electron-[^/ ]*/bin/electron') + test "$(info "$app" CFBundleVersion)" = "$(info "''${upstreamElectron%/bin/electron}/Applications/Electron.app" CFBundleVersion)" + + /usr/bin/codesign --verify --deep --strict "$app" + touch "$out" + ''; + # Skills are generated by running the installed Darwin CLIs, so only a build proves the bundled text. automation-cli-skills = pkgs.runCommand "automation-cli-skills" diff --git a/nix/home/default.nix b/nix/home/default.nix index a664956..706c528 100644 --- a/nix/home/default.nix +++ b/nix/home/default.nix @@ -44,7 +44,10 @@ let ] ++ lib.filter (provider: (provider.pname or "") != "codex") t3codeUpstream.providerPackages; }; - t3codeDesktopPackage = llm-agents.packages.${system}.t3code-desktop.override { + # The Dock shows T3, not Electron, only when the bundle holds the Electron it runs (#494). + # llm-agents builds T3 against the Electron of its own nixpkgs, not the dotfiles one. + t3codeDesktopPackage = pkgs.callPackage ../packages/t3code_desktop.nix { + inherit (llm-agents.inputs.nixpkgs.legacyPackages.${system}) electron_44; t3code = t3codePackage; }; agentDesktopPackage = pkgs.callPackage ../packages/agent_desktop.nix { }; diff --git a/nix/packages/t3code_desktop.nix b/nix/packages/t3code_desktop.nix new file mode 100644 index 0000000..2265f1d --- /dev/null +++ b/nix/packages/t3code_desktop.nix @@ -0,0 +1,64 @@ +{ + electron_44, + lib, + makeBinaryWrapper, + stdenvNoCC, + t3code, +}: + +# macOS names the Dock and Cmd+Tab entry after the bundle that holds the running binary, so +# llm-agents' launcher, which execs nixpkgs' Electron.app, shows up as "Electron". This copies +# that Electron.app, renames it to T3, and execs the copy's own Electron with T3's app directory. +let + inherit (t3code.unwrapped) appName; + upstreamApp = "${t3code.desktop}/Applications/${appName}.app"; + appDirectory = "${t3code.unwrapped.desktop}/libexec/t3code/apps/desktop"; + # llm-agents' "org.nixos.T3 Code (Beta)" has characters Apple does not allow in an identifier. + bundleIdentifier = "org.nixos.t3code-desktop"; +in +stdenvNoCC.mkDerivation { + pname = "t3code-desktop"; + inherit (t3code) version; + + dontUnpack = true; + # Fixup would strip or rewrite Mach-O files after the ad-hoc signature is applied. + dontFixup = true; + + nativeBuildInputs = [ makeBinaryWrapper ]; + + installPhase = '' + runHook preInstall + + app="$out/Applications/${appName}.app" + mkdir -p "$out/Applications" "$out/bin" + cp -R ${electron_44}/Applications/Electron.app "$app" + chmod -R u+w "$app" + + install -m444 "${upstreamApp}/Contents/Resources/t3code.icns" "$app/Contents/Resources/t3code.icns" + plist="$app/Contents/Info.plist" + /usr/bin/plutil -replace CFBundleName -string "${appName}" "$plist" + /usr/bin/plutil -replace CFBundleDisplayName -string "${appName}" "$plist" + /usr/bin/plutil -replace CFBundleIdentifier -string ${bundleIdentifier} "$plist" + /usr/bin/plutil -replace CFBundleIconFile -string t3code.icns "$plist" + /usr/bin/plutil -replace CFBundleExecutable -string "${appName}" "$plist" + + # Same arguments and PATH as llm-agents' two wrappers, which keeps the signed Codex (ADR-0041). + makeWrapper "$app/Contents/MacOS/Electron" "$app/Contents/MacOS/${appName}" \ + --add-flags ${lib.escapeShellArg appDirectory} \ + --prefix PATH : ${lib.escapeShellArg (lib.makeBinPath t3code.providerPackages)} \ + --inherit-argv0 + ln -s "../Applications/${appName}.app/Contents/MacOS/${appName}" "$out/bin/t3code-desktop" + ln -s ${t3code.desktop}/share "$out/share" + + # Editing Info.plist and adding the launcher invalidate the copied signature. + /usr/bin/codesign --force --deep --sign - "$app" + + runHook postInstall + ''; + + meta = t3code.meta // { + description = "T3 Code desktop app bundled under its own name and icon"; + mainProgram = "t3code-desktop"; + platforms = [ "aarch64-darwin" ]; + }; +}