Skip to content

Commit 7f3604b

Browse files
authored
Merge pull request #184 from konard/issue-183-72f0b1a052f2
feat(config): add longcontx profile to codex config.toml
2 parents 1ceedd2 + 4f69fcd commit 7f3604b

File tree

3 files changed

+120
-105
lines changed

3 files changed

+120
-105
lines changed
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: 8 additions & 96 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
@@ -65,8 +66,6 @@ else
6566
cat <<'EOF' > "$CODEX_CONFIG_FILE"
6667
# docker-git codex config
6768
model = "gpt-5.4"
68-
model_context_window = 1050000
69-
model_auto_compact_token_limit = 945000
7069
model_reasoning_effort = "xhigh"
7170
plan_mode_reasoning_effort = "xhigh"
7271
personality = "pragmatic"
@@ -80,6 +79,13 @@ shell_snapshot = true
8079
multi_agent = true
8180
apps = true
8281
shell_tool = true
82+
83+
[profiles.longcontx]
84+
model = "gpt-5.4"
85+
model_context_window = 1050000
86+
model_auto_compact_token_limit = 945000
87+
model_reasoning_effort = "xhigh"
88+
plan_mode_reasoning_effort = "xhigh"
8389
EOF
8490
chown 1000:1000 "$CODEX_CONFIG_FILE" || true
8591
fi
@@ -114,100 +120,6 @@ export const renderEntrypointMcpPlaywright = (config: TemplateConfig): string =>
114120
.replaceAll("__CODEX_HOME__", config.codexHome)
115121
.replaceAll("__SERVICE_NAME__", config.serviceName)
116122

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

packages/lib/src/usecases/auth-sync-helpers.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,19 @@ const JsonRecordFromStringSchema = Schema.parseJson(JsonRecordSchema)
2929
const defaultEnvContents = "# docker-git env\n# KEY=value\n"
3030
const codexConfigMarker = "# docker-git codex config"
3131

32-
// CHANGE: switch default model to gpt-5.4 and pin xhigh reasoning for default + plan mode
33-
// WHY: keep plan mode aligned with development mode while preserving long-context defaults
34-
// QUOTE(ТЗ): "Сделать plan mode тоже с xhigh режимом как и разработка по дефолту. Так же заменить модель на gpt-5.4"
35-
// REF: github-issue-109
32+
// CHANGE: move model_context_window and model_auto_compact_token_limit to [profiles.longcontx]
33+
// WHY: global context window settings apply to all models; profile-scoped settings allow opt-in
34+
// QUOTE(ТЗ): "добавь longcontx"
35+
// REF: github-issue-183
3636
// SOURCE: n/a
37-
// FORMAT THEOREM: ∀c: config(c) -> model(c)="gpt-5.4" ∧ reasoning(c)=xhigh ∧ plan_reasoning(c)=xhigh
37+
// FORMAT THEOREM: ∀c: config(c) -> model(c)="gpt-5.4" ∧ reasoning(c)=xhigh ∧ longcontx_profile(c)=defined
3838
// PURITY: CORE
3939
// EFFECT: n/a
40-
// INVARIANT: default config stays deterministic
40+
// INVARIANT: default config stays deterministic; longcontx profile always present
4141
// COMPLEXITY: O(1)
4242
export const defaultCodexConfig = [
4343
"# docker-git codex config",
4444
"model = \"gpt-5.4\"",
45-
"model_context_window = 1050000",
46-
"model_auto_compact_token_limit = 945000",
4745
"model_reasoning_effort = \"xhigh\"",
4846
"plan_mode_reasoning_effort = \"xhigh\"",
4947
"personality = \"pragmatic\"",
@@ -56,7 +54,14 @@ export const defaultCodexConfig = [
5654
"shell_snapshot = true",
5755
"multi_agent = true",
5856
"apps = true",
59-
"shell_tool = true"
57+
"shell_tool = true",
58+
"",
59+
"[profiles.longcontx]",
60+
"model = \"gpt-5.4\"",
61+
"model_context_window = 1050000",
62+
"model_auto_compact_token_limit = 945000",
63+
"model_reasoning_effort = \"xhigh\"",
64+
"plan_mode_reasoning_effort = \"xhigh\""
6065
].join("\n")
6166

6267
export const resolvePathFromBase = (

0 commit comments

Comments
 (0)