Skip to content

Commit f736ff5

Browse files
authored
feat(terminal-browser): zenbu-labs/terminal-browser を宣言に入れる (#510)
端末の中で動く実ブラウザ。狙いは閲覧より agent 側で、`terminal-browser action` が開いているブラウザに対する agent 向け CLI になっている。Claude in Chrome の 拡張を使わず、実ウィンドウも出さずに web を触らせられる。agent の隣にペインで 開き、ssh 越しにも使える — 拡張の経路では両方できない。 上流は `curl -fsSL https://terminal-browser.sh/install | bash` で入れる形で、 $HOME に書き込み `terminal-browser upgrade` で自己更新する。宣言に置く理由は そこで、版は flake.lock が決める。 同梱 Electron ごと運ぶので展開 307MB。ソースからはビルドせず、配布物の バイナリをそのまま置くので署名も保たれる。 罠を2つ踏んだ: - stdenv の unpackPhase が tar の唯一の最上位ディレクトリに自動で降りるので、 `cp -R terminal-browser` は空振りする。cwd が既にその中 - AppleDouble のサイドカー (._default_app.asar など) が実ファイルとして 書き出され、署名が封印していないファイルが増えて codesign が落ちる (pkgs/keebmouse.nix と同じ)。ここでは実害が明確で、署名の壊れた Electron は 起動せず --help すら返さない 検証: `codesign -v` が無言 (Developer ID: Robert Pruzan)、`--help` が返る、 system の sw/bin に出る。
1 parent 0c42c16 commit f736ff5

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

nix/hosts/darwin.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ in
5757
# 経緯)。systemPackages なのは omniwmctl の置き場所のため — /run/current-system/sw/bin という
5858
# 版にもユーザー名にも依存しない固定パスに出るので、configs 側のスクリプトが直に書ける。
5959
(pkgs.callPackage ../pkgs/omniwm.nix { })
60+
# terminal-browser: 端末の中で動く実ブラウザ。狙いは閲覧より agent 側で、
61+
# `terminal-browser action` が開いているブラウザに対する agent 向け CLI になっている。
62+
# Claude in Chrome の拡張を使わず、実ウィンドウも出さずに web を触らせられる。
63+
# 上流は curl | bash のインストーラで自己更新するので、版を握るために宣言側に置く。
64+
(pkgs.callPackage ../pkgs/terminal-browser.nix { })
6065
# codex: 自前インストーラで ~/.local/bin に入っていたものを宣言に移す。home.packages
6166
# ではなく systemPackages なのは PATH の順で、/run/current-system/sw/bin が
6267
# ~/.local/bin より前に来る。profile 側だと手動インストール版が勝ってしまう。

nix/pkgs/terminal-browser.nix

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# terminal-browser (zenbu-labs): a real browser that runs inside the terminal.
2+
#
3+
# The point of it here is the agent side rather than the browsing: `terminal-browser action` is an
4+
# agent-facing CLI over whatever browsers are open, so an agent gets the web without the Claude in
5+
# Chrome extension and without a visible Chrome window. It also opens in a split pane beside the
6+
# agent and works over ssh, which the extension path cannot do.
7+
#
8+
# Upstream ships `curl -fsSL https://terminal-browser.sh/install | bash`. That is the thing this
9+
# package exists to avoid: the installer writes into $HOME and self-updates (`terminal-browser
10+
# upgrade`), so the version would be whatever the last run left behind. Here it is whatever
11+
# flake.lock says.
12+
#
13+
# The tarball bundles its own Electron, so it is 307MB unpacked and nothing is built from source —
14+
# the shipped binaries are copied as-is, which also leaves their signatures untouched.
15+
{
16+
lib,
17+
stdenvNoCC,
18+
fetchurl,
19+
}:
20+
stdenvNoCC.mkDerivation (finalAttrs: {
21+
pname = "terminal-browser";
22+
version = "0.7.5";
23+
24+
src = fetchurl {
25+
url = "https://github.com/zenbu-labs/terminal-browser/releases/download/v${finalAttrs.version}/terminal-browser-darwin-arm64.tar.gz";
26+
hash = "sha256-Wnnrf3sl1BhpdfdYR0BAIw0ZnbqsNEXW8exTftrlWuc=";
27+
};
28+
29+
# An Electron bundle: patching anything in it would only break code signatures, and the
30+
# shebangs it does have already point at /bin/sh.
31+
dontPatchShebangs = true;
32+
dontStrip = true;
33+
34+
installPhase = ''
35+
runHook preInstall
36+
# stdenv の unpackPhase が tar の唯一の最上位ディレクトリ (terminal-browser/) に自動で
37+
# 降りるので、ここでの cwd は既にその中。`cp -R terminal-browser` は空振りする。
38+
# 同梱 Electron の署名を守るため、AppleDouble のサイドカーを落としてから運ぶ。
39+
# tar が ._default_app.asar のような実ファイルを書き出し、署名が封印していない
40+
# ファイルが増えるので `codesign -v` が落ちる (pkgs/keebmouse.nix と同じ罠)。
41+
# ここでは実害が分かりやすく、署名が壊れた Electron は起動せず --help すら返さない。
42+
find . -name '._*' -delete
43+
find . -name '.DS_Store' -delete
44+
mkdir -p $out/libexec/terminal-browser $out/bin
45+
cp -R . $out/libexec/terminal-browser/
46+
# bin/terminal-browser is a /bin/sh wrapper that resolves its own symlink to find the bundle,
47+
# so a plain symlink onto PATH is all that is needed — it follows the link back to $out.
48+
ln -s $out/libexec/terminal-browser/bin/terminal-browser $out/bin/terminal-browser
49+
runHook postInstall
50+
'';
51+
52+
meta = {
53+
description = "A real browser that runs inside your terminal";
54+
homepage = "https://github.com/zenbu-labs/terminal-browser";
55+
license = lib.licenses.mit;
56+
platforms = [ "aarch64-darwin" ];
57+
mainProgram = "terminal-browser";
58+
};
59+
})

0 commit comments

Comments
 (0)