Files
HomerandClaude Opus 5.5 b52263d0bb Security (S11, S14, S16): the shell's own autocomplete is gone; least privilege in CI; set-up refuses root and another version's release
S11. autocomplete = 'shell' had the shell integration send what was typed
to the engine itself: it could not see a private pane or the AI switch,
and had its own timeout and no chosen model. autocomplete.bash and
autocomplete.zsh are removed, with what exported their switch; the shell
integration keeps its zones and the status record. 'shell' turns nothing
on and is said in the log.

S14. The build job may only read the repository; a job of its own,
for a tag only and after the build passed, downloads the build's artefact
and publishes the release with write access. Every action is pinned by
its commit, with the tag it was taken from beside it.

S16. The set-up program refuses to run as root (everything goes into the
person's own home). A signed SHA256SUMS whose first line names a product
and version must name the release asked for: an older signed release served
under the newest tag is refused. Sums that name nothing yet are still taken,
and that is said. Tests for both, and for the root refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 08:07:20 +00:00

204 lines
7.8 KiB
Bash

# shellcheck shell=bash
# LLeMbas TERM: shell integration for bash and zsh.
#
# Sourced from /etc/profile.d by the package; or source it from ~/.bashrc or
# ~/.zshrc (zsh does not read /etc/profile.d on every system):
#
# [ -n "$LLEMBAS_TERM" ] && . /usr/share/llembas-term/shell/llembas-term.sh
#
# It does two things, and only inside LLeMbas TERM, only in an interactive shell:
#
# 1. Semantic zones and the working directory (OSC 133, OSC 7), by WezTerm's
# own integration script, shipped beside this file as wezterm.sh. That is
# what lets the terminal tell one command and its output from the next.
# The WEZTERM_SHELL_SKIP_* variables documented in that file apply.
# (Suggestions and the AI's autocomplete are drawn by the terminal itself
# on the line these mark; nothing of them runs in the shell.)
# 2. The pane's status record: at every prompt, and when a command starts, a
# few lines that say where this shell stands - at its prompt or running a
# command, how the last command ended, when, in which directory. It says
# nothing of what the command was. It is how the terminal, and LLeMbas when
# it types a command into this pane for you, know that the command has
# ended. It goes two ways:
# - the file pane-<LLEMBAS_TERM_PANE>.status in the status directory
# ($LLEMBAS_TERM_STATUS_DIR, else $XDG_RUNTIME_DIR/llembas-term, else
# $XDG_STATE_HOME/llembas-term), readable by you alone, replaced whole.
# Not in a shell reached over SSH: the file would be on the wrong machine;
# - the user variable llembas_term_status of the pane (OSC 1337 SetUserVar),
# which reaches the terminal from another machine too.
# LLEMBAS_TERM_SKIP_STATUS=1 turns it off.
#
# The record, a key=value line each:
# llembas-term-status=1
# id=<this shell: its process id and when it started>
# seq=<up by one at every prompt>
# state=prompt | running
# exit=<status of the command before this prompt; absent before the first>
# ran=1 (at a prompt: a command line ran since the prompt before)
# time=<seconds since the epoch>
# shell=bash | zsh
# pid=<the shell's process id; not over SSH>
# host=<the machine; only over SSH>
# cwd=<the working directory>
if [ -z "${LLEMBAS_TERM-}" ]; then
return 0
fi
# shellcheck disable=SC2166
if [ -z "${BASH_VERSION-}" -a -z "${ZSH_NAME-}" ]; then
return 0
fi
case "$-" in
*i*) ;;
*) return 0 ;;
esac
if [ -n "${ZSH_NAME-}" ]; then
# shellcheck disable=SC2296,SC2298 # zsh: the file being sourced
__llembas_term_dir="${${(%):-%x}:A:h}"
else
__llembas_term_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)"
fi
if [ -n "${LLEMBAS_TERM_SHELL_DIR-}" ]; then
__llembas_term_dir="$LLEMBAS_TERM_SHELL_DIR"
fi
# Not twice: a WezTerm installed beside us may have loaded the same script.
if ! typeset -f __wezterm_semantic_precmd >/dev/null 2>&1; then
if [ -r "$__llembas_term_dir/wezterm.sh" ]; then
# shellcheck source=/dev/null
. "$__llembas_term_dir/wezterm.sh"
fi
fi
if [ "${LLEMBAS_TERM_SKIP_STATUS-}" != "1" ] && [ -z "${__llembas_term_seq-}" ]; then
__llembas_term_seq=0
__llembas_term_ran=
__llembas_term_exit=
__llembas_term_now="${EPOCHSECONDS-}"
[ -n "$__llembas_term_now" ] || __llembas_term_now="$(date +%s)"
__llembas_term_id="$$.$__llembas_term_now"
if [ -n "${ZSH_NAME-}" ]; then
__llembas_term_shell=zsh
else
__llembas_term_shell=bash
fi
# The file, on the terminal's own machine only and for a pane with a number.
__llembas_term_status_file=
if [ -z "${SSH_CONNECTION-}" ] && [ -z "${SSH_TTY-}" ]; then
case "${LLEMBAS_TERM_PANE-}" in
'' | *[!0-9]*) ;;
*)
case "${LLEMBAS_TERM_STATUS_DIR-}" in
/*) __llembas_term_status_file="$LLEMBAS_TERM_STATUS_DIR" ;;
*)
case "${XDG_RUNTIME_DIR-}" in
/*) __llembas_term_status_file="$XDG_RUNTIME_DIR/llembas-term" ;;
*)
case "${XDG_STATE_HOME-}" in
/*) __llembas_term_status_file="$XDG_STATE_HOME/llembas-term" ;;
*) [ -z "${HOME-}" ] || __llembas_term_status_file="$HOME/.local/state/llembas-term" ;;
esac
;;
esac
;;
esac
[ -z "$__llembas_term_status_file" ] || __llembas_term_status_file="$__llembas_term_status_file/pane-$LLEMBAS_TERM_PANE.status"
;;
esac
fi
# __llembas_term_record <state>: write the record both ways. The directory's
# name is cut at a line break: a record is one fact a line.
__llembas_term_record() {
local now record cwd="${PWD%%$'\n'*}"
now="${EPOCHSECONDS-}"
[ -n "$now" ] || now="$(date +%s)"
record="llembas-term-status=1
id=$__llembas_term_id
seq=$__llembas_term_seq
state=$1"
[ -z "$__llembas_term_exit" ] || record="$record
exit=$__llembas_term_exit"
if [ "$1" = prompt ] && [ -n "$__llembas_term_ran" ]; then
record="$record
ran=1"
fi
record="$record
time=$now
shell=$__llembas_term_shell"
if [ -n "${SSH_CONNECTION-}" ] || [ -n "${SSH_TTY-}" ]; then
record="$record
host=${HOSTNAME:-${HOST:-unknown}}"
else
record="$record
pid=$$"
fi
record="$record
cwd=${cwd:0:1024}"
if [ -n "$__llembas_term_status_file" ]; then
# Made beside the file, closed to everybody else, then moved over it:
# a reader sees the old record or the new one, never half of one.
(
umask 077
[ -d "${__llembas_term_status_file%/*}" ] || mkdir -p "${__llembas_term_status_file%/*}"
printf '%s\n' "$record" >"$__llembas_term_status_file.$$" &&
mv -f "$__llembas_term_status_file.$$" "$__llembas_term_status_file"
) 2>/dev/null
fi
if command -v base64 >/dev/null 2>&1; then
if [ -z "${TMUX-}" ]; then
printf '\033]1337;SetUserVar=%s=%s\007' llembas_term_status "$(printf '%s\n' "$record" | base64 | tr -d '\r\n')"
else
# shellcheck disable=SC1003 # the backslash that ends tmux's passthrough
printf '\033Ptmux;\033\033]1337;SetUserVar=%s=%s\007\033\\' llembas_term_status "$(printf '%s\n' "$record" | base64 | tr -d '\r\n')"
fi
fi
}
__llembas_term_preexec() {
__llembas_term_ran=1
__llembas_term_record running
}
__llembas_term_precmd() {
local ret="$?"
__llembas_term_seq=$((__llembas_term_seq + 1))
# Before the first prompt no command of this shell has ended.
if [ "$__llembas_term_seq" -gt 1 ]; then
__llembas_term_exit="$ret"
fi
__llembas_term_record prompt
__llembas_term_ran=
return "$ret"
}
if [ -n "${ZSH_NAME-}" ] || [ -n "${bash_preexec_imported-}" ]; then
# First of the prompt's functions, so that $? is still the command's.
precmd_functions=(__llembas_term_precmd "${precmd_functions[@]}")
else
PROMPT_COMMAND="__llembas_term_precmd${PROMPT_COMMAND:+;$PROMPT_COMMAND}"
fi
if [ -n "${ZSH_NAME-}" ]; then
preexec_functions+=(__llembas_term_preexec)
elif [ "${BASH_VERSINFO[0]}" -gt 4 ] || { [ "${BASH_VERSINFO[0]}" -eq 4 ] && [ "${BASH_VERSINFO[1]}" -ge 4 ]; }; then
# bash 4.4 and newer expand PS0 after every command line that is about to
# run, and never for an empty one. (bash-preexec, which WezTerm's script
# brings, does not see a command line that is all one subshell.) What the
# first expansion prints is the record's user variable; the second prints
# nothing and notes, in this shell, that a command ran.
__llembas_term_mark=
# shellcheck disable=SC2016 # expanded by bash at each command, not here
PS0="${PS0-}"'$(__llembas_term_record running)${__llembas_term_mark:$((__llembas_term_ran=1,0)):0}'
elif [ -n "${bash_preexec_imported-}" ]; then
preexec_functions+=(__llembas_term_preexec)
else
# Nothing tells a command from an empty line here: none is said to have run.
:
fi
fi
unset __llembas_term_dir
true