Run Holmes repairs through interactive tool approvals
Homelab Main / validate (push) Failing after 11s Details
Homelab Main / running-update (push) Has been skipped Details
Homelab Main / debian-ops (push) Has been skipped Details

This commit is contained in:
juvenal.diaz 2026-11-14 10:34:53 -06:00
parent d783b94c7f
commit 38b301f9fb
4 changed files with 70 additions and 7 deletions

View File

@ -70,9 +70,9 @@ cluster context, records a change journal entry, enables Holmes tools and
automatically allows Bash commands. **Holmes has the Debian user's host-level
permissions**, including any passwordless sudo access; this is not a sandbox or
an application-scoped permission boundary. Its actions can change the cluster
or host. Repair mode sets Holmes's `BASH_TOOL_UNSAFE_ALLOW_ALL` environment
variable in addition to the CLI flag; support depends on the installed Holmes
version. Holmes is asked for a diagnosis, an evidence-based five whys analysis,
or host. Repair mode uses Holmes's interactive path on a pseudo-terminal and
ends the session after Holmes saves its first response. Holmes is asked for a
diagnosis, an evidence-based five whys analysis,
the repair, validation and recommendations, marking unsupported causes as
unknown. Doctor saves its output, errors and a report in a private artifact
directory, then independently checks the selected application's Argo CD health

View File

@ -135,12 +135,13 @@ doctor_focus_holmes_fix() {
} >"${artifact}/holmes-prompt.txt"
record_change_journal "doctor-holmes-k8s-repair" "${item}"
echo "Holmes is authorized to execute commands to repair ${item}; its Bash tool has host-level access."
if ! timeout "${LAB_HOLMES_TRIAGE_TIMEOUT_SECONDS:-360}" env KUBECONFIG="${KUBECONFIG_PATH}" BASH_TOOL_UNSAFE_ALLOW_ALL=true \
if ! timeout "${LAB_HOLMES_TRIAGE_TIMEOUT_SECONDS:-360}" env KUBECONFIG="${KUBECONFIG_PATH}" \
OPENAI_BASE_URL="${OPENAI_BASE_URL:-http://127.0.0.1:20128/v1}" \
OPENAI_API_BASE="${OPENAI_BASE_URL:-http://127.0.0.1:20128/v1}" OPENAI_API_KEY="${key}" \
python3 "${REPO_ROOT}/scripts/doctor-holmes-interactive.py" "${artifact}/conversation.json" -- \
"${bin}" ask --config "${config}" --prompt-file "${artifact}/holmes-prompt.txt" \
--api-key "${key}" --model "${model}" --fast-model "${fast}" \
--max-steps "${LAB_HOLMES_MAX_STEPS:-12}" --no-interactive --bash-always-allow \
--max-steps "${LAB_HOLMES_MAX_STEPS:-12}" --interactive --bash-always-allow --json-output-file "${artifact}/conversation.json" \
>"${artifact}/holmes-output.txt" 2>"${artifact}/holmes-error.txt"; then
status=1
fi

View File

@ -0,0 +1,60 @@
#!/usr/bin/env python3
"""Run one Holmes interactive investigation on a PTY, then exit after its report."""
import os
import pty
import select
import signal
import subprocess
import sys
from pathlib import Path
def main():
if len(sys.argv) < 4 or sys.argv[2] != "--":
raise ValueError("usage: doctor-holmes-interactive.py CONVERSATION -- COMMAND [ARGS...]")
conversation = Path(sys.argv[1])
master, slave = pty.openpty()
child = subprocess.Popen(sys.argv[3:], stdin=slave, stdout=slave, stderr=slave, start_new_session=True)
os.close(slave)
exiting = False
def terminate(_signum, _frame):
try:
os.killpg(child.pid, signal.SIGTERM)
except ProcessLookupError:
pass
raise SystemExit(124)
signal.signal(signal.SIGTERM, terminate)
signal.signal(signal.SIGINT, terminate)
try:
while child.poll() is None:
ready, _, _ = select.select([master], [], [], 0.2)
if ready:
try:
chunk = os.read(master, 65536)
except OSError:
break
if chunk:
sys.stdout.buffer.write(chunk)
sys.stdout.buffer.flush()
if not exiting and conversation.is_file() and conversation.stat().st_size:
os.write(master, b"/exit\n")
exiting = True
returncode = child.wait()
if not exiting and returncode == 0:
print("Holmes exited without saving a completed conversation.", file=sys.stderr)
return 1
return returncode
finally:
if child.poll() is None:
terminate(signal.SIGTERM, None)
os.close(master)
if __name__ == "__main__":
try:
sys.exit(main())
except (OSError, ValueError) as exc:
print(f"Holmes interactive runner: {exc}", file=sys.stderr)
sys.exit(1)

View File

@ -27,7 +27,9 @@ class DoctorFocusTests(unittest.TestCase):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
binary = root / "jeannie-holmes"
binary.write_text("#!/bin/sh\n[ \"${BASH_TOOL_UNSAFE_ALLOW_ALL:-}\" = true ] || exit 4\ncase \" $* \" in *' --bash-always-allow '*) echo 'attempted repair';; *) exit 3;; esac\n")
binary.write_text("#!/bin/sh\ncase \" $* \" in *' --interactive '*' --bash-always-allow '*) ;; *) exit 3;; esac\n"
"while [ $# -gt 0 ]; do if [ \"$1\" = --json-output-file ]; then shift; printf '{}' > \"$1\"; break; fi; shift; done\n"
"echo 'attempted repair'\nread -r line\n[ \"$line\" = /exit ]\n")
binary.chmod(0o755)
rows = root / "rows"
rows.write_text("warn\tKubernetes apps\tn8n\tUnavailable\n")
@ -53,7 +55,7 @@ doctor_focus_holmes_fix n8n'''
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
binary = root / "jeannie-holmes"
binary.write_text("#!/bin/sh\necho repaired\n")
binary.write_text("#!/bin/sh\nwhile [ $# -gt 0 ]; do if [ \"$1\" = --json-output-file ]; then shift; printf '{}' > \"$1\"; break; fi; shift; done\necho repaired\nread -r line\n")
binary.chmod(0o755)
rows = root / "rows"
rows.write_text("warn\tKubernetes apps\tn8n\tUnavailable\n")