agentmux_common/
github_broker_shim.rs1pub const GH_FUNCTION_NAME: &str = "BASH_FUNC_gh%%";
12
13pub const GH_FUNCTION_BODY: &str = r#"() { if [ -n "${AGENTMUX_GITHUB_BROKER:-}" ]; then
28 local _amx_t _amx_x _amx_n _amx_r _amx_c0 _amx_c1 _amx_a=();
29 if [ "$1" = auth ] && [ "$2" = status ] && [ "$#" -eq 2 ]; then
30 printf '%s
31' 'github.com' ' AgentMux signs gh in per repository: each gh command in a repository gets a short-lived token for it' ' (the AgentMux GitHub App, acting for your user). There is no stored login, so gh auth does not list one.';
32 return 0;
33 fi;
34 _amx_c0=$1; _amx_c1=${2:-};
35 case "$1" in
36 -R|--repo) _amx_c0=${3:-}; _amx_c1=${4:-};;
37 -R?*|--repo=*) _amx_c0=${2:-}; _amx_c1=${3:-};;
38 esac;
39 if [ "${AGENTMUX_IN_CONTAINER:-}" = 1 ] && { [ "$_amx_c0" = api ] || [ "$_amx_c0" = release ] || { [ "$_amx_c0" = pr ] && [ "$_amx_c1" = merge ]; }; }; then
40 if agentmux-bashwrap github-container -- "$@"; then return 0; else _amx_r=$?; fi;
41 [ "$_amx_r" -eq 3 ] || return "$_amx_r";
42 fi;
43 if [ "$_amx_c0" = pr ] || [ "$_amx_c0" = issue ] || [ "$_amx_c0" = release ] || [ "$_amx_c0" = api ]; then
44 while IFS= read -r -d '' _amx_x; do _amx_a+=("$_amx_x"); done < <(agentmux-bashwrap github-text-guard -- "$@");
45 _amx_n=${#_amx_a[@]};
46 if [ "$_amx_n" -eq 0 ]; then
47 echo 'agentmux: this gh command was not run: the text it sends could not be checked.' >&2;
48 return 1;
49 fi;
50 _amx_x="${_amx_a[$((_amx_n - 1))]}";
51 [ "$_amx_x" = ok ] || return 1;
52 unset "_amx_a[$((_amx_n - 1))]";
53 set -- "${_amx_a[@]}";
54 _amx_a=();
55 fi;
56 _amx_t="$(agentmux-bashwrap github-token -- "$@")";
57 if [ "$_amx_c0" = pr ] && { [ "$_amx_c1" = create ] || [ "$_amx_c1" = new ] || [ "$_amx_c1" = edit ]; }; then
58 while IFS= read -r -d '' _amx_x; do _amx_a+=("$_amx_x"); done < <(agentmux-bashwrap github-owner-tag -- "$@" 2>/dev/null);
59 if [ "${#_amx_a[@]}" -gt 0 ]; then set -- "${_amx_a[@]}"; fi;
60 fi;
61 if [ -n "$_amx_t" ]; then
62 GH_TOKEN="$_amx_t" GITHUB_TOKEN="$_amx_t" AGENTMUX_GH_SHIM_DONE=1 command gh "$@";
63 else
64 GH_TOKEN= GITHUB_TOKEN= AGENTMUX_GH_SHIM_DONE=1 command gh "$@";
65 fi;
66 else
67 command gh "$@";
68 fi
69}"#;
70
71pub const GIT_FUNCTION_NAME: &str = "BASH_FUNC_git%%";
73
74pub const GIT_FUNCTION_BODY: &str = r#"() { if [ -n "${AGENTMUX_GITHUB_BROKER:-}" ]; then
78 case " $* " in
79 *" push "*|*" commit "*|*" merge "*|*" rebase "*|*" cherry-pick "*|*" am "*|*" revert "*|*" pull "*|*" stash "*)
80 local _amx_e _amx_v=();
81 _amx_e="$(agentmux-bashwrap git-env -- "$@")" || return $?;
82 if [ -n "$_amx_e" ]; then
83 IFS=$'\n' read -r -d '' -a _amx_v <<< "$_amx_e" || true;
84 ( export "${_amx_v[@]}"; command git "$@" );
85 return $?;
86 fi;;
87 esac;
88 fi;
89 command git "$@"
90}"#;