diff --git a/CHANGELOG.md b/CHANGELOG.md index f22736a..8e071ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/). +## [0.78.2] - 2026-10-06 + +### Fixed +- **macOS の対話インストールでプラグインマーケットプレイスの追加とプラグインのインストールが失敗する問題を修正**: `install.sh` は `curl | bash` でもウィザードが入力を受け取れるように `setup.sh` の stdin を `/dev/tty` へ付け替えて起動する。ネイティブ版 Claude Code CLI(Bun でビルドされたバイナリ)はこの stdin を kqueue で監視しようとするが、macOS の kqueue は `/dev/tty` という別名デバイスを受け付けないため、`claude plugin marketplace add` / `claude plugin list` / `claude plugin install` が `error: EINVAL: invalid argument, kqueue` で異常終了していた。その結果、新規 Mac では `claude-plugins-official`(Full プロファイルでは `anthropic-agent-skills` も)の追加失敗に続いて「Could not refresh installed plugins after marketplace setup」が表示され、既定プラグインが 1 つも入らなかった。この失敗で `install_selected_plugins` が非 0 を返すため、後続の Codex Plugin セットアップ(有効時)と Claude CLI の最終確認も実行されずに終了していた。stdin が `/dev/null` の場合や、`/dev/tty` ではなく実際の pty デバイスの場合は発生しないため、`bash setup.sh` を直接実行した場合や非対話インストールでは再現しない + - キットから実行する `claude plugin` / `claude mcp` / `claude --version` の呼び出し(`setup.sh` のプラグイン導入、`lib/codex-setup.sh` の Codex プラグイン導入とレガシー MCP 削除、`lib/deploy.sh` のバージョン取得、`uninstall.sh` の Codex 後片付け)を、すべて stdin を `/dev/null` にして実行するよう変更した。`setup.sh` と `lib/codex-setup.sh` の呼び出しは新設の `_claude_cli()` を経由させ、`lib/deploy.sh` のバージョン取得と、自己完結が必要な `uninstall.sh` はリダイレクトを直接書いている。これらのサブコマンドは入力を読まないため挙動は変わらない。`uninstall.sh` の確認プロンプトは従来どおり利用者の入力を読む + - **回帰テスト**: `tests/unit/test-codex-setup.sh` に、`_claude_cli` が呼び出し元の stdin を引き継がないことの検証と、同梱スクリプト内の `claude plugin|mcp|--version` 呼び出しが `_claude_cli` か `/dev/null \ - && _plugin_list="$(claude plugin list 2>/dev/null)" \ + && _plugin_list="$(_claude_cli plugin list 2>/dev/null)" \ && _claude_plugin_list_has "$_plugin_list" "codex" } _has_legacy_mcp() { - command -v claude &>/dev/null && claude mcp list 2>/dev/null | grep -qw "codex" 2>/dev/null + command -v claude &>/dev/null && _claude_cli mcp list 2>/dev/null | grep -qw "codex" 2>/dev/null } _install_codex_plugin() { @@ -394,11 +407,11 @@ _install_codex_plugin() { return 1 fi local _marketplace_output="" _install_output="" - if ! _run_capture _marketplace_output claude plugin marketplace add openai/codex-plugin-cc; then + if ! _run_capture _marketplace_output _claude_cli plugin marketplace add openai/codex-plugin-cc; then warn "${STR_CODEX_PLUGIN_MARKETPLACE_FAILED:-Failed to add Codex plugin marketplace. Continuing to install attempt:}" [[ -n "$_marketplace_output" ]] && info " $_marketplace_output" fi - if _run_capture _install_output claude plugin install codex --scope user; then + if _run_capture _install_output _claude_cli plugin install codex --scope user; then return 0 fi warn "${STR_CODEX_PLUGIN_FAILED:-Failed to install Codex plugin}" @@ -411,7 +424,7 @@ _install_codex_plugin() { _remove_legacy_mcp() { if _has_legacy_mcp; then local _remove_output="" - if _run_capture _remove_output claude mcp remove codex; then + if _run_capture _remove_output _claude_cli mcp remove codex; then return 0 fi warn "${STR_CODEX_MCP_REMOVE_FAILED:-Failed to remove Codex MCP. Remove manually:}" diff --git a/lib/deploy.sh b/lib/deploy.sh index 97ed93d..881397d 100644 --- a/lib/deploy.sh +++ b/lib/deploy.sh @@ -98,7 +98,9 @@ _claude_cli_semver() { return 0 fi _CLAUDE_SEMVER_CACHE_SET=true - raw="$(claude --version 2>/dev/null | head -1)" + # --version exits before touching stdin; detached anyway for consistency with + # _claude_cli() in lib/codex-setup.sh (macOS kqueue rejects a /dev/tty stdin). + raw="$(claude --version /dev/null | head -1)" if ! [[ "$raw" =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then _CLAUDE_SEMVER_CACHE="" return 1 diff --git a/setup.sh b/setup.sh index c7bbeb6..d09fa4d 100755 --- a/setup.sh +++ b/setup.sh @@ -1417,7 +1417,7 @@ _read_claude_plugin_list() { # local output_var="$1" plugin_snapshot="" printf -v "$output_var" '%s' "" command -v claude &>/dev/null || return 1 - if ! plugin_snapshot="$(claude plugin list 2>/dev/null)"; then + if ! plugin_snapshot="$(_claude_cli plugin list 2>/dev/null)"; then return 1 fi printf -v "$output_var" '%s' "$plugin_snapshot" @@ -1521,7 +1521,7 @@ install_selected_plugins() { mp_repo="${_PLUGIN_INSTALL_REPOS[$i]}" [[ ",$registered_repos," == *",$mp_repo,"* ]] && continue mp_output="" - if ! _run_capture mp_output claude plugin marketplace add "$mp_repo"; then + if ! _run_capture mp_output _claude_cli plugin marketplace add "$mp_repo"; then warn "${STR_DEPLOY_PLUGINS_MARKETPLACE_FAILED:-Failed to add plugin marketplace} $p_mp" [[ -n "$mp_output" ]] && info " $mp_output" failed_repos="${failed_repos:+${failed_repos},}${mp_repo}" @@ -1632,7 +1632,7 @@ install_selected_plugins() { plugin_output="" if _run_capture plugin_output \ - claude plugin install "$p" --scope user; then + _claude_cli plugin install "$p" --scope user; then post_install_plugins="" if ! _read_claude_plugin_list post_install_plugins; then warn "Could not verify installed plugin exactly: $p_qualified" diff --git a/tests/unit/test-codex-setup.sh b/tests/unit/test-codex-setup.sh index d30e23f..5e261ad 100644 --- a/tests/unit/test-codex-setup.sh +++ b/tests/unit/test-codex-setup.sh @@ -203,6 +203,50 @@ else fi teardown_fake_claude +# install.sh runs setup.sh with stdin from /dev/tty; the Bun-based CLI fails on +# macOS with "EINVAL: invalid argument, kqueue" when it inherits that stdin. +# _claude_cli must hand the CLI an empty, non-terminal stdin instead. +_stdin_probe_dir="$(mktemp -d)" +_SETUP_TMP_FILES+=("$_stdin_probe_dir") +cat >"$_stdin_probe_dir/claude" <<'EOF' +#!/bin/bash +if [[ -t 0 ]]; then printf 'tty\n'; else printf 'stdin=[%s]\n' "$(cat)"; fi +EOF +chmod +x "$_stdin_probe_dir/claude" +if assert_equals "stdin=[]" \ + "$(printf 'inherited-input' | PATH="$_stdin_probe_dir:$PATH" _claude_cli plugin list)"; then + pass "codex-setup: _claude_cli detaches stdin from the caller" +else + fail "codex-setup: _claude_cli must run claude with stdin from /dev/null" +fi + +# Every shipped `claude plugin|mcp|--version` call must detach stdin, either via +# _claude_cli or an explicit /dev/null; then + skip "codex-setup: shipped claude plugin/mcp/--version calls never inherit stdin" "needs a git checkout" +else + _bare_claude_calls="$( + cd "$PROJECT_DIR" && git grep -nE '(^|[^A-Za-z0-9_./-])claude[[:space:]]+(plugin|mcp|--version)' \ + -- setup.sh install.sh uninstall.sh 'lib/*.sh' 'wizard/*.sh' 'mdm/*.sh' 'features/*.sh' \ + | grep -vE ':[0-9]+:[[:space:]]*#' \ + | grep -vE '^[^:]+:[0-9]+:[[:space:]]*(info|warn|printf|echo|_dryrun_log)[[:space:]]([^;|&$`]|[$][^(])*claude[[:space:]]+(plugin|mcp|--version)' \ + | grep -vE '^[^:]+:[0-9]+:[[:space:]]*"claude plugin (marketplace add|install) ' \ + | grep -vE '`claude plugin install`' \ + | grep -vE 'claude[[:space:]]+(plugin|mcp|--version)([^|;&#]|>&|&>)*<[[:space:]]*/dev/null' || true + )" + if assert_equals "" "$_bare_claude_calls"; then + pass "codex-setup: shipped claude plugin/mcp/--version calls never inherit stdin" + else + fail "codex-setup: claude CLI calls must use _claude_cli or /dev/null; then + # Every `claude` call in this block detaches stdin: when stdin is /dev/tty (e.g. a + # `curl | bash` wrapper), the Bun-based CLI fails on macOS with + # "EINVAL: invalid argument, kqueue". Mirrors _claude_cli() in lib/codex-setup.sh. # Check for Codex plugin - _codex_plugin_list="$(claude plugin list 2>/dev/null || true)" + _codex_plugin_list="$(claude plugin list /dev/null || true)" if _claude_plugin_list_has "$_codex_plugin_list" "codex"; then printf "\n" read -r -p "$STR_CODEX_PLUGIN_REMOVE_ASK" _codex_plugin_confirm case "$_codex_plugin_confirm" in y|Y|yes|YES) - if claude plugin uninstall codex --scope user; then + if claude plugin uninstall codex --scope user /dev/null; then # format), so match on an anchored "name:" prefix instead of the # plugin-list helper above — a bare `grep -qw "codex"` would also # false-positive on e.g. "codex-tools: ...". - _codex_mcp_list="$(claude mcp list 2>/dev/null || true)" + _codex_mcp_list="$(claude mcp list /dev/null || true)" if echo "$_codex_mcp_list" | grep -qE '^codex:' 2>/dev/null; then printf "\n" read -r -p "$STR_CODEX_MCP_REMOVE_ASK" _codex_mcp_confirm case "$_codex_mcp_confirm" in y|Y|yes|YES) - if claude mcp remove -s user codex; then + if claude mcp remove -s user codex