Let Supermarket use Hermes' Anthropic key and model

Hermes is already set up with an Anthropic key, so AI needn't be set up
twice. `supermarket hermes` asks once, then it and update.sh copy just
the key and model to hermes-ai.json in the data folder (0600). The app
uses them when it has no key of its own, re-reading the file on each use.

Generation still calls the model directly rather than through Hermes'
API: post writing feeds it text from the web, which must not reach an
agent with a terminal, a browser and write access to the CRM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 14:58:06 -07:00
co-authored by Claude Opus 5.5
parent 434a9093b0
commit 81a7d0596c
10 changed files with 175 additions and 5 deletions
+53
View File
@@ -91,6 +91,59 @@ write_ai_servers() {
}
# Wait until the app answers, for up to $1 seconds.
# Supermarket can use the Anthropic key and model Hermes already has, so AI
# is set up once. hermes/setup.sh asks, and records the answer in
# $HERMES_AI_CHOICE; this copies just the key and model (never the rest of
# Hermes' .env) to $HERMES_AI, which the app reads when it has no key of its
# own. The app calls the model directly, without Hermes' tools.
HERMES_AI="$DATA/hermes-ai.json"
HERMES_AI_CHOICE="$DATA/hermes-ai.choice"
# hermes_config KEY: a value from Hermes' config, read with the real command
# (CoreDesktop's `hermes` is the sandboxed one).
hermes_config() {
local unsandboxed="$COREDESKTOP/sandbox/bin/unsandboxed"
if [ -x "$unsandboxed" ]; then
PATH="$HOME/.local/bin:$PATH" "$unsandboxed" hermes config get "$1" 2> /dev/null
elif [ -x "$HOME/.local/bin/hermes" ]; then
"$HOME/.local/bin/hermes" config get "$1" 2> /dev/null
fi
}
# hermes_ai_key prints Hermes' Anthropic key, if it has one.
hermes_ai_key() {
sed -n 's/^ANTHROPIC_API_KEY=//p' "${HERMES_HOME:-$HOME/.hermes}/.env" 2> /dev/null | tail -n 1 | tr -d "\"' \r"
}
# sync_hermes_ai: refresh (or remove) the shared key. Quiet unless asked to
# report with "-v".
sync_hermes_ai() {
local key provider model tmp
if [ "$(cat "$HERMES_AI_CHOICE" 2> /dev/null)" != yes ]; then
rm -f "$HERMES_AI"
return 0
fi
key="$(hermes_ai_key)"
provider="$(hermes_config model.provider)"
model="$(hermes_config model.default)"
if [ "$provider" != anthropic ] || [ -z "$key" ] || ! command -v jq > /dev/null; then
rm -f "$HERMES_AI"
[ "${1:-}" = -v ] && echo "Hermes doesn't use an Anthropic key, so there's none to share; set Supermarket's AI provider under Settings."
return 0
fi
mkdir -p "$DATA"
tmp="$(mktemp "$HERMES_AI.XXXXXX")"
chmod 600 "$tmp"
# The key goes through the environment, not the command line.
if KEY="$key" MODEL="$model" jq -n '{provider: "anthropic", model: env.MODEL, api_key: env.KEY}' > "$tmp"; then
mv -f "$tmp" "$HERMES_AI"
[ "${1:-}" = -v ] && echo "Supermarket uses Hermes' Anthropic key and model ($model)."
else
rm -f "$tmp"
fi
return 0
}
wait_until_up() {
local i
for ((i = 0; i < ${1:-60}; i++)); do