Skip to content

Commit 4f69fcd

Browse files
konardclaude
andcommitted
fix(lint): extract codex-resume-hint to separate file to fix max-lines violation
- Extracted `renderEntrypointCodexResumeHint` and `escapeForDoubleQuotes` from `codex.ts` into `codex-resume-hint.ts` to bring `codex.ts` under 300-line limit - `codex.ts` re-exports `renderEntrypointCodexResumeHint` to preserve public API - WHY: ESLint max-lines rule requires files <= 300 lines; codex.ts exceeded limit after adding longcontx profile config in feat(config) commit Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent acd3a0e commit 4f69fcd

2 files changed

Lines changed: 99 additions & 94 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import type { TemplateConfig } from "../domain.js"
2+
3+
const escapeForDoubleQuotes = (value: string): string => {
4+
const backslash = String.fromCodePoint(92)
5+
return value
6+
.replaceAll(backslash, `${backslash}${backslash}`)
7+
.replaceAll(String.fromCodePoint(34), `${backslash}${String.fromCodePoint(34)}`)
8+
}
9+
10+
const entrypointCodexResumeHintTemplate = `# Ensure codex resume hint is shown for interactive shells
11+
CODEX_HINT_PATH="/etc/profile.d/zz-codex-resume.sh"
12+
if [[ ! -s "$CODEX_HINT_PATH" ]]; then
13+
cat <<'EOF' > "$CODEX_HINT_PATH"
14+
docker_git_workspace_context_line() {
15+
REPO_REF_VALUE="\${REPO_REF:-__REPO_REF_DEFAULT__}"
16+
REPO_URL_VALUE="\${REPO_URL:-__REPO_URL_DEFAULT__}"
17+
18+
if [[ "$REPO_REF_VALUE" == issue-* ]]; then
19+
ISSUE_ID_VALUE="$(printf "%s" "$REPO_REF_VALUE" | sed -E 's#^issue-##')"
20+
ISSUE_URL_VALUE=""
21+
if [[ "$REPO_URL_VALUE" == https://github.com/* ]]; then
22+
ISSUE_REPO_VALUE="$(printf "%s" "$REPO_URL_VALUE" | sed -E 's#^https://github.com/##; s#[.]git$##; s#/*$##')"
23+
if [[ -n "$ISSUE_REPO_VALUE" ]]; then
24+
ISSUE_URL_VALUE="https://github.com/$ISSUE_REPO_VALUE/issues/$ISSUE_ID_VALUE"
25+
fi
26+
fi
27+
if [[ -n "$ISSUE_URL_VALUE" ]]; then
28+
printf "%s\n" "Контекст workspace: issue #$ISSUE_ID_VALUE ($ISSUE_URL_VALUE)"
29+
else
30+
printf "%s\n" "Контекст workspace: issue #$ISSUE_ID_VALUE"
31+
fi
32+
return
33+
fi
34+
35+
if [[ "$REPO_REF_VALUE" == refs/pull/*/head ]]; then
36+
PR_ID_VALUE="$(printf "%s" "$REPO_REF_VALUE" | sed -nE 's#^refs/pull/([0-9]+)/head$#\\1#p')"
37+
PR_URL_VALUE=""
38+
if [[ "$REPO_URL_VALUE" == https://github.com/* && -n "$PR_ID_VALUE" ]]; then
39+
PR_REPO_VALUE="$(printf "%s" "$REPO_URL_VALUE" | sed -E 's#^https://github.com/##; s#[.]git$##; s#/*$##')"
40+
if [[ -n "$PR_REPO_VALUE" ]]; then
41+
PR_URL_VALUE="https://github.com/$PR_REPO_VALUE/pull/$PR_ID_VALUE"
42+
fi
43+
fi
44+
if [[ -n "$PR_ID_VALUE" && -n "$PR_URL_VALUE" ]]; then
45+
printf "%s\n" "Контекст workspace: PR #$PR_ID_VALUE ($PR_URL_VALUE)"
46+
elif [[ -n "$PR_ID_VALUE" ]]; then
47+
printf "%s\n" "Контекст workspace: PR #$PR_ID_VALUE"
48+
elif [[ -n "$REPO_REF_VALUE" ]]; then
49+
printf "%s\n" "Контекст workspace: pull request ($REPO_REF_VALUE)"
50+
fi
51+
return
52+
fi
53+
54+
if [[ -n "$REPO_URL_VALUE" ]]; then
55+
printf "%s\n" "Контекст workspace: $REPO_URL_VALUE"
56+
fi
57+
}
58+
59+
docker_git_print_codex_resume_hint() {
60+
if [ -z "\${CODEX_RESUME_HINT_SHOWN-}" ]; then
61+
DOCKER_GIT_CONTEXT_LINE="$(docker_git_workspace_context_line)"
62+
if [[ -n "$DOCKER_GIT_CONTEXT_LINE" ]]; then
63+
echo "$DOCKER_GIT_CONTEXT_LINE"
64+
fi
65+
echo "Старые сессии можно запустить с помощью codex resume или codex resume <id>, если знаешь айди."
66+
export CODEX_RESUME_HINT_SHOWN=1
67+
fi
68+
}
69+
70+
if [ -n "$BASH_VERSION" ]; then
71+
case "$-" in
72+
*i*)
73+
docker_git_print_codex_resume_hint
74+
;;
75+
esac
76+
fi
77+
if [ -n "$ZSH_VERSION" ]; then
78+
if [[ "$-" == *i* ]]; then
79+
docker_git_print_codex_resume_hint
80+
fi
81+
fi
82+
EOF
83+
chmod 0644 "$CODEX_HINT_PATH"
84+
fi
85+
if ! grep -q "zz-codex-resume.sh" /etc/bash.bashrc 2>/dev/null; then
86+
printf "%s\\n" "if [ -f /etc/profile.d/zz-codex-resume.sh ]; then . /etc/profile.d/zz-codex-resume.sh; fi" >> /etc/bash.bashrc
87+
fi
88+
if [[ -s /etc/zsh/zshrc ]] && ! grep -q "zz-codex-resume.sh" /etc/zsh/zshrc 2>/dev/null; then
89+
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
90+
fi`
91+
92+
// PURITY: CORE
93+
// INVARIANT: rendered output contains shell-escaped repo ref and url placeholders
94+
// COMPLEXITY: O(1)
95+
export const renderEntrypointCodexResumeHint = (config: TemplateConfig): string =>
96+
entrypointCodexResumeHintTemplate
97+
.replaceAll("__REPO_REF_DEFAULT__", escapeForDoubleQuotes(config.repoRef))
98+
.replaceAll("__REPO_URL_DEFAULT__", escapeForDoubleQuotes(config.repoUrl))

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

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { TemplateConfig } from "../domain.js"
2+
export { renderEntrypointCodexResumeHint } from "./codex-resume-hint.js"
23

34
export const renderEntrypointCodexHome = (config: TemplateConfig): string =>
45
`# Ensure Codex home exists if mounted
@@ -119,100 +120,6 @@ export const renderEntrypointMcpPlaywright = (config: TemplateConfig): string =>
119120
.replaceAll("__CODEX_HOME__", config.codexHome)
120121
.replaceAll("__SERVICE_NAME__", config.serviceName)
121122

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-
216123
const entrypointAgentsNoticeTemplate = String.raw`# Ensure global AGENTS.md exists for container context
217124
AGENTS_PATH="__CODEX_HOME__/AGENTS.md"
218125
LEGACY_AGENTS_PATH="/home/__SSH_USER__/AGENTS.md"

0 commit comments

Comments
 (0)