Skip to content

Commit 52dbbd9

Browse files
committed
fix(shell): make login context hint independent from ssh env
1 parent 96ab7f4 commit 52dbbd9

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

packages/docker-git/tests/core/templates.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ describe("planFiles", () => {
140140
expect(entrypointSpec.contents).toContain("ISSUE_AGENTS_PATH=\"$TARGET_DIR/AGENTS.md\"")
141141
expect(entrypointSpec.contents).toContain("grep -qx \"AGENTS.md\" \"$EXCLUDE_PATH\"")
142142
expect(entrypointSpec.contents).toContain("docker_git_workspace_context_line()")
143+
expect(entrypointSpec.contents).toContain("REPO_REF_VALUE=\"${REPO_REF:-issue-5}\"")
144+
expect(entrypointSpec.contents).toContain("REPO_URL_VALUE=\"${REPO_URL:-https://github.com/org/repo.git}\"")
143145
expect(entrypointSpec.contents).toContain("Контекст workspace: issue #$ISSUE_ID_VALUE ($ISSUE_URL_VALUE)")
144146
}
145147
}))
@@ -171,6 +173,8 @@ describe("planFiles", () => {
171173
)
172174
expect(entrypointSpec !== undefined && entrypointSpec._tag === "File").toBe(true)
173175
if (entrypointSpec && entrypointSpec._tag === "File") {
176+
expect(entrypointSpec.contents).toContain("REPO_REF_VALUE=\"${REPO_REF:-refs/pull/42/head}\"")
177+
expect(entrypointSpec.contents).toContain("REPO_URL_VALUE=\"${REPO_URL:-https://github.com/org/repo.git}\"")
174178
expect(entrypointSpec.contents).toContain(
175179
"PR_ID=\"$(printf \"%s\" \"$REPO_REF\" | sed -nE 's#^refs/pull/([0-9]+)/head$#\\1#p')\""
176180
)

packages/lib/src/core/templates-entrypoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const renderEntrypoint = (config: TemplateConfig): string =>
4444
renderEntrypointBashHistory(),
4545
renderEntrypointInputRc(config),
4646
renderEntrypointZshConfig(),
47-
renderEntrypointCodexResumeHint(),
47+
renderEntrypointCodexResumeHint(config),
4848
renderEntrypointAgentsNotice(config),
4949
renderEntrypointDockerSocket(config),
5050
renderEntrypointGitConfig(config),

packages/lib/src/core/templates-entrypoint/codex.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ CODEX_HINT_PATH="/etc/profile.d/zz-codex-resume.sh"
107107
if [[ ! -s "$CODEX_HINT_PATH" ]]; then
108108
cat <<'EOF' > "$CODEX_HINT_PATH"
109109
docker_git_workspace_context_line() {
110-
REPO_REF_VALUE="\${REPO_REF:-}"
111-
REPO_URL_VALUE="\${REPO_URL:-}"
110+
REPO_REF_VALUE="\${REPO_REF:-__REPO_REF_DEFAULT__}"
111+
REPO_URL_VALUE="\${REPO_URL:-__REPO_URL_DEFAULT__}"
112112
113113
if [[ "$REPO_REF_VALUE" == issue-* ]]; then
114114
ISSUE_ID_VALUE="$(printf "%s" "$REPO_REF_VALUE" | sed -E 's#^issue-##')"
@@ -184,7 +184,20 @@ if [[ -s /etc/zsh/zshrc ]] && ! grep -q "zz-codex-resume.sh" /etc/zsh/zshrc 2>/d
184184
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
185185
fi`
186186

187-
export const renderEntrypointCodexResumeHint = (): string => entrypointCodexResumeHintTemplate
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))
188201

189202
const entrypointAgentsNoticeTemplate = String.raw`# Ensure global AGENTS.md exists for container context
190203
AGENTS_PATH="__CODEX_HOME__/AGENTS.md"

0 commit comments

Comments
 (0)