@@ -102,27 +102,76 @@ export const renderEntrypointMcpPlaywright = (config: TemplateConfig): string =>
102102 . replaceAll ( "__CODEX_HOME__" , config . codexHome )
103103 . replaceAll ( "__SERVICE_NAME__" , config . serviceName )
104104
105- export const renderEntrypointCodexResumeHint = ( ) : string =>
106- `# Ensure codex resume hint is shown for interactive shells
105+ const entrypointCodexResumeHintTemplate = `# Ensure codex resume hint is shown for interactive shells
107106CODEX_HINT_PATH="/etc/profile.d/zz-codex-resume.sh"
108107if [[ ! -s "$CODEX_HINT_PATH" ]]; then
109108 cat <<'EOF' > "$CODEX_HINT_PATH"
109+ docker_git_workspace_context_line() {
110+ REPO_REF_VALUE="\${REPO_REF:-__REPO_REF_DEFAULT__}"
111+ REPO_URL_VALUE="\${REPO_URL:-__REPO_URL_DEFAULT__}"
112+
113+ if [[ "$REPO_REF_VALUE" == issue-* ]]; then
114+ ISSUE_ID_VALUE="$(printf "%s" "$REPO_REF_VALUE" | sed -E 's#^issue-##')"
115+ ISSUE_URL_VALUE=""
116+ if [[ "$REPO_URL_VALUE" == https://github.com/* ]]; then
117+ ISSUE_REPO_VALUE="$(printf "%s" "$REPO_URL_VALUE" | sed -E 's#^https://github.com/##; s#[.]git$##; s#/*$##')"
118+ if [[ -n "$ISSUE_REPO_VALUE" ]]; then
119+ ISSUE_URL_VALUE="https://github.com/$ISSUE_REPO_VALUE/issues/$ISSUE_ID_VALUE"
120+ fi
121+ fi
122+ if [[ -n "$ISSUE_URL_VALUE" ]]; then
123+ printf "%s\n" "Контекст workspace: issue #$ISSUE_ID_VALUE ($ISSUE_URL_VALUE)"
124+ else
125+ printf "%s\n" "Контекст workspace: issue #$ISSUE_ID_VALUE"
126+ fi
127+ return
128+ fi
129+
130+ if [[ "$REPO_REF_VALUE" == refs/pull/*/head ]]; then
131+ PR_ID_VALUE="$(printf "%s" "$REPO_REF_VALUE" | sed -nE 's#^refs/pull/([0-9]+)/head$#\\1#p')"
132+ PR_URL_VALUE=""
133+ if [[ "$REPO_URL_VALUE" == https://github.com/* && -n "$PR_ID_VALUE" ]]; then
134+ PR_REPO_VALUE="$(printf "%s" "$REPO_URL_VALUE" | sed -E 's#^https://github.com/##; s#[.]git$##; s#/*$##')"
135+ if [[ -n "$PR_REPO_VALUE" ]]; then
136+ PR_URL_VALUE="https://github.com/$PR_REPO_VALUE/pull/$PR_ID_VALUE"
137+ fi
138+ fi
139+ if [[ -n "$PR_ID_VALUE" && -n "$PR_URL_VALUE" ]]; then
140+ printf "%s\n" "Контекст workspace: PR #$PR_ID_VALUE ($PR_URL_VALUE)"
141+ elif [[ -n "$PR_ID_VALUE" ]]; then
142+ printf "%s\n" "Контекст workspace: PR #$PR_ID_VALUE"
143+ elif [[ -n "$REPO_REF_VALUE" ]]; then
144+ printf "%s\n" "Контекст workspace: pull request ($REPO_REF_VALUE)"
145+ fi
146+ return
147+ fi
148+
149+ if [[ -n "$REPO_URL_VALUE" ]]; then
150+ printf "%s\n" "Контекст workspace: $REPO_URL_VALUE"
151+ fi
152+ }
153+
154+ docker_git_print_codex_resume_hint() {
155+ if [ -z "\${CODEX_RESUME_HINT_SHOWN-}" ]; then
156+ DOCKER_GIT_CONTEXT_LINE="$(docker_git_workspace_context_line)"
157+ if [[ -n "$DOCKER_GIT_CONTEXT_LINE" ]]; then
158+ echo "$DOCKER_GIT_CONTEXT_LINE"
159+ fi
160+ echo "Старые сессии можно запустить с помощью codex resume или codex resume <id>, если знаешь айди."
161+ export CODEX_RESUME_HINT_SHOWN=1
162+ fi
163+ }
164+
110165if [ -n "$BASH_VERSION" ]; then
111166 case "$-" in
112167 *i*)
113- if [ -z "\${CODEX_RESUME_HINT_SHOWN-}" ]; then
114- echo "Старые сессии можно запустить с помощью codex resume или codex resume <id>, если знаешь айди."
115- export CODEX_RESUME_HINT_SHOWN=1
116- fi
168+ docker_git_print_codex_resume_hint
117169 ;;
118170 esac
119171fi
120172if [ -n "$ZSH_VERSION" ]; then
121173 if [[ "$-" == *i* ]]; then
122- if [[ -z "\${CODEX_RESUME_HINT_SHOWN-}" ]]; then
123- echo "Старые сессии можно запустить с помощью codex resume или codex resume <id>, если знаешь айди."
124- export CODEX_RESUME_HINT_SHOWN=1
125- fi
174+ docker_git_print_codex_resume_hint
126175 fi
127176fi
128177EOF
@@ -135,6 +184,21 @@ if [[ -s /etc/zsh/zshrc ]] && ! grep -q "zz-codex-resume.sh" /etc/zsh/zshrc 2>/d
135184 printf "%s\\n" "if [ -f /etc/profile.d/zz-codex-resume.sh ]; then source /etc/profile.d/zz-codex-resume.sh; fi" >> /etc/zsh/zshrc
136185fi`
137186
187+ const escapeForDoubleQuotes = ( value : string ) : string => {
188+ const backslash = String . fromCodePoint ( 92 )
189+ const quote = String . fromCodePoint ( 34 )
190+ const escapedBackslash = `${ backslash } ${ backslash } `
191+ const escapedQuote = `${ backslash } ${ quote } `
192+ return value
193+ . replaceAll ( backslash , escapedBackslash )
194+ . replaceAll ( quote , escapedQuote )
195+ }
196+
197+ export const renderEntrypointCodexResumeHint = ( config : TemplateConfig ) : string =>
198+ entrypointCodexResumeHintTemplate
199+ . replaceAll ( "__REPO_REF_DEFAULT__" , escapeForDoubleQuotes ( config . repoRef ) )
200+ . replaceAll ( "__REPO_URL_DEFAULT__" , escapeForDoubleQuotes ( config . repoUrl ) )
201+
138202const entrypointAgentsNoticeTemplate = String . raw `# Ensure global AGENTS.md exists for container context
139203AGENTS_PATH="__CODEX_HOME__/AGENTS.md"
140204LEGACY_AGENTS_PATH="/home/__SSH_USER__/AGENTS.md"
@@ -160,8 +224,17 @@ if [[ "$REPO_REF" == issue-* ]]; then
160224 fi
161225 ISSUE_AGENTS_HINT_LINE="Issue AGENTS.md: __TARGET_DIR__/AGENTS.md"
162226elif [[ "$REPO_REF" == refs/pull/*/head ]]; then
163- PR_ID="$(printf "%s" "$REPO_REF" | sed -E 's#^refs/pull/([0-9]+)/head$#\1#')"
164- if [[ -n "$PR_ID" ]]; then
227+ PR_ID="$(printf "%s" "$REPO_REF" | sed -nE 's#^refs/pull/([0-9]+)/head$#\1#p')"
228+ PR_URL=""
229+ if [[ "$REPO_URL" == https://github.com/* && -n "$PR_ID" ]]; then
230+ PR_REPO="$(printf "%s" "$REPO_URL" | sed -E 's#^https://github.com/##; s#[.]git$##; s#/*$##')"
231+ if [[ -n "$PR_REPO" ]]; then
232+ PR_URL="https://github.com/$PR_REPO/pull/$PR_ID"
233+ fi
234+ fi
235+ if [[ -n "$PR_ID" && -n "$PR_URL" ]]; then
236+ WORKSPACE_INFO_LINE="Контекст workspace: PR #$PR_ID ($PR_URL)"
237+ elif [[ -n "$PR_ID" ]]; then
165238 WORKSPACE_INFO_LINE="Контекст workspace: PR #$PR_ID"
166239 else
167240 WORKSPACE_INFO_LINE="Контекст workspace: pull request ($REPO_REF)"
0 commit comments