-
Notifications
You must be signed in to change notification settings - Fork 319
feat(macos): create macos switchyard deamon #863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
messiaen
wants to merge
8
commits into
main
Choose a base branch
from
grclark/mac-deamon
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+610
−124
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7843ff6
feat(macos): create macos switchyard deamon
messiaen bdd2cfe
chore: add macos to make help
messiaen 368b903
refactor(macos): separate menu bar from daemon install
messiaen 042211d
chore: cleanup
messiaen 35b6d9a
chore: fix xlm
messiaen 9d632ce
chore: cleanup
messiaen 23a8b77
chore: remove cmd alias
messiaen 569aaf6
chore: review feedback
messiaen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| SY_HOME="${SY_HOME:-$HOME/.switchyard}" | ||
| SY_PORT="${SY_PORT:-4123}" | ||
| CODEX_DIR="${CODEX_HOME:-$HOME/.codex}" | ||
| # Both installers use Codex's standalone profile file for the CLI. | ||
| CODEX_PROFILE_CONFIG="$CODEX_DIR/sy.config.toml" | ||
| ALIAS_START="# >>> switchyard codex alias >>>" | ||
| ALIAS_END="# <<< switchyard codex alias <<<" | ||
|
|
||
| say() { printf '%s\n' "$*"; } | ||
| step() { printf '\n==> %s\n' "$*"; } | ||
|
|
||
| strip_block() { | ||
| local path="$1" start="$2" end="$3" label="${4:-the switchyard block}" | ||
| if [[ ! -f "$path" ]] || ! grep -qF "$start" "$path"; then | ||
| return 1 | ||
| fi | ||
| if ! grep -qF "$end" "$path"; then | ||
| say " $path has no end marker for $label; not editing it" >&2 | ||
| return 1 | ||
| fi | ||
| if (( DRY_RUN )); then | ||
| say " would remove $label from $path" | ||
| return 0 | ||
| fi | ||
| local temp | ||
| temp="$(mktemp)" | ||
| awk -v start="$start" -v end="$end" ' | ||
| index($0, start) { skipping = 1 } | ||
| !skipping { print } | ||
| index($0, end) { skipping = 0 } | ||
| END { if (skipping) exit 1 } | ||
| ' "$path" > "$temp" | ||
| cat "$temp" > "$path" | ||
| rm -f "$temp" | ||
| say " removed $label from $path" | ||
| return 0 | ||
| } | ||
|
|
||
| run() { | ||
| if (( DRY_RUN )); then | ||
| say " would run: $*" | ||
| else | ||
| "$@" | ||
| fi | ||
| } | ||
|
|
||
| write_once() { | ||
| local path="$1" | ||
| if [[ -f "$path" ]]; then | ||
| say " keeping existing $path" | ||
| cat >/dev/null | ||
| return | ||
| fi | ||
| if (( DRY_RUN )); then | ||
| say " would create $path" | ||
| cat >/dev/null | ||
| else | ||
| mkdir -p "$(dirname "$path")" | ||
| cat > "$path" | ||
| say " created $path" | ||
| fi | ||
| } | ||
|
|
||
| write_with_backup() { | ||
| local path="$1" | ||
| if (( DRY_RUN )); then | ||
| [[ -f "$path" ]] && say " would back up $path" | ||
| say " would write $path" | ||
| cat >/dev/null | ||
| return | ||
| fi | ||
| mkdir -p "$(dirname "$path")" | ||
| local incoming | ||
| incoming="$(mktemp)" | ||
| cat > "$incoming" | ||
| if [[ -f "$path" ]] && cmp -s "$incoming" "$path"; then | ||
| say " $path is already up to date" | ||
| rm -f "$incoming" | ||
| return | ||
| fi | ||
| if [[ -f "$path" ]]; then | ||
| local backup | ||
| backup="$path.switchyard-backup.$(date +%Y%m%d%H%M%S)" | ||
| cp "$path" "$backup" | ||
| say " backed up $path to $backup" | ||
| fi | ||
| cat "$incoming" > "$path" | ||
| rm -f "$incoming" | ||
| say " wrote $path" | ||
| } | ||
|
|
||
| write_always() { | ||
| local path="$1" | ||
| if (( DRY_RUN )); then | ||
| say " would write $path" | ||
| cat >/dev/null | ||
| else | ||
| mkdir -p "$(dirname "$path")" | ||
| cat > "$path" | ||
| say " wrote $path" | ||
| fi | ||
| } | ||
|
|
||
| remove_file() { | ||
| local path="$1" | ||
| if [[ ! -e "$path" ]]; then | ||
| say " nothing to remove at $path" | ||
| elif (( DRY_RUN )); then | ||
| say " would delete $path" | ||
| else | ||
| rm -f "$path" | ||
| say " deleted $path" | ||
| fi | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,8 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Paths, markers, and helpers shared by install.sh and uninstall.sh. | ||
| # The markers must match between the two, which is why they live here. | ||
| # shellcheck source=scripts/common.sh | ||
| source "$(dirname "${BASH_SOURCE[0]}")/../common.sh" | ||
|
|
||
| SY_HOME="${SY_HOME:-$HOME/.switchyard}" | ||
| SY_PORT="${SY_PORT:-4123}" | ||
| SERVICE_NAME="switchyard.service" | ||
| SYSTEMD_USER_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user" | ||
| CODEX_DIR="${CODEX_HOME:-$HOME/.codex}" | ||
| # Since Codex 0.134.0, `--profile sy` reads sy.config.toml and fails if | ||
| # config.toml still has [profiles.sy]. | ||
| CODEX_PROFILE_CONFIG="$CODEX_DIR/sy.config.toml" | ||
| ALIAS_START="# >>> switchyard codex alias >>>" | ||
| ALIAS_END="# <<< switchyard codex alias <<<" | ||
|
|
||
| say() { printf '%s\n' "$*"; } | ||
| step() { printf '\n==> %s\n' "$*"; } | ||
|
|
||
| # Deletes the marked block, inclusive, leaving the rest of the file alone. | ||
| strip_block() { | ||
| local path="$1" start="$2" end="$3" label="${4:-the switchyard block}" | ||
| if [[ ! -f "$path" ]] || ! grep -qF "$start" "$path"; then | ||
| return 1 | ||
| fi | ||
| if ! grep -qF "$end" "$path"; then | ||
| say " $path has no end marker for $label; not editing it" >&2 | ||
| return 1 | ||
| fi | ||
| if (( DRY_RUN )); then | ||
| say " would remove $label from $path" | ||
| return 0 | ||
| fi | ||
| local temp | ||
| temp="$(mktemp)" | ||
| awk -v start="$start" -v end="$end" ' | ||
| index($0, start) { skipping = 1 } | ||
| !skipping { print } | ||
| index($0, end) { skipping = 0 } | ||
| END { if (skipping) exit 1 } | ||
| ' "$path" > "$temp" | ||
| cat "$temp" > "$path" | ||
| rm -f "$temp" | ||
| say " removed $label from $path" | ||
| return 0 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Paths, markers, and helpers shared by install.sh and uninstall.sh. | ||
| # The markers must match between the two, which is why they live here. | ||
|
|
||
| # shellcheck source=scripts/common.sh | ||
| source "$(dirname "${BASH_SOURCE[0]}")/../common.sh" | ||
|
|
||
| SERVER_LABEL="com.nvidia.switchyard.server" | ||
| LAUNCH_AGENTS="$HOME/Library/LaunchAgents" | ||
| CODEX_CONFIG="$CODEX_DIR/config.toml" | ||
| # Codex reads `--profile sy` from its own file next to config.toml. A | ||
| # [profiles.sy] table in config.toml is rejected outright as legacy config. | ||
| # Codex.app ignores profiles entirely, so it gets a whole config.toml with the | ||
| # routing inlined. Keep the generated file beside the original for reference. | ||
| CODEX_SWITCHYARD_CONFIG="$CODEX_DIR/config.sy.toml" | ||
| CODEX_DIRECT_CONFIG="$CODEX_DIR/config.toml.direct" | ||
| PROFILE_START="# >>> switchyard sy profile >>>" | ||
| PROFILE_END="# <<< switchyard sy profile <<<" | ||
|
|
||
| codex_config_uses_switchyard() { | ||
| local path="$1" | ||
| [[ -f "$path" ]] || return 1 | ||
| grep -Fq '[model_providers.sy]' "$path" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.