|
1 | 1 | import type { TemplateConfig } from "../domain.js" |
| 2 | +export { renderEntrypointCodexResumeHint } from "./codex-resume-hint.js" |
2 | 3 |
|
3 | 4 | export const renderEntrypointCodexHome = (config: TemplateConfig): string => |
4 | 5 | `# Ensure Codex home exists if mounted |
@@ -119,100 +120,6 @@ export const renderEntrypointMcpPlaywright = (config: TemplateConfig): string => |
119 | 120 | .replaceAll("__CODEX_HOME__", config.codexHome) |
120 | 121 | .replaceAll("__SERVICE_NAME__", config.serviceName) |
121 | 122 |
|
122 | | -const entrypointCodexResumeHintTemplate = `# Ensure codex resume hint is shown for interactive shells |
123 | | -CODEX_HINT_PATH="/etc/profile.d/zz-codex-resume.sh" |
124 | | -if [[ ! -s "$CODEX_HINT_PATH" ]]; then |
125 | | - cat <<'EOF' > "$CODEX_HINT_PATH" |
126 | | -docker_git_workspace_context_line() { |
127 | | - REPO_REF_VALUE="\${REPO_REF:-__REPO_REF_DEFAULT__}" |
128 | | - REPO_URL_VALUE="\${REPO_URL:-__REPO_URL_DEFAULT__}" |
129 | | -
|
130 | | - if [[ "$REPO_REF_VALUE" == issue-* ]]; then |
131 | | - ISSUE_ID_VALUE="$(printf "%s" "$REPO_REF_VALUE" | sed -E 's#^issue-##')" |
132 | | - ISSUE_URL_VALUE="" |
133 | | - if [[ "$REPO_URL_VALUE" == https://github.com/* ]]; then |
134 | | - ISSUE_REPO_VALUE="$(printf "%s" "$REPO_URL_VALUE" | sed -E 's#^https://github.com/##; s#[.]git$##; s#/*$##')" |
135 | | - if [[ -n "$ISSUE_REPO_VALUE" ]]; then |
136 | | - ISSUE_URL_VALUE="https://github.com/$ISSUE_REPO_VALUE/issues/$ISSUE_ID_VALUE" |
137 | | - fi |
138 | | - fi |
139 | | - if [[ -n "$ISSUE_URL_VALUE" ]]; then |
140 | | - printf "%s\n" "Контекст workspace: issue #$ISSUE_ID_VALUE ($ISSUE_URL_VALUE)" |
141 | | - else |
142 | | - printf "%s\n" "Контекст workspace: issue #$ISSUE_ID_VALUE" |
143 | | - fi |
144 | | - return |
145 | | - fi |
146 | | -
|
147 | | - if [[ "$REPO_REF_VALUE" == refs/pull/*/head ]]; then |
148 | | - PR_ID_VALUE="$(printf "%s" "$REPO_REF_VALUE" | sed -nE 's#^refs/pull/([0-9]+)/head$#\\1#p')" |
149 | | - PR_URL_VALUE="" |
150 | | - if [[ "$REPO_URL_VALUE" == https://github.com/* && -n "$PR_ID_VALUE" ]]; then |
151 | | - PR_REPO_VALUE="$(printf "%s" "$REPO_URL_VALUE" | sed -E 's#^https://github.com/##; s#[.]git$##; s#/*$##')" |
152 | | - if [[ -n "$PR_REPO_VALUE" ]]; then |
153 | | - PR_URL_VALUE="https://github.com/$PR_REPO_VALUE/pull/$PR_ID_VALUE" |
154 | | - fi |
155 | | - fi |
156 | | - if [[ -n "$PR_ID_VALUE" && -n "$PR_URL_VALUE" ]]; then |
157 | | - printf "%s\n" "Контекст workspace: PR #$PR_ID_VALUE ($PR_URL_VALUE)" |
158 | | - elif [[ -n "$PR_ID_VALUE" ]]; then |
159 | | - printf "%s\n" "Контекст workspace: PR #$PR_ID_VALUE" |
160 | | - elif [[ -n "$REPO_REF_VALUE" ]]; then |
161 | | - printf "%s\n" "Контекст workspace: pull request ($REPO_REF_VALUE)" |
162 | | - fi |
163 | | - return |
164 | | - fi |
165 | | -
|
166 | | - if [[ -n "$REPO_URL_VALUE" ]]; then |
167 | | - printf "%s\n" "Контекст workspace: $REPO_URL_VALUE" |
168 | | - fi |
169 | | -} |
170 | | -
|
171 | | -docker_git_print_codex_resume_hint() { |
172 | | - if [ -z "\${CODEX_RESUME_HINT_SHOWN-}" ]; then |
173 | | - DOCKER_GIT_CONTEXT_LINE="$(docker_git_workspace_context_line)" |
174 | | - if [[ -n "$DOCKER_GIT_CONTEXT_LINE" ]]; then |
175 | | - echo "$DOCKER_GIT_CONTEXT_LINE" |
176 | | - fi |
177 | | - echo "Старые сессии можно запустить с помощью codex resume или codex resume <id>, если знаешь айди." |
178 | | - export CODEX_RESUME_HINT_SHOWN=1 |
179 | | - fi |
180 | | -} |
181 | | -
|
182 | | -if [ -n "$BASH_VERSION" ]; then |
183 | | - case "$-" in |
184 | | - *i*) |
185 | | - docker_git_print_codex_resume_hint |
186 | | - ;; |
187 | | - esac |
188 | | -fi |
189 | | -if [ -n "$ZSH_VERSION" ]; then |
190 | | - if [[ "$-" == *i* ]]; then |
191 | | - docker_git_print_codex_resume_hint |
192 | | - fi |
193 | | -fi |
194 | | -EOF |
195 | | - chmod 0644 "$CODEX_HINT_PATH" |
196 | | -fi |
197 | | -if ! grep -q "zz-codex-resume.sh" /etc/bash.bashrc 2>/dev/null; then |
198 | | - printf "%s\\n" "if [ -f /etc/profile.d/zz-codex-resume.sh ]; then . /etc/profile.d/zz-codex-resume.sh; fi" >> /etc/bash.bashrc |
199 | | -fi |
200 | | -if [[ -s /etc/zsh/zshrc ]] && ! grep -q "zz-codex-resume.sh" /etc/zsh/zshrc 2>/dev/null; then |
201 | | - 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 |
202 | | -fi` |
203 | | - |
204 | | -const escapeForDoubleQuotes = (value: string): string => { |
205 | | - const backslash = String.fromCodePoint(92) |
206 | | - return value |
207 | | - .replaceAll(backslash, `${backslash}${backslash}`) |
208 | | - .replaceAll(String.fromCodePoint(34), `${backslash}${String.fromCodePoint(34)}`) |
209 | | -} |
210 | | - |
211 | | -export const renderEntrypointCodexResumeHint = (config: TemplateConfig): string => |
212 | | - entrypointCodexResumeHintTemplate |
213 | | - .replaceAll("__REPO_REF_DEFAULT__", escapeForDoubleQuotes(config.repoRef)) |
214 | | - .replaceAll("__REPO_URL_DEFAULT__", escapeForDoubleQuotes(config.repoUrl)) |
215 | | - |
216 | 123 | const entrypointAgentsNoticeTemplate = String.raw`# Ensure global AGENTS.md exists for container context |
217 | 124 | AGENTS_PATH="__CODEX_HOME__/AGENTS.md" |
218 | 125 | LEGACY_AGENTS_PATH="/home/__SSH_USER__/AGENTS.md" |
|
0 commit comments