From fc180af54ea7842efa126e9885f929141ce349ee Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Sat, 23 May 2026 04:15:50 -0400 Subject: [PATCH] Add default AI and launch command --- bin/omarchy-default-ai | 32 +++++++++++++ bin/omarchy-launch-ai | 105 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100755 bin/omarchy-default-ai create mode 100755 bin/omarchy-launch-ai diff --git a/bin/omarchy-default-ai b/bin/omarchy-default-ai new file mode 100755 index 00000000..e1d40280 --- /dev/null +++ b/bin/omarchy-default-ai @@ -0,0 +1,32 @@ +#!/bin/bash + +# omarchy:summary=Set the default AI harness used by omarchy-launch-ai +# omarchy:args=[pi|claude|codex|opencode] +# omarchy:examples=omarchy default ai | omarchy default ai pi | omarchy default ai claude + +ai_file="$HOME/.local/state/omarchy/defaults/ai" + +if (( $# == 0 )); then + if [[ -f $ai_file ]]; then + read -r harness <"$ai_file" + fi + + [[ -n ${harness:-} ]] && echo "$harness" || echo "pi" + exit 0 +fi + +case "$1" in +pi) harness="pi"; name="Pi"; glyph=󰚩 ;; +claude) harness="claude"; name="Claude Code"; glyph=󰚩 ;; +codex) harness="codex"; name="Codex"; glyph=󰚩 ;; +opencode) harness="opencode"; name="OpenCode"; glyph=󰚩 ;; +*) + echo "Usage: omarchy-default-ai " >&2 + exit 1 + ;; +esac + +mkdir -p "$(dirname "$ai_file")" +printf '%s\n' "$harness" >"$ai_file" + +omarchy-notification-send -g "$glyph" "$name is now the default AI harness" diff --git a/bin/omarchy-launch-ai b/bin/omarchy-launch-ai new file mode 100755 index 00000000..368c2ece --- /dev/null +++ b/bin/omarchy-launch-ai @@ -0,0 +1,105 @@ +#!/bin/bash + +# omarchy:summary=Launch the default AI coding harness in a project path +# omarchy:args=[--path ] [--prompt ] [--harness ] [path] +# omarchy:examples=omarchy launch ai --path ~/.config/omarchy/plugins/local.clock | omarchy launch ai --harness claude --path . --prompt "Review this plugin" + +set -euo pipefail + +path="." +prompt="" +harness="" + +usage() { + cat <<'USAGE' +Usage: omarchy-launch-ai [--path ] [--prompt ] [--harness ] [path] + +Launches an interactive AI coding harness in the given path. If no harness is +provided, uses the value from `omarchy default ai`. +USAGE +} + +fail() { + echo "omarchy-launch-ai: $*" >&2 + exit 1 +} + +while (( $# > 0 )); do + case "$1" in + --path) + path="${2:-}" + [[ -n $path ]] || fail "--path requires a value" + shift 2 + ;; + --prompt) + prompt="${2:-}" + shift 2 + ;; + --harness) + harness="${2:-}" + [[ -n $harness ]] || fail "--harness requires a value" + shift 2 + ;; + -h | --help) + usage + exit 0 + ;; + --) + shift + break + ;; + --*) + fail "unknown option: $1" + ;; + *) + path="$1" + shift + ;; + esac +done + +[[ -d $path ]] || fail "path is not a directory: $path" +path=$(cd "$path" && pwd) + +if [[ -z $harness ]]; then + harness=$(omarchy-default-ai) +fi + +case "$harness" in +pi | claude | codex | opencode) + ;; +*) + fail "unknown AI harness: $harness" + ;; +esac + +launch_in_place() { + cd "$path" + case "$harness" in + pi) + omarchy-cmd-present pi || fail "pi is not installed" + if [[ -n $prompt ]]; then exec pi "$prompt"; else exec pi; fi + ;; + claude) + omarchy-cmd-present claude || fail "claude is not installed" + if [[ -n $prompt ]]; then exec claude "$prompt"; else exec claude; fi + ;; + codex) + omarchy-cmd-present codex || fail "codex is not installed" + if [[ -n $prompt ]]; then exec codex "$prompt"; else exec codex; fi + ;; + opencode) + omarchy-cmd-present opencode || fail "opencode is not installed" + if [[ -n $prompt ]]; then exec opencode --prompt "$prompt" .; else exec opencode .; fi + ;; + esac +} + +if [[ -t 0 && -t 1 ]]; then + launch_in_place +fi + +quoted_path=$(printf '%q' "$path") +quoted_prompt=$(printf '%q' "$prompt") +quoted_harness=$(printf '%q' "$harness") +exec omarchy-launch-tui bash -lc "cd $quoted_path && exec omarchy-launch-ai --harness $quoted_harness --prompt $quoted_prompt --path ."