@@ -1676,152 +1676,186 @@ EOF
16761676
16771677# Check and update Codex CLI configuration
16781678check_codex_cli_integration () {
1679- # Check if Codex is installed
16801679 if ! command -v codex & > /dev/null; then
1681- # Codex CLI not installed
16821680 return 0
16831681 fi
16841682
16851683 local codex_config=" $HOME /.codex/config.toml"
1686-
1687- # Check if zen is already configured
1684+ local codex_has_zen=false
16881685 if [[ -f " $codex_config " ]] && grep -q ' \[mcp_servers\.zen\]' " $codex_config " 2> /dev/null; then
1689- # Already configured
1690- return 0
1686+ codex_has_zen=true
16911687 fi
16921688
1693- # Ask user if they want to add Zen to Codex CLI
1694- echo " "
1695- read -p " Configure Zen for Codex CLI? (Y/n): " -n 1 -r
1696- echo " "
1697- if [[ $REPLY =~ ^[Nn]$ ]]; then
1698- print_info " Skipping Codex CLI integration"
1699- return 0
1700- fi
1689+ if [[ " $codex_has_zen " == false ]] ; then
1690+ echo " "
1691+ read -p " Configure Zen for Codex CLI? (Y/n): " -n 1 -r
1692+ echo " "
1693+ if [[ $REPLY =~ ^[Nn]$ ]]; then
1694+ print_info " Skipping Codex CLI integration"
1695+ return 0
1696+ fi
17011697
1702- print_info " Updating Codex CLI configuration..."
1698+ print_info " Updating Codex CLI configuration..."
17031699
1704- # Create config directory if it doesn't exist
1705- mkdir -p " $( dirname " $codex_config " ) " 2> /dev/null || true
1700+ mkdir -p " $( dirname " $codex_config " ) " 2> /dev/null || true
17061701
1707- # Create backup if config exists
1708- if [[ -f " $codex_config " ]]; then
1709- cp " $codex_config " " ${codex_config} .backup_$( date +%Y%m%d_%H%M%S) "
1710- fi
1702+ if [[ -f " $codex_config " ]]; then
1703+ cp " $codex_config " " ${codex_config} .backup_$( date +%Y%m%d_%H%M%S) "
1704+ fi
17111705
1712- # Get environment variables using shared function
1713- local env_vars=$( parse_env_variables)
1706+ local env_vars=$( parse_env_variables)
17141707
1715- # Write zen configuration to config.toml
1716- {
1717- echo " "
1718- echo " [mcp_servers.zen]"
1719- echo " command = \" bash\" "
1720- echo " args = [\" -c\" , \" for p in \$ (which uvx 2>/dev/null) \$ HOME/.local/bin/uvx /opt/homebrew/bin/uvx /usr/local/bin/uvx uvx; do [ -x \\\"\$ p\\\" ] && exec \\\"\$ p\\\" --from git+https://github.com/BeehiveInnovations/zen-mcp-server.git zen-mcp-server; done; echo 'uvx not found' >&2; exit 1\" ]"
1721- echo " tool_timeout_sec = 1200"
1722- echo " "
1723- echo " [mcp_servers.zen.env]"
1724- echo " PATH = \" /usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin:\$ HOME/.local/bin:\$ HOME/.cargo/bin:\$ HOME/bin\" "
1725- if [[ -n " $env_vars " ]]; then
1726- # Convert KEY=VALUE format to TOML KEY = "VALUE" format
1727- while IFS= read -r line; do
1728- if [[ -n " $line " && " $line " =~ ^([^= ]+)= (.* )$ ]]; then
1729- local key=" ${BASH_REMATCH[1]} "
1730- local value=" ${BASH_REMATCH[2]} "
1731- # Escape backslashes first, then double quotes for TOML compatibility
1732- local escaped_value
1733- escaped_value=$( echo " $value " | sed -e ' s/\\/\\\\/g' -e ' s/"/\\"/g' )
1734- echo " $key = \" $escaped_value \" "
1735- fi
1736- done <<< " $env_vars"
1708+ {
1709+ echo " "
1710+ echo " [mcp_servers.zen]"
1711+ echo " command = \" bash\" "
1712+ echo " args = [\" -c\" , \" for p in \$ (which uvx 2>/dev/null) \$ HOME/.local/bin/uvx /opt/homebrew/bin/uvx /usr/local/bin/uvx uvx; do [ -x \\\"\$ p\\\" ] && exec \\\"\$ p\\\" --from git+https://github.com/BeehiveInnovations/zen-mcp-server.git zen-mcp-server; done; echo 'uvx not found' >&2; exit 1\" ]"
1713+ echo " tool_timeout_sec = 1200"
1714+ echo " "
1715+ echo " [mcp_servers.zen.env]"
1716+ echo " PATH = \" /usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin:\$ HOME/.local/bin:\$ HOME/.cargo/bin:\$ HOME/bin\" "
1717+ if [[ -n " $env_vars " ]]; then
1718+ while IFS= read -r line; do
1719+ if [[ -n " $line " && " $line " =~ ^([^= ]+)= (.* )$ ]]; then
1720+ local key=" ${BASH_REMATCH[1]} "
1721+ local value=" ${BASH_REMATCH[2]} "
1722+ local escaped_value
1723+ escaped_value=$( echo " $value " | sed -e ' s/\\/\\\\/g' -e ' s/"/\\"/g' )
1724+ echo " $key = \" $escaped_value \" "
1725+ fi
1726+ done <<< " $env_vars"
1727+ fi
1728+ } >> " $codex_config "
1729+
1730+ if [[ $? -ne 0 ]]; then
1731+ print_error " Failed to update Codex CLI config"
1732+ echo " Manual config location: $codex_config "
1733+ echo " Add this configuration:"
1734+ cat << 'CODExEOF '
1735+ [mcp_servers.zen]
1736+ command = "sh"
1737+ args = ["-c", "exec \$(which uvx 2>/dev/null || echo uvx) --from git+https://github.com/BeehiveInnovations/zen-mcp-server.git zen-mcp-server"]
1738+ tool_timeout_sec = 1200
1739+
1740+ [mcp_servers.zen.env]
1741+ PATH = "/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin:\$HOME/.local/bin:\$HOME/.cargo/bin:\$HOME/bin"
1742+
1743+ [features]
1744+ web_search_request = true
1745+ CODExEOF
1746+
1747+ if [[ -n " $env_vars " ]]; then
1748+ while IFS= read -r line; do
1749+ if [[ -n " $line " && " $line " =~ ^([^= ]+)= (.* )$ ]]; then
1750+ local key=" ${BASH_REMATCH[1]} "
1751+ echo " ${key} = \" your_$( echo " ${key} " | tr ' [:upper:]' ' [:lower:]' ) \" "
1752+ fi
1753+ done <<< " $env_vars"
1754+ else
1755+ echo " GEMINI_API_KEY = \" your_gemini_api_key_here\" "
1756+ fi
1757+ return 0
17371758 fi
1738- } >> " $codex_config "
17391759
1740- if [[ $? -eq 0 ]]; then
17411760 print_success " Successfully configured Codex CLI"
17421761 echo " Config: $codex_config "
17431762 echo " Restart Codex CLI to use Zen MCP Server"
1763+ codex_has_zen=true
1764+ else
1765+ print_info " Codex CLI already configured; refreshing Codex settings..."
1766+ fi
17441767
1745- if ! grep -Eq ' ^\s*web_search\s*=' " $codex_config " 2> /dev/null; then
1768+ if [[ " $codex_has_zen " == true ]]; then
1769+ if ! grep -Eq ' ^\s*web_search_request\s*=' " $codex_config " 2> /dev/null; then
17461770 echo " "
1747- print_info " Web search lets Codex pull fresh documentation for Zen's API lookup tooling."
1748- read -p " Enable Codex CLI web search tool ? (Y/n): " -n 1 -r
1771+ print_info " Web search requests let Codex pull fresh documentation for Zen's API lookup tooling."
1772+ read -p " Enable Codex CLI web search requests ? (Y/n): " -n 1 -r
17491773 echo " "
17501774 if [[ ! $REPLY =~ ^[Nn]$ ]]; then
1751- if grep -Eq ' ^\s*\[tools \]' " $codex_config " 2> /dev/null; then
1775+ if grep -Eq ' ^\s*\[features \]' " $codex_config " 2> /dev/null; then
17521776 if ! python3 - " $codex_config " << 'PY '
17531777import sys
17541778from pathlib import Path
17551779
17561780cfg_path = Path(sys.argv[1])
17571781content = cfg_path.read_text().splitlines()
17581782output = []
1759- in_tools = False
1783+ in_features = False
17601784added = False
17611785
17621786for line in content:
17631787 stripped = line.strip()
17641788 if stripped.startswith("[") and stripped.endswith("]"):
1765- if in_tools and not added:
1766- output.append("web_search = true")
1789+ if in_features and not added:
1790+ output.append("web_search_request = true")
17671791 added = True
1768- in_tools = stripped == "[tools ]"
1792+ in_features = stripped == "[features ]"
17691793 output.append(line)
17701794 continue
1771- if in_tools and stripped.startswith("web_search "):
1795+ if in_features and stripped.startswith("web_search_request "):
17721796 added = True
17731797 output.append(line)
17741798
1775- if in_tools and not added:
1776- output.append("web_search = true")
1799+ if in_features and not added:
1800+ output.append("web_search_request = true")
17771801
17781802cfg_path.write_text("\n".join(output) + "\n")
17791803PY
17801804 then
1781- print_error " Failed to enable Codex web search tool . Add 'web_search = true' under [tools ] in $codex_config manually."
1805+ print_error " Failed to enable Codex web search request feature . Add 'web_search_request = true' under [features ] in $codex_config manually."
17821806 else
1783- print_success " Enabled Codex web search tool "
1807+ print_success " Enabled Codex web search request feature "
17841808 fi
17851809 else
17861810 {
17871811 echo " "
1788- echo " [tools ]"
1789- echo " web_search = true"
1790- } >> " $codex_config " && print_success " Enabled Codex web search tool " || \
1791- print_error " Failed to enable Codex web search tool . Add 'web_search = true' under [tools ] in $codex_config manually."
1812+ echo " [features ]"
1813+ echo " web_search_request = true"
1814+ } >> " $codex_config " && print_success " Enabled Codex web search request feature " || \
1815+ print_error " Failed to enable Codex web search request feature . Add 'web_search_request = true' under [features ] in $codex_config manually."
17921816 fi
17931817 else
1794- print_info " Skipping Codex web search tool enablement "
1818+ print_info " Skipping Codex web search request feature "
17951819 fi
17961820 fi
1797- else
1798- print_error " Failed to update Codex CLI config"
1799- echo " Manual config location: $codex_config "
1800- echo " Add this configuration:"
1801-
1802- # Generate example with actual environment variables for error case
1803- env_vars=$( parse_env_variables)
1804- cat << EOF
1805- [mcp_servers.zen]
1806- command = "sh"
1807- args = ["-c", "exec \$ (which uvx 2>/dev/null || echo uvx) --from git+https://github.com/BeehiveInnovations/zen-mcp-server.git zen-mcp-server"]
1808- tool_timeout_sec = 1200
18091821
1810- [mcp_servers.zen.env]
1811- PATH = "/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin:\$ HOME/.local/bin:\$ HOME/.cargo/bin:\$ HOME/bin"
1812- EOF
1813-
1814- # Add environment variable examples only if they exist
1815- if [[ -n " $env_vars " ]]; then
1816- while IFS= read -r line; do
1817- if [[ -n " $line " && " $line " =~ ^([^= ]+)= (.* )$ ]]; then
1818- local key=" ${BASH_REMATCH[1]} "
1819- echo " ${key} = \" your_$( echo " ${key} " | tr ' [:upper:]' ' [:lower:]' ) \" "
1822+ if grep -Eq ' ^\s*\[tools\]' " $codex_config " 2> /dev/null && \
1823+ grep -Eq ' ^\s*web_search\s*=' " $codex_config " 2> /dev/null; then
1824+ local removal_status
1825+ if removal_status=$( python3 - " $codex_config " << 'PY ' | tr -d '\n'
1826+ import sys
1827+ from pathlib import Path
1828+
1829+ cfg_path = Path(sys.argv[1])
1830+ lines = cfg_path.read_text().splitlines()
1831+ output = []
1832+ in_tools = False
1833+ removed = False
1834+
1835+ for line in lines:
1836+ stripped = line.strip()
1837+ if stripped.startswith('[') and stripped.endswith(']'):
1838+ in_tools = stripped == '[tools]'
1839+ output.append(line)
1840+ continue
1841+ if in_tools and stripped.startswith('web_search'):
1842+ removed = True
1843+ continue
1844+ output.append(line)
1845+
1846+ if removed:
1847+ cfg_path.write_text("\n".join(output) + "\n")
1848+ print('REMOVED', end='')
1849+ else:
1850+ print('UNCHANGED', end='')
1851+ PY
1852+ ) ; then
1853+ if [[ " $removal_status " == " REMOVED" ]]; then
1854+ print_success " Removed deprecated Codex [tools].web_search entry"
18201855 fi
1821- done <<< " $env_vars"
1822- else
1823- # Show GEMINI_API_KEY example if no environment variables exist
1824- echo " GEMINI_API_KEY = \" your_gemini_api_key_here\" "
1856+ else
1857+ print_warning " Failed to clean up deprecated Codex [tools].web_search entry; remove manually from $codex_config "
1858+ fi
18251859 fi
18261860 fi
18271861}
0 commit comments